vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- Thanks to #wowace for help, Arantxa for ideas and support, the PocketHelper/Squeenix/FruityLoots/oSkin addons for various code snippets and trial and error. |
2 | -- May your brain not spontaneously explode from the reading of this disorganized mod. |
||
3 | -- Positioning code re-write first implimented and then inspired by Dead_LAN! Thanks |
||
4 | -- localization (and koKR locals) by fenlis. Thanks =) |
||
5 | -- Dreaded Esc bug (hopefully) fixed by ckknight! Thanks so much ^_~ |
||
6 | -- Todo: Add "Link all to party/raid" button. Split loot frame display into modules, add Slim layout, add Block layout. Add indicator icons to the items. Dice for items that will be rolled on. Lock or something else for BoP items. |
||
7 | local L = AceLibrary("AceLocale-2.0"):new("XLoot") |
||
8 | |||
9 | XLoot = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceDB-2.0", "AceConsole-2.0", "AceHook-2.0");--, "AceModuleCore-2.0" Shhhhh |
||
10 | --libs\AceModuleCore\AceModuleCore-2.0.lua |
||
11 | --XLoot:SetModuleMixins("AceEvent-2.0", "AceHook-2.0") |
||
12 | XLoot.dewdrop = AceLibrary("Dewdrop-2.0") |
||
13 | |||
14 | local _G = getfenv(0) -- Lovely shortcut, if it works. |
||
15 | |||
16 | XLoot.compat = string.find(GetBuildInfo(), "^2%.") |
||
17 | |||
18 | function XLoot:OnInitialize() |
||
19 | self:RegisterDB("XLootDB") |
||
20 | self.dbDefaults = { |
||
21 | scale = 1.0, |
||
22 | cursor = true, |
||
23 | debug = false, |
||
24 | smartsnap = true, |
||
25 | snapoffset = 0, |
||
26 | altoptions = true, |
||
27 | collapse = true, |
||
28 | dragborder = true, |
||
29 | lootexpand = true, |
||
30 | swiftloot = false, |
||
31 | qualityborder = false, |
||
32 | qualityframe = false, |
||
33 | lootqualityborder = true, |
||
34 | qualitytext = false, |
||
35 | infotext = true, |
||
36 | oskin = true, |
||
37 | lock = false, |
||
38 | pos = { x = (UIParent:GetWidth()/2), y = (UIParent:GetHeight()/2) }, |
||
39 | bgcolor = { 0, 0, 0, .7 }, |
||
40 | bordercolor = { .7, .7, .7, 1 }, |
||
41 | lootbgcolor = { 0, 0, 0, .9 }, |
||
42 | lootbordercolor = { .5, .5, .5, 1 } |
||
43 | }; |
||
44 | self:RegisterDefaults("profile", self.dbDefaults) |
||
45 | self:DoOptions() |
||
46 | --Initial session variables |
||
47 | self.numButtons = 0 -- Buttons currently created |
||
48 | self.buttons = {} -- Easy reference array by ID |
||
49 | self.frames = {} |
||
50 | self.visible = false |
||
51 | self.closing = false |
||
52 | self.setexpandedtext = false |
||
53 | self.loothasbeenexpanded = false |
||
54 | self.swiftlooting = false |
||
55 | self.swifthooked = false |
||
56 | self:SetupFrames() |
||
57 | |||
58 | --Setup menu |
||
59 | self.dewdrop:Register(XLootFrame, |
||
60 | 'children', function() |
||
61 | self:DewdropFunc(level, value) |
||
62 | end, |
||
63 | 'cursorX', true, |
||
64 | 'cursorY', true |
||
65 | ) |
||
66 | self.dewdrop:Register(UIParent, |
||
67 | 'children', function(level, value) |
||
68 | self:DewdropFunc(level, value) |
||
69 | end, |
||
70 | 'cursorX', true, |
||
71 | 'cursorY', true, |
||
72 | 'dontHook', true |
||
73 | ) |
||
74 | end |
||
75 | |||
76 | function XLoot:DewdropFunc(level, value) |
||
77 | if level == 1 then |
||
78 | self.dewdrop:AddLine('text', L["guiTitle"], 'isTitle', true, 'textR', 0.5, 'textG', 0.7, 'textB', 1) |
||
79 | end |
||
80 | self.dewdrop:FeedAceOptionsTable(self.opts) |
||
81 | end |
||
82 | |||
83 | --Hook builtin functions |
||
84 | function XLoot:OnEnable() |
||
85 | self:Hook("CloseWindows") |
||
86 | self:Hook("LootFrame_OnEvent") |
||
87 | self:Hook("LootFrame_OnShow") |
||
88 | self:Hook("LootFrame_OnHide") |
||
89 | self:Hook("LootFrame_Update") |
||
90 | if self.compat then |
||
91 | self:Hook("LootButton_OnClick", "OnButtonClick") |
||
92 | self:Hook("LootButton_OnModifiedClick", "OnModifiedButtonClick") |
||
93 | else |
||
94 | self:Hook("LootFrameItem_OnClick", "OnClick") |
||
95 | end |
||
96 | if self.db.profile.swiftloot then |
||
97 | self:SwiftMouseEvents(true) |
||
98 | end |
||
99 | self:RegisterEvent("LOOT_OPENED", "OnOpen") |
||
100 | self:RegisterEvent("LOOT_SLOT_CLEARED", "OnClear") |
||
101 | self:RegisterEvent("LOOT_CLOSED", "OnClose") |
||
102 | end |
||
103 | |||
104 | function XLoot:OnDisable() |
||
105 | self:UnregisterAllEvents() |
||
106 | end |
||
107 | |||
108 | function XLoot:Defaults() |
||
109 | self:Print("Default values restored.") |
||
110 | for k, v in pairs(self.dbDefaults) do |
||
111 | self.db.profile[k] = v |
||
112 | end |
||
113 | end |
||
114 | |||
115 | local ItemInfo -- Is this code familiar? Hmm.... shhh |
||
116 | do |
||
117 | if XLoot.compat then |
||
118 | -- 2.0.0 |
||
119 | function ItemInfo(num) -- itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, invTexture |
||
120 | local itemName, itemLink, itemRarity, _, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc = GetItemInfo(num) |
||
121 | return itemName, itemLink, itemRarity, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc |
||
122 | end |
||
123 | else |
||
124 | function ItemInfo(num) -- itemName, itemString, itemQuality, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture |
||
125 | return GetItemInfo(num) |
||
126 | end |
||
127 | end |
||
128 | end |
||
129 | |||
130 | ---------- Shift-Looting detection. Fear the monster 'if' hives ----------- |
||
131 | |||
132 | function XLoot:SwiftMouseEvents(state) |
||
133 | if state and not self:IsEventRegistered("UPDATE_MOUSEOVER_UNIT") then |
||
134 | self:RegisterEvent("PLAYER_TARGET_CHANGED", "SwiftTargetChange") |
||
135 | self:RegisterEvent("UPDATE_MOUSEOVER_UNIT", "SwiftMouseover") |
||
136 | elseif not state and self:IsEventRegistered("UPDATE_MOUSEOVER_UNIT") then |
||
137 | self:UnregisterEvent("PLAYER_TARGET_CHANGED") |
||
138 | self:UnregisterEvent("UPDATE_MOUSEOVER_UNIT") |
||
139 | end |
||
140 | end |
||
141 | |||
142 | function XLoot:SwiftErrmsg(message) |
||
143 | if message == ERR_INV_FULL then |
||
144 | self:SwiftHooks(false) |
||
145 | self.swiftlooting = false |
||
146 | self:Update() |
||
147 | end |
||
148 | end |
||
149 | |||
150 | function XLoot:SwiftMouseover() |
||
151 | if not self.swiftlooting then |
||
152 | if UnitIsDead("target") then |
||
153 | if UnitIsUnit("mouseover", "target") then |
||
154 | if not UnitIsPlayer("target") then |
||
155 | if CheckInteractDistance("target", 1) then |
||
156 | if not self.swifthooked then |
||
157 | self:SwiftHooks(true) |
||
158 | end |
||
159 | end |
||
160 | end |
||
161 | end |
||
162 | end |
||
163 | end |
||
164 | end |
||
165 | |||
166 | function XLoot:SwiftHooks(state) |
||
167 | if state then |
||
168 | --self:Print("Hooking for swiftloot...") |
||
169 | self:RegisterEvent("UI_ERROR_MESSAGE", "SwiftErrmsg") |
||
170 | self:HookScript(WorldFrame, "OnMouseUp", "SwiftMouseUp") |
||
171 | self.swifthooked = true |
||
172 | else |
||
173 | --self:Print("Releasing swiftloot hooks...") |
||
174 | self:UnregisterEvent("UI_ERROR_MESSAGE") |
||
175 | if self:IsHooked(WorldFrame, "OnMouseUp") then |
||
176 | self:Unhook(WorldFrame, "OnMouseUp") |
||
177 | end |
||
178 | self.swifthooked = false |
||
179 | end |
||
180 | end |
||
181 | |||
182 | function XLoot:SwiftTargetChange(lastevent) |
||
183 | if self.swifthooked then |
||
184 | if not UnitIsUnit("mouseover", "target") then |
||
185 | self:SwiftHooks(false) |
||
186 | self.swiftlooting = false |
||
187 | end |
||
188 | end |
||
189 | if not lastevent then |
||
190 | if UnitIsDead("target") then |
||
191 | if not UnitIsPlayer("target") then |
||
192 | if CheckInteractDistance("target", 1) then |
||
193 | self:SwiftMouseUp() |
||
194 | end |
||
195 | end |
||
196 | end |
||
197 | end |
||
198 | end |
||
199 | |||
200 | function XLoot:SwiftMouseUp() |
||
201 | if IsShiftKeyDown() then |
||
202 | --self:Print("Swiftlooting...") |
||
203 | if not self.swifthooked then |
||
204 | self:RegisterEvent("UI_ERROR_MESSAGE", "SwiftErrmsg") |
||
205 | self.swifthooked = true |
||
206 | end |
||
207 | self.swiftlooting = true |
||
208 | else |
||
209 | self.swiftlooting = false |
||
210 | end |
||
211 | end |
||
212 | |||
213 | |||
214 | function XLoot:CloseWindows(ignoreCenter) |
||
215 | local hookedresult = self.hooks["CloseWindows"].orig(ignoreCenter) |
||
216 | if self.frame:IsShown() then |
||
217 | self:AutoClose(true) |
||
218 | return true |
||
219 | end |
||
220 | return hookedresult |
||
221 | end |
||
222 | |||
223 | function XLoot:OnOpen() |
||
224 | -- if not self:AutoClose() then |
||
225 | -- self:OnClear() |
||
226 | -- end |
||
227 | end |
||
228 | |||
229 | function XLoot:OnClear() |
||
230 | self.refreshing = true |
||
231 | self:Clear(); |
||
232 | self:Update(); |
||
233 | end |
||
234 | |||
235 | function XLoot:OnClose() |
||
236 | self:Clear(); |
||
237 | end |
||
238 | |||
239 | function XLoot:OnHide() |
||
240 | if not self.refreshing then |
||
241 | self:AutoClose(true) |
||
242 | else |
||
243 | self.refreshing = false |
||
244 | end |
||
245 | end |
||
246 | |||
247 | function XLoot:ClickCheck(button) |
||
248 | if IsAltKeyDown() and button == "RightButton" and self.db.profile.altoptions and not IsShiftKeyDown() and not IsControlKeyDown() then |
||
249 | self.dewdrop:Open(XLootFrame) |
||
250 | return 1 |
||
251 | end |
||
252 | end |
||
253 | |||
254 | function XLoot:OnClick(button) |
||
255 | if not self:ClickCheck(button) then |
||
256 | self.hooks["LootFrameItem_OnClick"].orig(button) |
||
257 | end |
||
258 | end |
||
259 | |||
260 | function XLoot:OnButtonClick(button) |
||
261 | if not self:ClickCheck(button) then |
||
262 | self.hooks["LootButton_OnClick"].orig(button) |
||
263 | end |
||
264 | end |
||
265 | |||
266 | function XLoot:OnModifiedButtonClick(button) |
||
267 | if not self:ClickCheck(button) then |
||
268 | self.hooks["LootButton_OnModifiedClick"].orig(button) |
||
269 | end |
||
270 | end |
||
271 | |||
272 | function XLoot:LootFrame_OnEvent(event) |
||
273 | if event ~= "LOOT_SLOT_CLEARED" then |
||
274 | self.hooks["LootFrame_OnEvent"].orig(event) |
||
275 | end |
||
276 | if event == "LOOT_OPENED" then |
||
277 | HideUIPanel(LootFrame); |
||
278 | end |
||
279 | end |
||
280 | |||
281 | -- Show our frame and hide the old one |
||
282 | function XLoot:LootFrame_OnShow() |
||
283 | --self.hooks["LootFrame_OnShow"].orig() |
||
284 | if self:AutoClose() == nil then |
||
285 | if not self.visible and IsFishingLoot() then |
||
286 | PlaySound("FISHING REEL IN") |
||
287 | end |
||
288 | self:Clear() |
||
289 | self:Update() |
||
290 | end |
||
291 | end |
||
292 | |||
293 | -- Block closing loot |
||
294 | function XLoot:LootFrame_OnHide() |
||
295 | end |
||
296 | |||
297 | -- Update our lootframe |
||
298 | function XLoot:LootFrame_Update() |
||
299 | --XLoot.hooks["LootFrame_Update"].orig() |
||
300 | if self:AutoClose() then |
||
301 | self:Update() |
||
302 | end |
||
303 | end |
||
304 | |||
305 | function XLoot:AutoClose(force) -- Thanks, FruityLoots. |
||
306 | if (GetNumLootItems() == 0) or force then |
||
307 | self:Clear() |
||
308 | HideUIPanel(LootFrame) |
||
309 | CloseLoot() |
||
310 | self:msg("AutoClosing ("..GetNumLootItems() ..")"..(force and " Forced!" or "")) |
||
311 | return 1 |
||
312 | end |
||
313 | self:msg("AutoClose check passed") |
||
314 | return nil |
||
315 | end |
||
316 | |||
317 | function XLoot:SetSlotInfo(slot, button) -- Yay wowwiki demo |
||
318 | local link = GetLootSlotLink(slot) |
||
319 | --local justName = string.gsub(link,"^.-%[(.*)%].*", "%1") |
||
320 | local justItemId = string.gsub(link,".-\124H([^\124]*)\124h.*", "%1") |
||
321 | local itemName, itemLink, itemRarity, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc = ItemInfo(justItemId) |
||
322 | if itemType == "Weapon" then |
||
323 | itemEquipLoc = "Weapon" |
||
324 | else |
||
325 | --local ielfunc = assert(loadstring("return "..itemEquipLoc)); |
||
326 | itemEquipLoc = _G[itemEquipLoc]--ielfunc(); |
||
327 | end |
||
328 | if itemSubType == "Junk" then |
||
329 | itemSubType = (itemRarity > 0) and "Quest Item" or itemSubType |
||
330 | end |
||
331 | _G[button:GetName().."Description"]:SetText((itemEquipLoc and itemEquipLoc..", " or "") .. ((itemSubType == itemSubType) and itemSubType or itemSubType.." "..itemType)) |
||
332 | --((itemMinLevel > 0) and "Lv"..itemMinLevel.." " or "") .. |
||
333 | end |
||
334 | |||
335 | -- Core |
||
336 | function XLoot:Update() |
||
337 | if self.swiftlooting then |
||
338 | self:msg("Overrode update, swiftlooting") |
||
339 | return |
||
340 | end |
||
341 | local db = self.db.profile |
||
342 | local numLoot = GetNumLootItems() |
||
343 | --Build frames if we need more |
||
344 | if (numLoot > self.numButtons) then |
||
345 | for i = (self.numButtons + 1), numLoot do |
||
346 | self:msg("Adding needed frame["..(i).."], numButtons = "..XLoot.numButtons.." & numLoot = "..numLoot) |
||
347 | self:AddLootFrame(i) |
||
348 | end |
||
349 | end |
||
350 | -- LootLoop |
||
351 | local curslot, button, frame, texture, item, quantity, quality, color, qualitytext, textobj, infoobj, qualityobj |
||
352 | local curshift, qualityTower, framewidth = 0, 0, 0 |
||
353 | for slot = 1, numLoot do |
||
354 | texture, item, quantity, quality = GetLootSlotInfo(slot) |
||
355 | if (texture) then |
||
356 | curshift = curshift +1 |
||
357 | -- If we're shifting loot, use position slots instead of item slots |
||
358 | if db.collapse then |
||
359 | button = self.buttons[curshift] |
||
360 | frame = self.frames[curshift] |
||
361 | curslot = curshift |
||
362 | else |
||
363 | button = self.buttons[slot] |
||
364 | frame = self.frames[slot] |
||
365 | curslot = slot |
||
366 | end |
||
367 | -- Update slot ID's for WoW's sanity |
||
368 | if not self.compat then |
||
369 | button:SetSlot(slot) |
||
370 | end |
||
371 | button:SetID(slot) |
||
372 | button.slot = slot |
||
373 | self:msg("Attaching loot["..slot.."] ["..item.."] to slot ["..curslot.."], bSlot = "..button.slot); |
||
374 | color = ITEM_QUALITY_COLORS[quality] |
||
375 | qualityTower = max(qualityTower, quality) |
||
376 | SetItemButtonTexture(button, texture) |
||
377 | textobj = _G["XLootButton"..curslot.."Text"] |
||
378 | infoobj = _G["XLootButton"..curslot.."Description"] |
||
379 | qualityobj = _G["XLootButton"..curslot.."Quality"] |
||
380 | infoobj:SetText("") |
||
381 | qualityobj:SetText("") |
||
382 | if LootSlotIsCoin(slot) then -- Fix and performance fix thanks to Dead_LAN |
||
383 | item = string.gsub(item, "\n", " ", 1, true); |
||
384 | end |
||
385 | if db.lootexpand then |
||
386 | textobj:SetWidth(700) |
||
387 | infoobj:SetWidth(700) |
||
388 | else |
||
389 | textobj:SetWidth(155) |
||
390 | infoobj:SetWidth(155) |
||
391 | end |
||
392 | textobj:SetVertexColor(color.r, color.g, color.b); |
||
393 | textobj:SetText(item); |
||
394 | |||
395 | if db.qualitytext and not LootSlotIsCoin(slot) then |
||
396 | qualityobj:SetText(_G["ITEM_QUALITY"..quality.."_DESC"]) |
||
397 | qualityobj:SetVertexColor(.8, .8, .8, 1); |
||
398 | textobj:SetPoint("TOPLEFT", button, "TOPLEFT", 42, -12) |
||
399 | infoobj:SetPoint("TOPLEFT", button, "TOPLEFT", 45, -22) |
||
400 | textobj:SetHeight(10) |
||
401 | elseif LootSlotIsCoin(slot) then |
||
402 | textobj:SetPoint("TOPLEFT", button, "TOPLEFT", 42, 2) |
||
403 | qualityobj:SetText("") |
||
404 | textobj:SetHeight(XLootButton1:GetHeight()+1) |
||
405 | else |
||
406 | qualityobj:SetText("") |
||
407 | if db.infotext then |
||
408 | textobj:SetPoint("TOPLEFT", button, "TOPLEFT", 42, -8) |
||
409 | else |
||
410 | textobj:SetPoint("TOPLEFT", button, "TOPLEFT", 42, -12) |
||
411 | infoobj:SetText("") |
||
412 | end |
||
413 | infoobj:SetPoint("TOPLEFT", button, "TOPLEFT", 45, -18) |
||
414 | textobj:SetHeight(10) |
||
415 | end |
||
416 | if db.lootqualityborder then |
||
417 | frame:SetBackdropBorderColor(color.r, color.g, color.b, 1) |
||
418 | else |
||
419 | frame:SetBackdropBorderColor(unpack(db.lootbordercolor)) |
||
420 | end |
||
421 | if LootSlotIsItem(slot) and db.infotext then |
||
422 | self:SetSlotInfo(slot, button) |
||
423 | end |
||
424 | if db.lootexpand then |
||
425 | framewidth = max(framewidth, textobj:GetStringWidth(), infoobj:GetStringWidth()) |
||
426 | end |
||
427 | |||
428 | SetItemButtonCount(button, quantity) |
||
429 | button.quality = quality |
||
430 | button:Show() |
||
431 | frame:Show() |
||
432 | elseif not db.collapse then |
||
433 | curshift = curshift + 1 |
||
434 | self.buttons[slot]:Hide() |
||
435 | self:msg("Hiding slot "..slot..", curshift: "..curshift) |
||
436 | end |
||
437 | end |
||
438 | |||
439 | if slot == curshift then --Collapse lower buttons |
||
440 | curshift = curshift -1 |
||
441 | self:msg("Collapsing end slot "..slot..", curshift now "..curshift) |
||
442 | end |
||
443 | |||
444 | XLootFrame:SetScale(db.scale) |
||
445 | local color = ITEM_QUALITY_COLORS[qualityTower] |
||
446 | if db.qualityborder and not self.visible then |
||
447 | self:msg("Quality tower: "..qualityTower) |
||
448 | self.frame:SetBackdropBorderColor(color.r, color.g, color.b, 1) |
||
449 | else |
||
450 | self.frame:SetBackdropBorderColor(unpack(db.bordercolor)) |
||
451 | end |
||
452 | |||
453 | if db.qualityframe and not self.visible then |
||
454 | self.frame:SetBackdropColor(color.r, color.g, color.b, db.bgcolor[4]) |
||
455 | else |
||
456 | self.frame:SetBackdropColor(unpack(db.bgcolor)) |
||
457 | end |
||
458 | |||
459 | XLootFrame:SetHeight(20 + (curshift*XLootButtonFrame1:GetHeight())) |
||
460 | |||
461 | if db.lootexpand then |
||
462 | self.loothasbeenexpanded = true |
||
463 | local fwidth, bwidth = (self.buttons[1]:GetWidth() + framewidth + 21), -(framewidth + 16) |
||
464 | self:UpdateWidths(curshift, fwidth, bwidth, fwidth+24) |
||
465 | elseif self.loothasbeenexpanded then |
||
466 | self.loothasbeenexpanded = false |
||
467 | self:UpdateWidths(curshift, 200, -163, 222) |
||
468 | end |
||
469 | |||
470 | |||
471 | if (db.collapse and db.cursor) or (not self.visible and db.cursor) then -- FruityLoot |
||
472 | self:PositionAtCursor() |
||
473 | end |
||
474 | |||
475 | self.frame:Show() |
||
476 | self.closebutton:Show() |
||
477 | self:msg("Displaying at position: "..XLootFrame:GetLeft().." "..XLootFrame:GetTop()); |
||
478 | self.visible = true |
||
479 | |||
480 | --Hopefully avoid non-looting/empty bar |
||
481 | if self:AutoClose() then |
||
482 | self:msg("Possible hanger frame. Closing.. "..numLoot..", "..curshift) |
||
483 | end |
||
484 | end |
||
485 | |||
486 | function XLoot:UpdateWidths(framenum, fwidth, bwidth, ofwidth) |
||
487 | for i = 1, framenum do |
||
488 | self.frames[i]:SetWidth(fwidth) |
||
489 | self.buttons[i]:SetHitRectInsets(0, bwidth, 0, -1) |
||
490 | end |
||
491 | self.frame:SetWidth(ofwidth) |
||
492 | end |
||
493 | |||
494 | function XLoot:PositionAtCursor() --Fruityloots mixup, only called if cursor snapping is enabled |
||
495 | local x, y = GetCursorPosition() |
||
496 | local s = XLootFrame:GetEffectiveScale() |
||
497 | x = (x / s) - 30 |
||
498 | y = (y / s) + 30 |
||
499 | local screenWidth = GetScreenWidth() |
||
500 | if (UIParent:GetWidth() > screenWidth) then screenWidth = UIParent:GetWidth() end |
||
501 | local screenHeight = GetScreenHeight() |
||
502 | local windowWidth = XLootFrame:GetWidth() |
||
503 | local windowHeight = XLootFrame:GetHeight() |
||
504 | if (x + windowWidth) > screenWidth then x = screenWidth - windowWidth end |
||
505 | if y > screenHeight then y = screenHeight end |
||
506 | if x < 0 then x = 0 end |
||
507 | if (y - windowHeight) < 0 then y = windowHeight end |
||
508 | LootFrame:ClearAllPoints() |
||
509 | if (self.db.profile.smartsnap and self.visible) then |
||
510 | x = XLootFrame:GetLeft(); |
||
511 | else |
||
512 | x = x + self.db.profile.snapoffset |
||
513 | end |
||
514 | XLootFrame:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", x, y); |
||
515 | end |
||
516 | |||
517 | -- Add a single lootframe |
||
518 | function XLoot:AddLootFrame(id) |
||
519 | local frame = CreateFrame("Frame", "XLootButtonFrame"..id, self.frame) |
||
520 | local button = CreateFrame(LootButton1:GetObjectType(), "XLootButton"..id, frame, "LootButtonTemplate") |
||
521 | -- Equivalent of XLootButtonTemplate |
||
522 | local buttontext = _G["XLootButton"..id.."Text"] |
||
523 | local buttondesc = button:CreateFontString("XLootButton"..id.."Description", "ARTWORK", "GameFontNormalSmall") |
||
524 | local buttonquality = button:CreateFontString("XLootButton"..id.."Quality", "GameFontNormalSmall") |
||
525 | local font = {buttontext:GetFont()} |
||
526 | font[2] = 10 |
||
527 | buttontext:SetDrawLayer("OVERLAY") |
||
528 | buttondesc:SetDrawLayer("OVERLAY") |
||
529 | buttonquality:SetDrawLayer("OVERLAY") |
||
530 | buttondesc:SetFont(unpack(font)) |
||
531 | buttonquality:SetFont(unpack(font)) |
||
532 | buttondesc:SetJustifyH("LEFT") |
||
533 | buttonquality:SetJustifyH("LEFT") |
||
534 | buttondesc:SetHeight(10) |
||
535 | buttonquality:SetWidth(155) |
||
536 | buttonquality:SetHeight(10) |
||
537 | buttontext:SetHeight(10) |
||
538 | buttonquality:SetPoint("TOPLEFT", button, "TOPLEFT", 45, -3) |
||
539 | button:SetHitRectInsets(0, -165, 0, -1) |
||
540 | -- End template |
||
541 | frame:SetWidth(200) |
||
542 | frame:SetHeight(button:GetHeight()+1) |
||
543 | button:ClearAllPoints() |
||
544 | frame:ClearAllPoints() |
||
545 | if (id == 1) then |
||
546 | frame:SetPoint("TOPLEFT", self.frame, "TOPLEFT", 10, -10) |
||
547 | else |
||
548 | frame:SetPoint("TOPLEFT", self.frames[id-1], "BOTTOMLEFT") |
||
549 | end |
||
550 | button:SetPoint("LEFT", frame, "LEFT") |
||
551 | button:RegisterForDrag("LeftButton") |
||
552 | button:SetScript("OnDragStart", function() self:DragStart() end) |
||
553 | button:SetScript("OnDragStop", function() self:DragStop() end) |
||
554 | button:SetScript("OnEnter", function() local slot = this:GetID(); if ( LootSlotIsItem(slot) ) then GameTooltip:SetOwner(this, "ANCHOR_RIGHT"); GameTooltip:SetLootItem(slot); CursorUpdate(); end end ) |
||
555 | self.buttons[id] = button; |
||
556 | self.frames[id] = frame |
||
557 | self:msg("Creation: self.buttons["..id.."] = ".. button:GetName()); |
||
558 | self.frame:SetHeight(self.frame:GetHeight() + frame:GetHeight()) |
||
559 | |||
560 | --Skin |
||
561 | if (IsAddOnLoaded("oSkin") and self.db.profile.oskin) then |
||
562 | oSkin:applySkin(button) |
||
563 | oSkin:applySkin(frame) |
||
564 | else |
||
565 | frame:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", |
||
566 | edgeFile = "Interface/Tooltips/UI-Tooltip-Border", |
||
567 | tile = true, tileSize = 32, edgeSize = 15, |
||
568 | insets = { left = 4, right = 4, top = 4, bottom = 4 }}) |
||
569 | self:oSkinTooltipModded(frame) |
||
570 | end |
||
571 | frame:SetBackdropColor(unpack(self.db.profile.lootbgcolor)) |
||
572 | frame:SetBackdropBorderColor(unpack(self.db.profile.lootbordercolor)) |
||
573 | button:DisableDrawLayer("ARTWORK") |
||
574 | button:Hide() |
||
575 | frame:Hide() |
||
576 | self.numButtons = self.numButtons +1 |
||
577 | end |
||
578 | |||
579 | function XLoot:DragStart() |
||
580 | if not self.db.profile.lock then |
||
581 | XLootFrame:StartMoving() |
||
582 | end |
||
583 | end |
||
584 | |||
585 | function XLoot:DragStop() |
||
586 | if not self.db.profile.lock then |
||
587 | XLootFrame:StopMovingOrSizing() |
||
588 | self.db.profile.pos.x = XLootFrame:GetLeft() |
||
589 | self.db.profile.pos.y = XLootFrame:GetTop() |
||
590 | XLoot:msg("Setting position: "..self.db.profile.pos.x.." "..self.db.profile.pos.y) |
||
591 | end |
||
592 | end |
||
593 | |||
594 | -- Setup lootframes & close button |
||
595 | function XLoot:SetupFrames() |
||
596 | -- Alright you XML nazis. Main frame |
||
597 | self.frame = CreateFrame("Frame", "XLootFrame", UIParent) |
||
598 | self.frame:SetFrameStrata("DIALOG") |
||
599 | self.frame:SetFrameLevel(5) |
||
600 | self.frame:SetWidth(222) |
||
601 | self.frame:SetHeight(20) |
||
602 | self.frame:SetMovable(1) |
||
603 | if self.db.profile.dragborder then |
||
604 | self.frame:EnableMouse(1) |
||
605 | end |
||
606 | self.frame:RegisterForDrag("LeftButton") |
||
607 | self.frame:SetScript("OnDragStart", function() XLoot:DragStart() end) |
||
608 | self.frame:SetScript("OnDragStop", function() XLoot:DragStop() end) |
||
609 | self.frame:SetScript("OnHide", function() XLoot:OnHide() end) |
||
610 | --self.frame:IsToplevel(1) |
||
611 | self.frame:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", |
||
612 | edgeFile = "Interface/Tooltips/UI-Tooltip-Border", |
||
613 | tile = true, tileSize = 32, edgeSize = 15, |
||
614 | insets = { left = 4, right = 4, top = 4, bottom = 4 }}) |
||
615 | self.frame:ClearAllPoints() |
||
616 | if not self.db.profile.cursor then |
||
617 | self.frame:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", self.db.profile.pos.x, self.db.profile.pos.y) |
||
618 | end |
||
619 | |||
620 | --Skin |
||
621 | if (IsAddOnLoaded("oSkin") and self.db.profile.oskin) then |
||
622 | oSkin:applySkin(XLootFrame, {1}) |
||
623 | else |
||
624 | self:oSkinTooltipModded(XLootFrame) |
||
625 | end |
||
626 | |||
627 | self.frame:SetBackdropColor(unpack(self.db.profile.bgcolor)) |
||
628 | self.frame:SetBackdropBorderColor(unpack(self.db.profile.bordercolor)) |
||
629 | |||
630 | self.frame:SetScale(self.db.profile.scale) |
||
631 | |||
632 | -- Close button |
||
633 | self.closebutton = CreateFrame("Button", "XLootCloseButton", XLootFrame) |
||
634 | self.closebutton:SetScript("OnClick", function() XLoot:AutoClose(true); end) |
||
635 | self.closebutton:SetFrameLevel(8) |
||
636 | self.closebutton:SetWidth(32) |
||
637 | self.closebutton:SetHeight(32) |
||
638 | self.closebutton:SetNormalTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Up") |
||
639 | self.closebutton:SetPushedTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Down") |
||
640 | self.closebutton:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight") |
||
641 | self.closebutton:ClearAllPoints() |
||
642 | self.closebutton:SetPoint("TOPRIGHT", XLootFrame, "TOPRIGHT", 3, 3) |
||
643 | self.closebutton:SetHitRectInsets(5, 5, 5, 5) |
||
644 | self.closebutton:Hide() |
||
645 | self:AddLootFrame(1) |
||
646 | self.frame:Hide() |
||
647 | end |
||
648 | |||
649 | function XLoot:msg( text ) |
||
650 | if self.db.profile.debug then |
||
651 | DEFAULT_CHAT_FRAME:AddMessage("|cff7fff7fXLoot|r: "..text); |
||
652 | end |
||
653 | end |
||
654 | |||
655 | function XLoot:Clear() |
||
656 | for slot, button in pairs(self.buttons) do |
||
657 | --SetItemButtonTexture(button, "") |
||
658 | SetItemButtonCount(button, 0) |
||
659 | --getglobal("XLootButton"..slot.."Text"):SetVertexColor(0, 0, 0) |
||
660 | --getglobal("XLootButton"..slot.."Text"):SetText("") |
||
661 | --getglobal("XLootButton"..slot.."Description"):SetText("") |
||
662 | --getglobal("XLootButton"..slot.."Quality"):SetText("") |
||
663 | button:Hide() |
||
664 | self.frames[slot]:Hide() |
||
665 | end |
||
666 | if GetNumLootItems() < 1 then |
||
667 | self.visible = false |
||
668 | end |
||
669 | XLootFrame:Hide() |
||
670 | end |
||
671 | |||
672 | -- Substitute oSkin function, full credit to oSkin devs :) |
||
673 | function XLoot:oSkinTooltipModded(frame) |
||
674 | if not frame.tfade then frame.tfade = frame:CreateTexture(nil, "BORDER") end |
||
675 | frame.tfade:SetTexture("Interface\\ChatFrame\\ChatFrameBackground") |
||
676 | |||
677 | frame.tfade:SetPoint("TOPLEFT", frame, "TOPLEFT",1,-1) |
||
678 | frame.tfade:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT",-1,1) |
||
679 | |||
680 | frame.tfade:SetBlendMode("ADD") |
||
681 | frame.tfade:SetGradientAlpha("VERTICAL", .1, .1, .1, 0, .2, .2, .2, 0.6) |
||
682 | |||
683 | frame.tfade:SetPoint("TOPLEFT", frame, "TOPLEFT", 6, -6) |
||
684 | frame.tfade:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", -6, -30) |
||
685 | end |