yellowfive@161
|
1 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
|
yellowfive@161
|
2 local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true)
|
yellowfive@161
|
3 local AceGUI = LibStub("AceGUI-3.0")
|
yellowfive@161
|
4
|
yellowfive@161
|
5 local _frameJunk
|
yellowfive@161
|
6 local _lblAction
|
yellowfive@161
|
7 local _lblBank
|
yellowfive@161
|
8 local _btnBank
|
yellowfive@161
|
9 local _panelContent
|
yellowfive@161
|
10
|
yellowfive@161
|
11 local _canDisenchant = false
|
yellowfive@161
|
12 local _isScrapOpen = false
|
yellowfive@161
|
13 local _isMerchantOpen = false
|
yellowfive@161
|
14 local _isBankOpen = false
|
yellowfive@161
|
15
|
yellowfive@161
|
16 --
|
yellowfive@161
|
17 -- Scan a bag for the specified item, returning the first exact match found
|
yellowfive@161
|
18 --
|
yellowfive@161
|
19 local function scanBag(bagId, matchItem, usedItems)
|
yellowfive@161
|
20
|
yellowfive@161
|
21 local numSlots = GetContainerNumSlots(bagId)
|
yellowfive@161
|
22 local loc = ItemLocation.CreateEmpty()
|
yellowfive@161
|
23
|
yellowfive@161
|
24 if not usedItems[bagId] then
|
yellowfive@161
|
25 usedItems[bagId] = {}
|
yellowfive@161
|
26 end
|
yellowfive@161
|
27
|
yellowfive@161
|
28 for slotId = 1, numSlots do
|
yellowfive@161
|
29 if not usedItems[bagId][slotId] then
|
yellowfive@161
|
30 local _, itemCount, _, _, _, _, itemLink = GetContainerItemInfo(bagId, slotId)
|
yellowfive@161
|
31 if itemLink ~= nil then
|
yellowfive@161
|
32 local itemData = Amr.Serializer.ParseItemLink(itemLink)
|
yellowfive@161
|
33 if itemData ~= nil then
|
yellowfive@161
|
34 -- see if this is an azerite item and read azerite power ids
|
yellowfive@161
|
35 loc:SetBagAndSlot(bagId, slotId)
|
yellowfive@161
|
36 if C_AzeriteEmpoweredItem.IsAzeriteEmpoweredItem(loc) then
|
yellowfive@161
|
37 local powers = Amr.ReadAzeritePowers(loc)
|
yellowfive@161
|
38 if powers then
|
yellowfive@161
|
39 itemData.azerite = powers
|
yellowfive@161
|
40 end
|
yellowfive@161
|
41 end
|
yellowfive@161
|
42
|
yellowfive@161
|
43 -- see if it matches
|
yellowfive@161
|
44 if Amr.CountItemDifferences(matchItem, itemData) == 0 then
|
yellowfive@161
|
45 usedItems[bagId][slotId] = true
|
yellowfive@161
|
46 itemData.bagId = bagId
|
yellowfive@161
|
47 itemData.slotId = slotId
|
yellowfive@161
|
48 return itemData
|
yellowfive@161
|
49 end
|
yellowfive@161
|
50 end
|
yellowfive@161
|
51 end
|
yellowfive@161
|
52 end
|
yellowfive@161
|
53 end
|
yellowfive@161
|
54
|
yellowfive@161
|
55 return nil
|
yellowfive@161
|
56 end
|
yellowfive@161
|
57
|
yellowfive@161
|
58 --
|
yellowfive@161
|
59 -- Find a matching item in the player's bags
|
yellowfive@161
|
60 --
|
yellowfive@161
|
61 local function findMatchingBagItem(item, usedItems)
|
yellowfive@161
|
62
|
yellowfive@161
|
63 local matchItem = scanBag(BACKPACK_CONTAINER, item, usedItems) -- backpack
|
yellowfive@161
|
64 if not matchItem then
|
yellowfive@161
|
65 for bagId = 1, NUM_BAG_SLOTS do
|
yellowfive@161
|
66 matchItem = scanBag(bagId, item, usedItems)
|
yellowfive@161
|
67 if matchItem then break end
|
yellowfive@161
|
68 end
|
yellowfive@161
|
69 end
|
yellowfive@161
|
70
|
yellowfive@161
|
71 return matchItem
|
yellowfive@161
|
72 end
|
yellowfive@161
|
73
|
yellowfive@161
|
74
|
yellowfive@161
|
75 --
|
yellowfive@161
|
76 -- item actions
|
yellowfive@161
|
77 --
|
yellowfive@161
|
78 local _deSpellName = GetSpellInfo(13262);
|
yellowfive@161
|
79 local _deMacro = "/stopmacro [combat][btn:2]\n/stopcasting\n/cast %s\n/use %s %s";
|
yellowfive@161
|
80
|
yellowfive@161
|
81 local function onItemPreClick(widget)
|
yellowfive@161
|
82
|
yellowfive@161
|
83 local item = widget:GetUserData("itemData")
|
yellowfive@161
|
84
|
yellowfive@161
|
85 if item and _canDisenchant and (not _isScrapOpen and not _isMerchantOpen) then
|
yellowfive@161
|
86 -- only way i can find to disenchant and item on click is to call a macro, gross but works
|
yellowfive@161
|
87 local matchItem = findMatchingBagItem(item, {})
|
yellowfive@161
|
88 if matchItem then
|
yellowfive@161
|
89 widget:SetMacroText(_deMacro:format(_deSpellName, matchItem.bagId, matchItem.slotId))
|
yellowfive@161
|
90 else
|
yellowfive@161
|
91 widget:SetMacroText(nil)
|
yellowfive@161
|
92 Amr:Print(L.JunkItemNotFound)
|
yellowfive@161
|
93 end
|
yellowfive@161
|
94 else
|
yellowfive@161
|
95 widget:SetMacroText(nil)
|
yellowfive@161
|
96 end
|
yellowfive@161
|
97 end
|
yellowfive@161
|
98
|
yellowfive@161
|
99 local function onItemClick(widget)
|
yellowfive@161
|
100
|
yellowfive@161
|
101 local item = widget:GetUserData("itemData")
|
yellowfive@161
|
102 if not item then return end
|
yellowfive@161
|
103
|
yellowfive@161
|
104 local action = nil
|
yellowfive@161
|
105 if _isScrapOpen then
|
yellowfive@161
|
106 action = "scrap"
|
yellowfive@161
|
107 elseif _isMerchantOpen then
|
yellowfive@161
|
108 action = "sell"
|
yellowfive@161
|
109 elseif _canDisenchant then
|
yellowfive@161
|
110 action = "disenchant"
|
yellowfive@161
|
111 end
|
yellowfive@161
|
112
|
yellowfive@161
|
113 if not action then return end
|
yellowfive@161
|
114
|
yellowfive@161
|
115 local matchItem = findMatchingBagItem(item, {})
|
yellowfive@161
|
116 if matchItem then
|
yellowfive@161
|
117 if action == "scrap" then
|
yellowfive@161
|
118 UseContainerItem(matchItem.bagId, matchItem.slotId)
|
yellowfive@161
|
119 elseif action == "sell" then
|
yellowfive@161
|
120 UseContainerItem(matchItem.bagId, matchItem.slotId)
|
yellowfive@161
|
121 end
|
yellowfive@161
|
122
|
yellowfive@161
|
123 -- note for disenchant, the macro has handled the action, this will simply remove the item from the list
|
yellowfive@161
|
124
|
yellowfive@161
|
125 -- re-render the list with this item removed;
|
yellowfive@161
|
126 -- AceGUI doesn't give a good way to remove a ui element from a container and re-render,
|
yellowfive@161
|
127 -- so we sort of hack it and modify the collection of children directly,
|
yellowfive@161
|
128 -- avoids the expensive logic of finding and matching all the items when the list changes as a user sells stuff
|
yellowfive@161
|
129 local scroll = widget.parent.parent
|
yellowfive@161
|
130 local newChildren = {}
|
yellowfive@161
|
131 for i = 1, #scroll.children do
|
yellowfive@161
|
132 local child = scroll.children[i]
|
yellowfive@161
|
133 if child ~= widget.parent then
|
yellowfive@161
|
134 table.insert(newChildren, child)
|
yellowfive@161
|
135 end
|
yellowfive@161
|
136 end
|
yellowfive@161
|
137 scroll.children = newChildren
|
yellowfive@161
|
138
|
yellowfive@161
|
139 -- dispose the item just removed, then re-render the list
|
yellowfive@161
|
140 widget.parent:Release()
|
yellowfive@161
|
141 widget.parent.parent:DoLayout()
|
yellowfive@161
|
142 else
|
yellowfive@161
|
143 Amr:Print(L.JunkItemNotFound)
|
yellowfive@161
|
144 end
|
yellowfive@161
|
145 end
|
yellowfive@161
|
146
|
yellowfive@161
|
147
|
yellowfive@161
|
148 --
|
yellowfive@161
|
149 -- bank withdraw stuff
|
yellowfive@161
|
150 --
|
yellowfive@161
|
151 local _bankUsedBagSlots = nil
|
yellowfive@161
|
152 local finishBankWithdraw
|
yellowfive@161
|
153 local doBankWithdraw
|
yellowfive@161
|
154
|
yellowfive@161
|
155 finishBankWithdraw = function()
|
yellowfive@161
|
156
|
yellowfive@161
|
157 local done = true
|
yellowfive@161
|
158
|
yellowfive@161
|
159 if _isBankOpen and _bankUsedBagSlots then
|
yellowfive@161
|
160 for bagId,v in pairs(_bankUsedBagSlots) do
|
yellowfive@161
|
161 for slotId,v in pairs(v) do
|
yellowfive@161
|
162 local _, _, _, _, _, _, itemLink = GetContainerItemInfo(bagId, slotId)
|
yellowfive@161
|
163 if not itemLink then
|
yellowfive@161
|
164 done = false
|
yellowfive@161
|
165 break
|
yellowfive@161
|
166 end
|
yellowfive@161
|
167 end
|
yellowfive@161
|
168 if not done then break end
|
yellowfive@161
|
169 end
|
yellowfive@161
|
170 end
|
yellowfive@161
|
171
|
yellowfive@161
|
172 if not done then
|
yellowfive@161
|
173 -- wait a second and try again
|
yellowfive@161
|
174 Amr.Wait(1, function()
|
yellowfive@161
|
175 doBankWithdraw()
|
yellowfive@161
|
176 end)
|
yellowfive@161
|
177 else
|
yellowfive@161
|
178
|
yellowfive@161
|
179 print("bank withdraw done")
|
yellowfive@161
|
180
|
yellowfive@161
|
181 -- reset state
|
yellowfive@161
|
182 _bankUsedBagSlots = nil
|
yellowfive@161
|
183 _btnBank:SetDisabled(not _isBankOpen)
|
yellowfive@161
|
184
|
yellowfive@161
|
185 -- re-render the junk list
|
yellowfive@161
|
186 Amr:RefreshJunkUi()
|
yellowfive@161
|
187 end
|
yellowfive@161
|
188 end
|
yellowfive@161
|
189
|
yellowfive@161
|
190 doBankWithdraw = function()
|
yellowfive@161
|
191 if not _isBankOpen then return end
|
yellowfive@161
|
192
|
yellowfive@161
|
193 local data = Amr.db.char.JunkData
|
yellowfive@161
|
194 if not data.Junk then return end
|
yellowfive@161
|
195
|
yellowfive@161
|
196 print("doing bank withdraw...")
|
yellowfive@161
|
197
|
yellowfive@161
|
198 -- disable button while processing
|
yellowfive@161
|
199 _btnBank:SetDisabled(true)
|
yellowfive@161
|
200
|
yellowfive@161
|
201 local bagList = {}
|
yellowfive@161
|
202 table.insert(bagList, BANK_CONTAINER)
|
yellowfive@161
|
203 for bagId = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS do
|
yellowfive@161
|
204 table.insert(bagList, bagId)
|
yellowfive@161
|
205 end
|
yellowfive@161
|
206
|
yellowfive@161
|
207 local usedItems = {}
|
yellowfive@161
|
208 _bankUsedBagSlots = {}
|
yellowfive@161
|
209
|
yellowfive@161
|
210 for i,item in ipairs(data.Junk) do
|
yellowfive@161
|
211 -- stop immediately if the bank is closed
|
yellowfive@161
|
212 if not _isBankOpen then
|
yellowfive@161
|
213 finishBankWithdraw()
|
yellowfive@161
|
214 return
|
yellowfive@161
|
215 end
|
yellowfive@161
|
216
|
yellowfive@161
|
217 -- check if already in bags
|
yellowfive@161
|
218 local matchItem = findMatchingBagItem(item, usedItems)
|
yellowfive@161
|
219 if not matchItem then
|
yellowfive@161
|
220 -- find it in the bank
|
yellowfive@161
|
221 for j = 1, #bagList do
|
yellowfive@161
|
222 matchItem = scanBag(bagList[j], item, usedItems)
|
yellowfive@161
|
223 if matchItem then break end
|
yellowfive@161
|
224 end
|
yellowfive@161
|
225 else
|
yellowfive@161
|
226 matchItem = nil
|
yellowfive@161
|
227 end
|
yellowfive@161
|
228
|
yellowfive@161
|
229 if matchItem then
|
yellowfive@161
|
230 -- move it to the player's bags if there is space
|
yellowfive@161
|
231 local bagId, slotId = Amr.FindFirstEmptyBagSlot(_bankUsedBagSlots)
|
yellowfive@161
|
232 if bagId then
|
yellowfive@161
|
233 UseContainerItem(matchItem.bagId, matchItem.slotId)
|
yellowfive@161
|
234 else
|
yellowfive@161
|
235 -- no more empty bag slots
|
yellowfive@161
|
236 break
|
yellowfive@161
|
237 end
|
yellowfive@161
|
238 end
|
yellowfive@161
|
239 end
|
yellowfive@161
|
240
|
yellowfive@161
|
241 -- wait a second and see if all the moves actually finished
|
yellowfive@161
|
242 Amr.Wait(1, function()
|
yellowfive@161
|
243 finishBankWithdraw()
|
yellowfive@161
|
244 end)
|
yellowfive@161
|
245 end
|
yellowfive@161
|
246
|
yellowfive@161
|
247 local function onBankClick()
|
yellowfive@161
|
248 if not _frameJunk or not _isBankOpen then return end
|
yellowfive@161
|
249
|
yellowfive@161
|
250 doBankWithdraw()
|
yellowfive@161
|
251 end
|
yellowfive@161
|
252
|
yellowfive@161
|
253
|
yellowfive@161
|
254 local function onJunkFrameClose(widget)
|
yellowfive@161
|
255 AceGUI:Release(widget)
|
yellowfive@161
|
256 _frameJunk = nil
|
yellowfive@161
|
257 _lblAction = nil
|
yellowfive@161
|
258 _lblBank = nil
|
yellowfive@161
|
259 _btnBank = nil
|
yellowfive@161
|
260 _panelContent = nil
|
yellowfive@161
|
261 end
|
yellowfive@161
|
262
|
yellowfive@161
|
263 function Amr:HideJunkWindow()
|
yellowfive@161
|
264 if not _frameJunk then return end
|
yellowfive@161
|
265 _frameJunk:Hide()
|
yellowfive@161
|
266 end
|
yellowfive@161
|
267
|
yellowfive@161
|
268 function Amr:ShowJunkWindow()
|
yellowfive@161
|
269
|
yellowfive@161
|
270 if not _frameJunk then
|
yellowfive@161
|
271 _frameJunk = AceGUI:Create("AmrUiFrame")
|
yellowfive@161
|
272 _frameJunk:SetStatusTable(Amr.db.profile.junkWindow) -- window position is remembered in db
|
yellowfive@161
|
273 _frameJunk:SetCallback("OnClose", onJunkFrameClose)
|
yellowfive@161
|
274 _frameJunk:SetLayout("None")
|
yellowfive@161
|
275 _frameJunk:SetWidth(400)
|
yellowfive@161
|
276 _frameJunk:SetHeight(700)
|
yellowfive@161
|
277 _frameJunk:SetBorderColor(Amr.Colors.BorderBlue)
|
yellowfive@161
|
278 _frameJunk:SetBackgroundColor(Amr.Colors.Bg)
|
yellowfive@161
|
279
|
yellowfive@161
|
280 if Amr.db.profile.options.uiScale ~= 1 then
|
yellowfive@161
|
281 local scale = tonumber(Amr.db.profile.options.uiScale)
|
yellowfive@161
|
282 _frameJunk:SetScale(scale)
|
yellowfive@161
|
283 end
|
yellowfive@161
|
284
|
yellowfive@161
|
285 local lbl = AceGUI:Create("AmrUiLabel")
|
yellowfive@161
|
286 _frameJunk:AddChild(lbl)
|
yellowfive@161
|
287 lbl:SetWidth(300)
|
yellowfive@161
|
288 lbl:SetFont(Amr.CreateFont("Bold", 28, Amr.Colors.White))
|
yellowfive@161
|
289 lbl:SetText(L.JunkTitle)
|
yellowfive@161
|
290 lbl:SetWordWrap(false)
|
yellowfive@161
|
291 lbl:SetJustifyH("CENTER")
|
yellowfive@161
|
292 lbl:SetPoint("TOP", _frameJunk.content, "TOP", 0, 30)
|
yellowfive@161
|
293 lbl:SetCallback("OnMouseDown", function(widget) _frameJunk:StartMove() end)
|
yellowfive@161
|
294 lbl:SetCallback("OnMouseUp", function(widget) _frameJunk:EndMove() end)
|
yellowfive@161
|
295
|
yellowfive@161
|
296 _lblAction = AceGUI:Create("AmrUiLabel")
|
yellowfive@161
|
297 _frameJunk:AddChild(_lblAction)
|
yellowfive@161
|
298 _lblAction:SetWidth(380)
|
yellowfive@161
|
299 _lblAction:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.TextTan))
|
yellowfive@161
|
300 _lblAction:SetText(" ")
|
yellowfive@161
|
301 _lblAction:SetWordWrap(false)
|
yellowfive@161
|
302 _lblAction:SetPoint("TOPLEFT", _frameJunk.content, "TOPLEFT", 0, -10)
|
yellowfive@161
|
303
|
yellowfive@161
|
304 _btnBank = AceGUI:Create("AmrUiButton")
|
yellowfive@161
|
305 _frameJunk:AddChild(_btnBank)
|
yellowfive@161
|
306 _btnBank:SetText(L.JunkButtonBank)
|
yellowfive@161
|
307 _btnBank:SetBackgroundColor(Amr.Colors.Green)
|
yellowfive@161
|
308 _btnBank:SetFont(Amr.CreateFont("Bold", 14, Amr.Colors.White))
|
yellowfive@161
|
309 _btnBank:SetWidth(180)
|
yellowfive@161
|
310 _btnBank:SetHeight(26)
|
yellowfive@161
|
311 _btnBank:SetDisabled(true)
|
yellowfive@161
|
312 _btnBank:SetCallback("OnClick", onBankClick)
|
yellowfive@161
|
313 _btnBank:SetPoint("BOTTOMLEFT", _frameJunk.content, "BOTTOMLEFT")
|
yellowfive@161
|
314
|
yellowfive@161
|
315 _lblBank = AceGUI:Create("AmrUiLabel")
|
yellowfive@161
|
316 _frameJunk:AddChild(_lblBank)
|
yellowfive@161
|
317 _lblBank:SetWidth(380)
|
yellowfive@161
|
318 _lblBank:SetFont(Amr.CreateFont("Bold", 15, Amr.Colors.TextHeaderActive))
|
yellowfive@161
|
319 _lblBank:SetText(L.JunkBankText(0))
|
yellowfive@161
|
320 _lblBank:SetPoint("BOTTOMLEFT", _btnBank.frame, "TOPLEFT", 0, 10)
|
yellowfive@161
|
321
|
yellowfive@161
|
322 local line = AceGUI:Create("AmrUiPanel")
|
yellowfive@161
|
323 _frameJunk:AddChild(line)
|
yellowfive@161
|
324 line:SetHeight(1)
|
yellowfive@161
|
325 line:SetBackgroundColor(Amr.Colors.White)
|
yellowfive@161
|
326 line:SetPoint("TOPLEFT", _frameJunk.content, "TOPLEFT", 0, -30)
|
yellowfive@161
|
327 line:SetPoint("TOPRIGHT", _frameJunk.content, "TOPRIGHT", 0, -30)
|
yellowfive@161
|
328
|
yellowfive@161
|
329 line = AceGUI:Create("AmrUiPanel")
|
yellowfive@161
|
330 _frameJunk:AddChild(line)
|
yellowfive@161
|
331 line:SetHeight(1)
|
yellowfive@161
|
332 line:SetBackgroundColor(Amr.Colors.White)
|
yellowfive@161
|
333 line:SetPoint("TOPLEFT", _frameJunk.content, "BOTTOMLEFT", 0, 60)
|
yellowfive@161
|
334 line:SetPoint("TOPRIGHT", _frameJunk.content, "BOTTOMRIGHT", 0, 60)
|
yellowfive@161
|
335
|
yellowfive@161
|
336 _panelContent = AceGUI:Create("AmrUiPanel")
|
yellowfive@161
|
337 _panelContent:SetLayout("None")
|
yellowfive@161
|
338 _panelContent:SetTransparent()
|
yellowfive@161
|
339 _frameJunk:AddChild(_panelContent)
|
yellowfive@161
|
340 _panelContent:SetPoint("TOPLEFT", _frameJunk.content, "TOPLEFT", 0, -31)
|
yellowfive@161
|
341 _panelContent:SetPoint("BOTTOMRIGHT", _frameJunk.content, "BOTTOMRIGHT", 0, 60)
|
yellowfive@161
|
342
|
yellowfive@161
|
343
|
yellowfive@161
|
344 Amr:RefreshJunkUi()
|
yellowfive@161
|
345 else
|
yellowfive@161
|
346 _frameJunk:Show()
|
yellowfive@161
|
347 Amr:RefreshJunkUi()
|
yellowfive@161
|
348 end
|
yellowfive@161
|
349
|
yellowfive@161
|
350 _frameJunk:Raise()
|
yellowfive@161
|
351 end
|
yellowfive@161
|
352
|
yellowfive@161
|
353 local function canDisenchant()
|
yellowfive@161
|
354
|
yellowfive@161
|
355 local prof1, prof2 = GetProfessions();
|
yellowfive@161
|
356 local profs = {}
|
yellowfive@161
|
357 table.insert(profs, prof1)
|
yellowfive@161
|
358 table.insert(profs, prof2)
|
yellowfive@161
|
359 for i,prof in ipairs(profs) do
|
yellowfive@161
|
360 if prof then
|
yellowfive@161
|
361 local _, _, skillLevel, _, _, _, skillLine = GetProfessionInfo(prof);
|
yellowfive@161
|
362 if Amr.ProfessionSkillLineToName[skillLine] == "Enchanting" and skillLevel > 0 then
|
yellowfive@161
|
363 return true
|
yellowfive@161
|
364 end
|
yellowfive@161
|
365 end
|
yellowfive@161
|
366 end
|
yellowfive@161
|
367
|
yellowfive@161
|
368 return false
|
yellowfive@161
|
369 end
|
yellowfive@161
|
370
|
yellowfive@161
|
371 --
|
yellowfive@161
|
372 -- Find a matching item that is not in the player's inventory (bank or equipped)
|
yellowfive@161
|
373 --
|
yellowfive@161
|
374 local function findMatchingNonBagItem(matchItem, usedItems)
|
yellowfive@161
|
375
|
yellowfive@161
|
376 local loc = ItemLocation.CreateEmpty()
|
yellowfive@161
|
377
|
yellowfive@161
|
378 -- check equipped
|
yellowfive@161
|
379 local equippedBagId = -1000
|
yellowfive@161
|
380 if not usedItems[equippedBagId] then
|
yellowfive@161
|
381 usedItems[equippedBagId] = {}
|
yellowfive@161
|
382 end
|
yellowfive@161
|
383
|
yellowfive@161
|
384 for slotNum = 1, #Amr.SlotIds do
|
yellowfive@161
|
385 local slotId = Amr.SlotIds[slotNum]
|
yellowfive@161
|
386 if not usedItems[equippedBagId][slotId] then
|
yellowfive@161
|
387 local itemLink = GetInventoryItemLink("player", slotId)
|
yellowfive@161
|
388 if itemLink then
|
yellowfive@161
|
389 local itemData = Amr.ParseItemLink(itemLink)
|
yellowfive@161
|
390 if itemData then
|
yellowfive@161
|
391 -- see if this is an azerite item and read azerite power ids
|
yellowfive@161
|
392 loc:SetEquipmentSlot(slotId)
|
yellowfive@161
|
393 if C_AzeriteEmpoweredItem.IsAzeriteEmpoweredItem(loc) then
|
yellowfive@161
|
394 local powers = Amr.ReadAzeritePowers(loc)
|
yellowfive@161
|
395 if powers then
|
yellowfive@161
|
396 itemData.azerite = powers
|
yellowfive@161
|
397 end
|
yellowfive@161
|
398 end
|
yellowfive@161
|
399
|
yellowfive@161
|
400 -- see if it matches
|
yellowfive@161
|
401 if Amr.CountItemDifferences(matchItem, itemData) == 0 then
|
yellowfive@161
|
402 usedItems[equippedBagId][slotId] = true
|
yellowfive@161
|
403 itemData.bagId = bagId
|
yellowfive@161
|
404 itemData.slotId = slotId
|
yellowfive@161
|
405 return itemData
|
yellowfive@161
|
406 end
|
yellowfive@161
|
407 end
|
yellowfive@161
|
408 end
|
yellowfive@161
|
409 end
|
yellowfive@161
|
410 end
|
yellowfive@161
|
411
|
yellowfive@161
|
412 -- check bank data
|
yellowfive@161
|
413 if Amr.db.char.BankItems then
|
yellowfive@161
|
414 for bagId, v in pairs(Amr.db.char.BankItems) do
|
yellowfive@161
|
415 if not usedItems[bagId] then
|
yellowfive@161
|
416 usedItems[bagId] = {}
|
yellowfive@161
|
417 end
|
yellowfive@161
|
418
|
yellowfive@161
|
419 for i, itemData in ipairs(v) do
|
yellowfive@161
|
420 if itemData and not usedItems[bagId][i] then
|
yellowfive@161
|
421 -- see if it matches
|
yellowfive@161
|
422 if Amr.CountItemDifferences(matchItem, itemData) == 0 then
|
yellowfive@161
|
423 usedItems[bagId][i] = true
|
yellowfive@161
|
424 itemData.bagId = bagId
|
yellowfive@161
|
425 itemData.slotId = i
|
yellowfive@161
|
426 return itemData
|
yellowfive@161
|
427 end
|
yellowfive@161
|
428 end
|
yellowfive@161
|
429 end
|
yellowfive@161
|
430 end
|
yellowfive@161
|
431 end
|
yellowfive@161
|
432
|
yellowfive@161
|
433 return nil
|
yellowfive@161
|
434 end
|
yellowfive@161
|
435
|
yellowfive@161
|
436 local function renderItem(item, itemLink, scroll)
|
yellowfive@161
|
437
|
yellowfive@161
|
438 local panel = AceGUI:Create("AmrUiPanel")
|
yellowfive@161
|
439 scroll:AddChild(panel)
|
yellowfive@161
|
440 panel:SetLayout("None")
|
yellowfive@161
|
441 panel:SetTransparent()
|
yellowfive@161
|
442 panel:SetWidth(380)
|
yellowfive@161
|
443 panel:SetHeight(40)
|
yellowfive@161
|
444
|
yellowfive@161
|
445 -- ilvl label
|
yellowfive@161
|
446 local lblIlvl = AceGUI:Create("AmrUiLabel")
|
yellowfive@161
|
447 panel:AddChild(lblIlvl)
|
yellowfive@161
|
448 lblIlvl:SetPoint("LEFT", panel.content, "LEFT", 0, 0)
|
yellowfive@161
|
449 lblIlvl:SetWidth(35)
|
yellowfive@161
|
450 lblIlvl:SetFont(Amr.CreateFont("Italic", 13, Amr.Colors.TextTan))
|
yellowfive@161
|
451
|
yellowfive@161
|
452 -- icon
|
yellowfive@161
|
453 local icon = AceGUI:Create("AmrUiIcon")
|
yellowfive@161
|
454 panel:AddChild(icon)
|
yellowfive@161
|
455 icon:SetBorderWidth(1)
|
yellowfive@161
|
456 icon:SetIconBorderColor(Amr.Colors.White)
|
yellowfive@161
|
457 icon:SetWidth(28)
|
yellowfive@161
|
458 icon:SetHeight(28)
|
yellowfive@161
|
459 icon:SetPoint("LEFT", lblIlvl.frame, "RIGHT", 0, 0)
|
yellowfive@161
|
460
|
yellowfive@161
|
461 -- item name/link label
|
yellowfive@161
|
462 local lblItem = AceGUI:Create("AmrUiTextButton")
|
yellowfive@161
|
463 panel:AddChild(lblItem)
|
yellowfive@161
|
464 lblItem:SetPoint("LEFT", icon.frame, "RIGHT", 0, 0)
|
yellowfive@161
|
465 lblItem:SetWordWrap(false)
|
yellowfive@161
|
466 lblItem:SetJustifyH("LEFT")
|
yellowfive@161
|
467 lblItem:SetWidth(300)
|
yellowfive@161
|
468 lblItem:SetHeight(28)
|
yellowfive@161
|
469 lblItem:SetFont(Amr.CreateFont("Regular", 13, Amr.Colors.White))
|
yellowfive@161
|
470 lblItem:SetHoverBackgroundColor(Amr.Colors.Black, 0.3)
|
yellowfive@161
|
471 lblItem:SetTextPadding(0, 0, 0, 5)
|
yellowfive@161
|
472 lblItem:SetCallback("PreClick", onItemPreClick)
|
yellowfive@161
|
473 lblItem:SetCallback("OnClick", onItemClick)
|
yellowfive@161
|
474 lblItem:SetUserData("itemData", item)
|
yellowfive@161
|
475
|
yellowfive@161
|
476 -- fill the name/ilvl labels, which may require asynchronous loading of item information
|
yellowfive@161
|
477 if itemLink then
|
yellowfive@161
|
478 local gameItem = Item:CreateFromItemLink(itemLink)
|
yellowfive@161
|
479 if gameItem then
|
yellowfive@161
|
480 local q = gameItem:GetItemQuality()
|
yellowfive@161
|
481 lblItem:SetFont(Amr.CreateFont("Regular", 13, Amr.Colors.Qualities[q] or Amr.Colors.White))
|
yellowfive@161
|
482 lblItem:SetHoverFont(Amr.CreateFont("Regular", 13, Amr.Colors.Qualities[q] or Amr.Colors.White))
|
yellowfive@161
|
483 lblItem:SetText(gameItem:GetItemName())
|
yellowfive@161
|
484 lblIlvl:SetText(gameItem:GetCurrentItemLevel())
|
yellowfive@161
|
485 icon:SetIconBorderColor(Amr.Colors.Qualities[q] or Amr.Colors.White)
|
yellowfive@161
|
486 icon:SetIcon(gameItem:GetItemIcon())
|
yellowfive@161
|
487 Amr:SetItemTooltip(lblItem, gameItem:GetItemLink(), "ANCHOR_BOTTOMRIGHT", 0, 30)
|
yellowfive@161
|
488 end
|
yellowfive@161
|
489 end
|
yellowfive@161
|
490
|
yellowfive@161
|
491 end
|
yellowfive@161
|
492
|
yellowfive@161
|
493 --
|
yellowfive@161
|
494 -- Just updates state without re-rendering the list of junk
|
yellowfive@161
|
495 --
|
yellowfive@161
|
496 function Amr:SetJunkUiState()
|
yellowfive@161
|
497
|
yellowfive@161
|
498 -- don't do anything if the window is not open
|
yellowfive@161
|
499 if not _frameJunk then return end
|
yellowfive@161
|
500
|
yellowfive@161
|
501 -- cache whether the player can disenchant whenever the ui is refreshed
|
yellowfive@161
|
502 _canDisenchant = canDisenchant()
|
yellowfive@161
|
503
|
yellowfive@161
|
504 -- update action label
|
yellowfive@161
|
505 if _isScrapOpen then
|
yellowfive@161
|
506 _lblAction:SetText(L.JunkScrap)
|
yellowfive@161
|
507 elseif _isMerchantOpen then
|
yellowfive@161
|
508 _lblAction:SetText(L.JunkVendor)
|
yellowfive@161
|
509 elseif _canDisenchant then
|
yellowfive@161
|
510 _lblAction:SetText(L.JunkDisenchant)
|
yellowfive@161
|
511 else
|
yellowfive@161
|
512 _lblAction:SetText(" ")
|
yellowfive@161
|
513 end
|
yellowfive@161
|
514
|
yellowfive@161
|
515 -- update bank button state
|
yellowfive@161
|
516 _btnBank:SetDisabled(not _isBankOpen)
|
yellowfive@161
|
517 end
|
yellowfive@161
|
518
|
yellowfive@161
|
519 --
|
yellowfive@161
|
520 -- Refresh the entire UI, including re-rendering the junk list
|
yellowfive@161
|
521 --
|
yellowfive@161
|
522 function Amr:RefreshJunkUi()
|
yellowfive@161
|
523
|
yellowfive@161
|
524 -- don't do anything if the window is not open
|
yellowfive@161
|
525 if not _frameJunk then return end
|
yellowfive@161
|
526
|
yellowfive@161
|
527 Amr:SetJunkUiState()
|
yellowfive@161
|
528
|
yellowfive@161
|
529 -- clear out any previous data
|
yellowfive@161
|
530 _panelContent:ReleaseChildren()
|
yellowfive@161
|
531
|
yellowfive@161
|
532 local data = Amr.db.char.JunkData
|
yellowfive@161
|
533
|
yellowfive@161
|
534 if not data or not data.Junk or #data.Junk <= 0 then
|
yellowfive@161
|
535 local lbl = AceGUI:Create("AmrUiLabel")
|
yellowfive@161
|
536 _panelContent:AddChild(lbl)
|
yellowfive@161
|
537 lbl:SetFont(Amr.CreateFont("Italic", 16, Amr.Colors.TextGray))
|
yellowfive@161
|
538 lbl:SetText(L.JunkEmpty)
|
yellowfive@161
|
539 lbl:SetPoint("TOPLEFT", _panelContent.content, "TOPLEFT", 0, -10)
|
yellowfive@161
|
540 _lblBank:SetVisible(false)
|
yellowfive@161
|
541 _btnBank:SetVisible(false)
|
yellowfive@161
|
542 else
|
yellowfive@161
|
543
|
yellowfive@161
|
544 _panelContent:SetLayout("Fill")
|
yellowfive@161
|
545
|
yellowfive@161
|
546 local scroll = AceGUI:Create("AmrUiScrollFrame")
|
yellowfive@161
|
547 scroll:SetLayout("List")
|
yellowfive@161
|
548 _panelContent:AddChild(scroll)
|
yellowfive@161
|
549
|
yellowfive@161
|
550 -- render items currently in the player's inventory
|
yellowfive@161
|
551 local usedItems = {}
|
yellowfive@161
|
552 local bankCount = 0
|
yellowfive@161
|
553 local missingCount = 0
|
yellowfive@161
|
554
|
yellowfive@161
|
555 -- if we have any "keep" items, those are exact duplicates of ones to be junked,
|
yellowfive@161
|
556 -- be sure to "reserve" those first
|
yellowfive@161
|
557 if data.Keep then
|
yellowfive@161
|
558 for uniqueId, item in pairs(data.Keep) do
|
yellowfive@161
|
559 -- check if an exact match is in the player's bank data or equipped
|
yellowfive@161
|
560 local matchItem = findMatchingNonBagItem(item, usedItems)
|
yellowfive@161
|
561
|
yellowfive@161
|
562 -- if not, find one in the player's bags
|
yellowfive@161
|
563 if not matchItem then
|
yellowfive@161
|
564 matchItem = findMatchingBagItem(item, usedItems)
|
yellowfive@161
|
565 end
|
yellowfive@161
|
566
|
yellowfive@161
|
567 if not matchItem then
|
yellowfive@161
|
568 -- abort, player's data must be out of sync
|
yellowfive@161
|
569 local lbl = AceGUI:Create("AmrUiLabel")
|
yellowfive@161
|
570 _panelContent:AddChild(lbl)
|
yellowfive@161
|
571 lbl:SetWidth(380)
|
yellowfive@161
|
572 lbl:SetFont(Amr.CreateFont("Italic", 13, Amr.Colors.TextGray))
|
yellowfive@161
|
573 lbl:SetText(L.JunkOutOfSync)
|
yellowfive@161
|
574 lbl:SetPoint("TOPLEFT", _panelContent.content, "TOPLEFT", 0, -10)
|
yellowfive@161
|
575
|
yellowfive@161
|
576 _lblBank:SetVisible(false)
|
yellowfive@161
|
577 _btnBank:SetVisible(false)
|
yellowfive@161
|
578
|
yellowfive@161
|
579 return
|
yellowfive@161
|
580 end
|
yellowfive@161
|
581 end
|
yellowfive@161
|
582 end
|
yellowfive@161
|
583
|
yellowfive@161
|
584 -- now render any junk items in the player's bags, and a count of how many are elsewhere (usually bank)
|
yellowfive@161
|
585 for i, item in ipairs(data.Junk) do
|
yellowfive@161
|
586 local matchItem = findMatchingBagItem(item, usedItems)
|
yellowfive@161
|
587 if matchItem then
|
yellowfive@161
|
588 local itemLink = Amr.CreateItemLink(matchItem)
|
yellowfive@161
|
589 renderItem(matchItem, itemLink, scroll)
|
yellowfive@161
|
590 else
|
yellowfive@161
|
591 -- see if it is in the bank or equipped
|
yellowfive@161
|
592 matchItem = findMatchingNonBagItem(item, usedItems)
|
yellowfive@161
|
593 if matchItem then
|
yellowfive@161
|
594 bankCount = bankCount + 1
|
yellowfive@161
|
595 else
|
yellowfive@161
|
596 missingCount = missingCount + 1
|
yellowfive@161
|
597 end
|
yellowfive@161
|
598 end
|
yellowfive@161
|
599 end
|
yellowfive@161
|
600
|
yellowfive@161
|
601 _lblBank:SetText(L.JunkBankText(bankCount))
|
yellowfive@161
|
602 _lblBank:SetVisible(bankCount > 0)
|
yellowfive@161
|
603 _btnBank:SetVisible(bankCount > 0)
|
yellowfive@161
|
604
|
yellowfive@161
|
605 -- in most cases, this is because the user has sold/scrapped the items already
|
yellowfive@161
|
606 --if missingCount > 0 then
|
yellowfive@161
|
607 -- Amr:Print(L.JunkMissingText(missingCount))
|
yellowfive@161
|
608 --end
|
yellowfive@161
|
609 end
|
yellowfive@161
|
610 end
|
yellowfive@161
|
611
|
yellowfive@161
|
612 Amr:AddEventHandler("SCRAPPING_MACHINE_SHOW", function()
|
yellowfive@161
|
613 _isScrapOpen = true
|
yellowfive@161
|
614 if Amr.db.profile.options.junkVendor and Amr.db.char.JunkData and Amr.db.char.JunkData.Junk and #Amr.db.char.JunkData.Junk > 0 then
|
yellowfive@161
|
615 Amr:ShowJunkWindow()
|
yellowfive@161
|
616 else
|
yellowfive@161
|
617 Amr:SetJunkUiState()
|
yellowfive@161
|
618 end
|
yellowfive@161
|
619 end)
|
yellowfive@161
|
620
|
yellowfive@161
|
621 Amr:AddEventHandler("SCRAPPING_MACHINE_CLOSE", function()
|
yellowfive@161
|
622 _isScrapOpen = false
|
yellowfive@161
|
623 if Amr.db.profile.options.junkVendor then
|
yellowfive@161
|
624 Amr:HideJunkWindow()
|
yellowfive@161
|
625 else
|
yellowfive@161
|
626 Amr:SetJunkUiState()
|
yellowfive@161
|
627 end
|
yellowfive@161
|
628 end)
|
yellowfive@161
|
629
|
yellowfive@161
|
630 Amr:AddEventHandler("MERCHANT_SHOW", function()
|
yellowfive@161
|
631 _isMerchantOpen = true
|
yellowfive@161
|
632 if Amr.db.profile.options.junkVendor and Amr.db.char.JunkData and Amr.db.char.JunkData.Junk and #Amr.db.char.JunkData.Junk > 0 then
|
yellowfive@161
|
633 Amr:ShowJunkWindow()
|
yellowfive@161
|
634 else
|
yellowfive@161
|
635 Amr:SetJunkUiState()
|
yellowfive@161
|
636 end
|
yellowfive@161
|
637 end)
|
yellowfive@161
|
638
|
yellowfive@161
|
639 Amr:AddEventHandler("MERCHANT_CLOSED", function()
|
yellowfive@161
|
640 _isMerchantOpen = false
|
yellowfive@161
|
641 if Amr.db.profile.options.junkVendor then
|
yellowfive@161
|
642 Amr:HideJunkWindow()
|
yellowfive@161
|
643 else
|
yellowfive@161
|
644 Amr:SetJunkUiState()
|
yellowfive@161
|
645 end
|
yellowfive@161
|
646 end)
|
yellowfive@161
|
647
|
yellowfive@161
|
648 Amr:AddEventHandler("BANKFRAME_OPENED", function()
|
yellowfive@161
|
649 _isBankOpen = true
|
yellowfive@161
|
650 Amr:SetJunkUiState()
|
yellowfive@161
|
651 end)
|
yellowfive@161
|
652
|
yellowfive@161
|
653 Amr:AddEventHandler("BANKFRAME_CLOSED", function()
|
yellowfive@161
|
654 _isBankOpen = false
|
yellowfive@161
|
655 Amr:SetJunkUiState()
|
yellowfive@161
|
656 end)
|