Mercurial > wow > askmrrobot
comparison ui/SummaryTab.lua @ 0:ec731d2fe6ba
Version 1.2.12.0
author | Adam tegen <adam.tegen@gmail.com> |
---|---|
date | Tue, 20 May 2014 21:43:23 -0500 |
parents | |
children | ece9167c0d1c |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ec731d2fe6ba |
---|---|
1 local _, AskMrRobot = ... | |
2 | |
3 AskMrRobot.SummaryTab = AskMrRobot.inheritsFrom(AskMrRobot.Frame) | |
4 | |
5 function AskMrRobot.SummaryTab:new(parent) | |
6 | |
7 local tab = AskMrRobot.Frame:new(nil, parent) | |
8 setmetatable(tab, { __index = AskMrRobot.SummaryTab }) | |
9 tab:SetPoint("TOPLEFT") | |
10 tab:SetPoint("BOTTOMRIGHT") | |
11 tab:Hide() | |
12 | |
13 | |
14 tab.importDate = "" | |
15 | |
16 local text = tab:CreateFontString("AmrSummaryText1", "ARTWORK", "GameFontNormalLarge") | |
17 text:SetPoint("TOPLEFT", 0, -5) | |
18 text:SetFormattedText("Summary") | |
19 | |
20 -- error text | |
21 tab.errorText1 = tab:CreateFontString("AmrSummaryErrorText1", "ARTWORK", "GameFontRedLarge") | |
22 tab.errorText1:SetPoint("TOPLEFT", "AmrSummaryText1", "BOTTOMLEFT", 0, -20) | |
23 tab.errorText1:SetText("You have no optimizations imported.") | |
24 tab.errorText1:SetPoint("RIGHT", -20, 0) | |
25 tab.errorText1:SetWidth(tab.errorText1:GetWidth()) | |
26 tab.errorText1:SetWordWrap(true) | |
27 tab.errorText1:SetJustifyH("LEFT") | |
28 | |
29 tab.errorText2 = tab:CreateFontString("AmrSummaryErrorText2", "ARTWORK", "GameFontWhite") | |
30 tab.errorText2:SetPoint("TOPLEFT", "AmrSummaryErrorText1", "BOTTOMLEFT", 0, -15) | |
31 tab.errorText2:SetPoint("RIGHT", -20, 0) | |
32 tab.errorText2:SetWidth(tab.errorText2:GetWidth()) | |
33 tab.errorText2:SetJustifyH("LEFT") | |
34 tab.errorText2:SetText('Click the "Import" tab to get started.') | |
35 | |
36 -- bad items | |
37 tab.badItemSlots = {} | |
38 tab.badItemNames = {} | |
39 | |
40 local itemText = tab:CreateFontString("AmrBadItemSlot0", "ARTWORK", "GameFontNormal") | |
41 itemText:SetPoint("TOPLEFT", "AmrSummaryErrorText2", "BOTTOMLEFT", 0, -20) | |
42 itemText:SetText("Slot") | |
43 itemText:SetWidth(100) | |
44 itemText:SetJustifyH("LEFT") | |
45 itemText:Hide() | |
46 tinsert(tab.badItemSlots, itemText) | |
47 | |
48 itemText = tab:CreateFontString("AmrBadItemName0", "ARTWORK", "GameFontNormal") | |
49 itemText:SetPoint("TOPLEFT", "AmrBadItemSlot0", "TOPLEFT", 120, 0) | |
50 itemText:SetPoint("RIGHT", -30, 0) | |
51 itemText:SetText("Item Name") | |
52 itemText:SetJustifyH("LEFT") | |
53 itemText:Hide() | |
54 tinsert(tab.badItemNames, itemText) | |
55 | |
56 itemText = tab:CreateFontString(nil, "ARTWORK", "GameFontWhite") | |
57 itemText:SetPoint("LEFT", 0, 0) | |
58 itemText:SetPoint("RIGHT", -30, 0) | |
59 itemText:SetPoint("TOP", "AmrBadItemSlot0", "TOP", 0, 0 ) | |
60 itemText:SetText("Please upgrade the following items:") | |
61 itemText:SetJustifyH("LEFT") | |
62 itemText:Hide() | |
63 tab.upgradeInstructions = itemText | |
64 | |
65 itemText = tab:CreateFontString(nil, "ARTWORK", "GameFontNormal") | |
66 itemText:SetPoint("LEFT", "AmrBadItemSlot0", "LEFT", 0, -20) | |
67 itemText:SetPoint("RIGHT", "AmrBadItemSlot0", "RIGHT", 0, -20) | |
68 itemText:SetPoint("TOP", tab.upgradeInstructions, "BOTTOM", 0, -10 ) | |
69 itemText:SetHeight(20) | |
70 itemText:SetText("Slot") | |
71 itemText:SetJustifyH("LEFT") | |
72 itemText:Hide() | |
73 tab.upgradeSlotHeader = itemText | |
74 | |
75 itemText = tab:CreateFontString(nil, "ARTWORK", "GameFontNormal") | |
76 itemText:SetPoint("LEFT", "AmrBadItemName0", "LEFT", 0, 0) | |
77 itemText:SetPoint("RIGHT", "AmrBadItemName0", "RIGHT", 0, 0) | |
78 itemText:SetPoint("TOP", tab.upgradeSlotHeader, "TOP", 0, 0) | |
79 itemText:SetPoint("BOTTOM", tab.upgradeSlotHeader, "BOTTOM", 0, 0) | |
80 itemText:SetText("Item Name") | |
81 itemText:SetJustifyH("LEFT") | |
82 itemText:Hide() | |
83 tab.upgradeItemHeader = itemText | |
84 | |
85 for i = 1, #AskMrRobot.slotNames do | |
86 local itemText = tab:CreateFontString("AmrBadItemSlot" .. i, "ARTWORK", "GameFontWhite") | |
87 itemText:SetPoint("TOPLEFT", "AmrBadItemSlot" .. (i-1), "BOTTOMLEFT", 0, -5) | |
88 itemText:SetPoint("TOPRIGHT", "AmrBadItemSlot" .. (i-1), "BOTTOMRIGHT", 0, -5) | |
89 itemText:SetJustifyH("LEFT") | |
90 itemText:Hide() | |
91 tinsert(tab.badItemSlots, itemText) | |
92 | |
93 itemText = AskMrRobot.ItemLinkText:new(nil, tab) | |
94 itemText:SetPoint("LEFT", "AmrBadItemName0", "TOPLEFT", 0, 0) | |
95 itemText:SetPoint("RIGHT", "AmrBadItemName0", "BOTTOMRIGHT", 0, 0) | |
96 itemText:SetPoint("TOP", "AmrBadItemSlot" .. i, 0, 0) | |
97 itemText:SetPoint("BOTTOM", "AmrBadItemSlot" .. i, 0, 0) | |
98 itemText:Hide() | |
99 tinsert(tab.badItemNames, itemText) | |
100 end | |
101 | |
102 tab.upgradeItemSlots = {} | |
103 tab.upgradeItemNames = {} | |
104 for i = 1, #AskMrRobot.slotNames do | |
105 local itemText = tab:CreateFontString(nil, "ARTWORK", "GameFontWhite") | |
106 if i == 1 then | |
107 itemText:SetPoint("TOPLEFT", tab.upgradeSlotHeader, "BOTTOMLEFT", 0, -5) | |
108 itemText:SetPoint("TOPRIGHT", tab.upgradeSlotHeader, "BOTTOMRIGHT", 0, -5) | |
109 else | |
110 itemText:SetPoint("TOPLEFT", tab.upgradeItemSlots[i-1], "BOTTOMLEFT", 0, -5) | |
111 itemText:SetPoint("TOPRIGHT", tab.upgradeItemSlots[i-1], "BOTTOMRIGHT", 0, -5) | |
112 end | |
113 itemText:SetJustifyH("LEFT") | |
114 itemText:Hide() | |
115 tinsert(tab.upgradeItemSlots, itemText) | |
116 | |
117 itemText = AskMrRobot.ItemLinkText:new(nil, tab) | |
118 itemText:SetFormat("|cff00ff00Upgrade|r %s") | |
119 itemText:SetPoint("LEFT", tab.upgradeItemHeader, "LEFT", 0, 0) | |
120 itemText:SetPoint("RIGHT", tab.upgradeItemHeader, "RIGHT", 0, 0) | |
121 itemText:SetPoint("TOP", tab.upgradeItemSlots[i], 0, 0) | |
122 itemText:SetPoint("BOTTOM", tab.upgradeItemSlots[i], 0, 0) | |
123 itemText:Hide() | |
124 tinsert(tab.upgradeItemNames, itemText) | |
125 end | |
126 | |
127 tab.importInfo = tab:CreateFontString(nil, "ARTWORK", "GameFontNormal") | |
128 tab.importInfo:SetText("Last import: ?\rThese optimizations are for ?") | |
129 tab.importInfo:SetPoint("TOPLEFT", text, "BOTTOMLEFT", 0, -20) | |
130 tab.importInfo:SetJustifyH("LEFT") | |
131 tab.importInfo:Hide() | |
132 | |
133 tab.specIcon = tab:CreateTexture(nil, "BACKGROUND") | |
134 tab.specIcon:SetPoint("TOPLEFT") | |
135 tab.specIcon:SetWidth(64) | |
136 tab.specIcon:SetHeight(64) | |
137 tab.specIcon:SetPoint("TOPLEFT", tab.importInfo, "BOTTOMLEFT", 0, -10) | |
138 tab.specIcon:Hide() | |
139 | |
140 tab.stamp = AskMrRobot.RobotStamp:new(nil, tab) | |
141 tab.stamp:Hide() | |
142 tab.stamp.smallText:SetText("Congratulations! You are 100% optimal") | |
143 tab.stamp:SetPoint("TOPLEFT", tab.specIcon, "BOTTOMLEFT", 2, -25) | |
144 tab.stamp:SetPoint("RIGHT", tab, "RIGHT", -20, 0) | |
145 tab.stamp:Hide() | |
146 | |
147 tab.specText = tab:CreateFontString(nil, "ARTWORK", "GameFontHighlightLarge") | |
148 local Path, Size, Flags = tab.specText:GetFont() | |
149 tab.specText:SetFont(Path, 24, Flags); | |
150 tab.specText:SetPoint("LEFT", tab.specIcon, "RIGHT", 10, 0) | |
151 tab.specText:SetText("?") | |
152 tab.specText:Hide() | |
153 | |
154 tab.optimizationSummary = tab:CreateFontString(nil, "ARTWORK", "GameFontNormal") | |
155 tab.optimizationSummary:SetPoint("TOPLEFT", tab.specIcon, "BOTTOMLEFT", 0, -15) | |
156 tab.optimizationSummary:SetText("You have ? optimizations to make:") | |
157 tab.optimizationSummary:Hide() | |
158 | |
159 tab.gemCount = tab:CreateFontString(nil, "ARTWORK", "GameFontWhite") | |
160 tab.gemCount:SetPoint("TOPLEFT", tab.optimizationSummary, "BOTTOMLEFT", 0, -15) | |
161 tab.gemCount:SetText("? gems") | |
162 tab.gemCount:Hide() | |
163 | |
164 tab.enchantCount = tab:CreateFontString(nil, "ARTWORK", "GameFontWhite") | |
165 tab.enchantCount:SetPoint("TOPLEFT", tab.gemCount, "BOTTOMLEFT", 0, -5) | |
166 tab.enchantCount:SetText("? enchants") | |
167 tab.enchantCount:Hide() | |
168 | |
169 tab.reforgeCount = tab:CreateFontString(nil, "ARTWORK", "GameFontWhite") | |
170 tab.reforgeCount:SetPoint("TOPLEFT", tab.enchantCount, "BOTTOMLEFT", 0, -5) | |
171 tab.reforgeCount:SetText("? reforges") | |
172 tab.reforgeCount:Hide() | |
173 | |
174 tab.instructions = tab:CreateFontString(nil, "ARTWORK", "GameFontWhite") | |
175 tab.instructions:SetPoint("TOPLEFT", tab.reforgeCount, "BOTTOMLEFT", 0, -15) | |
176 tab.instructions:SetText("View the Gem, Enchant and Reforge tabs for suggested optimizations.") | |
177 tab.instructions:Hide() | |
178 | |
179 return tab | |
180 end | |
181 | |
182 function AskMrRobot.SummaryTab:getSpecIcon(specId) | |
183 for i = 1, GetNumSpecializations() do | |
184 local id, _, _, icon = GetSpecializationInfo(i) | |
185 if id == specId then | |
186 return icon | |
187 end | |
188 end | |
189 return nil | |
190 end | |
191 | |
192 function AskMrRobot.SummaryTab:showBadItems() | |
193 local badItems = AskMrRobot.itemDiffs.items | |
194 | |
195 local i = 2 | |
196 | |
197 -- for all the bad items | |
198 for slotNum, badItem in AskMrRobot.sortSlots(badItems) do | |
199 if not badItem.needsUpgrade then | |
200 self.badItemSlots[i]:SetText(_G[strupper(AskMrRobot.slotNames[slotNum])]) | |
201 self.badItemSlots[i]:Show() | |
202 if badItem.optimized then | |
203 self.badItemNames[i]:SetItemId(badItem.optimized.itemId, badItem.optimized.upgradeId, badItem.optimized.suffixId) | |
204 else | |
205 self.badItemNames[i]:SetItemId(nil, 0, 0) | |
206 end | |
207 self.badItemNames[i]:Show() | |
208 i = i + 1 | |
209 end | |
210 end | |
211 | |
212 -- for all the upgrade items | |
213 local j = 1 | |
214 for slotNum, badItem in AskMrRobot.sortSlots(badItems) do | |
215 if badItem.needsUpgrade then | |
216 self.upgradeItemSlots[j]:SetText(_G[strupper(AskMrRobot.slotNames[slotNum])]) | |
217 self.upgradeItemSlots[j]:Show() | |
218 if badItem.optimized then | |
219 self.upgradeItemNames[j]:SetItemId(badItem.optimized.itemId, badItem.optimized.upgradeId, badItem.optimized.suffixId) | |
220 else | |
221 self.upgradeItemNames[j]:SetItemId(nil, 0, 0) | |
222 end | |
223 self.upgradeItemNames[j]:Show() | |
224 j = j + 1 | |
225 end | |
226 end | |
227 | |
228 -- hide / show the headers | |
229 if i == 2 and j == 1 then | |
230 self.badItemSlots[1]:Hide() | |
231 self.badItemNames[1]:Hide() | |
232 self:showImportError(nil) | |
233 self.importInfo:Show() | |
234 self.specIcon:Show() | |
235 self.optimizationSummary:Show() | |
236 self.gemCount:Show() | |
237 self.enchantCount:Show() | |
238 self.reforgeCount:Show() | |
239 self.instructions:Show() | |
240 self.specText:Show() | |
241 | |
242 local gemCount = 0 | |
243 for slotNum, badGems in pairs(AskMrRobot.itemDiffs.gems) do | |
244 for k, v in pairs(badGems.badGems) do | |
245 gemCount = gemCount + 1 | |
246 end | |
247 end | |
248 | |
249 self.gemCount:SetFormattedText("%d \1244gem:gems;", gemCount) | |
250 | |
251 local enchantCount = 0 | |
252 for slotNum, badEnchant in pairs(AskMrRobot.itemDiffs.enchants) do | |
253 enchantCount = enchantCount + 1 | |
254 end | |
255 | |
256 self.enchantCount:SetFormattedText("%d \1244enchant:enchants;", enchantCount) | |
257 | |
258 local reforgeCount = 0 | |
259 for slotNum, badReforge in pairs(AskMrRobot.itemDiffs.reforges) do | |
260 reforgeCount = reforgeCount + 1 | |
261 end | |
262 | |
263 self.reforgeCount:SetFormattedText("%d \1244reforge:reforges;", reforgeCount) | |
264 self.optimizationSummary:SetFormattedText("You have %d \1244optimization:optimizations; to make:", gemCount + enchantCount + reforgeCount) | |
265 | |
266 if gemCount + enchantCount + reforgeCount == 0 then | |
267 self.stamp:Show() | |
268 self.optimizationSummary:Hide() | |
269 self.enchantCount:Hide() | |
270 self.reforgeCount:Hide() | |
271 self.instructions:Hide() | |
272 self.gemCount:Hide() | |
273 else | |
274 self.stamp:Hide() | |
275 self.optimizationSummary:Show() | |
276 self.enchantCount:Show() | |
277 self.reforgeCount:Show() | |
278 self.instructions:Show() | |
279 self.gemCount:Show() | |
280 end | |
281 | |
282 local activeSpecGroup = GetActiveSpecGroup() | |
283 | |
284 if activeSpecGroup == nil then | |
285 self.importInfo:SetFormattedText("Last import: %s\rThese optimizations are for %s", self.importDate, UnitName("player")) | |
286 else | |
287 self.importInfo:SetFormattedText("Last import: %s\rThese optimizations are for %s's...", self.importDate, UnitName("player")) | |
288 local spec = GetSpecialization(false, false, group); | |
289 if spec then | |
290 local _, name, _, icon = GetSpecializationInfo(spec); | |
291 if activeSpecGroup == 1 then | |
292 self.specText:SetFormattedText("Primary Spec - %s", name) | |
293 else | |
294 self.specText:SetFormattedText("Secondary Spec - %s", name) | |
295 end | |
296 self.specIcon:SetTexture(icon) | |
297 end | |
298 end | |
299 | |
300 | |
301 --local currentSpec = GetAmrSpecialization(GetActiveSpecGroup()) | |
302 --return (not currentSpec and not spec) or tostring(currentSpec) == spec | |
303 else | |
304 self.importInfo:Hide() | |
305 self.specIcon:Hide() | |
306 self.optimizationSummary:Hide() | |
307 self.gemCount:Hide() | |
308 self.enchantCount:Hide() | |
309 self.reforgeCount:Hide() | |
310 self.instructions:Hide() | |
311 self.specText:Hide() | |
312 end | |
313 | |
314 if i == 2 then | |
315 self.badItemSlots[1]:Hide() | |
316 self.badItemNames[1]:Hide() | |
317 else | |
318 self.badItemSlots[1]:Show() | |
319 self.badItemNames[1]:Show() | |
320 local warnings = {} | |
321 if self.badRealm then | |
322 tinsert(warnings, "a different realm: " .. self.badRealm) | |
323 end | |
324 if self.badTalents then | |
325 tinsert(warnings, "different talents") | |
326 end | |
327 if self.badGlyphs then | |
328 tinsert(warnings, "different glyphs") | |
329 end | |
330 local message = "Mr. Robot optimized a different set of gear" | |
331 if #warnings > 0 then | |
332 message = message .. " (and " | |
333 for k = 1, #warnings do | |
334 if k > 1 then | |
335 message = message .. ', ' | |
336 end | |
337 message = message .. warnings[k] | |
338 end | |
339 message = message .. ")" | |
340 end | |
341 message = message .. ". Please equip the following items before proceeding with the optimizations." | |
342 self:showImportWarning("WARNING: Please check your character before proceeding:", message) | |
343 end | |
344 | |
345 if j == 1 then | |
346 self.upgradeItemHeader:Hide() | |
347 self.upgradeSlotHeader:Hide() | |
348 self.upgradeInstructions:Hide() | |
349 else | |
350 if i == 2 then | |
351 local warnings = {} | |
352 if self.badRealm then | |
353 tinsert(warnings, "a different realm: " .. self.badRealm) | |
354 end | |
355 if self.badTalents then | |
356 tinsert(warnings, "different talents") | |
357 end | |
358 if self.badGlyphs then | |
359 tinsert(warnings, "different glyphs") | |
360 end | |
361 local message = nil | |
362 if #warnings > 0 then | |
363 message = "Mr. Robot optimized for " | |
364 for k = 1, #warnings do | |
365 if k > 1 then | |
366 message = message .. ', ' | |
367 end | |
368 message = message .. warnings[k] | |
369 end | |
370 message = message .. "." | |
371 end | |
372 self:showImportWarning("WARNING: Please check your character before proceeding:", message) | |
373 end | |
374 self.upgradeItemHeader:Show() | |
375 self.upgradeSlotHeader:Show() | |
376 self.upgradeInstructions:Show() | |
377 if i == 2 then | |
378 self.upgradeInstructions:SetPoint("TOP", self.badItemSlots[1], "TOP", 0, 0) | |
379 self.errorText2:Hide() | |
380 else | |
381 self.upgradeInstructions:SetPoint("TOP", self.badItemSlots[i], "BOTTOM", 0, -20) | |
382 end | |
383 end | |
384 | |
385 -- hide the remaining slots | |
386 while i <= #self.badItemSlots do | |
387 self.badItemSlots[i]:Hide() | |
388 self.badItemNames[i]:Hide() | |
389 i = i + 1 | |
390 end | |
391 | |
392 -- hide the remaining slots | |
393 while j <= #self.upgradeItemSlots do | |
394 self.upgradeItemSlots[j]:Hide() | |
395 self.upgradeItemNames[j]:Hide() | |
396 j = j + 1 | |
397 end | |
398 end | |
399 | |
400 | |
401 function AskMrRobot.SummaryTab:showImportError(text, text2) | |
402 self.stamp:Hide() | |
403 self.gemCount:Hide() | |
404 self.instructions:Hide() | |
405 self.reforgeCount:Hide() | |
406 self.enchantCount:Hide() | |
407 self.optimizationSummary:Hide() | |
408 if text then | |
409 self.errorText1:Show() | |
410 self.errorText1:SetText('Error! Your import did not work:|n|n' .. text) | |
411 self.errorText1:Show() | |
412 self.errorText2:SetText(text2) | |
413 self.errorText2:Show() | |
414 self.importInfo:Hide() | |
415 self.upgradeSlotHeader:Hide() | |
416 self.upgradeItemHeader:Hide() | |
417 self.upgradeInstructions:Hide() | |
418 self.specIcon:Hide() | |
419 self.specText:Hide() | |
420 else | |
421 self.errorText1:Hide() | |
422 self.errorText2:Hide() | |
423 self.importInfo:Show() | |
424 end | |
425 for i = 1, #AskMrRobot.slotNames + 1 do | |
426 self.badItemSlots[i]:Hide() | |
427 self.badItemNames[i]:Hide() | |
428 end | |
429 for i = 1, #AskMrRobot.slotNames do | |
430 self.upgradeItemSlots[i]:Hide() | |
431 self.upgradeItemNames[i]:Hide() | |
432 end | |
433 end | |
434 | |
435 function AskMrRobot.SummaryTab:showImportWarning (text, text2) | |
436 self.stamp:Hide() | |
437 self.hasImportError = false | |
438 self.gemCount:Hide() | |
439 self.instructions:Hide() | |
440 self.reforgeCount:Hide() | |
441 self.enchantCount:Hide() | |
442 self.specIcon:Hide() | |
443 self.specText:Hide() | |
444 self.optimizationSummary:Hide() | |
445 if text then | |
446 self.errorText1:SetText(text) | |
447 self.errorText1:Show() | |
448 self.errorText2:SetText(text2) | |
449 self.errorText2:Show() | |
450 else | |
451 self.errorText1:Hide() | |
452 self.errorText2:Hide() | |
453 end | |
454 end |