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 -- reset state
|
yellowfive@161
|
180 _bankUsedBagSlots = nil
|
yellowfive@161
|
181 _btnBank:SetDisabled(not _isBankOpen)
|
yellowfive@161
|
182
|
yellowfive@161
|
183 -- re-render the junk list
|
yellowfive@161
|
184 Amr:RefreshJunkUi()
|
yellowfive@161
|
185 end
|
yellowfive@161
|
186 end
|
yellowfive@161
|
187
|
yellowfive@161
|
188 doBankWithdraw = function()
|
yellowfive@161
|
189 if not _isBankOpen then return end
|
yellowfive@161
|
190
|
yellowfive@161
|
191 local data = Amr.db.char.JunkData
|
yellowfive@161
|
192 if not data.Junk then return end
|
yellowfive@161
|
193
|
yellowfive@161
|
194 -- disable button while processing
|
yellowfive@161
|
195 _btnBank:SetDisabled(true)
|
yellowfive@161
|
196
|
yellowfive@161
|
197 local bagList = {}
|
yellowfive@161
|
198 table.insert(bagList, BANK_CONTAINER)
|
yellowfive@161
|
199 for bagId = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS do
|
yellowfive@161
|
200 table.insert(bagList, bagId)
|
yellowfive@161
|
201 end
|
yellowfive@161
|
202
|
yellowfive@161
|
203 local usedItems = {}
|
yellowfive@161
|
204 _bankUsedBagSlots = {}
|
yellowfive@161
|
205
|
yellowfive@161
|
206 for i,item in ipairs(data.Junk) do
|
yellowfive@161
|
207 -- stop immediately if the bank is closed
|
yellowfive@161
|
208 if not _isBankOpen then
|
yellowfive@161
|
209 finishBankWithdraw()
|
yellowfive@161
|
210 return
|
yellowfive@161
|
211 end
|
yellowfive@161
|
212
|
yellowfive@161
|
213 -- check if already in bags
|
yellowfive@161
|
214 local matchItem = findMatchingBagItem(item, usedItems)
|
yellowfive@161
|
215 if not matchItem then
|
yellowfive@161
|
216 -- find it in the bank
|
yellowfive@161
|
217 for j = 1, #bagList do
|
yellowfive@161
|
218 matchItem = scanBag(bagList[j], item, usedItems)
|
yellowfive@161
|
219 if matchItem then break end
|
yellowfive@161
|
220 end
|
yellowfive@161
|
221 else
|
yellowfive@161
|
222 matchItem = nil
|
yellowfive@161
|
223 end
|
yellowfive@161
|
224
|
yellowfive@161
|
225 if matchItem then
|
yellowfive@161
|
226 -- move it to the player's bags if there is space
|
yellowfive@161
|
227 local bagId, slotId = Amr.FindFirstEmptyBagSlot(_bankUsedBagSlots)
|
yellowfive@161
|
228 if bagId then
|
yellowfive@161
|
229 UseContainerItem(matchItem.bagId, matchItem.slotId)
|
yellowfive@161
|
230 else
|
yellowfive@161
|
231 -- no more empty bag slots
|
yellowfive@161
|
232 break
|
yellowfive@161
|
233 end
|
yellowfive@161
|
234 end
|
yellowfive@161
|
235 end
|
yellowfive@161
|
236
|
yellowfive@161
|
237 -- wait a second and see if all the moves actually finished
|
yellowfive@161
|
238 Amr.Wait(1, function()
|
yellowfive@161
|
239 finishBankWithdraw()
|
yellowfive@161
|
240 end)
|
yellowfive@161
|
241 end
|
yellowfive@161
|
242
|
yellowfive@161
|
243 local function onBankClick()
|
yellowfive@161
|
244 if not _frameJunk or not _isBankOpen then return end
|
yellowfive@161
|
245
|
yellowfive@161
|
246 doBankWithdraw()
|
yellowfive@161
|
247 end
|
yellowfive@161
|
248
|
yellowfive@161
|
249
|
yellowfive@161
|
250 local function onJunkFrameClose(widget)
|
yellowfive@161
|
251 AceGUI:Release(widget)
|
yellowfive@161
|
252 _frameJunk = nil
|
yellowfive@161
|
253 _lblAction = nil
|
yellowfive@161
|
254 _lblBank = nil
|
yellowfive@161
|
255 _btnBank = nil
|
yellowfive@161
|
256 _panelContent = nil
|
yellowfive@161
|
257 end
|
yellowfive@161
|
258
|
yellowfive@161
|
259 function Amr:HideJunkWindow()
|
yellowfive@161
|
260 if not _frameJunk then return end
|
yellowfive@161
|
261 _frameJunk:Hide()
|
yellowfive@161
|
262 end
|
yellowfive@161
|
263
|
yellowfive@161
|
264 function Amr:ShowJunkWindow()
|
yellowfive@161
|
265
|
yellowfive@161
|
266 if not _frameJunk then
|
yellowfive@161
|
267 _frameJunk = AceGUI:Create("AmrUiFrame")
|
yellowfive@161
|
268 _frameJunk:SetStatusTable(Amr.db.profile.junkWindow) -- window position is remembered in db
|
yellowfive@161
|
269 _frameJunk:SetCallback("OnClose", onJunkFrameClose)
|
yellowfive@161
|
270 _frameJunk:SetLayout("None")
|
yellowfive@161
|
271 _frameJunk:SetWidth(400)
|
yellowfive@161
|
272 _frameJunk:SetHeight(700)
|
yellowfive@161
|
273 _frameJunk:SetBorderColor(Amr.Colors.BorderBlue)
|
yellowfive@161
|
274 _frameJunk:SetBackgroundColor(Amr.Colors.Bg)
|
yellowfive@161
|
275
|
yellowfive@161
|
276 if Amr.db.profile.options.uiScale ~= 1 then
|
yellowfive@161
|
277 local scale = tonumber(Amr.db.profile.options.uiScale)
|
yellowfive@161
|
278 _frameJunk:SetScale(scale)
|
yellowfive@161
|
279 end
|
yellowfive@161
|
280
|
yellowfive@161
|
281 local lbl = AceGUI:Create("AmrUiLabel")
|
yellowfive@161
|
282 _frameJunk:AddChild(lbl)
|
yellowfive@161
|
283 lbl:SetWidth(300)
|
yellowfive@161
|
284 lbl:SetFont(Amr.CreateFont("Bold", 28, Amr.Colors.White))
|
yellowfive@161
|
285 lbl:SetText(L.JunkTitle)
|
yellowfive@161
|
286 lbl:SetWordWrap(false)
|
yellowfive@161
|
287 lbl:SetJustifyH("CENTER")
|
yellowfive@161
|
288 lbl:SetPoint("TOP", _frameJunk.content, "TOP", 0, 30)
|
yellowfive@161
|
289 lbl:SetCallback("OnMouseDown", function(widget) _frameJunk:StartMove() end)
|
yellowfive@161
|
290 lbl:SetCallback("OnMouseUp", function(widget) _frameJunk:EndMove() end)
|
yellowfive@161
|
291
|
yellowfive@161
|
292 _lblAction = AceGUI:Create("AmrUiLabel")
|
yellowfive@161
|
293 _frameJunk:AddChild(_lblAction)
|
yellowfive@161
|
294 _lblAction:SetWidth(380)
|
yellowfive@161
|
295 _lblAction:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.TextTan))
|
yellowfive@161
|
296 _lblAction:SetText(" ")
|
yellowfive@161
|
297 _lblAction:SetWordWrap(false)
|
yellowfive@161
|
298 _lblAction:SetPoint("TOPLEFT", _frameJunk.content, "TOPLEFT", 0, -10)
|
yellowfive@161
|
299
|
yellowfive@161
|
300 _btnBank = AceGUI:Create("AmrUiButton")
|
yellowfive@161
|
301 _frameJunk:AddChild(_btnBank)
|
yellowfive@161
|
302 _btnBank:SetText(L.JunkButtonBank)
|
yellowfive@161
|
303 _btnBank:SetBackgroundColor(Amr.Colors.Green)
|
yellowfive@161
|
304 _btnBank:SetFont(Amr.CreateFont("Bold", 14, Amr.Colors.White))
|
yellowfive@161
|
305 _btnBank:SetWidth(180)
|
yellowfive@161
|
306 _btnBank:SetHeight(26)
|
yellowfive@161
|
307 _btnBank:SetDisabled(true)
|
yellowfive@161
|
308 _btnBank:SetCallback("OnClick", onBankClick)
|
yellowfive@161
|
309 _btnBank:SetPoint("BOTTOMLEFT", _frameJunk.content, "BOTTOMLEFT")
|
yellowfive@161
|
310
|
yellowfive@161
|
311 _lblBank = AceGUI:Create("AmrUiLabel")
|
yellowfive@161
|
312 _frameJunk:AddChild(_lblBank)
|
yellowfive@161
|
313 _lblBank:SetWidth(380)
|
yellowfive@161
|
314 _lblBank:SetFont(Amr.CreateFont("Bold", 15, Amr.Colors.TextHeaderActive))
|
yellowfive@161
|
315 _lblBank:SetText(L.JunkBankText(0))
|
yellowfive@161
|
316 _lblBank:SetPoint("BOTTOMLEFT", _btnBank.frame, "TOPLEFT", 0, 10)
|
yellowfive@161
|
317
|
yellowfive@161
|
318 local line = AceGUI:Create("AmrUiPanel")
|
yellowfive@161
|
319 _frameJunk:AddChild(line)
|
yellowfive@161
|
320 line:SetHeight(1)
|
yellowfive@161
|
321 line:SetBackgroundColor(Amr.Colors.White)
|
yellowfive@161
|
322 line:SetPoint("TOPLEFT", _frameJunk.content, "TOPLEFT", 0, -30)
|
yellowfive@161
|
323 line:SetPoint("TOPRIGHT", _frameJunk.content, "TOPRIGHT", 0, -30)
|
yellowfive@161
|
324
|
yellowfive@161
|
325 line = AceGUI:Create("AmrUiPanel")
|
yellowfive@161
|
326 _frameJunk:AddChild(line)
|
yellowfive@161
|
327 line:SetHeight(1)
|
yellowfive@161
|
328 line:SetBackgroundColor(Amr.Colors.White)
|
yellowfive@161
|
329 line:SetPoint("TOPLEFT", _frameJunk.content, "BOTTOMLEFT", 0, 60)
|
yellowfive@161
|
330 line:SetPoint("TOPRIGHT", _frameJunk.content, "BOTTOMRIGHT", 0, 60)
|
yellowfive@161
|
331
|
yellowfive@161
|
332 _panelContent = AceGUI:Create("AmrUiPanel")
|
yellowfive@161
|
333 _panelContent:SetLayout("None")
|
yellowfive@161
|
334 _panelContent:SetTransparent()
|
yellowfive@161
|
335 _frameJunk:AddChild(_panelContent)
|
yellowfive@161
|
336 _panelContent:SetPoint("TOPLEFT", _frameJunk.content, "TOPLEFT", 0, -31)
|
yellowfive@161
|
337 _panelContent:SetPoint("BOTTOMRIGHT", _frameJunk.content, "BOTTOMRIGHT", 0, 60)
|
yellowfive@161
|
338
|
yellowfive@161
|
339
|
yellowfive@161
|
340 Amr:RefreshJunkUi()
|
yellowfive@161
|
341 else
|
yellowfive@161
|
342 _frameJunk:Show()
|
yellowfive@161
|
343 Amr:RefreshJunkUi()
|
yellowfive@161
|
344 end
|
yellowfive@161
|
345
|
yellowfive@161
|
346 _frameJunk:Raise()
|
yellowfive@161
|
347 end
|
yellowfive@161
|
348
|
yellowfive@161
|
349 local function canDisenchant()
|
yellowfive@161
|
350
|
yellowfive@161
|
351 local prof1, prof2 = GetProfessions();
|
yellowfive@161
|
352 local profs = {}
|
yellowfive@161
|
353 table.insert(profs, prof1)
|
yellowfive@161
|
354 table.insert(profs, prof2)
|
yellowfive@161
|
355 for i,prof in ipairs(profs) do
|
yellowfive@161
|
356 if prof then
|
yellowfive@161
|
357 local _, _, skillLevel, _, _, _, skillLine = GetProfessionInfo(prof);
|
yellowfive@161
|
358 if Amr.ProfessionSkillLineToName[skillLine] == "Enchanting" and skillLevel > 0 then
|
yellowfive@161
|
359 return true
|
yellowfive@161
|
360 end
|
yellowfive@161
|
361 end
|
yellowfive@161
|
362 end
|
yellowfive@161
|
363
|
yellowfive@161
|
364 return false
|
yellowfive@161
|
365 end
|
yellowfive@161
|
366
|
yellowfive@161
|
367 --
|
yellowfive@161
|
368 -- Find a matching item that is not in the player's inventory (bank or equipped)
|
yellowfive@161
|
369 --
|
yellowfive@161
|
370 local function findMatchingNonBagItem(matchItem, usedItems)
|
yellowfive@161
|
371
|
yellowfive@161
|
372 local loc = ItemLocation.CreateEmpty()
|
yellowfive@161
|
373
|
yellowfive@161
|
374 -- check equipped
|
yellowfive@161
|
375 local equippedBagId = -1000
|
yellowfive@161
|
376 if not usedItems[equippedBagId] then
|
yellowfive@161
|
377 usedItems[equippedBagId] = {}
|
yellowfive@161
|
378 end
|
yellowfive@161
|
379
|
yellowfive@161
|
380 for slotNum = 1, #Amr.SlotIds do
|
yellowfive@161
|
381 local slotId = Amr.SlotIds[slotNum]
|
yellowfive@161
|
382 if not usedItems[equippedBagId][slotId] then
|
yellowfive@161
|
383 local itemLink = GetInventoryItemLink("player", slotId)
|
yellowfive@161
|
384 if itemLink then
|
yellowfive@161
|
385 local itemData = Amr.ParseItemLink(itemLink)
|
yellowfive@161
|
386 if itemData then
|
yellowfive@161
|
387 -- see if this is an azerite item and read azerite power ids
|
yellowfive@161
|
388 loc:SetEquipmentSlot(slotId)
|
yellowfive@161
|
389 if C_AzeriteEmpoweredItem.IsAzeriteEmpoweredItem(loc) then
|
yellowfive@161
|
390 local powers = Amr.ReadAzeritePowers(loc)
|
yellowfive@161
|
391 if powers then
|
yellowfive@161
|
392 itemData.azerite = powers
|
yellowfive@161
|
393 end
|
yellowfive@161
|
394 end
|
yellowfive@161
|
395
|
yellowfive@161
|
396 -- see if it matches
|
yellowfive@161
|
397 if Amr.CountItemDifferences(matchItem, itemData) == 0 then
|
yellowfive@161
|
398 usedItems[equippedBagId][slotId] = true
|
yellowfive@161
|
399 itemData.bagId = bagId
|
yellowfive@161
|
400 itemData.slotId = slotId
|
yellowfive@161
|
401 return itemData
|
yellowfive@161
|
402 end
|
yellowfive@161
|
403 end
|
yellowfive@161
|
404 end
|
yellowfive@161
|
405 end
|
yellowfive@161
|
406 end
|
yellowfive@161
|
407
|
yellowfive@161
|
408 -- check bank data
|
yellowfive@161
|
409 if Amr.db.char.BankItems then
|
yellowfive@161
|
410 for bagId, v in pairs(Amr.db.char.BankItems) do
|
yellowfive@161
|
411 if not usedItems[bagId] then
|
yellowfive@161
|
412 usedItems[bagId] = {}
|
yellowfive@161
|
413 end
|
yellowfive@161
|
414
|
yellowfive@161
|
415 for i, itemData in ipairs(v) do
|
yellowfive@161
|
416 if itemData and not usedItems[bagId][i] then
|
yellowfive@161
|
417 -- see if it matches
|
yellowfive@161
|
418 if Amr.CountItemDifferences(matchItem, itemData) == 0 then
|
yellowfive@161
|
419 usedItems[bagId][i] = true
|
yellowfive@161
|
420 itemData.bagId = bagId
|
yellowfive@161
|
421 itemData.slotId = i
|
yellowfive@161
|
422 return itemData
|
yellowfive@161
|
423 end
|
yellowfive@161
|
424 end
|
yellowfive@161
|
425 end
|
yellowfive@161
|
426 end
|
yellowfive@161
|
427 end
|
yellowfive@161
|
428
|
yellowfive@161
|
429 return nil
|
yellowfive@161
|
430 end
|
yellowfive@161
|
431
|
yellowfive@161
|
432 local function renderItem(item, itemLink, scroll)
|
yellowfive@161
|
433
|
yellowfive@161
|
434 local panel = AceGUI:Create("AmrUiPanel")
|
yellowfive@161
|
435 scroll:AddChild(panel)
|
yellowfive@161
|
436 panel:SetLayout("None")
|
yellowfive@161
|
437 panel:SetTransparent()
|
yellowfive@161
|
438 panel:SetWidth(380)
|
yellowfive@161
|
439 panel:SetHeight(40)
|
yellowfive@161
|
440
|
yellowfive@161
|
441 -- ilvl label
|
yellowfive@161
|
442 local lblIlvl = AceGUI:Create("AmrUiLabel")
|
yellowfive@161
|
443 panel:AddChild(lblIlvl)
|
yellowfive@161
|
444 lblIlvl:SetPoint("LEFT", panel.content, "LEFT", 0, 0)
|
yellowfive@161
|
445 lblIlvl:SetWidth(35)
|
yellowfive@161
|
446 lblIlvl:SetFont(Amr.CreateFont("Italic", 13, Amr.Colors.TextTan))
|
yellowfive@161
|
447
|
yellowfive@161
|
448 -- icon
|
yellowfive@161
|
449 local icon = AceGUI:Create("AmrUiIcon")
|
yellowfive@161
|
450 panel:AddChild(icon)
|
yellowfive@161
|
451 icon:SetBorderWidth(1)
|
yellowfive@161
|
452 icon:SetIconBorderColor(Amr.Colors.White)
|
yellowfive@161
|
453 icon:SetWidth(28)
|
yellowfive@161
|
454 icon:SetHeight(28)
|
yellowfive@161
|
455 icon:SetPoint("LEFT", lblIlvl.frame, "RIGHT", 0, 0)
|
yellowfive@161
|
456
|
yellowfive@161
|
457 -- item name/link label
|
yellowfive@161
|
458 local lblItem = AceGUI:Create("AmrUiTextButton")
|
yellowfive@161
|
459 panel:AddChild(lblItem)
|
yellowfive@161
|
460 lblItem:SetPoint("LEFT", icon.frame, "RIGHT", 0, 0)
|
yellowfive@161
|
461 lblItem:SetWordWrap(false)
|
yellowfive@161
|
462 lblItem:SetJustifyH("LEFT")
|
yellowfive@161
|
463 lblItem:SetWidth(300)
|
yellowfive@161
|
464 lblItem:SetHeight(28)
|
yellowfive@161
|
465 lblItem:SetFont(Amr.CreateFont("Regular", 13, Amr.Colors.White))
|
yellowfive@161
|
466 lblItem:SetHoverBackgroundColor(Amr.Colors.Black, 0.3)
|
yellowfive@161
|
467 lblItem:SetTextPadding(0, 0, 0, 5)
|
yellowfive@161
|
468 lblItem:SetCallback("PreClick", onItemPreClick)
|
yellowfive@161
|
469 lblItem:SetCallback("OnClick", onItemClick)
|
yellowfive@161
|
470 lblItem:SetUserData("itemData", item)
|
yellowfive@161
|
471
|
yellowfive@161
|
472 -- fill the name/ilvl labels, which may require asynchronous loading of item information
|
yellowfive@161
|
473 if itemLink then
|
yellowfive@161
|
474 local gameItem = Item:CreateFromItemLink(itemLink)
|
yellowfive@161
|
475 if gameItem then
|
yellowfive@161
|
476 local q = gameItem:GetItemQuality()
|
yellowfive@161
|
477 lblItem:SetFont(Amr.CreateFont("Regular", 13, Amr.Colors.Qualities[q] or Amr.Colors.White))
|
yellowfive@161
|
478 lblItem:SetHoverFont(Amr.CreateFont("Regular", 13, Amr.Colors.Qualities[q] or Amr.Colors.White))
|
yellowfive@161
|
479 lblItem:SetText(gameItem:GetItemName())
|
yellowfive@161
|
480 lblIlvl:SetText(gameItem:GetCurrentItemLevel())
|
yellowfive@161
|
481 icon:SetIconBorderColor(Amr.Colors.Qualities[q] or Amr.Colors.White)
|
yellowfive@161
|
482 icon:SetIcon(gameItem:GetItemIcon())
|
yellowfive@161
|
483 Amr:SetItemTooltip(lblItem, gameItem:GetItemLink(), "ANCHOR_BOTTOMRIGHT", 0, 30)
|
yellowfive@161
|
484 end
|
yellowfive@161
|
485 end
|
yellowfive@161
|
486
|
yellowfive@161
|
487 end
|
yellowfive@161
|
488
|
yellowfive@161
|
489 --
|
yellowfive@161
|
490 -- Just updates state without re-rendering the list of junk
|
yellowfive@161
|
491 --
|
yellowfive@161
|
492 function Amr:SetJunkUiState()
|
yellowfive@161
|
493
|
yellowfive@161
|
494 -- don't do anything if the window is not open
|
yellowfive@161
|
495 if not _frameJunk then return end
|
yellowfive@161
|
496
|
yellowfive@161
|
497 -- cache whether the player can disenchant whenever the ui is refreshed
|
yellowfive@161
|
498 _canDisenchant = canDisenchant()
|
yellowfive@161
|
499
|
yellowfive@161
|
500 -- update action label
|
yellowfive@161
|
501 if _isScrapOpen then
|
yellowfive@161
|
502 _lblAction:SetText(L.JunkScrap)
|
yellowfive@161
|
503 elseif _isMerchantOpen then
|
yellowfive@161
|
504 _lblAction:SetText(L.JunkVendor)
|
yellowfive@161
|
505 elseif _canDisenchant then
|
yellowfive@161
|
506 _lblAction:SetText(L.JunkDisenchant)
|
yellowfive@161
|
507 else
|
yellowfive@161
|
508 _lblAction:SetText(" ")
|
yellowfive@161
|
509 end
|
yellowfive@161
|
510
|
yellowfive@161
|
511 -- update bank button state
|
yellowfive@161
|
512 _btnBank:SetDisabled(not _isBankOpen)
|
yellowfive@161
|
513 end
|
yellowfive@161
|
514
|
yellowfive@161
|
515 --
|
yellowfive@161
|
516 -- Refresh the entire UI, including re-rendering the junk list
|
yellowfive@161
|
517 --
|
yellowfive@161
|
518 function Amr:RefreshJunkUi()
|
yellowfive@161
|
519
|
yellowfive@161
|
520 -- don't do anything if the window is not open
|
yellowfive@161
|
521 if not _frameJunk then return end
|
yellowfive@161
|
522
|
yellowfive@161
|
523 Amr:SetJunkUiState()
|
yellowfive@161
|
524
|
yellowfive@161
|
525 -- clear out any previous data
|
yellowfive@161
|
526 _panelContent:ReleaseChildren()
|
yellowfive@161
|
527
|
yellowfive@161
|
528 local data = Amr.db.char.JunkData
|
yellowfive@161
|
529
|
yellowfive@161
|
530 if not data or not data.Junk or #data.Junk <= 0 then
|
yellowfive@161
|
531 local lbl = AceGUI:Create("AmrUiLabel")
|
yellowfive@161
|
532 _panelContent:AddChild(lbl)
|
yellowfive@161
|
533 lbl:SetFont(Amr.CreateFont("Italic", 16, Amr.Colors.TextGray))
|
yellowfive@161
|
534 lbl:SetText(L.JunkEmpty)
|
yellowfive@161
|
535 lbl:SetPoint("TOPLEFT", _panelContent.content, "TOPLEFT", 0, -10)
|
yellowfive@161
|
536 _lblBank:SetVisible(false)
|
yellowfive@161
|
537 _btnBank:SetVisible(false)
|
yellowfive@161
|
538 else
|
yellowfive@161
|
539
|
yellowfive@161
|
540 _panelContent:SetLayout("Fill")
|
yellowfive@161
|
541
|
yellowfive@161
|
542 local scroll = AceGUI:Create("AmrUiScrollFrame")
|
yellowfive@161
|
543 scroll:SetLayout("List")
|
yellowfive@161
|
544 _panelContent:AddChild(scroll)
|
yellowfive@161
|
545
|
yellowfive@161
|
546 -- render items currently in the player's inventory
|
yellowfive@161
|
547 local usedItems = {}
|
yellowfive@161
|
548 local bankCount = 0
|
yellowfive@161
|
549 local missingCount = 0
|
yellowfive@161
|
550
|
yellowfive@161
|
551 -- if we have any "keep" items, those are exact duplicates of ones to be junked,
|
yellowfive@161
|
552 -- be sure to "reserve" those first
|
yellowfive@161
|
553 if data.Keep then
|
yellowfive@161
|
554 for uniqueId, item in pairs(data.Keep) do
|
yellowfive@161
|
555 -- check if an exact match is in the player's bank data or equipped
|
yellowfive@161
|
556 local matchItem = findMatchingNonBagItem(item, usedItems)
|
yellowfive@161
|
557
|
yellowfive@161
|
558 -- if not, find one in the player's bags
|
yellowfive@161
|
559 if not matchItem then
|
yellowfive@161
|
560 matchItem = findMatchingBagItem(item, usedItems)
|
yellowfive@161
|
561 end
|
yellowfive@161
|
562
|
yellowfive@161
|
563 if not matchItem then
|
yellowfive@161
|
564 -- abort, player's data must be out of sync
|
yellowfive@161
|
565 local lbl = AceGUI:Create("AmrUiLabel")
|
yellowfive@161
|
566 _panelContent:AddChild(lbl)
|
yellowfive@161
|
567 lbl:SetWidth(380)
|
yellowfive@161
|
568 lbl:SetFont(Amr.CreateFont("Italic", 13, Amr.Colors.TextGray))
|
yellowfive@161
|
569 lbl:SetText(L.JunkOutOfSync)
|
yellowfive@161
|
570 lbl:SetPoint("TOPLEFT", _panelContent.content, "TOPLEFT", 0, -10)
|
yellowfive@161
|
571
|
yellowfive@161
|
572 _lblBank:SetVisible(false)
|
yellowfive@161
|
573 _btnBank:SetVisible(false)
|
yellowfive@161
|
574
|
yellowfive@161
|
575 return
|
yellowfive@161
|
576 end
|
yellowfive@161
|
577 end
|
yellowfive@161
|
578 end
|
yellowfive@161
|
579
|
yellowfive@161
|
580 -- now render any junk items in the player's bags, and a count of how many are elsewhere (usually bank)
|
yellowfive@161
|
581 for i, item in ipairs(data.Junk) do
|
yellowfive@161
|
582 local matchItem = findMatchingBagItem(item, usedItems)
|
yellowfive@161
|
583 if matchItem then
|
yellowfive@161
|
584 local itemLink = Amr.CreateItemLink(matchItem)
|
yellowfive@161
|
585 renderItem(matchItem, itemLink, scroll)
|
yellowfive@161
|
586 else
|
yellowfive@161
|
587 -- see if it is in the bank or equipped
|
yellowfive@161
|
588 matchItem = findMatchingNonBagItem(item, usedItems)
|
yellowfive@161
|
589 if matchItem then
|
yellowfive@161
|
590 bankCount = bankCount + 1
|
yellowfive@161
|
591 else
|
yellowfive@161
|
592 missingCount = missingCount + 1
|
yellowfive@161
|
593 end
|
yellowfive@161
|
594 end
|
yellowfive@161
|
595 end
|
yellowfive@161
|
596
|
yellowfive@161
|
597 _lblBank:SetText(L.JunkBankText(bankCount))
|
yellowfive@161
|
598 _lblBank:SetVisible(bankCount > 0)
|
yellowfive@161
|
599 _btnBank:SetVisible(bankCount > 0)
|
yellowfive@161
|
600 end
|
yellowfive@161
|
601 end
|
yellowfive@161
|
602
|
yellowfive@161
|
603 Amr:AddEventHandler("SCRAPPING_MACHINE_SHOW", function()
|
yellowfive@161
|
604 _isScrapOpen = true
|
yellowfive@161
|
605 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
|
606 Amr:ShowJunkWindow()
|
yellowfive@161
|
607 else
|
yellowfive@161
|
608 Amr:SetJunkUiState()
|
yellowfive@161
|
609 end
|
yellowfive@161
|
610 end)
|
yellowfive@161
|
611
|
yellowfive@161
|
612 Amr:AddEventHandler("SCRAPPING_MACHINE_CLOSE", function()
|
yellowfive@161
|
613 _isScrapOpen = false
|
yellowfive@161
|
614 if Amr.db.profile.options.junkVendor then
|
yellowfive@161
|
615 Amr:HideJunkWindow()
|
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("MERCHANT_SHOW", function()
|
yellowfive@161
|
622 _isMerchantOpen = true
|
yellowfive@161
|
623 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
|
624 Amr:ShowJunkWindow()
|
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_CLOSED", function()
|
yellowfive@161
|
631 _isMerchantOpen = false
|
yellowfive@161
|
632 if Amr.db.profile.options.junkVendor then
|
yellowfive@161
|
633 Amr:HideJunkWindow()
|
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("BANKFRAME_OPENED", function()
|
yellowfive@161
|
640 _isBankOpen = true
|
yellowfive@161
|
641 Amr:SetJunkUiState()
|
yellowfive@161
|
642 end)
|
yellowfive@161
|
643
|
yellowfive@161
|
644 Amr:AddEventHandler("BANKFRAME_CLOSED", function()
|
yellowfive@161
|
645 _isBankOpen = false
|
yellowfive@161
|
646 Amr:SetJunkUiState()
|
yellowfive@161
|
647 end)
|