-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGUI_Main.lua
1856 lines (1612 loc) · 55.8 KB
/
GUI_Main.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 Recount = _G.Recount
local SM = LibStub:GetLibrary("LibSharedMedia-3.0")
local AceLocale = LibStub("AceLocale-3.0")
local L = AceLocale:GetLocale("Recount")
local LD = LibStub("LibDropdown-1.0")
local revision = tonumber(string.sub("$Revision: 1540 $", 12, -3))
if Recount.Version < revision then
Recount.Version = revision
end
local ipairs = ipairs
local math_floor = math.floor
local math_max = math.max
local pairs = pairs
local string = string
local string_format = string.format
local string_match = string.match
local strsub = strsub
local table = table
local tinsert = table.insert
local tremove = table.remove
local type = type
local BNSendWhisper = BNSendWhisper
local CreateFrame = CreateFrame
local GetScreenHeight = GetScreenHeight
local GetScreenWidth = GetScreenWidth
local IsAltKeyDown = IsAltKeyDown
local IsControlKeyDown = IsControlKeyDown
local IsShiftKeyDown = IsShiftKeyDown
local SendChatMessage = SendChatMessage
local UIFrameFade = UIFrameFade
local GameTooltip = GameTooltip
local UIParent = UIParent
local FauxScrollFrame_GetOffset = FauxScrollFrame_GetOffset
local FauxScrollFrame_Update = FauxScrollFrame_Update
local FauxScrollFrame_OnVerticalScroll = FauxScrollFrame_OnVerticalScroll
local UIDropDownMenu_AddButton = UIDropDownMenu_AddButton
local UIDropDownMenu_SetAnchor = UIDropDownMenu_SetAnchor
local WOW_RETAIL = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
local me = {}
local dbCombatants
-- Based on cck's numeric Short code in DogTag-3.0.
function Recount.ShortNumber(value)
if not value then
return ""
end
if value >= 100000000000000 or value <= -100000000000000 then
return ("%.3fT"):format(value / 1000000000000)
elseif value >= 10000000000000 or value <= -10000000000000 then
return ("%.3fT"):format(value / 1000000000000)
elseif value >= 1000000000000 or value <= -1000000000000 then
return ("%.3fT"):format(value / 1000000000000)
elseif value >= 100000000000 or value <= -100000000000 then
return ("%.3fG"):format(value / 1000000000)
elseif value >= 10000000000 or value <= -10000000000 then
return ("%.3fG"):format(value / 1000000000)
elseif value >= 1000000000 or value <= -1000000000 then
return ("%.3fG"):format(value / 1000000000)
elseif value >= 100000000 or value <= -100000000 then
return ("%.2fM"):format(value / 1000000)
elseif value >= 10000000 or value <= -10000000 then
return ("%.2fM"):format(value / 1000000)
elseif value >= 1000000 or value <= -1000000 then
return ("%.2fM"):format(value / 1000000)
elseif value >= 100000 or value <= -100000 then
return ("%.1fk"):format(value / 1000)
elseif value >= 10000 or value <= -10000 then
return ("%.1fk"):format(value / 1000)
else
return math_floor(value + 0.5)..''
end
end
-- This is comma_value() by Richard Warburton from: http://lua-users.org/wiki/FormattingNumbers with slight modifications (and a bug fix)
function Recount.CommaNumber(value)
if not value then
return ""
end
value = ("%.0f"):format(math_floor(value + 0.5))
local left, num, right = string_match(value, "^([^%d]*%d)(%d+)(.-)$")
return left and left..(num:reverse():gsub("(%d%d%d)", "%1,"):reverse()) or value --..right
end
local NumFormats = {
function(value)
if not value then
return ""
end
return ("%.0f"):format(math_floor(value + 0.5))
end,
Recount.CommaNumber,
Recount.ShortNumber
}
function Recount:FormatLongNums(value)
return NumFormats[Recount.db.profile.MainWindow.BarText.NumFormat](value)
end
function me:SetFontSize(string, size)
local Font, Height, Flags = string:GetFont()
string:SetFont(Font, size, Flags)
end
local function Faded(self)
self:Release()
end
local function FadeMenu(self)
local fadeInfo = {}
fadeInfo.mode = "OUT"
fadeInfo.timeToFade = 0.1
fadeInfo.finishedFunc = Faded
fadeInfo.finishedArg1 = self
UIFrameFade(self, fadeInfo)
end
function Recount:OpenBarDropDown(myframe)
-- adopted from BulkMail
-- release if if already shown
local barmenuframe
barmenuframe = barmenuframe and barmenuframe:Release()
local baropts = {
type = 'group',
args = {
--[[title = {
name = self.relativeTo.LeftText:GetText(),
type = "description",
},]]
details = {
order = 10,
name = L["Show Details (Left Click)"],
type = "execute",
func = function()
me:ShowDetail(me.name)
FadeMenu(barmenuframe)
end,
--me.ShowDetailWrapper,
},
graph = {
order = 20,
name = L["Show Graph (Shift Click)"],
type = "execute",
func = function()
me:ShowGraphWindow(me.name)
FadeMenu(barmenuframe)
end,
--me.ShowGraphWindowWrapper,
},
addgraph = {
order = 30,
name = L["Add to Current Graph (Alt Click)"],
type = "execute",
func = function()
me:AddCombatantToGraph(me.name)
FadeMenu(barmenuframe)
end,
--me.AddCombatantToGraphWrapper,
},
delete = {
order = 40,
name = L["Delete Combatant (Ctrl-Alt Click)"],
type = "execute",
func = function()
me:DeleteCombatant(me.name)
FadeMenu(barmenuframe)
end,
--me.DeleteCombatantWrapper,
},
}
}
-- create the menu
if Recount.MainWindow.RealtimeSettings then
baropts.args.realtime = {
order = 35,
name = L["Show Realtime Graph (Ctrl Click)"],
type = "execute",
func = function()
me:ShowRealtime(me.name)
FadeMenu(barmenuframe)
end,
--me.ShowRealtimeWrapper,
}
else
baropts.args.realtime = nil
end
me.name = myframe.name
barmenuframe = barmenuframe or LD:OpenAce3Menu(baropts)
barmenuframe:SetClampedToScreen(true)
barmenuframe:SetAlpha(1.0)
barmenuframe:Show()
local leftPos = myframe:GetLeft() -- Elsia: Side code adapted from Mirror
local rightPos = myframe:GetRight()
local side
local oside
if not rightPos then
rightPos = 0
end
if not leftPos then
leftPos = 0
end
local rightDist = GetScreenWidth() - rightPos
if leftPos and rightDist < leftPos then
side = "TOPLEFT"
oside = "TOPRIGHT"
else
side = "TOPRIGHT"
oside = "TOPLEFT"
end
barmenuframe:ClearAllPoints()
barmenuframe:SetPoint(oside, myframe, side, 0, 0)
--barmenuframe:SetFrameLevel(myframe:GetFrameLevel() + 9)
end
function Recount:BarDropDownOpen(myframe)
local Recount_BarDropDownMenu = CreateFrame("Frame", "Recount_BarDropDownMenu", myframe)
Recount_BarDropDownMenu.displayMode = "MENU"
Recount_BarDropDownMenu.initialize = Recount.CreateBarDropdown
local leftPos = myframe:GetLeft() -- Elsia: Side code adapted from Mirror
local rightPos = myframe:GetRight()
local side
local oside
if not rightPos then
rightPos = 0
end
if not leftPos then
leftPos = 0
end
local rightDist = GetScreenWidth() - rightPos
if leftPos and rightDist < leftPos then
side = "TOPLEFT"
oside = "TOPRIGHT"
else
side = "TOPRIGHT"
oside = "TOPLEFT"
end
UIDropDownMenu_SetAnchor(Recount_BarDropDownMenu , 0, 0, oside, myframe, side)
end
function Recount:SetupBar(row)
row.StatusBar = CreateFrame("StatusBar", nil, row)
row.StatusBar:SetAllPoints(row)
local BarTexture
if not BarTexture then
BarTexture = Recount.db.profile.BarTexture
end
if BarTexture == nil then
BarTexture = SM:Fetch("statusbar", "BantoBar")
else
BarTexture = SM:Fetch("statusbar", BarTexture)
end
row.StatusBar:SetStatusBarTexture(BarTexture)
row.StatusBar:GetStatusBarTexture():SetHorizTile(false)
row.StatusBar:GetStatusBarTexture():SetVertTile(false)
row.StatusBar:SetStatusBarColor(5, .5, .5, 1)
row.StatusBar:SetMinMaxValues(0, 100)
row.StatusBar:SetValue(100)
row.StatusBar:Show()
row.LeftText = row.StatusBar:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
row.LeftText:SetPoint("LEFT", row.StatusBar, "LEFT", 2, 0)
row.LeftText:SetJustifyH("LEFT")
row.LeftText:SetText("Test")
row.LeftText:SetTextColor(1, 1, 1, 1)
row.LeftText:SetWordWrap(false)
me:SetFontSize(row.LeftText, math_max(Recount.db.profile.MainWindow.RowHeight * 0.75, Recount.db.profile.MainWindow.RowHeight - 3))
Recount:AddFontString(row.LeftText)
row.RightText = row.StatusBar:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
row.RightText:SetPoint("RIGHT", row.StatusBar, "RIGHT", -2, 0)
row.RightText:SetJustifyH("RIGHT")
row.RightText:SetText("0")
row.RightText:SetTextColor(1, 1, 1, 1)
me:SetFontSize(row.RightText, math_max(Recount.db.profile.MainWindow.RowHeight * 0.75, Recount.db.profile.MainWindow.RowHeight - 3))
Recount:AddFontString(row.RightText)
end
--Violation was my reference (I like the basic look of violation just not the backend)
--Make sure to start with row 1 and go upwards when creating though should be safe if you don't just more function calls
function me:CreateRow(num)
local rowmin = 1
local offs = 0
if not Recount.db.profile.MainWindow.HideTotalBar then
offs = 1
rowmin = 0
end
if num < rowmin or Recount.MainWindow.Rows[num] then
return
end
local row = CreateFrame("Button", "Recount_MainWindow_Bar"..num, Recount.MainWindow)
row:SetPoint("TOPLEFT", Recount.MainWindow, "TOPLEFT", 2, -32 - (Recount.db.profile.MainWindow.RowHeight + Recount.db.profile.MainWindow.RowSpacing) * (num - 1 + offs))
row:SetHeight(Recount.db.profile.MainWindow.RowHeight)
row:SetWidth(Recount.MainWindow:GetWidth() - 4)
if num ~= 0 then
row:SetScript("OnClick", function(self, button)
if button == "RightButton" then
Recount:OpenBarDropDown(self)
--[[Recount:BarDropDownOpen(self)
CloseDropDownMenus(1)
ToggleDropDownMenu(1, nil, Recount_BarDropDownMenu)]]
elseif type(self.clickFunc) == "function" and self.clickData then
self:clickFunc(self.clickData)
end
end)
row:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_TOPRIGHT")
Recount.MainWindow:TooltipFunc(self.Name, self.TooltipData)
GameTooltip:Show()
end)
row:SetScript("OnLeave", function(self)
GameTooltip:Hide()
end)
row:EnableMouse(true)
row:RegisterForClicks("LeftButtonDown", "RightButtonUp")
elseif RecountDeathTrack then
--Recount:DPrint("click")
RecountDeathTrack:AddDropDown(row)
else
row:EnableMouse(false)
end
--Add code for the button later
Recount:SetupBar(row)
Recount.MainWindow.Rows[num] = row
Recount.MainWindow.RowsCreated = num
Recount:UpdateBarTextColor(num)
row.id = num
end
local info = {}
function Recount.CreateBarDropdown(self, level)
if (not level) then
return
end
for k in pairs(info) do
info[k] = nil
end
if (level == 1) then
if self and self.relativeTo.LeftText then
info.isTitle = 1
info.text = self.relativeTo.LeftText:GetText()
info.notCheckable = 1
UIDropDownMenu_AddButton(info, level)
info = {}
info.isTitle = nil
info.notCheckable = 1
info.disabled = nil
info.text = L["Show Details (Left Click)"]
info.notCheckable = 1
info.func = me.ShowDetail
--info.arg1 = me
info.arg1 = self.relativeTo.name
UIDropDownMenu_AddButton(info, level)
info.text = L["Show Graph (Shift Click)"]
info.notCheckable = 1
info.func = me.ShowGraphWindow
--info.arg1 = me
info.arg1 = self.relativeTo.name
UIDropDownMenu_AddButton(info, level)
info.text = L["Add to Current Graph (Alt Click)"]
info.notCheckable = 1
info.func = me.AddCombatantToGraph
--info.arg1 = me
info.arg1 = self.relativeTo.name
UIDropDownMenu_AddButton(info, level)
local Settings = Recount.MainWindow.RealtimeSettings
if Settings then
info.text = L["Show Realtime Graph (Ctrl Click)"]
info.notCheckable = 1
info.func = me.ShowRealtime
--info.arg1 = me
info.arg1 = self.relativeTo.name
UIDropDownMenu_AddButton(info, level)
end
info.text = L["Delete Combatant (Ctrl-Alt Click)"]
info.notCheckable = 1
info.func = me.DeleteCombatant
--info.arg1 = me
info.arg1 = self.relativeTo.name
UIDropDownMenu_AddButton(info, level)
end
end
end
function Recount:DeleteCombatant(name)
if not dbCombatants[name] then
return
end
-- Recount:DPrint("Deleting combatant: "..name.." "..dbCombatants[name].type)
if dbCombatants[name].Owner then
local owner = dbCombatants[name].Owner
if dbCombatants[owner] and dbCombatants[owner].Pet then
for k, v in pairs(dbCombatants[owner].Pet) do
if v == name then
tremove(dbCombatants[owner].Pet, k) -- Elsia: Remove deleted pet
end
end
end
end
if dbCombatants[name].Pet then
for k, v in pairs(dbCombatants[name].Pet) do
me:DeleteCombatant(v) -- Elsia: Delete all pets with owner
end
end
Recount:DeleteGuardianOwnerByGUID(dbCombatants[name])
dbCombatants[name] = nil
Recount.NewData = true
end
--[[function me:DeleteCombatantWrapper(self)
me:DeleteCombatant(me.name)
FadeMenu(barmenuframe)
--barmenuframe = barmenuframe and barmenuframe:Release()
end]]
function me:DeleteCombatant(name) -- Elsia: Add delete combatant feature
Recount:DeleteCombatant(name)
Recount:SetMainWindowMode(Recount.db.profile.MainWindowMode)
Recount:FullRefreshMainWindow()
end
function Recount:FullRefreshMainWindow()
Recount:FreeTableRecurseLimit(Recount.MainWindow.DispTableSorted, 1)
Recount:FreeTable(Recount.MainWindow.DispTableLookup)
Recount.MainWindow.DispTableSorted = Recount:GetTable()
Recount.MainWindow.DispTableLookup = Recount:GetTable()
end
function me:FixRow(i)
local row = Recount.MainWindow.Rows[i]
local MaxNameWidth = row:GetWidth() - row.RightText:GetStringWidth() - 4
if MaxNameWidth < 16 then
MaxNameWidth = 16
end
local LText = row.LeftText:GetText()
if not Recount.db.profile.MainWindow.BarText.ServerName then
LText = string.gsub(LText, "%-[^ >]+", "")
end
row.LeftText:SetText(LText)
while row.LeftText:GetStringWidth() > MaxNameWidth and #LText >= 2 do
LText = string.sub(LText, 1, #LText - 1)
row.LeftText:SetText(LText.."...")
end
end
function Recount:BarsChanged()
local offs = 0
if not Recount.db.profile.MainWindow.HideTotalBar then
offs = 1
end
for k, v in pairs(Recount.MainWindow.Rows) do
v:SetHeight(Recount.db.profile.MainWindow.RowHeight)
v:SetPoint("TOPLEFT", Recount.MainWindow, "TOPLEFT", 2, -32 - (Recount.db.profile.MainWindow.RowHeight + Recount.db.profile.MainWindow.RowSpacing) * (k - 1 + offs))
me:SetFontSize(v.LeftText, math_max(Recount.db.profile.MainWindow.RowHeight * 0.75, Recount.db.profile.MainWindow.RowHeight - 3))
me:SetFontSize(v.RightText, math_max(Recount.db.profile.MainWindow.RowHeight * 0.75, Recount.db.profile.MainWindow.RowHeight - 3))
end
Recount:ResizeMainWindow()
end
function Recount:UpdateBarTextures()
for _, v in pairs(Recount.MainWindow.Rows) do
v.StatusBar:SetStatusBarTexture(SM:Fetch(SM.MediaType.STATUSBAR, Recount.db.profile.BarTexture))
v.StatusBar:GetStatusBarTexture():SetHorizTile(false)
v.StatusBar:GetStatusBarTexture():SetVertTile(false)
end
if Recount.db.profile.Font then
Recount:SetFont(Recount.db.profile.Font)
end
end
function Recount:SetBarTextures(handle)
local Texture = SM:Fetch(SM.MediaType.STATUSBAR, handle) -- "statusbar"
Recount.db.profile.BarTexture = handle
for _, v in pairs(Recount.MainWindow.Rows) do
v.StatusBar:SetStatusBarTexture(Texture)
v.StatusBar:GetStatusBarTexture():SetHorizTile(false)
v.StatusBar:GetStatusBarTexture():SetVertTile(false)
end
end
function me:SetBar(num, left, right, value, colorgroup, colorclass, clickData, clickFunc, tooltipData)
local rowmin = 1
if not Recount.db.profile.MainWindow.HideTotalBar then
rowmin = 0
end
if num < rowmin or not Recount.MainWindow.Rows[num] then
return
end
local Row = Recount.MainWindow.Rows[num]
Row:Show()
Row.StatusBar:SetValue(value)
Row.LeftText:SetText(left)
Row.RightText:SetText(right)
Row.Name = left
Row.TooltipData = tooltipData
Row.clickData = clickData
Row.clickFunc = clickFunc
if Recount.db.profile.BarTextColorSwap then
if colorgroup and colorclass and type(colorclass) == "string" then
Recount.Colors:UnregisterItem(Row.LeftText)
Recount.Colors:UnregisterItem(Row.RightText)
Recount.Colors:RegisterFont(colorgroup, Recount:FixUnitString(colorclass), Row.LeftText)
Recount.Colors:RegisterFont(colorgroup, Recount:FixUnitString(colorclass), Row.RightText)
--Row.StatusBar:SetStatusBarColor(color.r, color.g, color.b, 1)
end
Row.StatusBar:SetVertexColor(Recount.db.profile.Colors.Bar["Bar Text"].r, Recount.db.profile.Colors.Bar["Bar Text"].g, Recount.db.profile.Colors.Bar["Bar Text"].b, Recount.db.profile.Colors.Bar["Bar Text"].a)
else
if colorgroup and colorclass and type(colorclass) == "string" then
Recount.Colors:UnregisterItem(Row.StatusBar)
Recount.Colors:RegisterTexture(colorgroup, Recount:FixUnitString(colorclass),Row.StatusBar)
--Row.StatusBar:SetStatusBarColor(color.r, color.g, color.b, 1)
end
Row.LeftText:SetTextColor(Recount.db.profile.Colors.Bar["Bar Text"].r, Recount.db.profile.Colors.Bar["Bar Text"].g, Recount.db.profile.Colors.Bar["Bar Text"].b, Recount.db.profile.Colors.Bar["Bar Text"].a)
Row.RightText:SetTextColor(Recount.db.profile.Colors.Bar["Bar Text"].r, Recount.db.profile.Colors.Bar["Bar Text"].g, Recount.db.profile.Colors.Bar["Bar Text"].b, Recount.db.profile.Colors.Bar["Bar Text"].a)
end
end
function Recount:UpdateBarTextColor(num)
local Row = Recount.MainWindow.Rows[num]
if Row then
if Recount.db.profile.BarTextColorSwap then
Recount.Colors:UnregisterItem(Row.StatusBar)
Recount.Colors:RegisterTexture("Bar", "Bar Text", Row.StatusBar)
else
Recount.Colors:UnregisterItem(Row.LeftText)
Recount.Colors:UnregisterItem(Row.RightText)
Recount.Colors:RegisterFont("Bar", "Bar Text", Row.LeftText)
Recount.Colors:RegisterFont("Bar", "Bar Text", Row.RightText)
end
end
end
function Recount:UpdateBarTextColors()
for i = 0, Recount.MainWindow.RowsCreated do
Recount:UpdateBarTextColor(i)
end
end
--[[function me:SetBarColors(r, g, b)
self:SetStatusBarColor(r, g, b, 1)
end]]
function Recount:ResizeMainWindow()
--How many bars do we have now?
local Bars = math_floor((Recount.MainWindow:GetHeight() - 32.95) / (Recount.db.profile.MainWindow.RowHeight + Recount.db.profile.MainWindow.RowSpacing))
local minbar
if not Recount.db.profile.MainWindow.HideTotalBar then
minbar = 0
Bars = Bars - 1
else
minbar = 1
if Recount.MainWindow.Rows[0] then
Recount.MainWindow.Rows[0]:Hide()
end
end
if not Recount.db.profile.MainWindow.HideTotalBar and not Recount.MainWindow.Rows[0] then -- Elsia: Create Total Bar
me:CreateRow(0)
end
if Bars < Recount.MainWindow.CurRows then
for i = Bars + 1, Recount.MainWindow.CurRows do
Recount.MainWindow.Rows[i]:Hide()
end
elseif Bars > Recount.MainWindow.RowsCreated then
for i = Recount.MainWindow.RowsCreated + 1, Bars do
me:CreateRow(i)
end
end
--Update all the bar widths
local CurWidth = Recount.MainWindow:GetWidth() - 4
for i = minbar, Bars do
Recount.MainWindow.Rows[i]:Show()
Recount.MainWindow.Rows[i]:SetWidth(CurWidth)
end
Recount.MainWindow.CurRows = Bars
Recount.MainWindow.ScrollBar:SetPoint("TOPLEFT", Recount.MainWindow.Rows[1], "TOPLEFT", -4, 0)
Recount.MainWindow.ScrollBar:SetPoint("BOTTOMRIGHT", Recount.MainWindow.Rows[Bars], "BOTTOMRIGHT", -4, 0)
Recount:RefreshMainWindow()
end
function Recount:CreateMainWindow()
Recount.MainWindow = Recount:CreateFrame("Recount_MainWindow", L["Main"], 140, 200, function()
Recount.MainWindow.timeid = Recount:ScheduleRepeatingTimer("RefreshMainWindow", 1, true)
Recount.db.profile.MainWindowVis = true
end,
function()
if Recount.MainWindow.timeid then
Recount:CancelTimer(Recount.MainWindow.timeid)
Recount.MainWindow.timeid = nil
end
if not UIParent:IsShown() or (WOW_RETAIL and C_PetBattles.IsInBattle() or false) then
return
end
Recount.db.profile.MainWindowVis = false
end)
local theFrame = Recount.MainWindow
theFrame:SetResizable(true)
if theFrame.SetResizeBounds then
theFrame:SetResizeBounds(140, 63, 500, 520)
else
theFrame:SetMinResize(140, 63)
theFrame:SetMaxResize(500, 520)
end
theFrame.SaveMainWindowPosition = Recount.SaveMainWindowPosition
theFrame:SetScript("OnSizeChanged", function(self)
if (self.isResizing) then
Recount:ResizeMainWindow()
Recount.db.profile.MainWindowHeight = self:GetHeight()
Recount.db.profile.MainWindowWidth = self:GetWidth()
end
end)
theFrame.TitleClick = CreateFrame("FRAME", nil, theFrame)
theFrame.TitleClick:SetAllPoints(theFrame.Title)
theFrame.TitleClick:EnableMouse(true)
theFrame.TitleClick:SetScript("OnMouseDown", function(self, button)
if button == "RightButton" then
Recount:OpenModeDropDown(self)
--[[Recount:ModeDropDownOpen(self)
ToggleDropDownMenu(1, nil, Recount_ModeDropDownMenu)--]]
end
local parent = self:GetParent()
if (((not parent.isLocked) or (parent.isLocked == 0)) and (button == "LeftButton")) then
Recount:SetWindowTop(parent)
parent:StartMoving()
parent.isMoving = true
end
end)
theFrame.TitleClick:SetScript("OnMouseUp", function(self)
local parent = self:GetParent()
if (parent.isMoving) then
parent:StopMovingOrSizing()
parent.isMoving = false
parent:SaveMainWindowPosition()
end
end)
theFrame.TitleClick:SetScript("OnMouseWheel", function (self, delta)
if not IsAltKeyDown() then
return
end
if delta > 0 then
Recount:MainWindowPrevMode()
else
Recount:MainWindowNextMode()
end
end)
theFrame.ScrollBar = CreateFrame("SCROLLFRAME", "Recount_MainWindow_ScrollBar", theFrame, "FauxScrollFrameTemplate")
theFrame.ScrollBar:SetScript("OnVerticalScroll", function(self, offset)
FauxScrollFrame_OnVerticalScroll(self, offset, 20, Recount.RefreshMainWindow)
end)
Recount:SetupScrollbar("Recount_MainWindow_ScrollBar")
if not Recount.db.profile.MainWindow.ShowScrollbar then
Recount:HideScrollbarElements("Recount_MainWindow_ScrollBar")
end
theFrame.DragBottomRight = CreateFrame("Button", "RecountResizeGripRight", theFrame) -- Grip Buttons from Omen2
theFrame.DragBottomRight:Show()
theFrame.DragBottomRight:SetFrameLevel(theFrame:GetFrameLevel() + 10)
theFrame.DragBottomRight:SetNormalTexture("Interface\\AddOns\\Recount\\textures\\ResizeGripRight")
theFrame.DragBottomRight:SetHighlightTexture("Interface\\AddOns\\Recount\\textures\\ResizeGripRight")
theFrame.DragBottomRight:SetWidth(16)
theFrame.DragBottomRight:SetHeight(16)
theFrame.DragBottomRight:SetPoint("BOTTOMRIGHT", theFrame, "BOTTOMRIGHT", 0, 0)
theFrame.DragBottomRight:EnableMouse(true)
theFrame.DragBottomRight:SetScript("OnMouseDown", function(self, button)
if (((not self:GetParent().isLocked) or (self:GetParent().isLocked == 0)) and (button == "LeftButton")) then
self:GetParent().isResizing = true
self:GetParent():StartSizing("BOTTOMRIGHT")
end
end) -- Elsia: disallow resizing when locked.
theFrame.DragBottomRight:SetScript("OnMouseUp", function(self, button)
if self:GetParent().isResizing == true then
self:GetParent():StopMovingOrSizing()
self:GetParent():SaveMainWindowPosition()
self:GetParent().isResizing = false
end
end)
theFrame.DragBottomLeft = CreateFrame("Button", "RecountResizeGripLeft", theFrame)
theFrame.DragBottomLeft:Show()
theFrame.DragBottomLeft:SetFrameLevel(theFrame:GetFrameLevel() + 10)
theFrame.DragBottomLeft:SetNormalTexture("Interface\\AddOns\\Recount\\textures\\ResizeGripLeft")
theFrame.DragBottomLeft:SetHighlightTexture("Interface\\AddOns\\Recount\\textures\\ResizeGripLeft")
theFrame.DragBottomLeft:SetWidth(16)
theFrame.DragBottomLeft:SetHeight(16)
theFrame.DragBottomLeft:SetPoint("BOTTOMLEFT", theFrame, "BOTTOMLEFT", 0, 0)
theFrame.DragBottomLeft:EnableMouse(true)
theFrame.DragBottomLeft:SetScript("OnMouseDown", function(self, button)
if (((not self:GetParent().isLocked) or (self:GetParent().isLocked == 0)) and (button == "LeftButton")) then
self:GetParent().isResizing = true
self:GetParent():StartSizing("BOTTOMLEFT")
end
end) -- Elsia: disallow resizing when locked.
theFrame.DragBottomLeft:SetScript("OnMouseUp", function(self, button)
if self:GetParent().isResizing == true then
self:GetParent():StopMovingOrSizing()
self:GetParent():SaveMainWindowPosition()
self:GetParent().isResizing = false
end
end)
--Recount:ShowGrips(not Recount.db.profile.Locked)
theFrame.RightButton = CreateFrame("Button", nil, theFrame)
theFrame.RightButton:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Up.blp")
theFrame.RightButton:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Down.blp")
theFrame.RightButton:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight.blp")
theFrame.RightButton:SetWidth(16)
theFrame.RightButton:SetHeight(16)
--theFrame.RightButton:SetPoint("TOPRIGHT", theFrame, "TOPRIGHT", -38 + 16,-12)
theFrame.RightButton:SetPoint("RIGHT", theFrame.CloseButton, "LEFT", 0, 0)
theFrame.RightButton:SetScript("OnClick", function()
Recount:MainWindowNextMode()
end)
theFrame.RightButton:SetFrameLevel(theFrame.RightButton:GetFrameLevel() + 1)
theFrame.LeftButton = CreateFrame("Button", nil, theFrame)
theFrame.LeftButton:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Up.blp")
theFrame.LeftButton:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Down.blp")
theFrame.LeftButton:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight.blp")
theFrame.LeftButton:SetWidth(16)
theFrame.LeftButton:SetHeight(16)
theFrame.LeftButton:SetPoint("RIGHT", theFrame.RightButton, "LEFT", 0, 0)
theFrame.LeftButton:SetScript("OnClick",function()
Recount:MainWindowPrevMode()
end)
theFrame.LeftButton:SetFrameLevel(theFrame.LeftButton:GetFrameLevel() + 1)
theFrame.ResetButton = CreateFrame("Button", nil, theFrame)
theFrame.ResetButton:SetNormalTexture("Interface\\Addons\\Recount\\Textures\\icon-reset")
theFrame.ResetButton:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight.blp")
theFrame.ResetButton:SetWidth(16)
theFrame.ResetButton:SetHeight(16)
theFrame.ResetButton:SetPoint("RIGHT", theFrame.LeftButton, "LEFT", 0, 0)
theFrame.ResetButton:SetScript("OnClick", function()
if IsAltKeyDown() then
Recount:ResetData()
else
Recount:ShowReset()
end
end)
theFrame.ResetButton:SetFrameLevel(theFrame.ResetButton:GetFrameLevel() + 1)
theFrame.FileButton = CreateFrame("Button", nil, theFrame)
theFrame.FileButton:SetNormalTexture("Interface\\Buttons\\UI-GuildButton-PublicNote-Up.blp")
--theFrame.FileButton:SetPushedTexture("Interface\\Buttons\\UI-GuildButton-PublicNote-Down.blp") -- Texture disappeared with MOP
theFrame.FileButton:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight.blp")
theFrame.FileButton:SetWidth(16)
theFrame.FileButton:SetHeight(16)
theFrame.FileButton:SetPoint("RIGHT", theFrame.ResetButton, "LEFT", 0, 0)
theFrame.FileButton:SetScript("OnClick", function(self)
Recount:OpenFightDropDown(self)
--[[Recount:FightDropDownOpen(self)
ToggleDropDownMenu(1, nil, Recount_FightDropDownMenu) ]]
end)
theFrame.FileButton:SetFrameLevel(theFrame.FileButton:GetFrameLevel() + 1)
theFrame.ConfigButton = CreateFrame("Button", nil, theFrame)
theFrame.ConfigButton:SetNormalTexture("Interface\\Addons\\Recount\\Textures\\icon-config")
theFrame.ConfigButton:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight.blp")
theFrame.ConfigButton:SetWidth(16)
theFrame.ConfigButton:SetHeight(16)
theFrame.ConfigButton:SetPoint("RIGHT", theFrame.FileButton, "LEFT", 0, 0)
theFrame.ConfigButton:SetScript("OnClick", function()
Recount:ShowConfig()
end)
theFrame.ConfigButton:SetFrameLevel(theFrame.ConfigButton:GetFrameLevel() + 1)
theFrame.ReportButton = CreateFrame("Button",nil, theFrame)
theFrame.ReportButton:SetNormalTexture("Interface\\Buttons\\UI-GuildButton-MOTD-Up.blp")
theFrame.ReportButton:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight.blp")
theFrame.ReportButton:SetWidth(16)
theFrame.ReportButton:SetHeight(16)
theFrame.ReportButton:SetPoint("RIGHT", theFrame.ConfigButton, "LEFT", 0, 0)
theFrame.ReportButton:SetScript("OnClick", function()
Recount:ShowReport("Main", Recount.ReportData)
end)
theFrame.ReportButton:SetFrameLevel(theFrame.ReportButton:GetFrameLevel() + 1)
Recount.MainWindow.Rows = {}
Recount.MainWindow.CurRows = 0
Recount.MainWindow.RowsCreated = 0
Recount.MainWindow.DispTableSorted = {}
Recount.MainWindow.DispTableLookup = {}
theFrame.SavePosition = Recount.SaveMainWindowPosition
Recount:RestoreMainWindowPosition(Recount.db.profile.MainWindow.Position.x, Recount.db.profile.MainWindow.Position.y, Recount.db.profile.MainWindow.Position.w, Recount.db.profile.MainWindow.Position.h)
--Recount:ResizeMainWindow()
Recount:SetupMainWindowButtons()
Recount.MainWindow.timeid = Recount:ScheduleRepeatingTimer("RefreshMainWindow", 1, true)
if not Recount.db.profile.MainWindowVis then
theFrame:Hide()
end
end
function Recount:SetupMainWindowButtons()
for k, v in pairs(Recount.db.profile.MainWindow.Buttons) do
if v then
Recount.MainWindow[k]:Show()
if Recount.MainWindow[k] == Recount.MainWindow.CloseButton then
Recount.MainWindow[k]:SetWidth(20)
else
Recount.MainWindow[k]:SetWidth(16)
end
else
--Have to use width of 1 since 0 is invalid but you can't tell the diff really
Recount.MainWindow[k]:SetWidth(1)
Recount.MainWindow[k]:Hide()
end
end
end
--Actual Data Functions
local function sortFunc(a, b)
if a[2] > b[2] then
return true
elseif a[2] == b[2] then
if a[1] < b[1] then
return true
end
end
return false
end
function Recount:LoadMainWindowData(DataTable)
Recount.MainWindowData = DataTable
Recount:SetMainWindowMode(Recount.db.profile.MainWindowMode or 1)
end
local ConvertName = {
OverallData = "(Overall)",
CurrentFightData = "(Current)",
LastFightData = "(Last)",
}
function Recount:GetModeIndex(modestring)
for i = 1, #Recount.MainWindowData do
if Recount.MainWindowData[i][1] == modestring or Recount.MainWindowData[i][1] == L[modestring] then
return i
end
end
end
function Recount:SetMainWindowMode(mode)
if not mode or mode > #Recount.MainWindowData then
mode = 1
end
Recount.db.profile.MainWindowMode = mode
Recount.DetailMode = 1
local data = Recount.MainWindowData[mode]
Recount.MainWindow.Title:SetText(data[1])
Recount.MainWindow.GetData = data[2]
Recount.MainWindow.TooltipFunc = data[3]
Recount.MainWindow.SpecialTotal = data[4]
Recount.MainWindow.RealtimeSettings = data[5]
Recount:FreeTableRecurseLimit(Recount.MainWindow.DispTableSorted, 1)
Recount:FreeTable(Recount.MainWindow.DispTableLookup)
Recount.MainWindow.DispTableSorted = Recount:GetTable()
Recount.MainWindow.DispTableLookup = Recount:GetTable()
Recount:RefreshMainWindow()
end
function me:UpdateDetailData()
if Recount.DetailWindow:IsVisible() and Recount.MainWindow.Selected then
local _, Data = Recount.MainWindow:GetData(dbCombatants[Recount.MainWindow.Selected])
local mode = Recount.DetailMode
if type(Data) == "table" then
if type(Data[mode][2]) ~= "function" then
Recount:SetupDetailTitles(Recount.MainWindow.Selected, Data[mode][2], Data[mode][3])
Recount:FillUpperDetailTable(Data[mode][1])
else
Data[mode][2](Recount, Recount.MainWindow.Selected, Data[mode][1])
end
end
end
end
function Recount:MainWindowNextMode()
local mode = Recount.db.profile.MainWindowMode + 1
if mode > table.maxn(Recount.MainWindowData) then
mode = 1
end
Recount:SetMainWindowMode(mode)
me:UpdateDetailData()
end
function Recount:MainWindowPrevMode()
local mode = Recount.db.profile.MainWindowMode - 1
if mode == 0 then
mode = table.maxn(Recount.MainWindowData)
end
Recount:SetMainWindowMode(mode)
me:UpdateDetailData()
end
function Recount:DetailWindowNextMode()
local _, Data = Recount.MainWindow:GetData(dbCombatants[Recount.MainWindow.Selected])
local mode = Recount.DetailMode + 1
if not Data or type(Data) ~= "table" or mode > table.maxn(Data) then
mode = 1
end
Recount.DetailMode = mode
Recount.DetailWindow.Locked = false
me:MainWindowSelectPlayer(Recount.MainWindow.Selected)
end
function Recount:DetailWindowPrevMode()
local _, Data = Recount.MainWindow:GetData(dbCombatants[Recount.MainWindow.Selected])
local mode = Recount.DetailMode - 1
if mode == 0 then
mode = Data and type(Data) == "table" and table.maxn(Data) or 1
end
Recount.DetailMode = mode
Recount.DetailWindow.Locked = false
me:MainWindowSelectPlayer(Recount.MainWindow.Selected)
end
function me:MainWindowSelectPlayer(name)
if IsShiftKeyDown() then
me:ShowGraphWindow(name)