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 _lastExport = nil
|
yellowfive@57
|
6 local _txt = nil
|
yellowfive@57
|
7
|
yellowfive@57
|
8 local function createLabel(container, text, width)
|
yellowfive@57
|
9 local lbl = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
10 lbl:SetWidth(width or 800)
|
yellowfive@57
|
11 lbl:SetText(text)
|
yellowfive@57
|
12 lbl:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text))
|
yellowfive@57
|
13 container:AddChild(lbl)
|
yellowfive@57
|
14 return lbl
|
yellowfive@57
|
15 end
|
yellowfive@57
|
16
|
yellowfive@57
|
17 local function onSplashClose()
|
yellowfive@57
|
18 Amr:HideCover()
|
yellowfive@57
|
19 Amr.db.char.FirstUse = false
|
yellowfive@57
|
20 end
|
yellowfive@57
|
21
|
yellowfive@69
|
22 local function onTextChanged(widget)
|
yellowfive@69
|
23 local val = _txt:GetText()
|
yellowfive@69
|
24 if val == "overwolf-bib" then
|
yellowfive@69
|
25 -- go to the gear tab, open import window, and show a cover
|
yellowfive@69
|
26 Amr:ShowTab("Gear")
|
yellowfive@69
|
27 Amr:ShowImportWindow(true)
|
yellowfive@69
|
28 end
|
yellowfive@69
|
29 end
|
yellowfive@69
|
30
|
yellowfive@57
|
31 -- render a splash screen with first-time help
|
yellowfive@57
|
32 local function renderSplash(container)
|
yellowfive@57
|
33 local panel = Amr:RenderCoverChrome(container, 700, 450)
|
yellowfive@57
|
34
|
yellowfive@57
|
35 local lbl = createLabel(panel, L.ExportSplashTitle, 650)
|
yellowfive@57
|
36 lbl:SetJustifyH("CENTER")
|
yellowfive@57
|
37 lbl:SetFont(Amr.CreateFont("Bold", 24, Amr.Colors.TextHeaderActive))
|
yellowfive@57
|
38 lbl:SetPoint("TOP", panel.content, "TOP", 0, -10)
|
yellowfive@57
|
39
|
yellowfive@57
|
40 local lbl2 = createLabel(panel, L.ExportSplashSubtitle, 650)
|
yellowfive@57
|
41 lbl2:SetJustifyH("CENTER")
|
yellowfive@57
|
42 lbl2:SetFont(Amr.CreateFont("Bold", 18, Amr.Colors.TextTan))
|
yellowfive@57
|
43 lbl2:SetPoint("TOP", lbl.frame, "BOTTOM", 0, -20)
|
yellowfive@57
|
44
|
yellowfive@57
|
45 lbl = createLabel(panel, L.ExportSplash1, 650)
|
yellowfive@57
|
46 lbl:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text))
|
yellowfive@57
|
47 lbl:SetPoint("TOPLEFT", lbl2.frame, "BOTTOMLEFT", 0, -70)
|
yellowfive@57
|
48
|
yellowfive@57
|
49 lbl2 = createLabel(panel, L.ExportSplash2, 650)
|
yellowfive@57
|
50 lbl2:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text))
|
yellowfive@57
|
51 lbl2:SetPoint("TOPLEFT", lbl.frame, "BOTTOMLEFT", 0, -15)
|
yellowfive@57
|
52
|
yellowfive@57
|
53 lbl = createLabel(panel, L.ExportSplash3, 650)
|
yellowfive@57
|
54 lbl:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text))
|
yellowfive@57
|
55 lbl:SetPoint("TOPLEFT", lbl2.frame, "BOTTOMLEFT", 0, -15)
|
yellowfive@81
|
56
|
yellowfive@81
|
57 lbl2 = createLabel(panel, L.ExportSplash4, 650)
|
yellowfive@81
|
58 lbl2:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text))
|
yellowfive@81
|
59 lbl2:SetPoint("TOPLEFT", lbl.frame, "BOTTOMLEFT", 0, -15)
|
yellowfive@57
|
60
|
yellowfive@57
|
61 local btn = AceGUI:Create("AmrUiButton")
|
yellowfive@57
|
62 btn:SetText(L.ExportSplashClose)
|
yellowfive@57
|
63 btn:SetBackgroundColor(Amr.Colors.Green)
|
yellowfive@57
|
64 btn:SetFont(Amr.CreateFont("Bold", 16, Amr.Colors.White))
|
yellowfive@57
|
65 btn:SetWidth(120)
|
yellowfive@57
|
66 btn:SetHeight(28)
|
yellowfive@57
|
67 btn:SetPoint("BOTTOM", panel.content, "BOTTOM", 0, 20)
|
yellowfive@57
|
68 btn:SetCallback("OnClick", onSplashClose)
|
yellowfive@57
|
69 panel:AddChild(btn)
|
yellowfive@57
|
70 end
|
yellowfive@57
|
71
|
yellowfive@57
|
72 -- renders the main UI for the Export tab
|
yellowfive@57
|
73 function Amr:RenderTabExport(container)
|
yellowfive@57
|
74
|
yellowfive@57
|
75 local lbl = createLabel(container, L.ExportTitle)
|
yellowfive@57
|
76 lbl:SetFont(Amr.CreateFont("Bold", 24, Amr.Colors.TextHeaderActive))
|
yellowfive@57
|
77 lbl:SetPoint("TOPLEFT", container.content, "TOPLEFT", 0, -40)
|
yellowfive@57
|
78
|
yellowfive@57
|
79 local lbl2 = createLabel(container, L.ExportHelp1)
|
yellowfive@57
|
80 lbl2:SetPoint("TOPLEFT", lbl.frame, "BOTTOMLEFT", 0, -10)
|
yellowfive@57
|
81
|
yellowfive@57
|
82 lbl = createLabel(container, L.ExportHelp2)
|
yellowfive@57
|
83 lbl:SetPoint("TOPLEFT", lbl2.frame, "BOTTOMLEFT", 0, -10)
|
yellowfive@57
|
84
|
yellowfive@57
|
85 lbl2 = createLabel(container, L.ExportHelp3)
|
yellowfive@57
|
86 lbl2:SetPoint("TOPLEFT", lbl.frame, "BOTTOMLEFT", 0, -10)
|
yellowfive@57
|
87
|
yellowfive@57
|
88 _txt = AceGUI:Create("AmrUiTextarea")
|
yellowfive@57
|
89 _txt:SetWidth(800)
|
yellowfive@57
|
90 _txt:SetHeight(300)
|
yellowfive@81
|
91 _txt:SetPoint("TOP", lbl2.frame, "BOTTOM", 0, -20)
|
yellowfive@57
|
92 _txt:SetFont(Amr.CreateFont("Regular", 12, Amr.Colors.Text))
|
yellowfive@69
|
93 _txt:SetCallback("OnTextChanged", onTextChanged)
|
yellowfive@57
|
94 container:AddChild(_txt)
|
yellowfive@57
|
95
|
yellowfive@57
|
96 local data = self:ExportCharacter()
|
yellowfive@57
|
97 local txt = Amr.Serializer:SerializePlayerData(data, true)
|
yellowfive@57
|
98 _txt:SetText(txt)
|
yellowfive@57
|
99 _txt:SetFocus(true)
|
yellowfive@57
|
100
|
yellowfive@57
|
101 -- update shopping list data
|
yellowfive@57
|
102 Amr:UpdateShoppingData(data)
|
yellowfive@57
|
103
|
yellowfive@57
|
104 -- show help splash if first time a user is using this
|
yellowfive@57
|
105 if Amr.db.char.FirstUse then
|
yellowfive@57
|
106 Amr:ShowCover(renderSplash)
|
yellowfive@57
|
107 AceGUI:ClearFocus()
|
yellowfive@57
|
108 end
|
yellowfive@57
|
109 end
|
yellowfive@57
|
110
|
yellowfive@57
|
111 function Amr:ReleaseTabExport()
|
yellowfive@57
|
112 end
|
yellowfive@57
|
113
|
yellowfive@57
|
114 function Amr:GetExportText()
|
yellowfive@57
|
115 return _txt:GetText()
|
yellowfive@57
|
116 end
|
yellowfive@57
|
117
|
yellowfive@57
|
118
|
yellowfive@57
|
119 -- use some local variables to deal with the fact that a user can close the bank before a scan completes
|
yellowfive@57
|
120 local _lastBankBagId = nil
|
yellowfive@57
|
121 local _lastBankSlotId = nil
|
yellowfive@57
|
122
|
yellowfive@57
|
123 local function scanBag(bagId, isBank, bagTable, bagItemsWithCount)
|
yellowfive@57
|
124 local numSlots = GetContainerNumSlots(bagId)
|
yellowfive@57
|
125 for slotId = 1, numSlots do
|
yellowfive@57
|
126 local _, itemCount, _, _, _, _, itemLink = GetContainerItemInfo(bagId, slotId)
|
yellowfive@57
|
127 if itemLink ~= nil then
|
yellowfive@57
|
128 local itemData = Amr.Serializer.ParseItemLink(itemLink)
|
yellowfive@57
|
129 if itemData ~= nil then
|
yellowfive@57
|
130 -- only add equippable items to bag data
|
yellowfive@57
|
131 if IsEquippableItem(itemLink) or Amr.SetTokenIds[itemData.id] then
|
yellowfive@57
|
132 if isBank then
|
yellowfive@57
|
133 _lastBankBagId = bagId
|
yellowfive@57
|
134 _lastBankSlotId = slotId
|
yellowfive@57
|
135 end
|
yellowfive@57
|
136
|
yellowfive@57
|
137 table.insert(bagTable, itemLink)
|
yellowfive@57
|
138 end
|
yellowfive@57
|
139
|
yellowfive@57
|
140 -- all items and counts, used for e.g. shopping list and reagents, etc.
|
yellowfive@57
|
141 if bagItemsWithCount then
|
yellowfive@57
|
142 if bagItemsWithCount[itemData.id] then
|
yellowfive@57
|
143 bagItemsWithCount[itemData.id] = bagItemsWithCount[itemData.id] + itemCount
|
yellowfive@57
|
144 else
|
yellowfive@57
|
145 bagItemsWithCount[itemData.id] = itemCount
|
yellowfive@57
|
146 end
|
yellowfive@57
|
147 end
|
yellowfive@57
|
148 end
|
yellowfive@57
|
149 end
|
yellowfive@57
|
150 end
|
yellowfive@57
|
151 end
|
yellowfive@57
|
152
|
yellowfive@57
|
153 -- get the player's current gear and save it, also returns the data from GetPlayerData for efficiency
|
yellowfive@57
|
154 local function getEquipped()
|
yellowfive@81
|
155 local data = Amr.Serializer:GetPlayerData()
|
yellowfive@81
|
156 local spec = GetSpecialization()
|
yellowfive@57
|
157
|
yellowfive@57
|
158 Amr.db.char.Equipped[spec] = data.Equipped[spec]
|
yellowfive@57
|
159
|
yellowfive@57
|
160 return data
|
yellowfive@57
|
161 end
|
yellowfive@57
|
162
|
yellowfive@57
|
163 local function scanBags()
|
yellowfive@57
|
164
|
yellowfive@57
|
165 local bagItems = {}
|
yellowfive@57
|
166 local itemsAndCounts = {}
|
yellowfive@57
|
167
|
yellowfive@57
|
168 scanBag(BACKPACK_CONTAINER, false, bagItems, itemsAndCounts) -- backpack
|
yellowfive@57
|
169 for bagId = 1, NUM_BAG_SLOTS do
|
yellowfive@57
|
170 scanBag(bagId, false, bagItems, itemsAndCounts)
|
yellowfive@57
|
171 end
|
yellowfive@57
|
172
|
yellowfive@57
|
173 Amr.db.char.BagItems = bagItems
|
yellowfive@57
|
174 Amr.db.char.BagItemsAndCounts = itemsAndCounts
|
yellowfive@57
|
175 end
|
yellowfive@57
|
176
|
yellowfive@57
|
177 -- scan the player's bank and save the contents, must be at the bank
|
yellowfive@57
|
178 local function scanBank()
|
yellowfive@57
|
179
|
yellowfive@57
|
180 local bankItems = {}
|
yellowfive@57
|
181 local itemsAndCounts = {}
|
yellowfive@57
|
182
|
yellowfive@57
|
183 scanBag(BANK_CONTAINER, true, bankItems, itemsAndCounts)
|
yellowfive@57
|
184 scanBag(REAGENTBANK_CONTAINER, true, bankItems, itemsAndCounts)
|
yellowfive@57
|
185 for bagId = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS do
|
yellowfive@57
|
186 scanBag(bagId, true, bankItems, itemsAndCounts)
|
yellowfive@57
|
187 end
|
yellowfive@57
|
188
|
yellowfive@57
|
189 -- see if the scan completed before the window closed, otherwise we don't overwrite with partial data
|
yellowfive@57
|
190 if _lastBankBagId ~= nil then
|
yellowfive@57
|
191 local itemLink = GetContainerItemLink(_lastBankBagId, _lastBankSlotId)
|
yellowfive@57
|
192 if itemLink ~= nil then --still open
|
yellowfive@57
|
193 Amr.db.char.BankItems = bankItems
|
yellowfive@57
|
194 Amr.db.char.BankItemsAndCounts = itemsAndCounts
|
yellowfive@57
|
195 end
|
yellowfive@57
|
196 end
|
yellowfive@57
|
197
|
yellowfive@57
|
198 end
|
yellowfive@57
|
199
|
yellowfive@57
|
200 -- scan the player's void storage and save the contents, must be at void storage
|
yellowfive@57
|
201 local function scanVoid()
|
yellowfive@57
|
202
|
yellowfive@57
|
203 if IsVoidStorageReady() then
|
yellowfive@57
|
204 local voidItems = {}
|
yellowfive@57
|
205 local VOID_STORAGE_MAX = 80
|
yellowfive@57
|
206 local VOID_STORAGE_PAGES = 2
|
yellowfive@57
|
207
|
yellowfive@57
|
208 for page = 1,VOID_STORAGE_PAGES do
|
yellowfive@57
|
209 for i = 1,VOID_STORAGE_MAX do
|
yellowfive@57
|
210 local itemId = GetVoidItemInfo(page, i)
|
yellowfive@57
|
211 if itemId then
|
yellowfive@57
|
212 local itemLink = GetVoidItemHyperlinkString(((page - 1) * VOID_STORAGE_MAX) + i);
|
yellowfive@57
|
213 if itemLink then
|
yellowfive@57
|
214 tinsert(voidItems, itemLink)
|
yellowfive@57
|
215 end
|
yellowfive@57
|
216 end
|
yellowfive@57
|
217 end
|
yellowfive@57
|
218 end
|
yellowfive@57
|
219
|
yellowfive@57
|
220 Amr.db.char.VoidItems = voidItems
|
yellowfive@57
|
221 end
|
yellowfive@57
|
222
|
yellowfive@57
|
223 end
|
yellowfive@57
|
224
|
yellowfive@57
|
225 local function getRepStanding(factionId)
|
yellowfive@57
|
226 local name, description, standingId, _ = GetFactionInfoByID(factionId)
|
yellowfive@57
|
227 return standingId - 1; -- our rep enum correspond to what the armory returns, are 1 less than what the game returns
|
yellowfive@57
|
228 end
|
yellowfive@57
|
229
|
yellowfive@57
|
230 local function getReputations()
|
yellowfive@57
|
231 local reps = {}
|
yellowfive@57
|
232
|
yellowfive@57
|
233 local repList = {1375,1376,1270,1269,1341,1337,1387,1388,1435}
|
yellowfive@57
|
234 for i, repId in pairs(repList) do
|
yellowfive@57
|
235 local standing = getRepStanding(repId)
|
yellowfive@57
|
236 if standing >= 0 then
|
yellowfive@57
|
237 reps[repId] = standing
|
yellowfive@57
|
238 end
|
yellowfive@57
|
239 end
|
yellowfive@57
|
240
|
yellowfive@57
|
241 return reps
|
yellowfive@57
|
242 end
|
yellowfive@57
|
243
|
yellowfive@81
|
244 local function scanTalents()
|
yellowfive@81
|
245 local specPos = GetSpecialization()
|
yellowfive@81
|
246 if not specPos or specPos < 1 or specPos > 4 then return end
|
yellowfive@81
|
247
|
yellowfive@81
|
248 local talentInfo = {}
|
yellowfive@81
|
249 local maxTiers = 7
|
yellowfive@81
|
250 for tier = 1, maxTiers do
|
yellowfive@81
|
251 for col = 1, 3 do
|
yellowfive@81
|
252 local id, name, _, _, _, spellId, _, t, c, selected = GetTalentInfoBySpecialization(specPos, tier, col)
|
yellowfive@81
|
253 if selected then
|
yellowfive@81
|
254 talentInfo[tier] = col
|
yellowfive@81
|
255 end
|
yellowfive@81
|
256 end
|
yellowfive@81
|
257 end
|
yellowfive@81
|
258
|
yellowfive@81
|
259 local str = ""
|
yellowfive@81
|
260 for i = 1, maxTiers do
|
yellowfive@81
|
261 if talentInfo[i] then
|
yellowfive@81
|
262 str = str .. talentInfo[i]
|
yellowfive@81
|
263 else
|
yellowfive@81
|
264 str = str .. '0'
|
yellowfive@81
|
265 end
|
yellowfive@81
|
266 end
|
yellowfive@81
|
267
|
yellowfive@81
|
268 Amr.db.char.Talents[specPos] = str
|
yellowfive@81
|
269 end
|
yellowfive@81
|
270
|
yellowfive@81
|
271 local function scanArtifact()
|
yellowfive@81
|
272 -- TODO: when they put in a real API for this, switch to that instead of using UI methods directly
|
yellowfive@81
|
273 local powers = C_ArtifactUI.GetPowers()
|
yellowfive@81
|
274 if not powers then return end
|
yellowfive@81
|
275
|
yellowfive@81
|
276 local powerRanks = {}
|
yellowfive@81
|
277 for k,v in pairs(powers) do
|
yellowfive@81
|
278 local spellId, cost, rank, maxRank, relicRank = C_ArtifactUI.GetPowerInfo(v)
|
yellowfive@81
|
279 if rank - relicRank > 0 then
|
yellowfive@81
|
280 powerRanks[v] = rank - relicRank
|
yellowfive@81
|
281 end
|
yellowfive@81
|
282 end
|
yellowfive@81
|
283
|
yellowfive@81
|
284 local relicInfo = {}
|
yellowfive@81
|
285 for i = 1,3 do
|
yellowfive@81
|
286 local _, _, _, link = C_ArtifactUI.GetRelicInfo(i);
|
yellowfive@81
|
287 table.insert(relicInfo, link or "")
|
yellowfive@81
|
288 end
|
yellowfive@81
|
289
|
yellowfive@81
|
290 -- make sure that the artifact UI didn't get closed while we were reading it, GetPowers seems to return nil unless it is open
|
yellowfive@81
|
291 powers = C_ArtifactUI.GetPowers()
|
yellowfive@81
|
292 if not powers then return end
|
yellowfive@81
|
293
|
yellowfive@81
|
294 local spec = GetSpecialization()
|
yellowfive@81
|
295 Amr.db.char.Artifacts[spec] = {
|
yellowfive@81
|
296 Powers = powerRanks,
|
yellowfive@81
|
297 Relics = relicInfo
|
yellowfive@81
|
298 }
|
yellowfive@81
|
299 end
|
yellowfive@81
|
300
|
yellowfive@57
|
301 -- Returns a data object containing all information about the current player needed for an export:
|
yellowfive@57
|
302 -- gear, spec, reputations, bag, bank, and void storage items.
|
yellowfive@57
|
303 function Amr:ExportCharacter()
|
yellowfive@57
|
304
|
yellowfive@57
|
305 local data = getEquipped()
|
yellowfive@57
|
306 scanBags()
|
yellowfive@57
|
307
|
yellowfive@81
|
308 -- scan current spec's talents just before exporting
|
yellowfive@81
|
309 scanTalents()
|
yellowfive@81
|
310
|
yellowfive@81
|
311 data.Talents = Amr.db.char.Talents
|
yellowfive@81
|
312 data.Artifacts = Amr.db.char.Artifacts
|
yellowfive@57
|
313 data.Equipped = Amr.db.char.Equipped
|
yellowfive@57
|
314 data.Reputations = getReputations()
|
yellowfive@57
|
315 data.BagItems = Amr.db.char.BagItems
|
yellowfive@57
|
316 data.BankItems = Amr.db.char.BankItems
|
yellowfive@57
|
317 data.VoidItems = Amr.db.char.VoidItems
|
yellowfive@57
|
318
|
yellowfive@57
|
319 return data
|
yellowfive@57
|
320 end
|
yellowfive@57
|
321
|
yellowfive@57
|
322 function Amr:InitializeExport()
|
yellowfive@57
|
323 Amr:AddEventHandler("UNIT_INVENTORY_CHANGED", function(unitID)
|
yellowfive@57
|
324 if unitID and unitID ~= "player" then return end
|
yellowfive@57
|
325 getEquipped()
|
yellowfive@57
|
326 end)
|
yellowfive@57
|
327 end
|
yellowfive@57
|
328
|
yellowfive@57
|
329 Amr:AddEventHandler("BANKFRAME_OPENED", scanBank)
|
yellowfive@57
|
330 Amr:AddEventHandler("PLAYERBANKSLOTS_CHANGED", scanBank)
|
yellowfive@57
|
331
|
yellowfive@57
|
332 Amr:AddEventHandler("VOID_STORAGE_OPEN", scanVoid)
|
yellowfive@57
|
333 Amr:AddEventHandler("VOID_STORAGE_CONTENTS_UPDATE", scanVoid)
|
yellowfive@57
|
334 Amr:AddEventHandler("VOID_STORAGE_DEPOSIT_UPDATE", scanVoid)
|
yellowfive@57
|
335 Amr:AddEventHandler("VOID_STORAGE_UPDATE", scanVoid)
|
yellowfive@81
|
336
|
yellowfive@81
|
337 Amr:AddEventHandler("PLAYER_TALENT_UPDATE", scanTalents)
|
yellowfive@81
|
338 Amr:AddEventHandler("ARTIFACT_UPDATE", scanArtifact)
|