-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.lua
More file actions
2094 lines (1709 loc) · 64.1 KB
/
gui.lua
File metadata and controls
2094 lines (1709 loc) · 64.1 KB
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 GUI = ArenaHistorian:NewModule("GUI")
local L = ArenaHistLocals
local arenaData = {[2] = {}, [3] = {}, [5] = {}}
local arenaStats = {[2] = {}, [3] = {}, [5] = {}}
local arenaMap = {[2] = {}, [3] = {}, [5] = {}}
local arenaTeamStats = {[2] = {}, [3] = {}, [5] = {}}
local alreadyParsed = {}
local alreadyParsedStat = {}
local talentPopup, racePopup
local MAX_TEAMS_SHOWN = 5
local MAX_TEAM_MEMBERS = 5
local DEEP_THRESHOLD = 30
local FONT_SIZE = 10
local ICON_SIZE = 16
-- Stolen out of GlueXML
local RACE_ICONS = {
["HUMAN_MALE"] = {0, 0.125, 0, 0.25}, ["DWARF_MALE"] = {0.125, 0.25, 0, 0.25}, ["GNOME_MALE"] = {0.25, 0.375, 0, 0.25}, ["NIGHTELF_MALE"] = {0.375, 0.5, 0, 0.25},
["TAUREN_MALE"] = {0, 0.125, 0.25, 0.5}, ["SCOURGE_MALE"] = {0.125, 0.25, 0.25, 0.5}, ["TROLL_MALE"] = {0.25, 0.375, 0.25, 0.5}, ["ORC_MALE"] = {0.375, 0.5, 0.25, 0.5},
["HUMAN_FEMALE"] = {0, 0.125, 0.5, 0.75}, ["DWARF_FEMALE"] = {0.125, 0.25, 0.5, 0.75}, ["GNOME_FEMALE"] = {0.25, 0.375, 0.5, 0.75}, ["NIGHTELF_FEMALE"] = {0.375, 0.5, 0.5, 0.75},
["TAUREN_FEMALE"] = {0, 0.125, 0.75, 1.0}, ["SCOURGE_FEMALE"] = {0.125, 0.25, 0.75, 1.0}, ["TROLL_FEMALE"] = {0.25, 0.375, 0.75, 1.0}, ["ORC_FEMALE"] = {0.375, 0.5, 0.75, 1.0},
["BLOODELF_MALE"] = {0.5, 0.625, 0.25, 0.5}, ["BLOODELF_FEMALE"] = {0.5, 0.625, 0.75, 1.0}, ["DRAENEI_MALE"] = {0.5, 0.625, 0, 0.25}, ["DRAENEI_FEMALE"] = {0.5, 0.625, 0.5, 0.75},
}
-- Tree data
local TREE_ICONS = {
["SHAMAN"] = {"Spell_Nature_Lightning", "Spell_Nature_LightningShield", "Spell_Nature_MagicImmunity"},
["MAGE"] = {"Spell_Holy_MagicalSentry", "Spell_Fire_FlameBolt", "Spell_Frost_FrostBolt02"},
["WARLOCK"] = {"Spell_Shadow_DeathCoil", "Spell_Shadow_Metamorphosis", "Spell_Shadow_RainOfFire"},
["DRUID"] = {"Spell_Nature_Lightning", "Ability_Racial_BearForm", "Spell_Nature_HealingTouch"},
["WARRIOR"] = {"Ability_Rogue_Eviscerate", "Ability_Warrior_InnerRage", "INV_Shield_06"},
["ROGUE"] = {"Ability_Rogue_Eviscerate", "Ability_BackStab", "Ability_Stealth"},
["PALADIN"] = {"Spell_Holy_HolyBolt", "Spell_Holy_DevotionAura", "Spell_Holy_AuraOfLight"},
["HUNTER"] = {"Ability_Hunter_BeastTaming", "Ability_Marksmanship", "Ability_Hunter_SwiftStrike"},
["PRIEST"] = {"Spell_Holy_WordFortitude", "Spell_Holy_HolyBolt", "Spell_Shadow_ShadowWordPain"},
["DEATHKNIGHT"] = {"Spell_Shadow_BloodBoil", "Spell_Frost_FrostNova", "Spell_Shadow_ShadeTrueSight"}
}
-- Tree names
local TREE_NAMES = {
["SHAMAN"] = {L["Elemental"], L["Enhancement"], L["Restoration"]},
["MAGE"] = {L["Arcane"], L["Fire"], L["Frost"]},
["WARLOCK"] = {L["Affliction"], L["Demonology"], L["Destruction"]},
["DRUID"] = {L["Balance"], L["Feral"], L["Restoration"]},
["WARRIOR"] = {L["Arms"], L["Fury"], L["Protection"]},
["ROGUE"] = {L["Assassination"], L["Combat"], L["Subtlety"]},
["PALADIN"] = {L["Holy"], L["Protection"], L["Retribution"]},
["HUNTER"] = {L["Beast Mastery"], L["Marksmanship"], L["Survival"]},
["PRIEST"] = {L["Discipline"], L["Holy"], L["Shadow"]},
["DEATHKNIGHT"] = {L["Blood"], L["Frost"], L["Unholy"]},
}
function GUI:GetSpecName(class, spec)
local tree1, tree2, tree3 = string.split("/", spec)
tree1 = tonumber(tree1) or 0
tree2 = tonumber(tree2) or 0
tree3 = tonumber(tree3) or 0
if( tree1 == 0 and tree2 == 0 and tree3 == 0 ) then
return "INV_Misc_QuestionMark", L["Unknown"], L["Unknown"]
end
-- Now check specifics
if( tree1 > tree2 and tree1 > tree3 ) then
return TREE_ICONS[class][1], string.format("%d/%d/%d", tree1, tree2, tree3), TREE_NAMES[class][1]
elseif( tree2 > tree1 and tree2 > tree3 ) then
return TREE_ICONS[class][2], string.format("%d/%d/%d", tree1, tree2, tree3), TREE_NAMES[class][2]
elseif( tree3 > tree1 and tree3 > tree2 ) then
return TREE_ICONS[class][3], string.format("%d/%d/%d", tree1, tree2, tree3), TREE_NAMES[class][3]
end
return "INV_Misc_QuestionMark", L["Unknown"], L["Unknown"]
end
-- Quick tooltip showing function
local function OnEnter(self)
if( self.tooltip ) then
GameTooltip:SetOwner(self, "ANCHOR_TOPLEFT")
GameTooltip:SetText(self.tooltip)
GameTooltip:Show()
end
end
local function OnLeave(self)
GameTooltip:Hide()
end
-- Changes 1000 into 1,000 and 10000 into 10,000 and so on
local function formatNumber(number)
number = math.floor(number + 0.5)
while( true ) do
number, k = string.gsub(number, "^(-?%d+)(%d%d%d)", "%1,%2")
if( k == 0 ) then break end
end
return number
end
local talentPopup
local racePopup
-- Popup request window for talents
local function setTalentData(self)
local parent = self:GetParent()
local talents = string.format("%d/%d/%d", tonumber(parent.pointOne:GetNumber()) or 0, tonumber(parent.pointTwo:GetNumber()) or 0, tonumber(parent.pointThree:GetNumber()) or 0)
if( ArenaHistoryCustomData[parent.id] ) then
local _, race = string.split(":", ArenaHistoryCustomData[parent.id])
ArenaHistoryCustomData[parent.id] = string.format("%s:%s", talents, race)
else
ArenaHistoryCustomData[parent.id] = string.format("%s:", talents)
end
talentPopup:Hide()
GUI:RefreshView()
end
local function popupTalentRequest(frame, bracket, teamName, name)
local popup = talentPopup
if( not popup ) then
popup = CreateFrame("Frame", nil, GUI.frame)
popup:SetBackdrop(GameTooltip:GetBackdrop())
popup:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b);
popup:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b);
popup:SetScale(1.0)
popup:SetWidth(125)
popup:SetHeight(35)
popup:SetClampedToScreen(true)
popup:SetToplevel(true)
popup:SetFrameStrata("DIALOG")
popup:SetScript("OnHide", function(self) self.currentFrame = nil end)
popup:Hide()
popup.pointOne = CreateFrame("EditBox", "AHHistoryPopupOne", popup, "InputBoxTemplate")
popup.pointOne:SetHeight(20)
popup.pointOne:SetWidth(20)
popup.pointOne:SetNumeric(true)
popup.pointOne:SetAutoFocus(false)
popup.pointOne:SetScript("OnEnterPressed", setTalentData)
popup.pointOne:SetScript("OnTabPressed", function() popup.pointTwo:SetFocus(); end)
popup.pointOne:ClearAllPoints()
popup.pointOne:SetPoint("TOPLEFT", popup, "TOPLEFT", 10, -8)
popup.pointTwo = CreateFrame("EditBox", "AHHistoryPopupTwo", popup, "InputBoxTemplate")
popup.pointTwo:SetHeight(20)
popup.pointTwo:SetWidth(20)
popup.pointTwo:SetNumeric(true)
popup.pointTwo:SetAutoFocus(false)
popup.pointTwo:SetScript("OnEnterPressed", setTalentData)
popup.pointTwo:SetScript("OnTabPressed", function() popup.pointThree:SetFocus(); end)
popup.pointTwo:ClearAllPoints()
popup.pointTwo:SetPoint("TOPLEFT", popup.pointOne, "TOPRIGHT", 6, 0)
popup.pointThree = CreateFrame("EditBox", "AHHistoryPopupThree", popup, "InputBoxTemplate")
popup.pointThree:SetHeight(20)
popup.pointThree:SetWidth(20)
popup.pointThree:SetNumeric(true)
popup.pointThree:SetAutoFocus(false)
popup.pointThree:SetScript("OnEnterPressed", setTalentData)
popup.pointThree:SetScript("OnTabPressed", function() popup.pointOne:SetFocus(); end)
popup.pointThree:ClearAllPoints()
popup.pointThree:SetPoint("TOPLEFT", popup.pointTwo, "TOPRIGHT", 6, 0)
popup.confirmSave = CreateFrame("Button", nil, popup, "UIPanelButtonGrayTemplate")
popup.confirmSave:SetText(L["OK"])
popup.confirmSave:SetHeight(20)
popup.confirmSave:SetWidth(25)
popup.confirmSave:SetScript("OnClick", setTalentData)
popup.confirmSave:SetPoint("TOPLEFT", popup.pointThree, "TOPRIGHT", 6, 0)
talentPopup = popup
end
-- Hide it if it's visible still
if( popup.currentFrame == frame ) then
popup:Hide()
-- Reshow the old tooltip
GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT")
GameTooltip:SetText(frame.tooltip)
GameTooltip:Show()
return
-- We switched icons, so retoggle
elseif( popup:IsVisible() and popup.currentFrame ~= frame ) then
popup:Hide()
end
-- Hide the race frame if it's viewable
if( racePopup and racePopup:IsVisible() ) then
racePopup:Hide()
end
-- Setup!
popup.id = bracket .. teamName .. name
popup.teamName = teamName
popup.name = name
popup.bracket = bracket
popup.currentFrame = frame
popup:SetPoint("BOTTOMLEFT", frame, "TOPLEFT", 0, 0)
popup:Show()
popup.pointOne:SetFocus()
GameTooltip:Hide()
-- Annnd set other things
local one, two, three, talent
if( ArenaHistoryCustomData[popup.id] ) then
talent = string.split(":", ArenaHistoryCustomData[popup.id])
else
talent = frame.spec
end
if( talent and talent ~= "" ) then
one, two, three = string.split("/", talent)
end
popup.pointOne:SetNumber(tonumber(one) or 0)
popup.pointTwo:SetNumber(tonumber(two) or 0)
popup.pointThree:SetNumber(tonumber(three) or 0)
end
-- Popup request window for race/sex
local function dropdownSelected()
if( this.arg1 == "sex" ) then
UIDropDownMenu_SetSelectedValue(AHCustomSexDropdown, this.value)
elseif( this.arg1 == "race" ) then
UIDropDownMenu_SetSelectedValue(AHCustomRaceDropdown, this.value)
end
-- Compile the token
local sex = UIDropDownMenu_GetSelectedValue(AHCustomSexDropdown)
local race = UIDropDownMenu_GetSelectedValue(AHCustomRaceDropdown)
local raceToken = string.format("%s_%s", race, sex)
-- Now save
local parent = racePopup
local race = ""
if( ArenaHistoryCustomData[parent.id] ) then
local talents, _ = string.split(":", ArenaHistoryCustomData[parent.id])
ArenaHistoryCustomData[parent.id] = string.format("%s:%s", talents, raceToken)
else
ArenaHistoryCustomData[parent.id] = string.format(":%s", race)
end
GUI:RefreshView()
end
local function initSexDropdown()
UIDropDownMenu_AddButton({value = "MALE", text = L["Male"], arg1 = "sex", func = dropdownSelected})
UIDropDownMenu_AddButton({value = "FEMALE", text = L["Female"], arg1 = "sex", func = dropdownSelected})
end
local function initRaceDropdown()
for token, text in pairs(L["TOKENS"]) do
local race = string.split("_", token)
UIDropDownMenu_AddButton({value = race, text = text, arg1 = "race", func = dropdownSelected})
end
end
local function popupRaceRequest(frame, bracket, teamName, name)
local popup = racePopup
if( not popup ) then
popup = CreateFrame("Frame", nil, GUI.frame)
popup:SetBackdrop(GameTooltip:GetBackdrop())
popup:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b);
popup:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b);
popup:SetScale(1.0)
popup:SetWidth(260)
popup:SetHeight(35)
popup:SetClampedToScreen(true)
popup:SetToplevel(true)
popup:SetFrameStrata("DIALOG")
popup:SetScript("OnHide", function(self) self.currentFrame = nil end)
popup:Hide()
popup.sex = CreateFrame("Frame", "AHCustomSexDropdown", popup, "UIDropDownMenuTemplate")
popup.sex:SetPoint("TOPLEFT", popup, "TOPLEFT", -10, -4)
popup.sex:SetScript("OnShow", function(self)
UIDropDownMenu_Initialize(self, initSexDropdown)
UIDropDownMenu_SetWidth(self, 70)
UIDropDownMenu_SetSelectedValue(self, self.sex)
end)
popup.race = CreateFrame("Frame", "AHCustomRaceDropdown", popup, "UIDropDownMenuTemplate")
popup.race:SetPoint("TOPLEFT", popup, "TOPLEFT", 85, -4)
popup.race:SetScript("OnShow", function(self)
UIDropDownMenu_Initialize(self, initRaceDropdown)
UIDropDownMenu_SetWidth(self, 100)
UIDropDownMenu_SetSelectedValue(self, self.race)
end)
popup.confirmSave = CreateFrame("Button", nil, popup, "UIPanelButtonGrayTemplate")
popup.confirmSave:SetText(L["OK"])
popup.confirmSave:SetHeight(20)
popup.confirmSave:SetWidth(25)
popup.confirmSave:SetScript("OnClick", function() racePopup:Hide() end)
popup.confirmSave:SetPoint("TOPRIGHT", popup, "TOPRIGHT", -10, -8)
racePopup = popup
end
-- Hide it if it's visible still
if( popup.currentFrame == frame ) then
popup:Hide()
-- Reshow the old tooltip
GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT")
GameTooltip:SetText(frame.tooltip)
GameTooltip:Show()
return
-- We switched from one icon to another, so retoggle
elseif( popup:IsVisible() and popup.currentFrame ~= frame ) then
popup:Hide()
end
-- Hide the talent frame if it's viewable
if( talentPopup and talentPopup:IsVisible() ) then
talentPopup:Hide()
end
popup.id = bracket .. teamName .. name
-- Annnd set other things
local sex = "FEMALE"
local race = "BLOODELF"
if( ArenaHistoryCustomData[popup.id] ) then
local _, raceToken = string.split(":", ArenaHistoryCustomData[popup.id])
if( not raceToken or raceToken == "" ) then
raceToken = frame.race
end
else
raceToken = frame.race
end
if( raceToken and raceToken ~= "" ) then
race, sex = string.split("_", raceToken)
end
-- Setup!
popup.id = bracket .. teamName .. name
popup.teamName = teamName
popup.name = name
popup.bracket = bracket
popup.currentFrame = frame
popup.sex.sex = sex
popup.race.race = race
popup:SetPoint("BOTTOMLEFT", frame, "TOPLEFT", 0, 0)
popup:Show()
GameTooltip:Hide()
end
local function OnClick(self)
if( self.type == "talent" ) then
popupTalentRequest(self, self.bracket, self.teamName, self.name)
elseif( self.type == "race" ) then
popupRaceRequest(self, self.bracket, self.teamName, self.name)
end
end
-- Parse the team data into a table for handy access
local function sortTeamInfo(a, b)
if( not a ) then
return true
elseif( not b ) then
return false
end
return a.name < b.name
end
local function sortClassInfo(a, b)
if( not a ) then
return true
elseif( not b ) then
return false
end
return a.classToken < b.classToken
end
local function sortID(a, b)
return a > b
end
local function sortHistory(a, b)
if( not a ) then
return true
elseif( not b ) then
return false
end
return a.time > b.time
end
local function parseTeamData(...)
local teamData = {}
for i=1, select("#", ...) do
local name, spec, classToken, race, healingDone, damageDone = string.split(",", (select(i, ...)))
local row = {
name = name,
race = race,
classToken = classToken,
spec = (spec ~= "" and spec or nil),
healingDone = tonumber(healingDone) or 0,
damageDone = tonumber(damageDone) or 0,
}
table.insert(teamData, row)
end
-- Sort by makeup for the id
table.sort(teamData, sortClassInfo)
-- Create team's class id
local classID = ""
for id, data in pairs(teamData) do
if( id > 1 ) then
classID = classID .. ":" .. data.classToken
else
classID = data.classToken
end
end
-- Sort names in alpha order for viewing thing
table.sort(teamData, sortTeamInfo)
-- Create the team id
local teamID = ""
for id, data in pairs(teamData) do
teamID = teamID .. data.name
end
return teamData, teamID, classID
end
-- Win/lose stats per makeup
local classData = {}
local teamData = {}
function updateStatCache()
local self = GUI
local history = arenaData[self.frame.bracket]
local mapStats = arenaTeamStats[self.frame.bracket]
for id, data in pairs(history) do
if( not alreadyParsedStat[self.frame.bracket .. data.recordID] ) then
alreadyParsedStat[self.frame.bracket .. data.recordID] = true
for i=#(classData), 1, -1 do table.remove(classData, i) end
for i=#(teamData), 1, -1 do table.remove(teamData, i) end
for id, playerData in pairs(data.enemyTeam) do
local playerTalents = playerData.spec or ""
-- Load custom talent data (if any)
local id = GUI.frame.bracket .. data.eTeamName .. playerData.name
if( ArenaHistoryCustomData[id] ) then
local talents = string.split(":", ArenaHistoryCustomData[id])
if( talents ~= "" ) then
playerTalents = talents
end
end
local icon, _, name = self:GetSpecName(playerData.classToken, playerTalents)
table.insert(classData, playerData.classToken)
table.insert(teamData, string.format("%s:%s:%s", playerData.classToken, icon, name))
end
-- Make sure it has everyone recorded, if it doesn't it's a bugged game of some type
if( #(classData) == self.frame.bracket ) then
-- Make sure it stays consistent
table.sort(classData, sortID)
table.sort(teamData, sortID)
local classID = table.concat(classData, ":")
local teamID = table.concat(teamData, ";")
local talents = {}
for _, talentID in pairs(teamData) do
table.insert(talents, talentID)
end
-- Annd compile everything
if( not mapStats[classID] ) then
mapStats[classID] = {}
end
if( not mapStats[classID][teamID] ) then
mapStats[classID][teamID] = {totalGames = 0, won = 0, lost = 0, gameLength = 0, talents = talents}
end
local stats = mapStats[classID][teamID]
stats.gameLength = stats.gameLength + data.runTime
stats.totalGames = stats.totalGames + 1
if( data.won ) then
stats.won = stats.won + 1
else
stats.lost = stats.lost + 1
end
end
end
end
end
local function getMatchData(...)
if( select("#", ...) == 10 ) then
local arenaZone, bracket, runTime, playerWon, pRating, pChange, eRating, eChange, eServer, pServer = select(1, ...)
return arenaZone, bracket, runTime, playerWon, 0, pRating, pChange, 0, eRating, eChange, eServer, pServer
else
return select(1, ...)
end
end
-- Updates our data cache
local function updateCache()
local self = GUI
local history = arenaData[self.frame.bracket]
local mapStats = arenaMap[self.frame.bracket]
local stats = arenaStats
-- Convert it from our compact format, to the tably one
for id, data in pairs(ArenaHistoryData[self.frame.bracket]) do
local bracket = select(2, string.split(":", data))
-- Basically, this makes sure we only parse everything once
if( not alreadyParsed[bracket .. id] ) then
alreadyParsed[bracket .. id] = true
local endTime, _, playerTeamName, _, enemyTeamName = string.split("::", id)
endTime = tonumber(endTime)
if( playerTeamName ~= "" and enemyTeamName ~= "" and endTime ) then
local matchData, playerTeam, enemyTeam = string.split(";", data)
local arenaZone, _, runTime, playerWon, pSkill, pRating, pChange, eSkill, eRating, eChange, eServer, pServer = getMatchData(string.split(":", matchData))
if( arenaZone == "" ) then
arenaZone = L["Unknown"]
end
-- Generate the player and enemy team mate info
local playerTeam, playerTeamID, playerTeamClassID = parseTeamData(string.split(":", playerTeam))
local enemyTeam, enemyTeamID, enemyTeamClassID = parseTeamData(string.split(":", enemyTeam))
-- Map stat
if( not mapStats[arenaZone] ) then
mapStats[arenaZone] = {played = 0, won = 0, lost = 0}
end
mapStats[arenaZone].played = mapStats[arenaZone].played + 1
-- Store our win/lost record against this team, by the players they and we used
local teamID = playerTeamID .. enemyTeamID .. bracket .. enemyTeamName
if( not stats[teamID] ) then
stats[teamID] = {won = 0, lost = 0}
end
local result = 1
if( playerWon == "true" or playerWon == "1" ) then
result = 1
stats[teamID].won = stats[teamID].won + 1
mapStats[arenaZone].won = mapStats[arenaZone].won + 1
elseif( playerWon == "nil" or playerWon == "-1" ) then
result = -1
stats[teamID].lost = stats[teamID].lost + 1
mapStats[arenaZone].lost = mapStats[arenaZone].lost + 1
else
result = 0
end
-- Match information
local matchTbl = {
zone = arenaZone,
time = tonumber(endTime) or 0,
runTime = tonumber(runTime) or 0,
result = result,
won = (playerWon == "true" or playerWon == "1"),
draw = (playerWon == "0"),
teamID = teamID,
recordID = id,
pTeamName = playerTeamName,
pTeamClasses = playerTeamClassID,
pServer = pServer ~= "" and pServer or nil,
pRating = tonumber(pRating) or 0,
pChange = tonumber(pChange) or 0,
pSkill = tonumber(pSkill) or 0,
eTeamName = enemyTeamName,
eTeamClasses = enemyTeamClassID,
eServer = eServer ~= "" and eServer or nil,
eRating = tonumber(eRating) or 0,
eChange = tonumber(eChange) or 0,
eSkill = tonumber(eSkill) or 0,
playerTeam = playerTeam,
enemyTeam = enemyTeam,
}
table.insert(history, matchTbl)
end
end
end
table.sort(history, sortHistory)
-- Update win per class
updateStatCache()
end
-- Build the actual player page
local function setupTeamInfo(nameLimit, fsLimit, teamRows, teamData, teamName, teamServer, teamID)
for i=1, MAX_TEAM_MEMBERS do
local row = teamRows[i]
local data = teamData[i]
if( data ) then
-- Name, colored by class
if( teamServer ) then
row.name.tooltip = string.format(L["%s - %s\nDamage (|cffffffff%s|r)\nHealing (|cffffffff%s|r)"], data.name, teamServer, formatNumber(data.damageDone), formatNumber(data.healingDone))
else
row.name.tooltip = string.format(L["%s\nDamage (|cffffffff%s|r)\nHealing (|cffffffff%s|r)"], data.name, formatNumber(data.damageDone), formatNumber(data.healingDone))
end
row.name:SetFormattedText("|cff%02x%02x%02x%s|r", RAID_CLASS_COLORS[data.classToken].r * 255, RAID_CLASS_COLORS[data.classToken].g * 255, RAID_CLASS_COLORS[data.classToken].b * 255, data.name)
row.name:SetWidth(nameLimit)
row.name.fs:SetHeight(15)
row.name.fs:SetWidth(fsLimit)
row.name.fs:SetJustifyH("LEFT")
-- Check if we should override our saved data with custom data
local id = GUI.frame.bracket .. teamName .. data.name
if( ArenaHistoryCustomData[id] ) then
local talents, race = string.split(":", ArenaHistoryCustomData[id])
if( talents ~= "" ) then
data.spec = talents
end
if( race ~= "" ) then
data.race = race
end
end
-- Custom data
row.specIcon.bracket = GUI.frame.bracket
row.specIcon.teamName = teamName
row.specIcon.name = data.name
row.raceIcon.bracket = GUI.frame.bracket
row.raceIcon.teamName = teamName
row.raceIcon.name = data.name
-- Spec icon
if( data.spec and data.spec ~= "" ) then
local icon, tooltip = GUI:GetSpecName(data.classToken, data.spec)
row.specIcon.tooltip = tooltip
row.specIcon.classToken = data.classToken
row.specIcon.spec = data.spec
row.specIcon:SetNormalTexture("Interface\\Icons\\" .. icon)
row.specIcon:Show()
else
row.specIcon.tooltip = L["Unknown"]
row.specIcon:SetNormalTexture("Interface\\Icons\\INV_Misc_QuestionMark")
row.specIcon:Show()
end
-- Race icon
if( RACE_ICONS[data.race] ) then
local coords = RACE_ICONS[data.race]
row.raceIcon.tooltip = L[data.race] or L["Unknown"]
row.raceIcon.race = data.race
row.raceIcon:SetNormalTexture("Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Races")
row.raceIcon:GetNormalTexture():SetTexCoord(coords[1], coords[2], coords[3], coords[4])
row.raceIcon:Show()
else
row.raceIcon.tooltip = L["Unknown"]
row.raceIcon:SetNormalTexture("Interface\\Icons\\INV_Misc_QuestionMark")
row.raceIcon:Show()
end
row:Show()
else
row:Hide()
end
end
end
-- Wrap the class color around text
local function wrapClassColor(classToken, text)
local color = RAID_CLASS_COLORS[classToken]
return string.format("|cff%02x%02x%02x%s|r", color.r * 255, color.g * 255, color.b * 255, text)
end
-- Formats 120 seconds as 2m, 130 seconds as 2m10s and such
local function formatTime(totalTime)
totalTime = totalTime / 1000
local hour = ""
local minutes = ""
local seconds = ""
-- Hours
if( totalTime >= 3600 ) then
hour = floor(totalTime / 3600) .. "h"
totalTime = mod(totalTime, 3600)
end
-- Minutes
if( totalTime >= 60 ) then
minutes = floor(totalTime / 60) .. "m"
totalTime = mod(totalTime, 60)
end
-- Seconds
if( totalTime > 0 ) then
seconds = floor(totalTime + 0.5) .. "s"
end
return hour .. minutes .. seconds
end
-- Build the actual page
local function setStatPage(id, statData, ...)
local frame = GUI.statFrame.rows[id]
local fullMakeup, makeup
local classID = ""
for i=1, select("#", ...) do
local classToken = select(i, ...)
-- If it's 2vs2, we have enough space to show the full classes instead of abbrevs
local text = L[classToken]
if( GUI.frame.bracket > 2 ) then
text = string.sub(classToken, 0, 1)
-- Fucking DK's are too long regardless
elseif( classToken == "DEATHKNIGHT" ) then
text = L["DK"]
end
-- Create a full make up for the tooltip
if( i > 1 ) then
makeup = makeup .. "|cffffffff/|r" .. wrapClassColor(classToken, text)
fullMakeup = fullMakeup .. " / " .. L[classToken]
else
makeup = wrapClassColor(classToken, text)
fullMakeup = L[classToken]
end
classID = classID .. classToken
end
-- Setup the talent icons
frame.icons = frame.icons or {}
-- Hide everything
for _, rows in pairs(frame.icons) do
for _, row in pairs(rows) do
row:Hide()
end
end
local totalRows = 0
local totalGames = 0
local usedHeight = 25
for _, data in pairs(statData) do
totalRows = totalRows + 1
totalGames = totalGames + data.totalGames
usedHeight = usedHeight + 33
-- Create the icons quickly
local statRow = frame.icons[totalRows]
if( not icons ) then
frame.icons[totalRows] = {}
statRow = frame.icons[totalRows]
-- Icons
for i=1, 5 do
local icon = CreateFrame("Button", nil, frame)
icon:SetHeight(ICON_SIZE)
icon:SetWidth(ICON_SIZE)
icon:SetScript("OnEnter", OnEnter)
icon:SetScript("OnLeave", OnLeave)
icon:Hide()
if( i > 1 ) then
icon:SetPoint("TOPLEFT", statRow[i - 1], "TOPRIGHT", 5, 0)
elseif( totalRows > 1 ) then
icon:SetPoint("TOPLEFT", frame.icons[totalRows - 1][1], "BOTTOMLEFT", 0, -18)
else
icon:SetPoint("TOPLEFT", frame.makeup, "BOTTOMLEFT", 1, -1)
end
statRow[i] = icon
end
-- Stats below the icons
local statText = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
statText:SetFont(GameFontHighlightSmall:GetFont(), 11)
if( totalRows > 1 ) then
statText:SetPoint("TOPLEFT", frame.icons[totalRows - 1].text, "BOTTOMLEFT", 0, -24)
else
statText:SetPoint("TOPLEFT", frame.makeup, "TOPLEFT", -1, -37)
end
statText:Hide()
statRow.text = statText
end
for id, talentInfo in pairs(data.talents) do
local classToken, icon, name = string.split(":", talentInfo)
statRow[id].tooltip = string.format("%s %s", name, L[classToken])
statRow[id]:SetNormalTexture("Interface\\Icons\\" .. icon)
statRow[id]:Show()
end
statRow.text:SetFormattedText("%s:%s (%d%%) (%s)", GREEN_FONT_COLOR_CODE .. data.won .. FONT_COLOR_CODE_CLOSE, RED_FONT_COLOR_CODE .. data.lost .. FONT_COLOR_CODE_CLOSE, data.won / ( data.won + data.lost ) * 100, formatTime(data.gameLength / data.totalGames))
statRow.text:Show()
end
-- Base data and such
frame.totalGames = totalGames
frame.classID = classID
frame.makeup.tooltip = fullMakeup
frame.makeup:SetText(makeup)
frame:SetHeight(usedHeight)
end
local function sortGames(a, b)
if( not a ) then
return true
elseif( not b ) then
return false
end
if( a.totalGames == b.totalGames ) then
return a.classID > b.classID
end
return a.totalGames > b.totalGames
end
-- Update the team vs stats
local function updateStatPage()
local self = GUI
local history = arenaData[self.frame.bracket]
local statHistory = arenaTeamStats[self.frame.bracket]
-- Hide everything
for id, row in pairs(self.statFrame.rows) do
row.classID = "z"
row.totalGames = 100
row:Hide()
end
-- Update the display
local id = 0
for teamID, data in pairs(statHistory) do
id = id + 1
setStatPage(id, data, string.split(":", teamID))
end
table.sort(self.statFrame.rows, sortGames)
-- Reposition it all
local largestRow = 0
local heightUsed = 0
local rowsUsed = -1
local SPACING = 4
for id, row in pairs(self.statFrame.rows) do
rowsUsed = rowsUsed + 1
row:Show()
largestRow = max(row:GetHeight(), largestRow)
if( id == 1 ) then
row:SetPoint("TOPLEFT", self.statFrame, "TOPLEFT", 0, 0)
elseif( rowsUsed == 4 ) then
heightUsed = heightUsed - largestRow - SPACING
largestRow = row:GetHeight()
rowsUsed = 0
row:SetPoint("TOPLEFT", self.statFrame, "TOPLEFT", 0, heightUsed)
else
row:SetPoint("TOPLEFT", self.statFrame.rows[id - 1], "TOPRIGHT", SPACING, 0)
end
end
self.statFrame:Show()
self.statFrame.scroll:Show()
end
-- HISTORY PAGE WITH GAMES PLAYED
local function updateHistoryPage()
local self = GUI
local history = arenaData[self.frame.bracket]
-- Check how many rows are supposed to be used
local totalVisible = 0
for _, matchInfo in pairs(history) do
if( not matchInfo.hidden ) then
totalVisible = totalVisible + 1
end
end
FauxScrollFrame_Update(self.frame.scroll, totalVisible, MAX_TEAMS_SHOWN, 75)
-- Word wrap settings
local nameLimit = 55
local fsLimit = 60
-- When we're only showing 2 or 3 players, you can't possibly overflow so change the width limits
if( self.frame.bracket == 2 or self.frame.bracket == 3 ) then
nameLimit = 70
fsLimit = 70
end
-- Display
local offset = FauxScrollFrame_GetOffset(self.frame.scroll)
local usedRows = 0
local totalRows = 0
for id, matchInfo in pairs(history) do
if( not matchInfo.hidden ) then
totalRows = totalRows + 1
if( totalRows > offset and usedRows < MAX_TEAMS_SHOWN ) then
usedRows = usedRows + 1
local row = self.rows[usedRows]
row:Show()
local zone
if( matchInfo.zone == "BEA" ) then
zone = L["Blade's Edge Arena"]
elseif( matchInfo.zone == "RoL" ) then
zone = L["Ruins of Lordaeron"]
elseif( matchInfo.zone == "NA" ) then
zone = L["Nagrand Arena"]
elseif( matchInfo.zone == "DA" ) then
zone = L["Dalaran Arena"]
elseif( matchInfo.zone == "RoV" ) then
zone = L["The Ring of Valor"]
end
-- Delete ID
row.deleteButton.id = matchInfo.recordID
-- Row number
row.rowInfo:SetFormattedText("|cffffffff[%d]|r", (#(history) + 1) - id)
row.rowInfo.tooltip = string.format(L["Date: %s"], date("%B %Y, %A %d, %I:%M %p", matchInfo.time))
-- Match info
row.matchInfo:SetFormattedText(L["Run Time: %s"], SecondsToTime(matchInfo.runTime / 1000))
row.zoneText:SetText(zone or L["Unknown"])
-- Team stats
row.teamRecord:SetFormattedText(L["Record: %s/%s"], GREEN_FONT_COLOR_CODE .. arenaStats[matchInfo.teamID].won .. FONT_COLOR_CODE_CLOSE, RED_FONT_COLOR_CODE .. arenaStats[matchInfo.teamID].lost .. FONT_COLOR_CODE_CLOSE)
-- Enemy team display
row.enemyTeam:SetText(matchInfo.eTeamName)
if( matchInfo.eSkill == 0 ) then
row.enemyInfo:SetFormattedText(L["%d Rating (%d Points)"], matchInfo.eRating, matchInfo.eChange)
else
row.enemyInfo:SetFormattedText("%d (%d, %d)", matchInfo.eRating, matchInfo.eChange, matchInfo.eSkill)
end
setupTeamInfo(nameLimit, fsLimit, row.enemyRows, matchInfo.enemyTeam, matchInfo.eTeamName, matchInfo.eServer, matchInfo.teamID)
-- Player team display
row.playerTeam:SetText(matchInfo.pTeamName)
if( matchInfo.pSkill == 0 ) then
row.playerInfo:SetFormattedText(L["%d Rating (%d Points)"], matchInfo.pRating, matchInfo.pChange)
else
row.playerInfo:SetFormattedText("%d (%d, %d)", matchInfo.pRating, matchInfo.pSkill, matchInfo.pSkill)