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@85
|
130
|
yellowfive@57
|
131 -- only add equippable items to bag data
|
yellowfive@85
|
132 --if IsEquippableItem(itemLink) or Amr.SetTokenIds[itemData.id] then
|
yellowfive@57
|
133 if isBank then
|
yellowfive@57
|
134 _lastBankBagId = bagId
|
yellowfive@57
|
135 _lastBankSlotId = slotId
|
yellowfive@57
|
136 end
|
yellowfive@57
|
137
|
yellowfive@57
|
138 table.insert(bagTable, itemLink)
|
yellowfive@85
|
139 --end
|
yellowfive@57
|
140
|
yellowfive@57
|
141 -- all items and counts, used for e.g. shopping list and reagents, etc.
|
yellowfive@57
|
142 if bagItemsWithCount then
|
yellowfive@57
|
143 if bagItemsWithCount[itemData.id] then
|
yellowfive@57
|
144 bagItemsWithCount[itemData.id] = bagItemsWithCount[itemData.id] + itemCount
|
yellowfive@57
|
145 else
|
yellowfive@57
|
146 bagItemsWithCount[itemData.id] = itemCount
|
yellowfive@57
|
147 end
|
yellowfive@57
|
148 end
|
yellowfive@57
|
149 end
|
yellowfive@57
|
150 end
|
yellowfive@57
|
151 end
|
yellowfive@57
|
152 end
|
yellowfive@57
|
153
|
yellowfive@57
|
154 -- get the player's current gear and save it, also returns the data from GetPlayerData for efficiency
|
yellowfive@57
|
155 local function getEquipped()
|
yellowfive@81
|
156 local data = Amr.Serializer:GetPlayerData()
|
yellowfive@81
|
157 local spec = GetSpecialization()
|
yellowfive@57
|
158
|
yellowfive@57
|
159 Amr.db.char.Equipped[spec] = data.Equipped[spec]
|
yellowfive@57
|
160
|
yellowfive@57
|
161 return data
|
yellowfive@57
|
162 end
|
yellowfive@57
|
163
|
yellowfive@57
|
164 local function scanBags()
|
yellowfive@57
|
165
|
yellowfive@57
|
166 local bagItems = {}
|
yellowfive@57
|
167 local itemsAndCounts = {}
|
yellowfive@57
|
168
|
yellowfive@57
|
169 scanBag(BACKPACK_CONTAINER, false, bagItems, itemsAndCounts) -- backpack
|
yellowfive@57
|
170 for bagId = 1, NUM_BAG_SLOTS do
|
yellowfive@57
|
171 scanBag(bagId, false, bagItems, itemsAndCounts)
|
yellowfive@57
|
172 end
|
yellowfive@57
|
173
|
yellowfive@57
|
174 Amr.db.char.BagItems = bagItems
|
yellowfive@57
|
175 Amr.db.char.BagItemsAndCounts = itemsAndCounts
|
yellowfive@57
|
176 end
|
yellowfive@57
|
177
|
yellowfive@57
|
178 -- scan the player's bank and save the contents, must be at the bank
|
yellowfive@57
|
179 local function scanBank()
|
yellowfive@57
|
180
|
yellowfive@57
|
181 local bankItems = {}
|
yellowfive@57
|
182 local itemsAndCounts = {}
|
yellowfive@57
|
183
|
yellowfive@57
|
184 scanBag(BANK_CONTAINER, true, bankItems, itemsAndCounts)
|
yellowfive@57
|
185 scanBag(REAGENTBANK_CONTAINER, true, bankItems, itemsAndCounts)
|
yellowfive@57
|
186 for bagId = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS do
|
yellowfive@57
|
187 scanBag(bagId, true, bankItems, itemsAndCounts)
|
yellowfive@57
|
188 end
|
yellowfive@57
|
189
|
yellowfive@57
|
190 -- see if the scan completed before the window closed, otherwise we don't overwrite with partial data
|
yellowfive@57
|
191 if _lastBankBagId ~= nil then
|
yellowfive@57
|
192 local itemLink = GetContainerItemLink(_lastBankBagId, _lastBankSlotId)
|
yellowfive@57
|
193 if itemLink ~= nil then --still open
|
yellowfive@57
|
194 Amr.db.char.BankItems = bankItems
|
yellowfive@57
|
195 Amr.db.char.BankItemsAndCounts = itemsAndCounts
|
yellowfive@57
|
196 end
|
yellowfive@57
|
197 end
|
yellowfive@57
|
198
|
yellowfive@57
|
199 end
|
yellowfive@57
|
200
|
yellowfive@57
|
201 -- scan the player's void storage and save the contents, must be at void storage
|
yellowfive@57
|
202 local function scanVoid()
|
yellowfive@57
|
203
|
yellowfive@57
|
204 if IsVoidStorageReady() then
|
yellowfive@57
|
205 local voidItems = {}
|
yellowfive@57
|
206 local VOID_STORAGE_MAX = 80
|
yellowfive@57
|
207 local VOID_STORAGE_PAGES = 2
|
yellowfive@57
|
208
|
yellowfive@57
|
209 for page = 1,VOID_STORAGE_PAGES do
|
yellowfive@57
|
210 for i = 1,VOID_STORAGE_MAX do
|
yellowfive@57
|
211 local itemId = GetVoidItemInfo(page, i)
|
yellowfive@57
|
212 if itemId then
|
yellowfive@57
|
213 local itemLink = GetVoidItemHyperlinkString(((page - 1) * VOID_STORAGE_MAX) + i);
|
yellowfive@57
|
214 if itemLink then
|
yellowfive@57
|
215 tinsert(voidItems, itemLink)
|
yellowfive@57
|
216 end
|
yellowfive@57
|
217 end
|
yellowfive@57
|
218 end
|
yellowfive@57
|
219 end
|
yellowfive@57
|
220
|
yellowfive@57
|
221 Amr.db.char.VoidItems = voidItems
|
yellowfive@57
|
222 end
|
yellowfive@57
|
223
|
yellowfive@57
|
224 end
|
yellowfive@57
|
225
|
yellowfive@57
|
226 local function getRepStanding(factionId)
|
yellowfive@57
|
227 local name, description, standingId, _ = GetFactionInfoByID(factionId)
|
yellowfive@57
|
228 return standingId - 1; -- our rep enum correspond to what the armory returns, are 1 less than what the game returns
|
yellowfive@57
|
229 end
|
yellowfive@57
|
230
|
yellowfive@57
|
231 local function getReputations()
|
yellowfive@57
|
232 local reps = {}
|
yellowfive@57
|
233
|
yellowfive@57
|
234 local repList = {1375,1376,1270,1269,1341,1337,1387,1388,1435}
|
yellowfive@57
|
235 for i, repId in pairs(repList) do
|
yellowfive@57
|
236 local standing = getRepStanding(repId)
|
yellowfive@57
|
237 if standing >= 0 then
|
yellowfive@57
|
238 reps[repId] = standing
|
yellowfive@57
|
239 end
|
yellowfive@57
|
240 end
|
yellowfive@57
|
241
|
yellowfive@57
|
242 return reps
|
yellowfive@57
|
243 end
|
yellowfive@57
|
244
|
yellowfive@81
|
245 local function scanTalents()
|
yellowfive@81
|
246 local specPos = GetSpecialization()
|
yellowfive@81
|
247 if not specPos or specPos < 1 or specPos > 4 then return end
|
yellowfive@81
|
248
|
yellowfive@81
|
249 local talentInfo = {}
|
yellowfive@81
|
250 local maxTiers = 7
|
yellowfive@81
|
251 for tier = 1, maxTiers do
|
yellowfive@81
|
252 for col = 1, 3 do
|
yellowfive@81
|
253 local id, name, _, _, _, spellId, _, t, c, selected = GetTalentInfoBySpecialization(specPos, tier, col)
|
yellowfive@81
|
254 if selected then
|
yellowfive@81
|
255 talentInfo[tier] = col
|
yellowfive@81
|
256 end
|
yellowfive@81
|
257 end
|
yellowfive@81
|
258 end
|
yellowfive@81
|
259
|
yellowfive@81
|
260 local str = ""
|
yellowfive@81
|
261 for i = 1, maxTiers do
|
yellowfive@81
|
262 if talentInfo[i] then
|
yellowfive@81
|
263 str = str .. talentInfo[i]
|
yellowfive@81
|
264 else
|
yellowfive@81
|
265 str = str .. '0'
|
yellowfive@81
|
266 end
|
yellowfive@81
|
267 end
|
yellowfive@81
|
268
|
yellowfive@81
|
269 Amr.db.char.Talents[specPos] = str
|
yellowfive@81
|
270 end
|
yellowfive@81
|
271
|
yellowfive@81
|
272 local function scanArtifact()
|
yellowfive@91
|
273 if not Amr.db or not Amr.db.char or not Amr.db.char.Artifacts then return end
|
yellowfive@91
|
274
|
yellowfive@81
|
275 local powers = C_ArtifactUI.GetPowers()
|
yellowfive@81
|
276 if not powers then return end
|
yellowfive@81
|
277
|
yellowfive@81
|
278 local powerRanks = {}
|
yellowfive@81
|
279 for k,v in pairs(powers) do
|
yellowfive@106
|
280 local powerInfo = C_ArtifactUI.GetPowerInfo(v)
|
yellowfive@106
|
281 if powerInfo.currentRank - powerInfo.bonusRanks > 0 then
|
yellowfive@106
|
282 powerRanks[v] = powerInfo.currentRank - powerInfo.bonusRanks
|
yellowfive@81
|
283 end
|
yellowfive@81
|
284 end
|
yellowfive@81
|
285
|
yellowfive@81
|
286 local relicInfo = {}
|
yellowfive@81
|
287 for i = 1,3 do
|
yellowfive@81
|
288 local _, _, _, link = C_ArtifactUI.GetRelicInfo(i);
|
yellowfive@81
|
289 table.insert(relicInfo, link or "")
|
yellowfive@81
|
290 end
|
yellowfive@81
|
291
|
yellowfive@81
|
292 -- 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
|
293 powers = C_ArtifactUI.GetPowers()
|
yellowfive@81
|
294 if not powers then return end
|
yellowfive@81
|
295
|
yellowfive@89
|
296 -- use the artifact item ID to figure out which spec this is for, since you can open your artifact on any spec
|
yellowfive@91
|
297 local itemID = C_ArtifactUI.GetArtifactInfo()
|
yellowfive@89
|
298 local spec = Amr.ArtifactIdToSpecNumber[itemID]
|
yellowfive@89
|
299 --local spec = GetSpecialization()
|
yellowfive@89
|
300
|
yellowfive@91
|
301 if spec then
|
yellowfive@91
|
302 Amr.db.char.Artifacts[spec] = {
|
yellowfive@91
|
303 Powers = powerRanks,
|
yellowfive@91
|
304 Relics = relicInfo
|
yellowfive@91
|
305 }
|
yellowfive@91
|
306 end
|
yellowfive@81
|
307 end
|
yellowfive@81
|
308
|
yellowfive@57
|
309 -- Returns a data object containing all information about the current player needed for an export:
|
yellowfive@57
|
310 -- gear, spec, reputations, bag, bank, and void storage items.
|
yellowfive@57
|
311 function Amr:ExportCharacter()
|
yellowfive@57
|
312
|
yellowfive@57
|
313 local data = getEquipped()
|
yellowfive@57
|
314 scanBags()
|
yellowfive@57
|
315
|
yellowfive@81
|
316 -- scan current spec's talents just before exporting
|
yellowfive@81
|
317 scanTalents()
|
yellowfive@81
|
318
|
yellowfive@81
|
319 data.Talents = Amr.db.char.Talents
|
yellowfive@81
|
320 data.Artifacts = Amr.db.char.Artifacts
|
yellowfive@57
|
321 data.Equipped = Amr.db.char.Equipped
|
yellowfive@57
|
322 data.Reputations = getReputations()
|
yellowfive@57
|
323 data.BagItems = Amr.db.char.BagItems
|
yellowfive@57
|
324 data.BankItems = Amr.db.char.BankItems
|
yellowfive@57
|
325 data.VoidItems = Amr.db.char.VoidItems
|
yellowfive@57
|
326
|
yellowfive@57
|
327 return data
|
yellowfive@57
|
328 end
|
yellowfive@57
|
329
|
yellowfive@57
|
330 function Amr:InitializeExport()
|
yellowfive@57
|
331 Amr:AddEventHandler("UNIT_INVENTORY_CHANGED", function(unitID)
|
yellowfive@57
|
332 if unitID and unitID ~= "player" then return end
|
yellowfive@57
|
333 getEquipped()
|
yellowfive@57
|
334 end)
|
yellowfive@57
|
335 end
|
yellowfive@57
|
336
|
yellowfive@57
|
337 Amr:AddEventHandler("BANKFRAME_OPENED", scanBank)
|
yellowfive@57
|
338 Amr:AddEventHandler("PLAYERBANKSLOTS_CHANGED", scanBank)
|
yellowfive@57
|
339
|
yellowfive@57
|
340 Amr:AddEventHandler("VOID_STORAGE_OPEN", scanVoid)
|
yellowfive@57
|
341 Amr:AddEventHandler("VOID_STORAGE_CONTENTS_UPDATE", scanVoid)
|
yellowfive@57
|
342 Amr:AddEventHandler("VOID_STORAGE_DEPOSIT_UPDATE", scanVoid)
|
yellowfive@57
|
343 Amr:AddEventHandler("VOID_STORAGE_UPDATE", scanVoid)
|
yellowfive@81
|
344
|
yellowfive@81
|
345 Amr:AddEventHandler("PLAYER_TALENT_UPDATE", scanTalents)
|
yellowfive@81
|
346 Amr:AddEventHandler("ARTIFACT_UPDATE", scanArtifact)
|