-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathLevelingTracker.lua
1689 lines (1370 loc) · 61.6 KB
/
LevelingTracker.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local addonName, addon = ...
local _G = _G
local fmt, smatch, strsub, tinsert, srep, mmax, abs = string.format,
string.match, string.sub,
tinsert, string.rep,
math.max, abs
local UnitLevel, GetRealZoneText, IsInGroup, tonumber, GetTime, GetServerTime,
UnitXP = UnitLevel, GetRealZoneText, IsInGroup, tonumber, GetTime,
GetServerTime, UnitXP
local AceGUI = LibStub("AceGUI-3.0")
local LibDeflate = LibStub("LibDeflate")
local L = addon.locale.Get
local LibDD = LibStub:GetLibrary("LibUIDropDownMenu-4.0", true)
local EasyMenu = function(...)
if LibDD then
LibDD:EasyMenu(...)
else
_G.EasyMenu(...)
end
end
addon.tracker = addon:NewModule("LevelingTracker", "AceEvent-3.0",
"AceComm-3.0", "AceSerializer-3.0")
addon.tracker.playerLevel = UnitLevel("player")
addon.tracker.state = {otherReports = {}, inspectionRequests = {}}
addon.tracker.reportData = {}
addon.tracker.ui = {}
addon.tracker._commPrefix = "RXPLTComms"
addon.tracker.fonts = {["splits"] = "Fonts\\ARIALN.ttf"}
local playerName = _G.UnitName("player")
-- Silence our /played yellow text
local ReportPlayedTimeToChat = false
local hookedChatFrame_DisplayTimePlayed = ChatFrame_DisplayTimePlayed
local function RequestTimePlayed()
ReportPlayedTimeToChat = false
return _G.RequestTimePlayed()
end
-- Overwrite default handler
ChatFrame_DisplayTimePlayed = function(...)
if ReportPlayedTimeToChat then
return hookedChatFrame_DisplayTimePlayed(...)
end
-- Delay clearing /played output to account for other addons queueing
C_Timer.After(3, function() ReportPlayedTimeToChat = true end)
end
function addon.tracker:SetupTracker()
local trackerDefaults = {profile = {levels = {}, levelsArchive = {}}}
self.db = LibStub("AceDB-3.0"):New("RXPCTrackingData", trackerDefaults)
self.maxLevel = GetMaxPlayerLevel()
self.reportKey = fmt("%s|%s|%s", playerName, addon.player.class,
_G.GetRealmName())
if not self.db.profile.trackedGuid then
self.db.profile.trackedGuid = addon.player.guid
end
if self.db.profile.trackedGuid ~= addon.player.guid then
if addon.settings.profile.debug then
addon.comms.PrettyPrint(
"GUID changed, saving %s and resetting for %s",
addon.player.name, addon.player.guid)
end
local _, _, guid = strsplit('-', addon.player.guid)
-- Not displayed nor consumed, but a safety net for data
-- TODO add archives to splits for same-name speed splits
if not self.db.profile["levelsArchive"] then
self.db.profile["levelsArchive"] = {}
end
self.db.profile["levelsArchive"][guid] = self.db.profile["levels"]
-- Reset splits
if addon.db.profile.reports.splits[self.reportKey] then
local profileAlias = fmt("%s|%s|%s", playerName .. guid,
addon.player.class, _G.GetRealmName())
-- Copy existing data to new key with GUID
addon.db.profile.reports.splits[profileAlias] = addon.db.profile
.reports.splits[self.reportKey]
-- Delete data for old toon name
addon.db.profile.reports.splits[self.reportKey] = nil
end
-- Now that data's been reset, update trackedGuid
self.db.profile.trackedGuid = addon.player.guid
end
self:RegisterEvent("CHAT_MSG_COMBAT_XP_GAIN")
self:RegisterEvent("TIME_PLAYED_MSG")
self:RegisterEvent("PLAYER_LEVEL_UP")
self:RegisterEvent("QUEST_TURNED_IN")
self:RegisterEvent("PLAYER_DEAD")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:SetupInspections()
self:GenerateDBLevel(self.playerLevel)
self:UpgradeDB()
self:CompileData()
self:CreateGui(_G.CharacterFrame, playerName)
if addon.settings.profile.enablelevelSplits then self:CreateLevelSplits() end
end
function addon.tracker:SetupInspections()
if addon.settings.profile.enableLevelingReportInspections and
addon.settings.profile.enableBetaFeatures then
-- TODO reduce duplication with SettingsPanel
addon.settings.enabledBetaFeatures[L("Enable Leveling Report Inspections")]
= L("Send or receive inspection requests for other Leveling Reports")
self:RegisterEvent("INSPECT_READY")
self:RegisterComm(self._commPrefix)
local UnitGUID, UnitIsEnemy = UnitGUID, UnitIsEnemy
hooksecurefunc("NotifyInspect", function(unit)
if not addon.settings.profile.enableLevelingReportInspections then
return
end
-- Gearscore addons inspect on mouseover/nameplate/etc, RXP only inspects via target
if unit ~= "target" or UnitIsEnemy("player", unit) then
return
end
addon.tracker.state.inspectionRequests[UnitGUID(unit)] = true
end)
else
self:UnregisterEvent("INSPECT_READY")
end
end
function addon.tracker:UpgradeDB()
if not addon.tracker.db.profile["levels"] then
addon.tracker.db.profile["levels"] = {}
end
local levelDB = addon.tracker.db.profile["levels"]
for l, _ in pairs(levelDB) do
if not levelDB[l].groupExperience then
levelDB[l].groupExperience = 0
end
if levelDB[l].timestamp and levelDB[l].timestamp.started == -1 then
levelDB[l].timestamp.started = nil
end
if levelDB[l].timestamp and levelDB[l].timestamp.finished == -1 then
levelDB[l].timestamp.finished = nil
end
if not levelDB[l].mobs then levelDB[l].mobs = {} end
-- Repair started or finished timestamps if surrounding data exists
if not levelDB[l].timestamp.started and levelDB[l - 1] and
levelDB[l - 1].timestamp.finished then
addon.comms.PrettyPrint("Repairing level %d started timestamp", l)
levelDB[l].timestamp.started = levelDB[l - 1].timestamp.finished + 1
end
-- Repair finished if not current level
if l < addon.tracker.playerLevel and not levelDB[l].timestamp.finished and
levelDB[l + 1] and levelDB[l + 1].timestamp.started then
addon.comms.PrettyPrint("Repairing level %d finished timestamp", l)
levelDB[l].timestamp.finished = levelDB[l + 1].timestamp.started - 1
end
for _, questData in pairs(levelDB[l].quests) do
for i, questXP in pairs(questData) do
if questXP <= 0 then questData[i] = nil end
end
end
-- Repair DK starting time
if l == 55 and addon.player.class == "DEATHKNIGHT" and
not levelDB[l].timestamp.started then
levelDB[l].timestamp.started = 0
end
-- TODO repair level 70 duration, calculated as negative because of level 70 reset grace value
end
end
function addon.tracker:GenerateDBLevel(level)
local profile = addon.tracker.db.profile
if not profile["levels"] then profile["levels"] = {} end
if not profile["levels"][level] then
profile["levels"][level] = {
quests = {}, -- [zone] = { questId = xpReward }
mobs = {}, -- [zone] = xp
timestamp = {}, -- started, finished
groupExperience = 0,
deaths = 0
}
end
if level == 1 then
profile["levels"][level].timestamp.started = 0
elseif level == 55 and addon.player.class == "DEATHKNIGHT" then
profile["levels"][level].timestamp.started = 0
end
end
function addon.tracker:CHAT_MSG_COMBAT_XP_GAIN(_, text, ...)
-- Exclude "You gain 360 experience" from quest turnin, doubles up on mob kill
-- TODO use _G.COMBATLOG_XPGAIN_FIRSTPERSON or _G.COMBATLOG_XPGAIN_FIRSTPERSON_UNNAMED
-- TODO won't track zhCN
if 'You' == strsub(text, 0, #'You') then return end
local xpGained = tonumber(smatch(text, "%d+"))
if not xpGained or xpGained == 0 then return end
local zoneName = GetRealZoneText()
local levelData = addon.tracker.db.profile["levels"][addon.tracker
.playerLevel]
if not levelData.mobs[zoneName] then
levelData.mobs[zoneName] = {xp = 0, count = 0}
end
local zoneMobData = levelData.mobs[zoneName]
zoneMobData.xp = zoneMobData.xp + xpGained
zoneMobData.count = zoneMobData.count + 1
if IsInGroup() then
levelData.groupExperience = levelData.groupExperience + xpGained
-- else solo, total - group = solo, no need to keep track separately
end
end
function addon.tracker:TIME_PLAYED_MSG(_, totalTimePlayed, timePlayedThisLevel)
local data = self.waitingForTimePlayed
if not data then return end
if data.event == 'PLAYER_LEVEL_UP' then
self.db.profile["levels"][data.level - 1].timestamp.dateFinished =
data.date
self.db.profile["levels"][data.level - 1].timestamp.finished =
totalTimePlayed - 1
self.db.profile["levels"][data.level].timestamp.started =
totalTimePlayed
self.db.profile["levels"][data.level].timestamp.dateStarted = data.date
self.waitingForTimePlayed = false
-- Refresh baseline time on level up
self.state.login = {
time = time(),
timePlayedThisLevel = timePlayedThisLevel,
totalTimePlayed = totalTimePlayed
}
-- Build data after processing level up
self.reportData[data.level - 1] = self:CompileLevelData(data.level - 1)
self:UpdateLevelSplits("full")
elseif data.event == 'PLAYER_ENTERING_WORLD' then
self.state.login = {
time = time(),
timePlayedThisLevel = timePlayedThisLevel,
totalTimePlayed = totalTimePlayed
}
if not self.db.profile["levels"][self.playerLevel].timestamp.dateStarted and
timePlayedThisLevel < 60 then
self.db.profile["levels"][self.playerLevel].timestamp.dateStarted =
data.date
end
local remainingTime = totalTimePlayed - timePlayedThisLevel
local levelDB = self.db.profile["levels"]
local levelDuration
-- Reverse engineer splits repairing
for l = self.playerLevel - 1, 2, -1 do
if not levelDB[l] or not levelDB[l].timestamp then break end
if levelDB[l].timestamp.finished and levelDB[l].timestamp.started then
levelDuration = levelDB[l].timestamp.finished -
levelDB[l].timestamp.started
remainingTime = remainingTime - levelDuration
elseif levelDB[l].timestamp.finished and
not levelDB[l].timestamp.started then
addon.comms.PrettyPrint("Repairing level %d started timestamp",
l)
levelDB[l].timestamp.started = remainingTime -
levelDB[l].timestamp.finished
break
else
-- Not sure how we got here, but it's probably bad
break
end
end
-- On 60/70 login, set timestamp.started to now
-- aka ignore raiding time against 60-61 and 70-71
-- Also support fresh Wrath users of RXP
-- Must be later in client load order, returns 0 erroneously oftentimes on init
if UnitXP("player") == 0 and self.playerLevel == 70 and self.maxLevel >
self.playerLevel then
if levelDB[self.playerLevel].timestamp then
levelDB[self.playerLevel].timestamp.started = time()
else
levelDB[self.playerLevel].timestamp = {started = time()}
end
addon.comms.PrettyPrint(L("Resetting level %d start time to now!"),
self.playerLevel)
end
self:CompileData()
self:UpdateLevelSplits("full")
self.waitingForTimePlayed = false
end
end
function addon.tracker:PLAYER_LEVEL_UP(_, level)
addon.tracker:GenerateDBLevel(level)
addon.tracker.playerLevel = level
addon.tracker.waitingForTimePlayed = {
event = 'PLAYER_LEVEL_UP',
level = level,
date = C_DateAndTime.GetCurrentCalendarTime()
}
addon.tracker.state.reportLevelMenu = nil
RequestTimePlayed()
end
function addon.tracker:QUEST_TURNED_IN(_, questId, xpReward)
xpReward = tonumber(xpReward)
if not xpReward or xpReward <= 0 then return end
local zoneName = GetRealZoneText()
local levelData = addon.tracker.db.profile["levels"][addon.tracker
.playerLevel]
if not levelData.quests[zoneName] then levelData.quests[zoneName] = {} end
levelData.quests[zoneName][questId] = xpReward
-- Quest turnins can easily be miscategorized
-- e.g. complete quest solo, join dungeon group, then turn in before flying or inverse
-- However, summary report looks weird without it, calculate anyway
if IsInGroup() then
levelData.groupExperience = levelData.groupExperience + xpReward
-- else solo, total - group = solo, no need to keep track separately
end
end
function addon.tracker:PLAYER_DEAD()
if addon.tracker.db.profile["levels"][addon.tracker.playerLevel].deaths then
addon.tracker.db.profile["levels"][addon.tracker.playerLevel].deaths =
addon.tracker.db.profile["levels"][addon.tracker.playerLevel].deaths +
1
else
addon.tracker.db.profile["levels"][addon.tracker.playerLevel].deaths = 1
end
end
function addon.tracker:PLAYER_ENTERING_WORLD()
addon.tracker.waitingForTimePlayed = {
event = 'PLAYER_ENTERING_WORLD',
date = C_DateAndTime.GetCurrentCalendarTime()
}
RequestTimePlayed()
end
function addon.tracker.UpdateReportLevels(levelData, playerLevel, target,
attachment)
local trackerUi = addon.tracker.ui[attachment:GetName()]
if addon.tracker.state.reportLevelMenu then
EasyMenu(addon.tracker.state.reportLevelMenu, trackerUi.levelMenuFrame,
trackerUi.levelButton.frame, 0, 0, "MENU")
return
end
local sparse = {}
local insertData, parentIndex, lowerLevel, upperLevel
for level, _ in pairs(levelData) do
parentIndex = floor(level / 10) + 1
lowerLevel = mmax(floor(level / 10) * 10, 1) -- Handle 0 to 10 phrasing
upperLevel = floor(level / 10) * 10 + 10
if not sparse[parentIndex] then
sparse[parentIndex] = {
text = fmt("%d to %d", lowerLevel, upperLevel),
hasArrow = true,
menuList = {}
}
end
if level > playerLevel then break end
insertData = {
notCheckable = 1,
func = function(_, l, text)
addon.tracker:UpdateReport(l, target, attachment)
trackerUi.levelButton:SetText(text)
_G.CloseDropDownMenus()
end
}
if level == addon.tracker.maxLevel then
insertData.text = fmt("%d (%s)", level, L("Max"))
else
insertData.text = fmt("%d to %d", level, level + 1)
end
insertData.arg1 = level
insertData.arg2 = insertData.text
tinsert(sparse[parentIndex].menuList, insertData)
table.sort(sparse[parentIndex].menuList,
function(k1, k2) return k1.arg1 < k2.arg1 end)
end
local menu = {}
-- Shrink sparse array, e.g. missing data
for _, d in pairs(sparse) do tinsert(menu, d) end
addon.tracker.state.reportLevelMenu = menu
EasyMenu(menu, trackerUi.levelMenuFrame, trackerUi.levelButton.frame, 0, 0,
"MENU")
end
local function buildSpacer(height)
local spacer = AceGUI:Create("SimpleGroup")
spacer:SetLayout("Fill")
spacer:SetHeight(height)
spacer:SetWidth(30)
spacer:SetFullWidth(true)
return spacer
end
function addon.tracker:CreateGui(attachment, target)
if not attachment then return end
local attachmentName = attachment.GetName and attachment:GetName()
if not attachmentName then return end
if addon.tracker.ui[attachmentName] then return end
local offset = {
x = -38,
y = -32,
tabsHeight = _G.CharacterFrameTab1:GetHeight()
}
local padding = 4
local levelData, playerLevel
addon.tracker.ui[attachmentName] = AceGUI:Create("Frame")
local trackerUi = addon.tracker.ui[attachmentName]
trackerUi:SetLayout("Fill")
trackerUi:Hide()
trackerUi:EnableResize(false)
trackerUi.statustext:GetParent():Hide() -- Hide the statustext bar
trackerUi:SetTitle("RestedXP Leveling Report")
trackerUi.frame:ClearAllPoints()
trackerUi.frame:SetPoint("TOPLEFT", attachment, "TOPRIGHT", offset.x,
offset.y)
trackerUi:SetWidth(attachment:GetWidth() * 0.7)
trackerUi:SetHeight(attachment:GetHeight() + offset.y - 8 -
offset.tabsHeight * 2)
trackerUi.scrollContainer = AceGUI:Create("ScrollFrame")
trackerUi.scrollContainer:SetLayout("Flow")
trackerUi:AddChild(trackerUi.scrollContainer)
trackerUi.frame:SetBackdrop(addon.RXPFrame.backdrop.edge)
trackerUi.frame:SetBackdropColor(unpack(addon.colors.background))
if attachmentName == 'CharacterFrame' then
-- Firmly attach to CharacterFrame show/hide
if addon.settings.profile.openTrackerReportOnCharOpen then
attachment:HookScript("OnShow", function()
trackerUi:Show()
end)
trackerUi:SetCallback("OnClose", function()
-- Hide tracker frame when parent hides
-- Prevent tracker from being open next time character is
trackerUi:Hide()
end)
end
trackerUi:SetCallback("OnShow", function()
-- refresh data
addon.tracker:CompileData()
addon.tracker:UpdateReport(addon.tracker.playerLevel, playerName,
_G.CharacterFrame)
end)
levelData = addon.tracker.db.profile["levels"]
playerLevel = addon.tracker.playerLevel
else
levelData = self.state.otherReports[target].reportData
playerLevel = self.state.otherReports[target].playerLevel
end
attachment:HookScript("OnHide", function() trackerUi:Hide() end)
-- Make sure the window can be closed by pressing the escape button
_G["RESTEDXP_TRACKER_SUMMARY_WINDOW"] = trackerUi.frame
tinsert(_G.UISpecialFrames, "RESTEDXP_TRACKER_SUMMARY_WINDOW")
local topContainer = AceGUI:Create("SimpleGroup")
topContainer:SetLayout('Flow')
trackerUi.levelButton = AceGUI:Create("Button")
trackerUi.levelButton:SetRelativeWidth(0.45)
trackerUi.levelButton:SetText(fmt("%d to %d", playerLevel, playerLevel + 1))
trackerUi.levelMenuFrame = CreateFrame("Frame", "RXPG_LevelMenuFrame",
trackerUi.levelButton.frame,
"UIDropDownMenuTemplate")
trackerUi.levelButton:SetCallback("OnClick", function()
addon.tracker.UpdateReportLevels(levelData, playerLevel, target,
attachment)
end)
topContainer:AddChild(trackerUi.levelButton)
trackerUi.target = AceGUI:Create("Label")
trackerUi.target:SetText(target)
trackerUi.target:SetJustifyH("CENTER")
trackerUi.target:SetRelativeWidth(0.55)
topContainer:AddChild(trackerUi.target)
trackerUi.scrollContainer:AddChild(topContainer)
-- Reached block
trackerUi.reachedContainer = AceGUI:Create("SimpleGroup")
trackerUi.reachedContainer:SetLayout("List")
trackerUi.reachedContainer:SetFullWidth(true)
trackerUi.reachedContainer.label = AceGUI:Create("Heading")
trackerUi.reachedContainer.label:SetText(
L("Reached Level") .. " " .. playerLevel)
trackerUi.reachedContainer.label:SetFullWidth(true)
trackerUi.reachedContainer:AddChild(trackerUi.reachedContainer.label)
trackerUi.reachedContainer:AddChild(buildSpacer(padding))
trackerUi.reachedContainer.data = AceGUI:Create("Label")
trackerUi.reachedContainer.data:SetText(L("In-progress"))
trackerUi.reachedContainer.data:SetFont(addon.font, 12, "")
trackerUi.reachedContainer.data:SetFullWidth(true)
trackerUi.reachedContainer:AddChild(trackerUi.reachedContainer.data)
trackerUi.scrollContainer:AddChild(trackerUi.reachedContainer)
-- Speed block
trackerUi.speedContainer = AceGUI:Create("SimpleGroup")
trackerUi.speedContainer:SetLayout("List")
trackerUi.speedContainer:SetFullWidth(true)
trackerUi.speedContainer.label = AceGUI:Create("Heading")
trackerUi.speedContainer.label:SetText(L("Time spent"))
trackerUi.speedContainer.label:SetFullWidth(true)
trackerUi.speedContainer:AddChild(trackerUi.speedContainer.label)
trackerUi.speedContainer:AddChild(buildSpacer(padding))
trackerUi.speedContainer.data = AceGUI:Create("Label")
trackerUi.speedContainer.data:SetText(L("In-progress"))
trackerUi.speedContainer.data:SetFont(addon.font, 12, "")
trackerUi.speedContainer.data:SetFullWidth(true)
trackerUi.speedContainer:AddChild(trackerUi.speedContainer.data)
trackerUi.scrollContainer:AddChild(trackerUi.speedContainer)
-- Zones block
-- Dynamic text needs to be in parent scrollframe, not a child SimpleGroup
trackerUi.zonesContainer = {}
trackerUi.zonesContainer.label = AceGUI:Create("Heading")
trackerUi.zonesContainer.label:SetText(L("Zones & Dungeons"))
trackerUi.zonesContainer.label:SetFullWidth(true)
trackerUi.scrollContainer:AddChild(trackerUi.zonesContainer.label)
trackerUi.zonesContainer.data = AceGUI:Create("Label")
trackerUi.zonesContainer.data:SetText("")
trackerUi.zonesContainer.data:SetFont(addon.font, 12, "")
trackerUi.zonesContainer.data:SetFullWidth(true)
trackerUi.scrollContainer:AddChild(trackerUi.zonesContainer.data)
-- Sources block
trackerUi.sourcesContainer = AceGUI:Create("SimpleGroup")
trackerUi.sourcesContainer:SetLayout("List")
trackerUi.sourcesContainer:SetFullWidth(true)
trackerUi.sourcesContainer.label = AceGUI:Create("Heading")
trackerUi.sourcesContainer.label:SetText(L("Experience Sources"))
trackerUi.sourcesContainer.label:SetFullWidth(true)
trackerUi.sourcesContainer:AddChild(trackerUi.sourcesContainer.label)
trackerUi.sourcesContainer:AddChild(buildSpacer(padding))
trackerUi.sourcesContainer.data = {
quests = AceGUI:Create("Label"),
mobs = AceGUI:Create("Label")
}
trackerUi.sourcesContainer.data['quests']:SetText('quests')
trackerUi.sourcesContainer.data['quests']:SetFont(addon.font, 12, "")
trackerUi.sourcesContainer.data['quests']:SetFullWidth(true)
trackerUi.sourcesContainer:AddChild(
trackerUi.sourcesContainer.data['quests'])
trackerUi.sourcesContainer:AddChild(buildSpacer(padding))
trackerUi.sourcesContainer.data['mobs']:SetText('mobs')
trackerUi.sourcesContainer.data['mobs']:SetFont(addon.font, 12, "")
trackerUi.sourcesContainer.data['mobs']:SetFullWidth(true)
trackerUi.sourcesContainer:AddChild(trackerUi.sourcesContainer.data['mobs'])
trackerUi.scrollContainer:AddChild(trackerUi.sourcesContainer)
-- Teamwork block
trackerUi.teamworkContainer = AceGUI:Create("SimpleGroup")
trackerUi.teamworkContainer:SetLayout("List")
trackerUi.teamworkContainer:SetFullWidth(true)
trackerUi.teamworkContainer.label = AceGUI:Create("Heading")
trackerUi.teamworkContainer.label:SetText(L("Teamwork"))
trackerUi.teamworkContainer.label:SetFullWidth(true)
trackerUi.teamworkContainer:AddChild(trackerUi.teamworkContainer.label)
trackerUi.teamworkContainer:AddChild(buildSpacer(padding))
trackerUi.teamworkContainer.data = {}
trackerUi.teamworkContainer.data['solo'] = AceGUI:Create("Label")
trackerUi.teamworkContainer.data['solo']:SetText('solo')
trackerUi.teamworkContainer.data['solo']:SetFont(addon.font, 12, "")
trackerUi.teamworkContainer.data['solo']:SetFullWidth(true)
trackerUi.teamworkContainer:AddChild(
trackerUi.teamworkContainer.data['solo'])
trackerUi.teamworkContainer:AddChild(buildSpacer(padding))
trackerUi.teamworkContainer.data['group'] = AceGUI:Create("Label")
trackerUi.teamworkContainer.data['group']:SetText('group')
trackerUi.teamworkContainer.data['group']:SetFont(addon.font, 12, "")
trackerUi.teamworkContainer.data['group']:SetFullWidth(true)
trackerUi.teamworkContainer:AddChild(
trackerUi.teamworkContainer.data['group'])
trackerUi.scrollContainer:AddChild(trackerUi.teamworkContainer)
-- Extras block
trackerUi.extrasContainer = AceGUI:Create("SimpleGroup")
trackerUi.extrasContainer:SetLayout("List")
trackerUi.extrasContainer:SetFullWidth(true)
trackerUi.extrasContainer.label = AceGUI:Create("Heading")
trackerUi.extrasContainer.label:SetText(L("Extras"))
trackerUi.extrasContainer.label:SetFullWidth(true)
trackerUi.extrasContainer:AddChild(trackerUi.extrasContainer.label)
trackerUi.extrasContainer:AddChild(buildSpacer(padding))
trackerUi.extrasContainer.data = AceGUI:Create("Label")
trackerUi.extrasContainer.data:SetText("")
trackerUi.extrasContainer.data:SetFont(addon.font, 12, "")
trackerUi.extrasContainer.data:SetFullWidth(true)
trackerUi.extrasContainer:AddChild(trackerUi.extrasContainer.data)
trackerUi.scrollContainer:AddChild(trackerUi.extrasContainer)
end
function addon.tracker:ShowReport(attachment)
if not attachment then return end
addon.tracker.ui[attachment:GetName()]:Show()
ShowUIPanel(attachment)
end
function addon.tracker:CompileLevelData(level, d)
local data = d or addon.tracker.db.profile["levels"][level]
local report = {questXP = 0, mobXP = 0, zoneXP = {}}
local zoneXP = {}
for zoneName, questData in pairs(data.quests) do
if not zoneXP[zoneName] then
zoneXP[zoneName] = {xp = 0, name = zoneName}
end
for _, questXP in pairs(questData) do
report.questXP = report.questXP + questXP
zoneXP[zoneName].xp = zoneXP[zoneName].xp + questXP
end
end
for zoneName, mobData in pairs(data.mobs) do
if not zoneXP[zoneName] then
zoneXP[zoneName] = {xp = 0, name = zoneName}
end
for _, mobXP in pairs(mobData) do
report.mobXP = report.mobXP + mobXP
zoneXP[zoneName].xp = zoneXP[zoneName].xp + mobXP
end
end
-- Turn dictionary into array
for _, z in pairs(zoneXP) do tinsert(report.zoneXP, z) end
-- Sort report.zoneXP highest to the top
table.sort(report.zoneXP, function(a, b) return a.xp > b.xp end)
report.groupExperience = data.groupExperience
report.totalXP = report.mobXP + report.questXP
report.soloExperience = report.totalXP - data.groupExperience
report.timestamp = {
started = data.timestamp.started,
finished = data.timestamp.finished
}
report.deaths = data.deaths
if data.timestamp.dateStarted then -- Level 1
report.timestamp.dateStarted = fmt("%s %d, %d at %d:%02d %s Server",
_G.CALENDAR_FULLDATE_MONTH_NAMES[data.timestamp
.dateStarted.month],
data.timestamp.dateStarted.monthDay,
data.timestamp.dateStarted.year,
data.timestamp.dateStarted.hour % 12,
data.timestamp.dateStarted.minute,
data.timestamp.dateStarted.hour >= 12 and
"PM" or "AM")
end
if data.timestamp.dateFinished then
report.timestamp.dateFinished = fmt("%s %d, %d at %d:%02d %s Server",
_G.CALENDAR_FULLDATE_MONTH_NAMES[data.timestamp
.dateFinished.month],
data.timestamp.dateFinished.monthDay,
data.timestamp.dateFinished.year,
data.timestamp.dateFinished.hour %
12,
data.timestamp.dateFinished.minute,
data.timestamp.dateFinished.hour >=
12 and "PM" or "AM")
end
return report
end
function addon.tracker:CompileData()
self.reportData = {}
for level, data in pairs(self.db.profile["levels"]) do
self.reportData[level] = self:CompileLevelData(level, data)
end
return self.reportData
end
function addon.tracker:UpdateReport(selectedLevel, target, attachment)
if not attachment then return end
local trackerUi = addon.tracker.ui[attachment:GetName()]
if not trackerUi then return end
addon.enabledFrames["trackerUi"] = trackerUi
trackerUi.IsFeatureEnabled = function()
return addon.settings.profile.enableTracker
end
self.state.levelReportData = nil
if target and target ~= playerName then
if self.state.otherReports[target] and
self.state.otherReports[target].reportData and
self.state.otherReports[target].reportData[selectedLevel] then
self.state.levelReportData =
self.state.otherReports[target].reportData[selectedLevel]
self.state.levelReportData.playerLevel =
self.state.otherReports[target].playerLevel
self.state.levelReportData.timePlayedThisLevel = self.state
.otherReports[target]
.timePlayedThisLevel
end
else
local secondsSinceLogin = difftime(time(),
addon.tracker.state.login.time)
self.state.levelReportData = addon.tracker.reportData[selectedLevel]
self.state.levelReportData.playerLevel = addon.tracker.playerLevel
self.state.levelReportData.timePlayedThisLevel = secondsSinceLogin +
addon.tracker.state
.login
.timePlayedThisLevel
end
local report = self.state.levelReportData
if not report then
addon.comms.PrettyPrint(L("Unable to retrieve report for") .. " %s",
target)
return
end
if selectedLevel == self.state.levelReportData.playerLevel then
if selectedLevel == addon.tracker.maxLevel then
trackerUi.levelButton:SetText(
fmt("%d (%s)", selectedLevel, L("Max")))
trackerUi.reachedContainer.label:SetText("Reached max level")
else
trackerUi.levelButton:SetText(
fmt("%d to %d", selectedLevel, selectedLevel + 1))
trackerUi.reachedContainer.label:SetText("Started level " ..
selectedLevel)
end
trackerUi.speedContainer.data:SetText(
addon.comms:PrettyPrintTime(self.state.levelReportData
.timePlayedThisLevel or
"Missing data"))
if selectedLevel == 1 or
(selectedLevel == 55 and addon.player.class == "DEATHKNIGHT") then
trackerUi.reachedContainer.data:SetText(
addon.tracker.reportData[selectedLevel].timestamp.dateStarted or
"Missing data")
elseif addon.tracker.reportData[selectedLevel - 1] then
trackerUi.reachedContainer.data:SetText(
addon.tracker.reportData[selectedLevel - 1].timestamp
.dateFinished or "Missing data")
else
trackerUi.reachedContainer.data:SetText("Missing data")
end
else
trackerUi.levelButton:SetText(fmt("%d to %d", selectedLevel,
selectedLevel + 1))
trackerUi.reachedContainer.label:SetText("Reached Level " ..
selectedLevel + 1)
trackerUi.reachedContainer.data:SetText(
report.timestamp.dateFinished or "Missing data")
if report.timestamp and report.timestamp.started and
report.timestamp.finished then
local s = report.timestamp.finished - report.timestamp.started
trackerUi.speedContainer.data:SetText(addon.comms:PrettyPrintTime(s))
else
trackerUi.speedContainer.data:SetText("Missing data")
end
end
local ratio, percentage
if selectedLevel == addon.tracker.maxLevel or UnitXP("player") == 0 then
trackerUi.teamworkContainer.data['solo']:SetText(
fmt("* Solo: %s", 'N/A'))
trackerUi.teamworkContainer.data['group']:SetText(fmt("* Group: %s",
'N/A'))
elseif report.groupExperience == 0 then
trackerUi.teamworkContainer.data['solo']:SetText(
fmt("* Solo: %.2f%%", 100))
trackerUi.teamworkContainer.data['group']:SetText(
fmt("* Group: %.2f%%", 0))
elseif (report.soloExperience + report.groupExperience) == 0 then -- If division error
trackerUi.teamworkContainer.data['solo']:SetText(fmt("* Solo: %d%%", 0))
trackerUi.teamworkContainer.data['group']:SetText(
fmt("* Group: %d%%", 0))
else
ratio = report.groupExperience /
(report.soloExperience + report.groupExperience)
percentage = 100 * ratio
trackerUi.teamworkContainer.data['solo']:SetText(
fmt("* Solo: %.2f%%", 100 - percentage))
trackerUi.teamworkContainer.data['group']:SetText(
fmt("* Group: %.2f%%", percentage))
end
if selectedLevel == addon.tracker.maxLevel or UnitXP("player") == 0 then
trackerUi.sourcesContainer.data['quests']:SetText(fmt("* Quests: %s",
"N/A"))
trackerUi.sourcesContainer.data['mobs']:SetText(
fmt("* Killing: %s", "N/A"))
elseif report.questXP == 0 then
trackerUi.sourcesContainer.data['quests']:SetText(fmt(
"* Quests: %.2f%%",
0))
trackerUi.sourcesContainer.data['mobs']:SetText(
fmt("* Killing: %.2f%%", 100))
elseif (report.questXP + report.mobXP) == 0 then -- If division error
trackerUi.sourcesContainer.data['quests']:SetText(
fmt("* Quests: %d%%", 0))
trackerUi.sourcesContainer.data['mobs']:SetText(
fmt("* Killing: %d%%", 0))
else
ratio = report.mobXP / (report.questXP + report.mobXP)
percentage = 100 * ratio
trackerUi.sourcesContainer.data['quests']:SetText(fmt(
"* Quests: %.2f%%",
100 - percentage))
trackerUi.sourcesContainer.data['mobs']:SetText(
fmt("* Killing: %.2f%%", percentage))
end
local zonesBlock = ""
if selectedLevel ~= addon.tracker.maxLevel then
for _, data in pairs(report.zoneXP) do
zonesBlock = fmt("%s* %s - %.1f%%\n", zonesBlock, data.name,
data.xp * 100 / report.totalXP)
end
end
trackerUi.zonesContainer.data:SetText(zonesBlock)
local extrasBlock = ""
extrasBlock = fmt("%s* %s: %s\n", extrasBlock, "Deaths",
report.deaths or L("Missing data"))
if report.timestamp and report.timestamp.started and
report.timestamp.finished and selectedLevel ~= addon.tracker.maxLevel then
local levelSeconds
if report.timestamp.finished then
levelSeconds = report.timestamp.finished - report.timestamp.started
else
levelSeconds = difftime(time(), addon.tracker.state.login.time) +
addon.tracker.state.login.timePlayedThisLevel
end
local xpPerHour = report.totalXP / (levelSeconds / 60 / 60)
extrasBlock = fmt("%s* %s: %d\n", extrasBlock, "Experience/hour",
xpPerHour or "Missing data")
end
trackerUi.extrasContainer.data:SetText(extrasBlock)
trackerUi.scrollContainer:DoLayout()
end
function addon.tracker:PrintSplitsTime(s, isDelta)
local prefix = s < 0 and '-' or ''
if isDelta and s > 0 then prefix = '+' end
s = abs(s)
local hours = floor(s / 60 / 60)
s = mod(s, 60 * 60)
local minutes = floor(s / 60)
s = mod(s, 60)
local formattedString
if hours > 0 then
formattedString = fmt("%02d:%02d:%02d", hours, minutes, s)
elseif minutes > 0 then