yellowfive@57
|
1 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
|
yellowfive@57
|
2 local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true)
|
yellowfive@57
|
3 local AceGUI = LibStub("AceGUI-3.0")
|
yellowfive@57
|
4
|
yellowfive@57
|
5 local _gearTabs
|
yellowfive@57
|
6 local _activeTab
|
yellowfive@57
|
7
|
yellowfive@57
|
8 -- Returns a number indicating how different two items are (0 means the same, higher means more different)
|
yellowfive@57
|
9 local function countItemDifferences(item1, item2)
|
yellowfive@57
|
10 if item1 == nil and item2 == nil then return 0 end
|
yellowfive@57
|
11
|
yellowfive@57
|
12 -- different items (id + bonus ids + suffix, constitutes a different physical drop)
|
yellowfive@57
|
13 if Amr.GetItemUniqueId(item1, true) ~= Amr.GetItemUniqueId(item2, true) then
|
yellowfive@57
|
14 return 1000
|
yellowfive@57
|
15 end
|
yellowfive@57
|
16
|
yellowfive@57
|
17 -- different upgrade levels of the same item (only for older gear, player has control over upgrade level)
|
yellowfive@57
|
18 if item1.upgradeId ~= item2.upgradeId then
|
yellowfive@57
|
19 return 100
|
yellowfive@57
|
20 end
|
yellowfive@57
|
21
|
yellowfive@57
|
22 -- different gems
|
yellowfive@57
|
23 local gemDiffs = 0
|
yellowfive@57
|
24 for i = 1, 3 do
|
yellowfive@57
|
25 if item1.gemIds[i] ~= item2.gemIds[i] then
|
yellowfive@57
|
26 gemDiffs = gemDiffs + 1
|
yellowfive@57
|
27 end
|
yellowfive@57
|
28 end
|
yellowfive@57
|
29
|
yellowfive@57
|
30 -- different enchants
|
yellowfive@57
|
31 local enchantDiff = 0
|
yellowfive@57
|
32 if item1.enchantId ~= item2.enchantId then
|
yellowfive@57
|
33 enchantDiff = 1
|
yellowfive@57
|
34 end
|
yellowfive@57
|
35
|
yellowfive@57
|
36 return gemDiffs + enchantDiff
|
yellowfive@57
|
37 end
|
yellowfive@57
|
38
|
yellowfive@57
|
39 -- given a table of items (keyed or indexed doesn't matter) find closest match to item, or nil if none are a match
|
yellowfive@57
|
40 local function findMatchingItemFromTable(item, list, bestLink, bestItem, bestDiff, bestLoc, usedItems, tableType)
|
yellowfive@57
|
41 if not list then return nil end
|
yellowfive@57
|
42
|
yellowfive@57
|
43 for k,v in pairs(list) do
|
yellowfive@57
|
44 local listItem = Amr.ParseItemLink(v)
|
yellowfive@57
|
45 if listItem then
|
yellowfive@57
|
46 local diff = countItemDifferences(item, listItem)
|
yellowfive@57
|
47 if diff < bestDiff then
|
yellowfive@57
|
48 -- each physical item can only be used once, the usedItems table has items we can't use in this search
|
yellowfive@57
|
49 local key = string.format("%s_%s", tableType, k)
|
yellowfive@57
|
50 if not usedItems[key] then
|
yellowfive@57
|
51 bestLink = v
|
yellowfive@57
|
52 bestItem = listItem
|
yellowfive@57
|
53 bestDiff = diff
|
yellowfive@57
|
54 bestLoc = string.format("%s_%s", tableType, k)
|
yellowfive@57
|
55 end
|
yellowfive@57
|
56 end
|
yellowfive@57
|
57 if diff == 0 then break end
|
yellowfive@57
|
58 end
|
yellowfive@57
|
59 end
|
yellowfive@57
|
60
|
yellowfive@57
|
61 return bestLink, bestItem, bestDiff, bestLoc
|
yellowfive@57
|
62 end
|
yellowfive@57
|
63
|
yellowfive@57
|
64 -- search the player's equipped gear, bag, bank, and void storage for an item that best matches the specified item
|
yellowfive@57
|
65 function Amr:FindMatchingItem(item, player, usedItems)
|
yellowfive@57
|
66 if not item then return nil end
|
yellowfive@57
|
67
|
yellowfive@57
|
68 local equipped = player.Equipped and player.Equipped[player.ActiveSpec] or nil
|
yellowfive@57
|
69 local bestLink, bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, equipped, nil, nil, 1000, nil, usedItems, "equip")
|
yellowfive@57
|
70 bestLink, bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, player.BagItems, bestLink, bestItem, bestDiff, bestLoc, usedItems, "bag")
|
yellowfive@57
|
71 bestLink, bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, player.BankItems, bestLink, bestItem, bestDiff, bestLoc, usedItems, "bank")
|
yellowfive@57
|
72 bestLink, bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, player.VoidItems, bestLink, bestItem, bestDiff, bestLoc, usedItems, "void")
|
yellowfive@57
|
73
|
yellowfive@57
|
74 if bestDiff >= 1000 then
|
yellowfive@57
|
75 return nil, nil, 1000
|
yellowfive@57
|
76 else
|
yellowfive@57
|
77 usedItems[bestLoc] = true
|
yellowfive@57
|
78 return bestLink, bestItem, bestDiff
|
yellowfive@57
|
79 end
|
yellowfive@57
|
80 end
|
yellowfive@57
|
81
|
yellowfive@57
|
82 local function renderEmptyGear(container)
|
yellowfive@57
|
83
|
yellowfive@57
|
84 local panelBlank = AceGUI:Create("AmrUiPanel")
|
yellowfive@57
|
85 panelBlank:SetLayout("None")
|
yellowfive@57
|
86 panelBlank:SetBackgroundColor(Amr.Colors.Black, 0.4)
|
yellowfive@57
|
87 panelBlank:SetPoint("TOPLEFT", container.content, "TOPLEFT", 6, 0)
|
yellowfive@57
|
88 panelBlank:SetPoint("BOTTOMRIGHT", container.content, "BOTTOMRIGHT")
|
yellowfive@57
|
89 container:AddChild(panelBlank)
|
yellowfive@57
|
90
|
yellowfive@57
|
91 local lbl = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
92 lbl:SetText(L.GearBlank)
|
yellowfive@57
|
93 lbl:SetWidth(700)
|
yellowfive@57
|
94 lbl:SetJustifyH("MIDDLE")
|
yellowfive@57
|
95 lbl:SetFont(Amr.CreateFont("Italic", 16, Amr.Colors.TextTan))
|
yellowfive@57
|
96 lbl:SetPoint("BOTTOM", panelBlank.content, "CENTER", 0, 20)
|
yellowfive@57
|
97 panelBlank:AddChild(lbl)
|
yellowfive@57
|
98
|
yellowfive@57
|
99 local lbl2 = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
100 lbl2:SetText(L.GearBlank2)
|
yellowfive@57
|
101 lbl2:SetWidth(700)
|
yellowfive@57
|
102 lbl2:SetJustifyH("MIDDLE")
|
yellowfive@57
|
103 lbl2:SetFont(Amr.CreateFont("Italic", 16, Amr.Colors.TextTan))
|
yellowfive@57
|
104 lbl2:SetPoint("TOP", lbl.frame, "CENTER", 0, -20)
|
yellowfive@57
|
105 panelBlank:AddChild(lbl2)
|
yellowfive@57
|
106 end
|
yellowfive@57
|
107
|
yellowfive@57
|
108 local function renderGear(spec, container)
|
yellowfive@57
|
109
|
yellowfive@57
|
110 local player = Amr:ExportCharacter()
|
yellowfive@57
|
111 local gear = Amr.db.char.GearSets[spec]
|
yellowfive@57
|
112 local equipped = player.Equipped[player.ActiveSpec]
|
yellowfive@57
|
113
|
yellowfive@57
|
114 if not gear then
|
yellowfive@57
|
115 -- no gear has been imported for this spec so show a message
|
yellowfive@57
|
116 renderEmptyGear(container)
|
yellowfive@57
|
117 else
|
yellowfive@57
|
118 local panelGear = AceGUI:Create("AmrUiPanel")
|
yellowfive@57
|
119 panelGear:SetLayout("None")
|
yellowfive@57
|
120 panelGear:SetBackgroundColor(Amr.Colors.Black, 0.3)
|
yellowfive@57
|
121 panelGear:SetPoint("TOPLEFT", container.content, "TOPLEFT", 6, 0)
|
yellowfive@57
|
122 panelGear:SetPoint("BOTTOMRIGHT", container.content, "BOTTOMRIGHT", -300, 0)
|
yellowfive@57
|
123 container:AddChild(panelGear)
|
yellowfive@57
|
124
|
yellowfive@57
|
125 local panelMods = AceGUI:Create("AmrUiPanel")
|
yellowfive@57
|
126 panelMods:SetLayout("None")
|
yellowfive@57
|
127 panelMods:SetPoint("TOPLEFT", panelGear.frame, "TOPRIGHT", 15, 0)
|
yellowfive@57
|
128 panelMods:SetPoint("BOTTOMRIGHT", container.content, "BOTTOMRIGHT")
|
yellowfive@57
|
129 panelMods:SetBackgroundColor(Amr.Colors.Black, 0.3)
|
yellowfive@57
|
130 container:AddChild(panelMods)
|
yellowfive@57
|
131
|
yellowfive@57
|
132 -- spec icon
|
yellowfive@57
|
133 local icon = AceGUI:Create("AmrUiIcon")
|
yellowfive@57
|
134 icon:SetIconBorderColor(Amr.Colors.Classes[player.Class])
|
yellowfive@57
|
135 icon:SetWidth(48)
|
yellowfive@57
|
136 icon:SetHeight(48)
|
yellowfive@57
|
137
|
yellowfive@57
|
138 local iconSpec
|
yellowfive@57
|
139 if player.SubSpecs[spec] then
|
yellowfive@57
|
140 iconSpec = player.SubSpecs[spec]
|
yellowfive@57
|
141 else
|
yellowfive@57
|
142 iconSpec = player.Specs[spec]
|
yellowfive@57
|
143 end
|
yellowfive@57
|
144
|
yellowfive@57
|
145 icon:SetIcon("Interface\\Icons\\" .. Amr.SpecIcons[iconSpec])
|
yellowfive@57
|
146 icon:SetPoint("TOPLEFT", panelGear.content, "TOPLEFT", 10, -10)
|
yellowfive@57
|
147 panelGear:AddChild(icon)
|
yellowfive@57
|
148
|
yellowfive@57
|
149 local btnEquip = AceGUI:Create("AmrUiButton")
|
yellowfive@57
|
150 btnEquip:SetText(L.GearButtonEquip(spec))
|
yellowfive@57
|
151 btnEquip:SetBackgroundColor(Amr.Colors.Green)
|
yellowfive@57
|
152 btnEquip:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.White))
|
yellowfive@57
|
153 btnEquip:SetWidth(300)
|
yellowfive@57
|
154 btnEquip:SetHeight(26)
|
yellowfive@57
|
155 btnEquip:SetPoint("LEFT", icon.frame, "RIGHT", 40, 0)
|
yellowfive@57
|
156 btnEquip:SetPoint("RIGHT", panelGear.content, "RIGHT", -40, 0)
|
yellowfive@57
|
157 btnEquip:SetCallback("OnClick", function(widget)
|
yellowfive@57
|
158 Amr:EquipGearSet(spec)
|
yellowfive@57
|
159 end)
|
yellowfive@57
|
160 panelGear:AddChild(btnEquip)
|
yellowfive@57
|
161
|
yellowfive@61
|
162 --[[local btnShop = AceGUI:Create("AmrUiButton")
|
yellowfive@57
|
163 btnShop:SetText(L.GearButtonShop)
|
yellowfive@57
|
164 btnShop:SetBackgroundColor(Amr.Colors.Blue)
|
yellowfive@57
|
165 btnShop:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.White))
|
yellowfive@57
|
166 btnShop:SetWidth(300)
|
yellowfive@57
|
167 btnShop:SetHeight(26)
|
yellowfive@57
|
168 btnShop:SetPoint("LEFT", btnEquip.frame, "RIGHT", 75, 0)
|
yellowfive@57
|
169 btnShop:SetPoint("RIGHT", panelMods.content, "RIGHT", -20, 0)
|
yellowfive@57
|
170 btnShop:SetCallback("OnClick", function(widget) Amr:ShowShopWindow() end)
|
yellowfive@61
|
171 panelMods:AddChild(btnShop)]]
|
yellowfive@57
|
172
|
yellowfive@57
|
173 -- each physical item can only be used once, this tracks ones we have already used
|
yellowfive@57
|
174 local usedItems = {}
|
yellowfive@57
|
175
|
yellowfive@57
|
176 -- gear list
|
yellowfive@57
|
177 local prevElem = icon
|
yellowfive@57
|
178 for slotNum = 1, #Amr.SlotIds do
|
yellowfive@57
|
179 local slotId = Amr.SlotIds[slotNum]
|
yellowfive@57
|
180
|
yellowfive@57
|
181 local equippedItemLink = equipped and equipped[slotId] or nil
|
yellowfive@57
|
182 local equippedItem = Amr.ParseItemLink(equippedItemLink)
|
yellowfive@57
|
183 local optimalItem = gear[slotId]
|
yellowfive@57
|
184 local optimalItemLink = Amr.CreateItemLink(optimalItem)
|
yellowfive@57
|
185
|
yellowfive@57
|
186 -- see if item is currently equipped, is false if don't have any item for that slot (e.g. OH for a 2-hander)
|
yellowfive@57
|
187 local isEquipped = false
|
yellowfive@57
|
188 if equippedItem and optimalItem and Amr.GetItemUniqueId(equippedItem) == Amr.GetItemUniqueId(optimalItem) then
|
yellowfive@57
|
189 isEquipped = true
|
yellowfive@57
|
190 end
|
yellowfive@57
|
191
|
yellowfive@57
|
192 -- find the item in the player's inventory that best matches what the optimization wants to use
|
yellowfive@57
|
193 local matchItemLink, matchItem = Amr:FindMatchingItem(optimalItem, player, usedItems)
|
yellowfive@57
|
194
|
yellowfive@57
|
195 -- slot label
|
yellowfive@57
|
196 local lbl = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
197 lbl:SetText(Amr.SlotDisplayText[slotId])
|
yellowfive@57
|
198 lbl:SetWidth(85)
|
yellowfive@57
|
199 lbl:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.White))
|
yellowfive@57
|
200 lbl:SetPoint("TOPLEFT", prevElem.frame, "BOTTOMLEFT", 0, -12)
|
yellowfive@57
|
201 panelGear:AddChild(lbl)
|
yellowfive@57
|
202 prevElem = lbl
|
yellowfive@57
|
203
|
yellowfive@57
|
204 -- ilvl label
|
yellowfive@57
|
205 local lblIlvl = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
206 lblIlvl:SetWidth(45)
|
yellowfive@57
|
207 lblIlvl:SetFont(Amr.CreateFont("Italic", 14, Amr.Colors.TextTan))
|
yellowfive@57
|
208 lblIlvl:SetPoint("TOPLEFT", lbl.frame, "TOPRIGHT", 0, 0)
|
yellowfive@57
|
209 panelGear:AddChild(lblIlvl)
|
yellowfive@57
|
210
|
yellowfive@57
|
211 -- equipped label
|
yellowfive@57
|
212 local lblEquipped = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
213 lblEquipped:SetWidth(20)
|
yellowfive@57
|
214 lblEquipped:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.White))
|
yellowfive@57
|
215 lblEquipped:SetPoint("TOPLEFT", lblIlvl.frame, "TOPRIGHT", 0, 0)
|
yellowfive@57
|
216 lblEquipped:SetText(isEquipped and "E" or "")
|
yellowfive@57
|
217 panelGear:AddChild(lblEquipped)
|
yellowfive@57
|
218
|
yellowfive@57
|
219 -- item name/link label
|
yellowfive@57
|
220 local lblItem = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
221 lblItem:SetWordWrap(false)
|
yellowfive@57
|
222 lblItem:SetWidth(345)
|
yellowfive@57
|
223 lblItem:SetFont(Amr.CreateFont(isEquipped and "Regular" or "Bold", isEquipped and 14 or 15, Amr.Colors.White))
|
yellowfive@57
|
224 lblItem:SetPoint("TOPLEFT", lblEquipped.frame, "TOPRIGHT", 0, 0)
|
yellowfive@57
|
225 panelGear:AddChild(lblItem)
|
yellowfive@57
|
226
|
yellowfive@57
|
227 -- fill the name/ilvl labels, which may require asynchronous loading of item information
|
yellowfive@57
|
228 if optimalItemLink then
|
yellowfive@57
|
229 Amr.GetItemInfo(optimalItemLink, function(obj, name, link, quality, iLevel)
|
yellowfive@57
|
230 -- set item name, tooltip, and ilvl
|
yellowfive@57
|
231 obj.nameLabel:SetText(link:gsub("%[", ""):gsub("%]", ""))
|
yellowfive@57
|
232 Amr:SetItemTooltip(obj.nameLabel, link)
|
yellowfive@57
|
233 obj.ilvlLabel:SetText(iLevel)
|
yellowfive@57
|
234 end, { ilvlLabel = lblIlvl, nameLabel = lblItem })
|
yellowfive@57
|
235 end
|
yellowfive@57
|
236
|
yellowfive@57
|
237 -- modifications
|
yellowfive@57
|
238 if optimalItem then
|
yellowfive@57
|
239 local itemInfo = Amr.db.char.ExtraItemData[spec][optimalItem.id]
|
yellowfive@57
|
240
|
yellowfive@57
|
241 -- gems
|
yellowfive@57
|
242 if itemInfo and itemInfo.socketColors then
|
yellowfive@57
|
243 for i = 1, #itemInfo.socketColors do
|
yellowfive@57
|
244 local g = optimalItem.gemIds[i]
|
yellowfive@57
|
245 local isGemEquipped = g ~= 0 and matchItem and matchItem.gemIds and matchItem.gemIds[i] == g
|
yellowfive@57
|
246
|
yellowfive@57
|
247 -- highlight for gem that doesn't match
|
yellowfive@57
|
248 local socketBorder = AceGUI:Create("AmrUiPanel")
|
yellowfive@57
|
249 socketBorder:SetLayout("None")
|
yellowfive@57
|
250 socketBorder:SetBackgroundColor(Amr.Colors.Black, isGemEquipped and 0 or 1)
|
yellowfive@57
|
251 socketBorder:SetWidth(26)
|
yellowfive@57
|
252 socketBorder:SetHeight(26)
|
yellowfive@57
|
253 socketBorder:SetPoint("LEFT", lblItem.frame, "RIGHT", 30, 0)
|
yellowfive@57
|
254 if isGemEquipped then
|
yellowfive@57
|
255 socketBorder:SetAlpha(0.3)
|
yellowfive@57
|
256 end
|
yellowfive@57
|
257 panelMods:AddChild(socketBorder)
|
yellowfive@57
|
258
|
yellowfive@57
|
259 local socketBg = AceGUI:Create("AmrUiIcon")
|
yellowfive@57
|
260 socketBg:SetLayout("None")
|
yellowfive@57
|
261 socketBg:SetBorderWidth(2)
|
yellowfive@57
|
262 socketBg:SetIconBorderColor(Amr.Colors.Green, isGemEquipped and 0 or 1)
|
yellowfive@57
|
263 socketBg:SetWidth(24)
|
yellowfive@57
|
264 socketBg:SetHeight(24)
|
yellowfive@57
|
265 socketBg:SetPoint("TOPLEFT", socketBorder.content, "TOPLEFT", 1, -1)
|
yellowfive@57
|
266 socketBorder:AddChild(socketBg)
|
yellowfive@57
|
267
|
yellowfive@57
|
268 local socketIcon = AceGUI:Create("AmrUiIcon")
|
yellowfive@57
|
269 socketIcon:SetBorderWidth(1)
|
yellowfive@57
|
270 socketIcon:SetIconBorderColor(Amr.Colors.White)
|
yellowfive@57
|
271 socketIcon:SetWidth(18)
|
yellowfive@57
|
272 socketIcon:SetHeight(18)
|
yellowfive@57
|
273 socketIcon:SetPoint("CENTER", socketBg.content, "CENTER")
|
yellowfive@57
|
274 socketBg:AddChild(socketIcon)
|
yellowfive@57
|
275
|
yellowfive@57
|
276 -- get icon for optimized gem
|
yellowfive@57
|
277 if g ~= 0 then
|
yellowfive@57
|
278 local gemInfo = Amr.db.char.ExtraGemData[spec][g]
|
yellowfive@57
|
279 if gemInfo then
|
yellowfive@57
|
280 Amr.GetItemInfo(gemInfo.id, function(obj, name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture)
|
yellowfive@57
|
281 -- set icon and a tooltip
|
yellowfive@57
|
282 obj:SetIcon(texture)
|
yellowfive@57
|
283 Amr:SetItemTooltip(obj, link)
|
yellowfive@57
|
284 end, socketIcon)
|
yellowfive@57
|
285 end
|
yellowfive@57
|
286 end
|
yellowfive@57
|
287 end
|
yellowfive@57
|
288 end
|
yellowfive@57
|
289
|
yellowfive@57
|
290 -- enchant
|
yellowfive@57
|
291 if optimalItem.enchantId and optimalItem.enchantId ~= 0 then
|
yellowfive@57
|
292 local isEnchantEquipped = matchItem and matchItem.enchantId and matchItem.enchantId == optimalItem.enchantId
|
yellowfive@57
|
293
|
yellowfive@57
|
294 local lblEnchant = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
295 lblEnchant:SetWordWrap(false)
|
yellowfive@57
|
296 lblEnchant:SetWidth(170)
|
yellowfive@57
|
297 lblEnchant:SetFont(Amr.CreateFont(isEnchantEquipped and "Regular" or "Bold", 14, isEnchantEquipped and Amr.Colors.TextGray or Amr.Colors.White))
|
yellowfive@57
|
298 lblEnchant:SetPoint("TOPLEFT", lblItem.frame, "TOPRIGHT", 130, 0)
|
yellowfive@57
|
299
|
yellowfive@57
|
300 local enchInfo = Amr.db.char.ExtraEnchantData[spec][optimalItem.enchantId]
|
yellowfive@57
|
301 if enchInfo then
|
yellowfive@57
|
302 lblEnchant:SetText(enchInfo.text)
|
yellowfive@57
|
303
|
yellowfive@57
|
304 Amr.GetItemInfo(enchInfo.itemId, function(obj, name, link)
|
yellowfive@57
|
305 Amr:SetItemTooltip(obj, link)
|
yellowfive@57
|
306 end, lblEnchant)
|
yellowfive@57
|
307 --Amr:SetSpellTooltip(lblEnchant, enchInfo.spellId)
|
yellowfive@57
|
308 end
|
yellowfive@57
|
309 panelMods:AddChild(lblEnchant)
|
yellowfive@57
|
310 end
|
yellowfive@57
|
311 end
|
yellowfive@57
|
312
|
yellowfive@57
|
313 prevElem = lbl
|
yellowfive@57
|
314 end
|
yellowfive@57
|
315 end
|
yellowfive@57
|
316 end
|
yellowfive@57
|
317
|
yellowfive@57
|
318 local function onGearTabSelected(container, event, group)
|
yellowfive@57
|
319 container:ReleaseChildren()
|
yellowfive@57
|
320 _activeTab = group
|
yellowfive@57
|
321 renderGear(tonumber(group), container)
|
yellowfive@57
|
322 end
|
yellowfive@57
|
323
|
yellowfive@57
|
324 local function onImportClick(widget)
|
yellowfive@57
|
325 Amr:ShowImportWindow()
|
yellowfive@57
|
326 end
|
yellowfive@57
|
327
|
yellowfive@57
|
328 -- renders the main UI for the Gear tab
|
yellowfive@57
|
329 function Amr:RenderTabGear(container)
|
yellowfive@57
|
330
|
yellowfive@57
|
331 local btnImport = AceGUI:Create("AmrUiButton")
|
yellowfive@57
|
332 btnImport:SetText(L.GearButtonImportText)
|
yellowfive@57
|
333 btnImport:SetBackgroundColor(Amr.Colors.Orange)
|
yellowfive@57
|
334 btnImport:SetFont(Amr.CreateFont("Bold", 16, Amr.Colors.White))
|
yellowfive@57
|
335 btnImport:SetWidth(120)
|
yellowfive@57
|
336 btnImport:SetHeight(26)
|
yellowfive@57
|
337 btnImport:SetPoint("TOPLEFT", container.content, "TOPLEFT", 0, -81)
|
yellowfive@57
|
338 btnImport:SetCallback("OnClick", onImportClick)
|
yellowfive@57
|
339 container:AddChild(btnImport)
|
yellowfive@57
|
340
|
yellowfive@57
|
341 local lbl = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
342 lbl:SetText(L.GearImportNote)
|
yellowfive@57
|
343 lbl:SetWidth(100)
|
yellowfive@57
|
344 lbl:SetFont(Amr.CreateFont("Italic", 12, Amr.Colors.TextTan))
|
yellowfive@57
|
345 lbl:SetJustifyH("MIDDLE")
|
yellowfive@57
|
346 lbl:SetPoint("TOP", btnImport.frame, "BOTTOM", 0, -5)
|
yellowfive@57
|
347 container:AddChild(lbl)
|
yellowfive@57
|
348
|
yellowfive@57
|
349 local lbl2 = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
350 lbl2:SetText(L.GearTipTitle)
|
yellowfive@57
|
351 lbl2:SetWidth(140)
|
yellowfive@57
|
352 lbl2:SetFont(Amr.CreateFont("Italic", 20, Amr.Colors.Text))
|
yellowfive@57
|
353 lbl2:SetJustifyH("MIDDLE")
|
yellowfive@57
|
354 lbl2:SetPoint("TOP", lbl.frame, "BOTTOM", 0, -50)
|
yellowfive@57
|
355 container:AddChild(lbl2)
|
yellowfive@57
|
356
|
yellowfive@57
|
357 lbl = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
358 lbl:SetText(L.GearTipText)
|
yellowfive@57
|
359 lbl:SetWidth(140)
|
yellowfive@57
|
360 lbl:SetFont(Amr.CreateFont("Italic", 12, Amr.Colors.Text))
|
yellowfive@57
|
361 lbl:SetJustifyH("MIDDLE")
|
yellowfive@57
|
362 lbl:SetPoint("TOP", lbl2.frame, "BOTTOM", 0, -5)
|
yellowfive@57
|
363 container:AddChild(lbl)
|
yellowfive@57
|
364
|
yellowfive@57
|
365 lbl2 = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
366 lbl2:SetText(L.GearTipCommands)
|
yellowfive@57
|
367 lbl2:SetWidth(130)
|
yellowfive@57
|
368 lbl2:SetFont(Amr.CreateFont("Italic", 12, Amr.Colors.Text))
|
yellowfive@57
|
369 lbl2:SetPoint("TOP", lbl.frame, "BOTTOM", 10, -5)
|
yellowfive@57
|
370 container:AddChild(lbl2)
|
yellowfive@57
|
371
|
yellowfive@57
|
372 --[[
|
yellowfive@57
|
373 local btnClean = AceGUI:Create("AmrUiButton")
|
yellowfive@57
|
374 btnClean:SetText(L.GearButtonCleanText)
|
yellowfive@57
|
375 btnClean:SetBackgroundColor(Amr.Colors.Orange)
|
yellowfive@57
|
376 btnClean:SetFont(Amr.CreateFont("Bold", 16, Amr.Colors.White))
|
yellowfive@57
|
377 btnClean:SetWidth(120)
|
yellowfive@57
|
378 btnClean:SetHeight(26)
|
yellowfive@57
|
379 btnClean:SetPoint("BOTTOMLEFT", container.content, "BOTTOMLEFT", 0, 5)
|
yellowfive@57
|
380 btnClean:SetCallback("OnClick", function(widget) Amr:CleanBags() end)
|
yellowfive@57
|
381 container:AddChild(btnClean)
|
yellowfive@57
|
382 ]]
|
yellowfive@57
|
383
|
yellowfive@57
|
384 local t = AceGUI:Create("AmrUiTabGroup")
|
yellowfive@57
|
385 t:SetLayout("None")
|
yellowfive@57
|
386 t:SetTabs({
|
yellowfive@57
|
387 {text=L.GearTabPrimary, value="1", style="bold"},
|
yellowfive@57
|
388 {text=L.GearTabSecondary, value="2", style="bold"}
|
yellowfive@57
|
389 })
|
yellowfive@57
|
390 t:SetCallback("OnGroupSelected", onGearTabSelected)
|
yellowfive@57
|
391 t:SetPoint("TOPLEFT", container.content, "TOPLEFT", 144, -30)
|
yellowfive@57
|
392 t:SetPoint("BOTTOMRIGHT", container.content, "BOTTOMRIGHT")
|
yellowfive@57
|
393 container:AddChild(t)
|
yellowfive@57
|
394 _gearTabs = t;
|
yellowfive@57
|
395
|
yellowfive@61
|
396 local btnShop = AceGUI:Create("AmrUiButton")
|
yellowfive@61
|
397 btnShop:SetText(L.GearButtonShop)
|
yellowfive@61
|
398 btnShop:SetBackgroundColor(Amr.Colors.Blue)
|
yellowfive@61
|
399 btnShop:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.White))
|
yellowfive@61
|
400 btnShop:SetWidth(245)
|
yellowfive@61
|
401 btnShop:SetHeight(26)
|
yellowfive@61
|
402 btnShop:SetPoint("TOPRIGHT", container.content, "TOPRIGHT", -20, -25)
|
yellowfive@61
|
403 btnShop:SetCallback("OnClick", function(widget) Amr:ShowShopWindow() end)
|
yellowfive@61
|
404 container:AddChild(btnShop)
|
yellowfive@61
|
405
|
yellowfive@61
|
406
|
yellowfive@57
|
407 if not _activeTab then
|
yellowfive@57
|
408 _activeTab = tostring(GetActiveSpecGroup())
|
yellowfive@57
|
409 end
|
yellowfive@57
|
410
|
yellowfive@57
|
411 t:SelectTab(_activeTab)
|
yellowfive@57
|
412 end
|
yellowfive@57
|
413
|
yellowfive@57
|
414 -- do cleanup when the gear tab is released
|
yellowfive@57
|
415 function Amr:ReleaseTabGear()
|
yellowfive@57
|
416 _gearTabs = nil
|
yellowfive@57
|
417 end
|
yellowfive@57
|
418
|
yellowfive@57
|
419 -- show and update the gear tab for the specified spec
|
yellowfive@57
|
420 function Amr:ShowGearTab(spec)
|
yellowfive@57
|
421 if not _gearTabs then return end
|
yellowfive@57
|
422
|
yellowfive@57
|
423 _activeTab = tostring(spec)
|
yellowfive@57
|
424 _gearTabs:SelectTab(_activeTab)
|
yellowfive@57
|
425 end
|
yellowfive@57
|
426
|
yellowfive@57
|
427 -- refresh display of the current gear tab
|
yellowfive@57
|
428 function Amr:RefreshGearTab()
|
yellowfive@57
|
429 if not _gearTabs then return end
|
yellowfive@57
|
430 _gearTabs:SelectTab(_activeTab)
|
yellowfive@57
|
431 end
|
yellowfive@57
|
432
|
yellowfive@57
|
433
|
yellowfive@57
|
434 ------------------------------------------------------------------------------------------------
|
yellowfive@57
|
435 -- Gear Set Management
|
yellowfive@57
|
436 ------------------------------------------------------------------------------------------------
|
yellowfive@57
|
437 local _waitingForSpec = 0
|
yellowfive@57
|
438 local _waitingForItemLock = nil
|
yellowfive@57
|
439 local _pendingEquip = nil
|
yellowfive@57
|
440
|
yellowfive@57
|
441 -- scan a bag for the best matching item
|
yellowfive@57
|
442 local function scanBagForItem(item, bagId, bestItem, bestDiff, bestLink)
|
yellowfive@57
|
443 local numSlots = GetContainerNumSlots(bagId)
|
yellowfive@57
|
444 for slotId = 1, numSlots do
|
yellowfive@57
|
445 local _, _, _, _, _, _, itemLink = GetContainerItemInfo(bagId, slotId)
|
yellowfive@57
|
446 -- we skip any stackable item, as far as we know, there is no equippable gear that can be stacked
|
yellowfive@57
|
447 if itemLink then
|
yellowfive@57
|
448 local bagItem = Amr.ParseItemLink(itemLink)
|
yellowfive@57
|
449 if bagItem ~= nil then
|
yellowfive@57
|
450 local diff = countItemDifferences(item, bagItem)
|
yellowfive@57
|
451 if diff < bestDiff then
|
yellowfive@57
|
452 bestItem = { bag = bagId, slot = slotId }
|
yellowfive@57
|
453 bestDiff = diff
|
yellowfive@57
|
454 bestLink = itemLink
|
yellowfive@57
|
455 end
|
yellowfive@57
|
456 end
|
yellowfive@57
|
457 end
|
yellowfive@57
|
458 end
|
yellowfive@57
|
459 return bestItem, bestDiff, bestLink
|
yellowfive@57
|
460 end
|
yellowfive@57
|
461
|
yellowfive@57
|
462 -- find the first empty slot in the player's backpack+bags
|
yellowfive@57
|
463 local function findFirstEmptyBagSlot()
|
yellowfive@57
|
464
|
yellowfive@57
|
465 local bagIds = {}
|
yellowfive@57
|
466 table.insert(bagIds, BACKPACK_CONTAINER)
|
yellowfive@57
|
467 for bagId = 1, NUM_BAG_SLOTS do
|
yellowfive@57
|
468 table.insert(bagIds, bagId)
|
yellowfive@57
|
469 end
|
yellowfive@57
|
470
|
yellowfive@57
|
471 for i, bagId in ipairs(bagIds) do
|
yellowfive@57
|
472 local numSlots = GetContainerNumSlots(bagId)
|
yellowfive@57
|
473 for slotId = 1, numSlots do
|
yellowfive@57
|
474 local _, _, _, _, _, _, itemLink = GetContainerItemInfo(bagId, slotId)
|
yellowfive@57
|
475 if not itemLink then
|
yellowfive@57
|
476 return bagId, slotId
|
yellowfive@57
|
477 end
|
yellowfive@57
|
478 end
|
yellowfive@57
|
479 end
|
yellowfive@57
|
480
|
yellowfive@57
|
481 return nil, nil
|
yellowfive@57
|
482 end
|
yellowfive@57
|
483
|
yellowfive@57
|
484 local function finishEquipGearSet()
|
yellowfive@57
|
485 if not _pendingEquip then return end
|
yellowfive@57
|
486
|
yellowfive@57
|
487 _pendingEquip.tries = _pendingEquip.tries + 1
|
yellowfive@57
|
488 if _pendingEquip.tries > 16 then
|
yellowfive@61
|
489 -- too many tries, just give up (shouldn't happen but just to be safe)
|
yellowfive@57
|
490 _pendingEquip = nil
|
yellowfive@57
|
491 else
|
yellowfive@57
|
492 -- start over again, trying any items that could not be equipped in the previous pass (unique constraints)
|
yellowfive@57
|
493 Amr:EquipGearSet(_pendingEquip.spec)
|
yellowfive@57
|
494 end
|
yellowfive@57
|
495 end
|
yellowfive@57
|
496
|
yellowfive@57
|
497 -- equip the next slot in a pending equip
|
yellowfive@57
|
498 local function tryEquipNextItem()
|
yellowfive@57
|
499 if not _pendingEquip then return end
|
yellowfive@57
|
500
|
yellowfive@57
|
501 local item = _pendingEquip.itemsToEquip[_pendingEquip.nextSlot]
|
yellowfive@57
|
502
|
yellowfive@57
|
503 local bestItem = nil
|
yellowfive@57
|
504 local bestLink = nil
|
yellowfive@57
|
505 local bestDiff = 1000
|
yellowfive@57
|
506
|
yellowfive@57
|
507 -- find the best matching item
|
yellowfive@57
|
508
|
yellowfive@61
|
509 -- equipped items, but skip slots we have just equipped (to avoid e.g. just moving 2 of the same item back and forth between mh oh weapon slots)
|
yellowfive@57
|
510 for slotNum = 1, #Amr.SlotIds do
|
yellowfive@57
|
511 local slotId = Amr.SlotIds[slotNum]
|
yellowfive@61
|
512 if not _pendingEquip.doneSlots[slotId] then
|
yellowfive@61
|
513 local itemLink = GetInventoryItemLink("player", slotId)
|
yellowfive@61
|
514 if itemLink then
|
yellowfive@61
|
515 local invItem = Amr.ParseItemLink(itemLink)
|
yellowfive@61
|
516 if invItem ~= nil then
|
yellowfive@61
|
517 local diff = countItemDifferences(item, invItem)
|
yellowfive@61
|
518 if diff < bestDiff then
|
yellowfive@61
|
519 bestItem = { slot = slotId }
|
yellowfive@61
|
520 bestDiff = diff
|
yellowfive@61
|
521 bestLink = itemLink
|
yellowfive@61
|
522 end
|
yellowfive@57
|
523 end
|
yellowfive@57
|
524 end
|
yellowfive@57
|
525 end
|
yellowfive@57
|
526 end
|
yellowfive@57
|
527
|
yellowfive@57
|
528 -- inventory
|
yellowfive@57
|
529 bestItem, bestDiff, bestLink = scanBagForItem(item, BACKPACK_CONTAINER, bestItem, bestDiff, bestLink)
|
yellowfive@57
|
530 for bagId = 1, NUM_BAG_SLOTS do
|
yellowfive@57
|
531 bestItem, bestDiff, bestLink = scanBagForItem(item, bagId, bestItem, bestDiff, bestLink)
|
yellowfive@57
|
532 end
|
yellowfive@57
|
533
|
yellowfive@57
|
534 -- bank
|
yellowfive@67
|
535 bestItem, bestDiff, bestLink = scanBagForItem(item, BANK_CONTAINER, bestItem, bestDiff, bestLink)
|
yellowfive@57
|
536 for bagId = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS do
|
yellowfive@67
|
537 bestItem, bestDiff, bestLink = scanBagForItem(item, bagId, bestItem, bestDiff, bestLink)
|
yellowfive@57
|
538 end
|
yellowfive@57
|
539
|
yellowfive@57
|
540 ClearCursor()
|
yellowfive@57
|
541
|
yellowfive@57
|
542 if not bestItem then
|
yellowfive@57
|
543 -- stop if we can't find an item
|
yellowfive@57
|
544 Amr:Print(L.GearEquipErrorNotFound)
|
yellowfive@57
|
545 Amr:Print(L.GearEquipErrorNotFound2)
|
yellowfive@57
|
546 _pendingEquip = nil
|
yellowfive@57
|
547 return
|
yellowfive@57
|
548
|
yellowfive@57
|
549 elseif bestItem and bestItem.bag and bestItem.bag >= NUM_BAG_SLOTS + 1 and bestItem.bag <= NUM_BAG_SLOTS + NUM_BANKBAGSLOTS then
|
yellowfive@57
|
550 -- find first empty bag slot
|
yellowfive@57
|
551 local invBag, invSlot = findFirstEmptyBagSlot()
|
yellowfive@57
|
552 if not invBag then
|
yellowfive@57
|
553 -- stop if bags are too full
|
yellowfive@57
|
554 Amr:Print(L.GearEquipErrorBagFull)
|
yellowfive@57
|
555 _pendingEquip = nil
|
yellowfive@57
|
556 return
|
yellowfive@57
|
557 end
|
yellowfive@57
|
558
|
yellowfive@57
|
559 -- move from bank to bag
|
yellowfive@57
|
560 PickupContainerItem(bestItem.bag, bestItem.slot)
|
yellowfive@57
|
561 PickupContainerItem(invBag, invSlot)
|
yellowfive@57
|
562
|
yellowfive@57
|
563 -- set flag so that when we clear cursor and release the item lock, we can respond to the event and continue
|
yellowfive@57
|
564 _waitingForItemLock = {
|
yellowfive@57
|
565 bagId = invBag,
|
yellowfive@57
|
566 slotId = invSlot
|
yellowfive@57
|
567 }
|
yellowfive@57
|
568
|
yellowfive@57
|
569 ClearCursor()
|
yellowfive@57
|
570
|
yellowfive@57
|
571 -- now we need to wait for game event to continue and try this item again after it is in our bag
|
yellowfive@57
|
572 return
|
yellowfive@57
|
573 else
|
yellowfive@59
|
574 if not Amr:CanEquip(bestItem.bag, bestItem.slot) then
|
yellowfive@57
|
575 -- if an item is not soulbound, then warn the user and quit
|
yellowfive@57
|
576 Amr:Print(L.GearEquipErrorSoulbound(bestLink))
|
yellowfive@57
|
577 _pendingEquip = nil
|
yellowfive@57
|
578 return
|
yellowfive@57
|
579 else
|
yellowfive@57
|
580 local slotId = _pendingEquip.nextSlot
|
yellowfive@57
|
581
|
yellowfive@57
|
582 -- an item in the player's bags or already equipped, equip it
|
yellowfive@57
|
583 _pendingEquip.bag = bestItem.bag
|
yellowfive@57
|
584 _pendingEquip.slot = bestItem.slot
|
yellowfive@57
|
585 _pendingEquip.destSlot = slotId
|
yellowfive@57
|
586
|
yellowfive@57
|
587 if bestItem.bag then
|
yellowfive@57
|
588 PickupContainerItem(bestItem.bag, bestItem.slot)
|
yellowfive@57
|
589 else
|
yellowfive@57
|
590 PickupInventoryItem(bestItem.slot)
|
yellowfive@57
|
591 end
|
yellowfive@57
|
592 PickupInventoryItem(slotId)
|
yellowfive@57
|
593 ClearCursor()
|
yellowfive@61
|
594
|
yellowfive@61
|
595 -- wait for game events to continue
|
yellowfive@57
|
596 end
|
yellowfive@57
|
597 end
|
yellowfive@57
|
598
|
yellowfive@57
|
599 end
|
yellowfive@57
|
600
|
yellowfive@57
|
601 local function onItemUnlocked(bagId, slotId)
|
yellowfive@57
|
602
|
yellowfive@57
|
603 if _waitingForItemLock then
|
yellowfive@57
|
604 -- waiting on a move from bank to bags to complete, just continue as normal afterwards
|
yellowfive@57
|
605 if bagId == _waitingForItemLock.bagId and slotId == _waitingForItemLock.slotId then
|
yellowfive@57
|
606 _waitingForItemLock = nil
|
yellowfive@57
|
607 tryEquipNextItem()
|
yellowfive@57
|
608 end
|
yellowfive@57
|
609
|
yellowfive@57
|
610 elseif _pendingEquip and _pendingEquip.destSlot then
|
yellowfive@57
|
611 -- waiting on an item swap to complete successfully so that we can go on to the next item
|
yellowfive@57
|
612
|
yellowfive@57
|
613 -- inventory slot we're swapping to is still locked, can't continue yet
|
yellowfive@57
|
614 if IsInventoryItemLocked(_pendingEquip.destSlot) then return end
|
yellowfive@57
|
615
|
yellowfive@57
|
616 if _pendingEquip.bag then
|
yellowfive@57
|
617 local _, _, locked = GetContainerItemInfo(_pendingEquip.bag, _pendingEquip.slot)
|
yellowfive@57
|
618 -- the bag slot we're swapping from is still locked, can't continue yet
|
yellowfive@57
|
619 if locked then return end
|
yellowfive@57
|
620 else
|
yellowfive@57
|
621 -- inventory slot we're swapping from is still locked, can't continue yet
|
yellowfive@57
|
622 if IsInventoryItemLocked(_pendingEquip.slot) then return end
|
yellowfive@57
|
623 end
|
yellowfive@57
|
624
|
yellowfive@57
|
625 -- move on to the next item, this item is done
|
yellowfive@61
|
626 _pendingEquip.doneSlots[_pendingEquip.destSlot] = true
|
yellowfive@57
|
627 _pendingEquip.itemsToEquip[_pendingEquip.destSlot] = nil
|
yellowfive@57
|
628 _pendingEquip.destSlot = nil
|
yellowfive@57
|
629 _pendingEquip.bag = nil
|
yellowfive@57
|
630 _pendingEquip.slot = nil
|
yellowfive@57
|
631
|
yellowfive@57
|
632 _pendingEquip.remaining = _pendingEquip.remaining - 1
|
yellowfive@57
|
633 if _pendingEquip.remaining > 0 then
|
yellowfive@57
|
634 for slotId, item in pairs(_pendingEquip.itemsToEquip) do
|
yellowfive@57
|
635 _pendingEquip.nextSlot = slotId
|
yellowfive@57
|
636 break
|
yellowfive@57
|
637 end
|
yellowfive@57
|
638 tryEquipNextItem()
|
yellowfive@57
|
639 else
|
yellowfive@57
|
640 finishEquipGearSet()
|
yellowfive@57
|
641 end
|
yellowfive@57
|
642
|
yellowfive@57
|
643 end
|
yellowfive@57
|
644 end
|
yellowfive@57
|
645
|
yellowfive@57
|
646 local function startEquipGearSet(spec)
|
yellowfive@57
|
647
|
yellowfive@57
|
648 local gear = Amr.db.char.GearSets[spec]
|
yellowfive@57
|
649 if not gear then
|
yellowfive@57
|
650 Amr:Print(L.GearEquipErrorEmpty)
|
yellowfive@57
|
651 return
|
yellowfive@57
|
652 end
|
yellowfive@57
|
653
|
yellowfive@57
|
654 local player = Amr:ExportCharacter()
|
yellowfive@57
|
655
|
yellowfive@57
|
656 local itemsToEquip = {}
|
yellowfive@57
|
657 local remaining = 0
|
yellowfive@57
|
658 local usedItems = {}
|
yellowfive@57
|
659 local firstSlot = nil
|
yellowfive@57
|
660
|
yellowfive@57
|
661 -- check for items that need to be equipped
|
yellowfive@57
|
662 for slotNum = 1, #Amr.SlotIds do
|
yellowfive@57
|
663 local slotId = Amr.SlotIds[slotNum]
|
yellowfive@57
|
664
|
yellowfive@57
|
665 local old = player.Equipped[spec][slotId]
|
yellowfive@57
|
666 old = Amr.ParseItemLink(old)
|
yellowfive@57
|
667
|
yellowfive@57
|
668 local new = gear[slotId]
|
yellowfive@69
|
669 if new then
|
yellowfive@69
|
670 local diff = countItemDifferences(old, new)
|
yellowfive@69
|
671 if diff < 1000 then
|
yellowfive@69
|
672 -- same item, see if inventory has one that is closer (e.g. a duplicate item with correct enchants/gems)
|
yellowfive@69
|
673 local bestLink, bestItem, bestDiff = Amr:FindMatchingItem(new, player, usedItems)
|
yellowfive@69
|
674 if bestDiff and bestDiff < diff then
|
yellowfive@69
|
675 itemsToEquip[slotId] = new
|
yellowfive@69
|
676 remaining = remaining + 1
|
yellowfive@69
|
677 end
|
yellowfive@69
|
678 else
|
yellowfive@57
|
679 itemsToEquip[slotId] = new
|
yellowfive@57
|
680 remaining = remaining + 1
|
yellowfive@57
|
681 end
|
yellowfive@57
|
682 end
|
yellowfive@57
|
683 end
|
yellowfive@57
|
684
|
yellowfive@57
|
685 if remaining > 0 then
|
yellowfive@57
|
686 _pendingEquip = {
|
yellowfive@57
|
687 tries = _pendingEquip and _pendingEquip.spec == spec and _pendingEquip.tries or 0,
|
yellowfive@57
|
688 spec = spec,
|
yellowfive@57
|
689 itemsToEquip = itemsToEquip,
|
yellowfive@57
|
690 remaining = remaining,
|
yellowfive@61
|
691 doneSlots = {},
|
yellowfive@57
|
692 nextSlot = firstSlot
|
yellowfive@57
|
693 }
|
yellowfive@57
|
694
|
yellowfive@57
|
695 -- starting item
|
yellowfive@57
|
696 for slotId, item in pairs(_pendingEquip.itemsToEquip) do
|
yellowfive@57
|
697 _pendingEquip.nextSlot = slotId
|
yellowfive@57
|
698 break
|
yellowfive@57
|
699 end
|
yellowfive@57
|
700
|
yellowfive@57
|
701 tryEquipNextItem()
|
yellowfive@57
|
702 else
|
yellowfive@57
|
703 _pendingEquip = nil
|
yellowfive@57
|
704 end
|
yellowfive@57
|
705 end
|
yellowfive@57
|
706
|
yellowfive@57
|
707 local function onActiveTalentGroupChanged()
|
yellowfive@57
|
708 local auto = Amr.db.profile.options.autoGear
|
yellowfive@57
|
709 local currentSpec = GetActiveSpecGroup()
|
yellowfive@57
|
710
|
yellowfive@57
|
711 if currentSpec == _waitingForSpec or auto then
|
yellowfive@57
|
712 -- spec is what we want, now equip the gear
|
yellowfive@57
|
713 startEquipGearSet(currentSpec)
|
yellowfive@57
|
714 end
|
yellowfive@57
|
715
|
yellowfive@57
|
716 _waitingForSpec = 0
|
yellowfive@57
|
717 end
|
yellowfive@57
|
718
|
yellowfive@57
|
719 -- activate the specified spec and then equip the saved gear set for either primary (1) or secondary (2) spec
|
yellowfive@57
|
720 function Amr:EquipGearSet(spec)
|
yellowfive@57
|
721
|
yellowfive@57
|
722 -- if no argument, then toggle spec
|
yellowfive@57
|
723 if not spec then
|
yellowfive@57
|
724 spec = GetActiveSpecGroup() == 1 and 2 or 1
|
yellowfive@57
|
725 end
|
yellowfive@57
|
726
|
yellowfive@57
|
727 -- allow some flexibility in the arguments
|
yellowfive@57
|
728 if spec == "primary" or spec == "Primary" then spec = 1 end
|
yellowfive@57
|
729 if spec == "secondary" or spec == "Secondary" then spec = 2 end
|
yellowfive@57
|
730 if spec == "1" or spec == "2" then spec = tonumber(spec) end
|
yellowfive@57
|
731
|
yellowfive@57
|
732 -- only spec 1 or 2 are valid
|
yellowfive@57
|
733 if spec ~= 1 and spec ~= 2 then return end
|
yellowfive@57
|
734
|
yellowfive@57
|
735 if UnitAffectingCombat("player") then
|
yellowfive@57
|
736 Amr:Print(L.GearEquipErrorCombat)
|
yellowfive@57
|
737 return
|
yellowfive@57
|
738 end
|
yellowfive@57
|
739
|
yellowfive@57
|
740 _waitingForSpec = spec
|
yellowfive@57
|
741
|
yellowfive@57
|
742 local currentSpec = GetActiveSpecGroup()
|
yellowfive@57
|
743 if currentSpec ~= spec then
|
yellowfive@57
|
744 SetActiveSpecGroup(spec)
|
yellowfive@57
|
745 else
|
yellowfive@57
|
746 onActiveTalentGroupChanged()
|
yellowfive@57
|
747 end
|
yellowfive@57
|
748 end
|
yellowfive@57
|
749
|
yellowfive@57
|
750 -- moves any gear in bags to the bank if not part of main or off spec gear set
|
yellowfive@57
|
751 function Amr:CleanBags()
|
yellowfive@57
|
752 -- TODO: implement
|
yellowfive@57
|
753 end
|
yellowfive@57
|
754
|
yellowfive@57
|
755 function Amr:InitializeGear()
|
yellowfive@57
|
756 Amr:AddEventHandler("ACTIVE_TALENT_GROUP_CHANGED", onActiveTalentGroupChanged)
|
yellowfive@57
|
757
|
yellowfive@57
|
758 Amr:AddEventHandler("UNIT_INVENTORY_CHANGED", function(unitID)
|
yellowfive@57
|
759 if unitID and unitID ~= "player" then return end
|
yellowfive@57
|
760 Amr:RefreshGearTab()
|
yellowfive@57
|
761 end)
|
yellowfive@57
|
762
|
yellowfive@57
|
763 Amr:AddEventHandler("ITEM_UNLOCKED", onItemUnlocked)
|
yellowfive@57
|
764 end |