vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 local compost = AceLibrary("Compost-2.0")
2 local tablet = AceLibrary("Tablet-2.0")
3 local dewdrop = AceLibrary("Dewdrop-2.0")
4 local abacus = AceLibrary("Abacus-2.0")
5  
6 ExperienceFu = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "FuBarPlugin-2.0", "AceDB-2.0")
7 ExperienceFu.hasIcon = true
8 ExperienceFu:RegisterDB("ExperienceFuDB")
9 ExperienceFu:RegisterDefaults("profile", {
10 showValue = {
11 current = false,
12 rest = false,
13 pet = false,
14 },
15 showPercent = {
16 current = true,
17 rest = true,
18 pet = true
19 },
20 showDepletion = {
21 current = false,
22 rest = false,
23 pet = false,
24 },
25 })
26  
27 local L = ExperienceFuLocals
28  
29 ExperienceFu.options = {
30 type = "group",
31 handler = ExperienceFu,
32 args = {
33 reset_session = {
34 type = "execute",
35 name = L"Reset session",
36 desc = L"Reset session",
37 func = "ResetSession",
38 order = -1,
39 },
40 hidesixty = {
41 hidden = function() return UnitLevel("player") ~= 60 end,
42 type = "toggle",
43 name = L"Hide Text at maximum level",
44 desc = L"Hide Text at maximum level",
45 get = function() return ExperienceFu:IsPreSixtyOnly() end,
46 set = function() ExperienceFu:TogglePreSixtyOnly() end,
47 },
48 stats = {
49 type = "group",
50 name = L"Statistics",
51 desc = L"Display various XP statistics",
52 args = {
53 xp_hour = {
54 type = "toggle",
55 name = L"Show XP/hour",
56 desc = L"Show XP/hour",
57 get = function() return ExperienceFu:IsShowingXPPerHour() end,
58 set = function() ExperienceFu:ToggleShowingXPPerHour() end,
59 },
60 ttl = {
61 type = "toggle",
62 name = L"Show time to level",
63 desc = L"Show time to level",
64 get = function() return ExperienceFu:IsShowingTimeToLevel() end,
65 set = function() ExperienceFu:ToggleShowingTimeToLevel() end,
66 },
67 show_by = {
68 hidden = function() return not (ExperienceFu:IsShowingXPPerHour() or ExperienceFu:IsShowingTimeToLevel()) end,
69 type = "toggle",
70 name = L"Show in relation to level",
71 desc = L"Toggle between showing experience as an absolute or in relation to time.",
72 get = function() return ExperienceFu:IsShowingByLevel() end,
73 set = function() ExperienceFu:ToggleShowingByLevel() end,
74 order = 999,
75 },
76 },
77 },
78 show = {
79 type = "group",
80 name = L"Display Values",
81 desc = L"Display Value as...",
82 args = {
83 current = {
84 name = L"Current XP",
85 desc = L"Show current XP",
86 type = "group",
87 args = {
88 value = {
89 type = "toggle",
90 name = L"Show value",
91 desc = L"Show current XP value",
92 get = function() return ExperienceFu:IsShowingValue("current") end,
93 set = function() return ExperienceFu:ToggleShowingValue("current") end,
94 },
95 percent = {
96 type = "toggle",
97 name = L"Show percent",
98 desc = L"Show current XP percent",
99 get = function() return ExperienceFu:IsShowingPercent("current") end,
100 set = function() return ExperienceFu:ToggleShowingPercent("current") end,
101 },
102 depletion = {
103 type = "toggle",
104 name = L"View as Remaining XP",
105 desc = L"Show current XP until level",
106 get = function() return ExperienceFu:IsShowingDepletion("current") end,
107 set = function() return ExperienceFu:ToggleShowingDepletion("current") end,
108 },
109 },
110 },
111 rest = {
112 name = L"Rest XP",
113 desc = L"Show rest XP",
114 type = "group",
115 args = {
116 value = {
117 type = "toggle",
118 name = L"Show value",
119 desc = L"Show rest XP value",
120 get = function() return ExperienceFu:IsShowingValue("rest") end,
121 set = function() return ExperienceFu:ToggleShowingValue("rest") end,
122 },
123 percent = {
124 type = "toggle",
125 name = L"Show percent",
126 desc = L"Show rest XP percent",
127 get = function() return ExperienceFu:IsShowingPercent("rest") end,
128 set = function() return ExperienceFu:ToggleShowingPercent("rest") end,
129 },
130 },
131 },
132 pet = {
133 hidden = function() return ExperienceFu.playerClass ~= "HUNTER" end,
134 name = L"Pet XP",
135 desc = L"Show pet XP",
136 type = "group",
137 args = {
138 value = {
139 type = "toggle",
140 name = L"Show value",
141 desc = L"Show pet XP value",
142 get = function() return ExperienceFu:IsShowingValue("pet") end,
143 set = function() return ExperienceFu:ToggleShowingValue("pet") end,
144 },
145 percent = {
146 type = "toggle",
147 name = L"Show percent",
148 desc = L"Show pet XP percent",
149 get = function() return ExperienceFu:IsShowingPercent("pet") end,
150 set = function() return ExperienceFu:ToggleShowingPercent("pet") end,
151 },
152 depletion = {
153 type = "toggle",
154 name = L"View as Remaining XP",
155 desc = L"Show pet XP until level",
156 get = function() return ExperienceFu:IsShowingDepletion("pet") end,
157 set = function() return ExperienceFu:ToggleShowingDepletion("pet") end,
158 },
159 },
160 },
161 },
162 },
163 },
164 }
165  
166 function ExperienceFu:OnInitialize()
167 self.initialXP = UnitXP("player")
168 self.accumulatedXP = 0
169 self.sessionXP = 0
170 self.entranceTime = time()
171 self.levelUpTime = time()
172 self.totalTime = time()
173 self.levelTime = time()
174  
175 end
176  
177 function ExperienceFu:OnEnable()
178 self.timeSinceLastUpdate = 0
179  
180 self:RegisterEvent("PLAYER_XP_UPDATE", "OnPlayerXpUpdate")
181 self:RegisterEvent("PLAYER_LEVEL_UP", "OnPlayerLevelUp")
182 self:RegisterEvent("TIME_PLAYED_MSG", "OnTimePlayedMsg")
183  
184 RequestTimePlayed()
185  
186 self:ScheduleRepeatingEvent("ExperienceFu_Update", self.Update, 1, self)
187  
188 _, self.playerClass = UnitClass("player")
189 end
190  
191 function ExperienceFu:OnDisable()
192 self:CancelScheduledEvent("ExperienceFu_Update")
193 self:UnregisterEvent("PLAYER_XP_UPDATE")
194 self:UnregisterEvent("PLAYER_LEVEL_UP")
195 self:UnregisterEvent("TIME_PLAYED_MSG")
196 end
197  
198 function ExperienceFu:OnMenuRequest()
199 dewdrop:FeedAceOptionsTable(self.options)
200 end
201  
202 function ExperienceFu:IsShowingValue(setting)
203 return self.db.profile.showValue[setting]
204 end
205  
206 function ExperienceFu:ToggleShowingValue(setting, loud)
207 self.db.profile.showValue[setting] = not self.db.profile.showValue[setting]
208 self:UpdateText()
209 return self.db.profile.showValue[setting]
210 end
211  
212 function ExperienceFu:IsShowingPercent(setting)
213 return self.db.profile.showPercent[setting]
214 end
215  
216 function ExperienceFu:ToggleShowingPercent(setting, loud)
217 self.db.profile.showPercent[setting] = not self.db.profile.showPercent[setting]
218 self:UpdateText()
219 return self.db.profile.showPercent[setting]
220 end
221  
222 function ExperienceFu:IsShowingDepletion(setting)
223 return self.db.profile.showDepletion[setting]
224 end
225  
226 function ExperienceFu:ToggleShowingDepletion(setting, loud)
227 self.db.profile.showDepletion[setting] = not self.db.profile.showDepletion[setting]
228 self:UpdateText()
229 return self.db.profile.showDepletion[setting]
230 end
231  
232 function ExperienceFu:IsShowingXPPerHour()
233 return self.db.profile.xpPerHour
234 end
235  
236 function ExperienceFu:ToggleShowingXPPerHour(loud)
237 self.db.profile.xpPerHour = not self.db.profile.xpPerHour
238 self:UpdateText()
239 return self.db.profile.xpPerHour
240 end
241  
242 function ExperienceFu:IsShowingTimeToLevel()
243 return self.db.profile.timeToLevel
244 end
245  
246 function ExperienceFu:ToggleShowingTimeToLevel(loud)
247 self.db.profile.timeToLevel = not self.db.profile.timeToLevel
248 self:UpdateText()
249 return self.db.profile.timeToLevel
250 end
251  
252 function ExperienceFu:IsShowingByLevel()
253 return self.db.profile.byLevel
254 end
255  
256 function ExperienceFu:ToggleShowingByLevel(loud)
257 self.db.profile.byLevel = not self.db.profile.byLevel
258 self:UpdateText()
259 return self.db.profile.byLevel
260 end
261  
262 function ExperienceFu:IsPreSixtyOnly()
263 return self.db.profile.preSixtyOnly
264 end
265  
266 function ExperienceFu:TogglePreSixtyOnly()
267 self.db.profile.preSixtyOnly = not self.db.profile.preSixtyOnly
268 if (self.db.profile.preSixtyOnly) then self:SetText("") end
269 self:UpdateText()
270 return self.db.profile.preSixtyOnly
271 end
272  
273 function ExperienceFu:ResetSession()
274 self.initialXP = UnitXP("player")
275 self.accumulatedXP = 0
276 self.sessionXP = 0
277 self.entranceTime = time()
278 RequestTimePlayed()
279 end
280  
281 function ExperienceFu:GetLevelDuration()
282 return time() - self.levelUpTime
283 end
284  
285 function ExperienceFu:GetTotalDuration()
286 return time() - self.totalTime
287 end
288  
289 function ExperienceFu:GetSessionDuration()
290 return time() - self.entranceTime
291 end
292  
293 function ExperienceFu:OnPlayerXpUpdate()
294 self.sessionXP = UnitXP("player") - self.initialXP + self.accumulatedXP
295 end
296  
297 function ExperienceFu:OnPlayerLevelUp()
298 self.accumulatedXP = self.accumulatedXP + UnitXPMax("player") - self.initialXP
299 self.initialXP = 0
300 self.levelUpTime = time()
301 end
302  
303 function ExperienceFu:OnTimePlayedMsg()
304 self.totalTime = time() - arg1
305 self.levelUpTime = time() - arg2
306 end
307  
308 function ExperienceFu:UpdateText()
309 if (self.entranceTime == nil or (self:IsPreSixtyOnly() and UnitLevel("player") == 60)) then
310 return
311 end
312 local t = compost:Acquire()
313 if self:IsShowingValue("current") then
314 local val = UnitXP("player")
315 local max = UnitXPMax("player")
316 if self:IsShowingDepletion("current") then
317 val = max - val
318 end
319 table.insert(t, format("|cffffffff%d|r XP", val))
320 if self:IsShowingPercent("current") then
321 table.insert(t, format("(|cffffffff%.1f%%|r)", val/max * 100))
322 end
323 elseif self:IsShowingPercent("current") then
324 local val = UnitXP("player")
325 local max = UnitXPMax("player")
326 if self:IsShowingDepletion("current") then
327 val = max - val
328 end
329 table.insert(t, format("|cffffffff%.1f%%|r", val/max * 100))
330 end
331 if self:IsShowingValue("rest") then
332 local val = GetXPExhaustion() or 0
333 if val ~= 0 then
334 local max = UnitXPMax("player")
335 table.insert(t, format("R: |cffffffff%d|r XP", val))
336 if self:IsShowingPercent("rest") then
337 table.insert(t, format("(|cffffffff%.1f%%|r)", val/max * 100))
338 end
339 end
340 elseif self:IsShowingPercent("rest") then
341 local val = GetXPExhaustion() or 0
342 if val ~= 0 then
343 local max = UnitXPMax("player")
344 table.insert(t, format("R: |cffffffff%.1f%%|r", val/max * 100))
345 end
346 end
347 local _,class = UnitClass("player")
348 if class == "HUNTER" and UnitExists("pet") then
349 if self:IsShowingValue("pet") then
350 local val, max = GetPetExperience()
351 if self:IsShowingDepletion("pet") then
352 val = max - val
353 end
354 table.insert(t, format("P: |cffffffff%d|r XP", val))
355 if self:IsShowingPercent("pet") then
356 table.insert(t, format("(|cffffffff%.1f%%|r)", val/max * 100))
357 end
358 elseif self:IsShowingPercent("pet") then
359 local val, max = GetPetExperience()
360 if self:IsShowingDepletion("pet") then
361 val = max - val
362 end
363 table.insert(t, format("P: |cffffffff%.1f%%|r", val/max * 100))
364 end
365 end
366 if self:IsShowingXPPerHour() then
367 if self:IsShowingByLevel() then
368 local xpPerHourByLevel = floor(UnitXP("player") / self:GetLevelDuration() * 3600)
369 table.insert(t, format("|cffffffff%d|r XP/h", xpPerHourByLevel))
370 else
371 local xpPerHourBySession = floor(self.sessionXP / (time() - self.entranceTime) * 3600)
372 table.insert(t, format("|cffffffff%d|r XP/h", xpPerHourBySession))
373 end
374 end
375 if self:IsShowingTimeToLevel() then
376 if self:IsShowingByLevel() then
377 local timeToLevelByLevel = (UnitXPMax("player") - UnitXP("player")) * self:GetLevelDuration() / UnitXP("player")
378 table.insert(t, abacus:FormatDurationShort(timeToLevelByLevel, true))
379 else
380 local timeToLevelBySession = (UnitXPMax("player") - UnitXP("player")) * (time() - self.entranceTime) / self.sessionXP
381 table.insert(t, abacus:FormatDurationShort(timeToLevelBySession, true))
382 end
383 end
384 self:SetText(table.concat(t, " "))
385 compost:Reclaim(t)
386 end
387  
388 function ExperienceFu:OnTooltipUpdate()
389 local totalXP = UnitXPMax("player")
390 local currentXP = UnitXP("player")
391 local toLevelXP = totalXP - currentXP
392 local sessionXP = self.sessionXP
393 local sessionTime = time() - self.entranceTime
394 local levelTime = self:GetLevelDuration()
395 local xpPerHourByLevel = floor(currentXP / levelTime * 3600)
396 local timeToLevelByLevel = toLevelXP * levelTime / currentXP
397 local xpPerHourBySession = floor(sessionXP / sessionTime * 3600)
398 local timeToLevelBySession = toLevelXP * sessionTime / sessionXP
399 local restXP = GetXPExhaustion() or 0
400  
401 local cat = tablet:AddCategory(
402 'columns', 2,
403 'child_textR', 1,
404 'child_textG', 1,
405 'child_textB', 0,
406 'child_text2R', 1,
407 'child_text2G', 1,
408 'child_text2B', 1
409 )
410  
411 cat:AddLine(
412 'text', L"Total time played" .. ":",
413 'text2', abacus:FormatDurationFull(self:GetTotalDuration())
414 )
415  
416 cat:AddLine(
417 'text', L"Time this level" .. ":",
418 'text2', abacus:FormatDurationFull(self:GetLevelDuration())
419 )
420  
421 cat:AddLine(
422 'text', L"Time this session" .. ":",
423 'text2', abacus:FormatDurationFull(self:GetSessionDuration())
424 )
425  
426 cat = tablet:AddCategory(
427 'columns', 2,
428 'child_textR', 1,
429 'child_textG', 1,
430 'child_textB', 0,
431 'child_text2R', 1,
432 'child_text2G', 1,
433 'child_text2B', 1
434 )
435  
436 cat:AddLine(
437 'text', L"Level" .. ":",
438 'text2', UnitLevel("player")
439 )
440  
441 cat:AddLine(
442 'text', L"Total XP this level" .. ":",
443 'text2', totalXP
444 )
445  
446 cat:AddLine(
447 'text', L"Gained" .. ":",
448 'text2', format("%d (%.1f%%)", currentXP, currentXP / totalXP * 100)
449 )
450  
451 cat:AddLine(
452 'text', L"Remaining" .. ":",
453 'text2', format("%d (%.1f%%)", toLevelXP, toLevelXP / totalXP * 100)
454 )
455  
456 cat:AddLine(
457 'text', L"Total XP this session" .. ":",
458 'text2', sessionXP
459 )
460  
461 cat:AddLine(
462 'text', L"Rest XP" .. ":",
463 'text2', format("%d (%.1f%%)", restXP, restXP / totalXP * 100)
464 )
465  
466 local _,class = UnitClass("player")
467 if class == "HUNTER" and UnitExists("pet") then
468 local currXP, nextXP = GetPetExperience()
469 if currXP and nextXP and nextXP > 0 then
470 cat:AddLine(
471 'text', L"Pet XP" .. ":",
472 'text2', format("%d (%.1f%%)", currXP, currXP / nextXP * 100)
473 )
474 end
475 end
476  
477 local cat = tablet:AddCategory(
478 'columns', 2,
479 'child_textR', 1,
480 'child_textG', 1,
481 'child_textB', 0,
482 'child_text2R', 1,
483 'child_text2G', 1,
484 'child_text2B', 1
485 )
486  
487 cat:AddLine(
488 'text', L"XP/hour this level" .. ":",
489 'text2', xpPerHourByLevel
490 )
491  
492 cat:AddLine(
493 'text', L"XP/hour this session" .. ":",
494 'text2', xpPerHourBySession
495 )
496  
497 cat:AddLine(
498 'text', L"Time to level for this level" .. ":",
499 'text2', abacus:FormatDurationFull(timeToLevelByLevel)
500 )
501  
502 cat:AddLine(
503 'text', L"Time to level for this session" .. ":",
504 'text2', abacus:FormatDurationFull(timeToLevelBySession)
505 )
506 end