-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVortexMeter_UI.lua
1201 lines (1003 loc) · 34.1 KB
/
VortexMeter_UI.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
---------------------------------------------------------------------------------------
-- Vortex Meter
--- Maintained by Vim <Codex>
--- Original addon : Rift Meter by Vince (http://www.curse.com/addons/rift/rift-meter)
-- TODO: Tidy
local RM = Apollo.GetAddon("VortexMeter")
local L = RM.L
local NumberFormat = RM.numberFormat
local FormatSeconds = RM.formatSeconds
local BuildFormat = RM.BuildFormat
local Windows = {}
RM.Windows = Windows
local Modes = {}
local Sortmodes = {
"damage",
"heal",
"damageTaken",
"healTaken",
"absorb",
"absorbTaken",
"overheal",
"overkill",
"interrupts",
}
-- Tooltips
RM.Tooltip = { }
function RM.Tooltip:init()
self.tooltip = Apollo.LoadForm(RM.xmlMainDoc, "Tooltip", nil, RM)
self.tooltipText = self.tooltip:FindChild("TooltipText")
end
function RM.Tooltip:show(text, anchor, center)
if not self.tooltip then
self:init()
end
if not RM.settings.tooltips then return end
self.tooltipText:SetAML(text)
local mouse = Apollo:GetMouse()
self.tooltip:SetAnchorOffsets(mouse.x, mouse.y, mouse.x + 500, mouse.y + 100)
local nTextWidth, nTextHeight = self.tooltipText:SetHeightToContentHeight()
self.tooltip:SetAnchorOffsets(mouse.x + 10, mouse.y - 20, mouse.x + nTextWidth + 22, mouse.y + nTextHeight - 8)
self.tooltip:Show(true)
end
function RM.Tooltip:hide()
if not self.tooltip then
return
end
self.tooltip:Show(false)
end
-- Windows
local Window = {}
Window.__index = Window
function Window:new(settings)
local self = {}
self.settings = settings
self.frames = {}
self.lastData = {}
self.history = {}
self.maxValue = 0
self.rowCount = 0
self.scrollOffset = 0
self.showNpcs = false
self.selectedMode = Modes.combat
self.selectedSortmode = nil
self.selectedCombat = nil
self.selectedPlayer = nil
self.selectedPlayerDetail = nil
self.selectedAbility = nil
self.selectedAbilityDetail = nil
setmetatable(self, Window)
self:init()
return self
end
function Window:init()
local base = Apollo.LoadForm(RM.xmlMainDoc, "VortexMeterForm", nil, RM)
self.frames = {
base = base,
header = base:FindChild("Header"),
headerLabel = base:FindChild("HeaderText"),
buttons = {
close = base:FindChild("ButtonClose"),
copy = base:FindChild("ButtonCopy"),
clear = base:FindChild("ButtonClear"),
pin = base:FindChild("ButtonPin"),
config = base:FindChild("ButtonConfig"),
showEnemies = base:FindChild("ButtonEnemies"),
showPlayers = base:FindChild("ButtonPlayers"),
combatStart = base:FindChild("ButtonStart"),
combatEnd = base:FindChild("ButtonStop"),
},
rows = {},
background = base:FindChild("Background"),
opacitybackground = base:FindChild("OpacityBackground"),
footer = base:FindChild("Footer"),
solo = base:FindChild("btnSolo"),
resizerLeft = base:FindChild("ResizeLeft"),
resizerRight = base:FindChild("ResizeRight"),
timerLabel = base:FindChild("TimerLabel"),
globalStatLabel = base:FindChild("GlobalStatLabel"),
}
self.frames.base:SetData(self)
self.frames.base:SetAnchorOffsets(self.settings.x, self.settings.y, self.settings.x + self.settings.width, 0)
self.frames.base:SetSizingMinimum(140)
self:setRows(self.settings.rows)
local bSolo = Apollo.GetConsoleVariable("cmbtlog.disableOtherPlayers")
self.frames.solo:SetTextColor(bSolo and "xkcdAcidGreen" or "xkcdBloodOrange")
self:Lock(RM.settings.lock)
self.frames.opacitybackground:SetOpacity(RM.settings.opacity)
self.frames.header:SetOpacity(RM.settings.mousetransparency)
self.frames.footer:SetOpacity(RM.settings.mousetransparency)
self.selectedMode:init(self)
end
function Window:clearRows(count) -- from count to rowCount will be hidden
self.scrollOffset = 0
local rows = self.frames.rows
if not rows or count == #rows then return end
if not count then
count = 1
end
for i = count, #rows do
local row = rows[i]
row.icon:Show(false)
row.leftLabel:SetText("")
row.rightLabel:SetText("")
row.base:Show(false)
end
end
function Window:update()
self.lastData, self.rowCount, self.maxValue = self.selectedMode:update(self)
self.lastData = self.lastData or {}
self.rowCount = self.rowCount or 0
self.maxValue = math.max(self.maxValue or 1, 1)
for i = 1, self.settings.rows do
local row = self.frames.rows[i]
local data = self.lastData[i]
if data then
-- Default values
if not data.value then
data.value = 0
end
if not data.color then
data.color = {0, 0.5, 1}
end
if not data.leftLabel then
data.leftLabel = ""
end
if not data.rightLabel then
data.rightLabel = ""
end
if not data.leftClick then
data.leftClick = function() end
end
if not data.middleClick then
data.middleClick = function() end
end
if not data.rightClick then
data.rightClick = function() end
end
if data.icon and data.icon ~= "" then
row.icon:SetSprite(data.icon)
row.icon:Show(true)
else
row.icon:Show(false)
end
row.leftLabel:SetText(tostring(data.leftLabel))
row.rightLabel:SetText(tostring(data.rightLabel))
row.background:SetAnchorPoints(0, 0, data.value / self.maxValue, 1)
row.background:SetBGColor(ApolloColor.new(data.color[1], data.color[2], data.color[3], 1))
row.events.leftClick = data.leftClick
row.events.middleClick = data.middleClick
row.events.rightClick = data.rightClick
row.tooltip = data.tooltip
row.base:Show(true)
else
row.base:Show(false)
end
end
end
function Window.report(text)
if not text then return end
local chan = RM.settings.report_channel
local target = RM.settings.report_target
for i = 1, #text do
if ( chan == 'whisper' or chan == 'tell' or chan == 'w' or chan == 't' ) then
ChatSystemLib.Command("/" .. chan .. " " .. target .. " " .. text[i])
else
ChatSystemLib.Command("/" .. chan .. " " .. text[i])
end
end
end
function Window:setRows(count)
local forCount = count
local rowCount = #self.frames.rows
local rowpos = 1 + rowCount * (self.settings.rowHeight + 1)
count = math.max(count, 1)
if rowCount ~= count then
self.settings.rows = count
for i = count + 1, rowCount do
table.remove(self.frames.rows).base:Destroy()
end
self.scrollOffset = math.max(math.min(self.scrollOffset, rowCount - #self.frames.rows), 0)
for i = rowCount + 1, count do
local base = Apollo.LoadForm(RM.xmlMainDoc, "Row", self.frames.background, RM)
local row = {
events = {},
base = base,
background = base:FindChild("Background"),
icon = base:FindChild("Icon"),
leftLabel = base:FindChild("LeftLabel"),
rightLabel = base:FindChild("RightLabel"),
}
row.base:SetData(row)
row.background:SetOpacity(0.7)
self.frames.rows[i] = row
local left, top, right, bottom = row.base:GetAnchorOffsets()
row.base:SetAnchorOffsets(left, rowpos, right, rowpos + self.settings.rowHeight)
row.base:Show(false)
rowpos = rowpos + self.settings.rowHeight + 1
end
end
local left, top, right, bottom = self.frames.base:GetAnchorOffsets()
self.frames.base:SetAnchorOffsets(left,top,right, top + 45 + count * (self.settings.rowHeight + 1))
self:update()
end
function Window:timerUpdate(duration)
self.frames.timerLabel:SetText(FormatSeconds(duration))
end
function Window:setMode(mode, ...)
RM.Tooltip:hide()
local newMode = {}
if type(mode) == "string" then
newMode = Modes[mode]
else
newMode = mode
end
if newMode ~= self.selectedMode then -- prevent endless loop
table.insert(self.history, self.selectedMode)
self.selectedMode = newMode
end
self:clearRows()
self.selectedMode:init(self, ...)
self:update()
end
function Window:getLastMode()
-- sortmode selection is skipped (Modes.modes)
-- two same modes can't be behind one another
local index = #self.history
if self.history[index] == Modes.modes then
index = index - 1
end
if self.history[index] == self.selectedMode then
index = index - 1
end
return self.history[math.max(index, 1)]
end
function Window:getCurrentMode()
return self.selectedMode
end
function Window:setTitle(title)
self.frames.headerLabel:SetText(tostring(title))
end
function Window:setGlobalLabel(text)
self.frames.globalStatLabel:SetText(NumberFormat(text))
end
function Window:Lock(state)
self.frames.resizerLeft:Show(not state)
self.frames.resizerRight:Show(not state)
self.frames.base:SetStyle("Sizable", not state)
self.frames.base:SetStyle("Moveable", not state)
end
-- Window Event Handlers
function RM:OnHeaderTextButtonUp(wndHandler, wndControl, eMouseButton, nLastRelativeMouseX, nLastRelativeMouseY)
if eMouseButton == 1 then
local window = wndHandler:GetParent():GetParent():GetData()
window:setMode("modes")
end
end
function RM:OnHeaderTextMouseEnter(wndHandler, wndControl, x, y)
wndHandler:SetTextColor(ApolloColor.new(1, 1, 1, 1))
end
function RM:OnHeaderTextMouseExit(wndHandler, wndControl, x, y)
wndHandler:SetTextColor(ApolloColor.new(0.8, 0.8, 0.8, 1))
end
function RM:OnFrameMouseEnter(wndHandler, wndControl, x, y)
if wndHandler ~= wndControl then return end
local window = wndHandler:GetData()
window.frames.header:SetOpacity(1)
window.frames.footer:SetOpacity(1)
end
function RM:OnFrameMouseExit(wndHandler, wndControl, x, y)
if wndHandler ~= wndControl then return end
local window = wndHandler:GetData()
window.frames.header:SetOpacity(RM.settings.mousetransparency)
window.frames.footer:SetOpacity(RM.settings.mousetransparency)
end
function RM:OnFrameWindowMove(wndHandler, wndControl, left, top, right, bottom)
local window = wndHandler:GetData()
window.settings.x = left
window.settings.y = top
window.settings.width = right - left
-- return when height is unchanged (i.e. only width changes or this event is fired by a window move)
if (bottom-top) == (45 + #window.frames.rows * (window.settings.rowHeight + 1)) then return end
-- have to use actual cursor position instead of height to account for repeated movements smaller than rowHeight
window:setRows(math.round((Apollo.GetMouse().y - window.settings.y - 45) / (window.settings.rowHeight+1)))
end
function RM:OnButtonSolo(wndHandler, wndControl, eMouseButton, nLastRelativeMouseX, nLastRelativeMouseY, bDoubleClick, bStopPropagation )
RM.UI.Solo(not Apollo.GetConsoleVariable("cmbtlog.disableOtherPlayers"))
end
function RM:OnButtonClose(wndHandler, wndControl, eMouseButton)
local window = wndHandler:GetParent():GetParent():GetData()
RM.UI.Close(window)
RM.Tooltip:hide()
end
function RM:OnButtonConfig(wndHandler, wndControl, eMouseButton)
RM.ConfigInit()
end
function RM:OnButtonClear(wndHandler, wndControl, eMouseButton)
RM.Clear()
end
function RM:OnButtonStart(wndHandler, wndControl, eMouseButton)
RM.NewCombat(true)
end
function RM:OnButtonStop(wndHandler, wndControl, eMouseButton)
RM.EndCombat()
end
function RM:OnButtonPin(wndHandler, wndControl, eMouseButton)
local window = wndHandler:GetParent():GetParent():GetData()
window:setMode("combat", RM.Combats[#RM.Combats])
end
function RM:OnButtonEnemies(wndHandler, wndControl, eMouseButton)
local window = wndHandler:GetParent():GetParent():GetData()
window.frames.buttons.showPlayers:Show(true)
window.frames.buttons.showEnemies:Show(false)
window.showEnemies = true
window:update()
end
function RM:OnButtonPlayers(wndHandler, wndControl, eMouseButton)
local window = wndHandler:GetParent():GetParent():GetData()
window.frames.buttons.showPlayers:Show(false)
window.frames.buttons.showEnemies:Show(true)
window.showEnemies = false
window:update()
end
function RM:OnBackgroundButtonUp(wndHandler, wndControl, eMouseButton, nLastRelativeMouseX, nLastRelativeMouseY)
local window = wndHandler:GetParent():GetData()
if eMouseButton == 1 then
window.selectedMode:rightClick(window)
elseif eMouseButton == 4 then
window.selectedMode:mouse4Click(window)
elseif eMouseButton == 5 then
window.selectedMode:mouse5Click(window)
end
end
function RM:OnBackgroundScroll(wndHandler, wndControl, nLastRelativeMouseX, nLastRelativeMouseY, fScrollAmount, bConsumeMouseWheel)
local window = wndHandler:GetParent():GetData()
local val = window.scrollOffset + ((fScrollAmount < 0) and 1 or -1)
val = math.max(0, math.min(val, window.rowCount - #window.frames.rows))
if val ~= window.scrollOffset then
window.scrollOffset = val
window:update()
end
return true
end
function RM:OnButtonReport(wndHandler, wndControl, eMouseButton)
local window = wndHandler:GetParent():GetParent():GetData()
local wndReport = Apollo.LoadForm(RM.xmlMainDoc, "ReportForm", nil, RM)
wndReport:SetData(window)
wndReport:FindChild('ReportChannelEditBox'):SetText(RM.settings.report_channel or 's')
wndReport:FindChild('ReportTargetEditBox'):SetText(RM.settings.report_target or 'none')
wndReport:FindChild('ReportLinesEditBox'):SetText(RM.settings.report_lines or '5')
wndReport:Show(true)
end
function RM:OnReportConfirmButton(wndHandler, wndControl)
local wndReport = wndHandler:GetParent():GetParent()
local window = wndReport:GetData()
RM.settings.report_channel = wndReport:FindChild('ReportChannelEditBox'):GetText()
RM.settings.report_target = wndReport:FindChild('ReportTargetEditBox'):GetText()
RM.settings.report_lines = tonumber(wndReport:FindChild('ReportLinesEditBox'):GetText())
wndReport:Destroy()
local selectedMode = window.selectedMode or Modes.interactionAbilities
window.report(selectedMode:getReportText(window))
end
function RM:OnReportClose(wndHandler, wndControl, eMouseButton)
wndHandler:GetParent():Destroy()
end
function RM:OnReportCancel(wndHandler, wndControl, eMouseButton)
wndHandler:GetParent():GetParent():Destroy()
end
function RM:OnButtonMouseEnter(wndHandler, wndControl, x, y)
local window = wndHandler:GetParent():GetParent():GetData()
if wndControl == window.frames.buttons.close then
RM.Tooltip:show(L["Close"])
elseif wndControl == window.frames.buttons.copy then
RM.Tooltip:show(L["Report"])
elseif wndControl == window.frames.buttons.clear then
RM.Tooltip:show(L["Clear data"])
elseif wndControl == window.frames.buttons.pin then
RM.Tooltip:show(L["Jump to current fight"])
elseif wndControl == window.frames.buttons.config then
RM.Tooltip:show(L["Configuration"])
elseif wndControl == window.frames.buttons.showEnemies then
RM.Tooltip:show(L["Show Enemies"])
elseif wndControl == window.frames.buttons.showPlayers then
RM.Tooltip:show(L["Show Players"])
elseif wndControl == window.frames.buttons.combatStart then
RM.Tooltip:show(L["Force combat start"])
elseif wndControl == window.frames.buttons.combatEnd then
RM.Tooltip:show(L["Force combat end"])
end
end
function RM:OnButtonMouseExit(wndHandler, wndControl, x, y)
if wndHandler == wndControl then
RM.Tooltip:hide()
end
end
function RM:OnRowButtonUp(wndHandler, wndControl, eMouseButton, nLastRelativeMouseX, nLastRelativeMouseY)
if wndHandler ~= wndControl then return end
local row = wndHandler:GetData()
if eMouseButton == 0 then
row.events.leftClick()
elseif eMouseButton == 1 then
row.events.rightClick()
elseif eMouseButton == 2 then
row.events.middleClick()
end
end
function RM:OnRowMouseEnter(wndHandler, wndControl, x, y)
if wndHandler ~= wndControl then return end
local row = wndHandler:GetData()
row.background:SetOpacity(0.9)
if row.tooltip then
RM.Tooltip:show(row.tooltip())
end
end
function RM:OnRowMouseExit(wndHandler, wndControl, x, y)
if wndHandler ~= wndControl then return end
local row = wndHandler:GetData()
row.background:SetOpacity(0.7)
RM.Tooltip:hide()
end
-- Modes
local Mode = {}
Mode.__index = Mode
function Mode:new(name)
local self = {}
self.name = name
return setmetatable(self, Mode)
end
function Mode:rightClick() end
function Mode:mouse4Click() end
function Mode:mouse5Click() end
function Mode:init() end
function Mode:update() end
function Mode:onSortmodeChange(window, newSortmode) return true end
function Mode:getReportText() end
-- Mode: Sort Modes
Modes.modes = Mode:new("modes")
function Modes.modes:init(window)
window:setTitle("VortexMeter: " .. L["Sort Modes"])
end
function Modes.modes:update(window)
local rows = {}
local limit = math.min(#Sortmodes, #window.frames.rows)
for i = 1, limit do
local data = {}
local lastMode = window:getLastMode()
local sortMode = Sortmodes[i + window.scrollOffset]
data.leftLabel = L[sortMode]
data.rightlabel = ""
data.value = 1
data.leftClick = function()
local oldSortmode = window.settings.sort
window.settings.sort = Sortmodes[i + window.scrollOffset]
if lastMode:onSortmodeChange(window, oldSortmode) then
window:setMode(lastMode)
end
end
rows[i] = data
end
return rows, #Sortmodes, 1
end
-- Mode: Combat
Modes.combat = Mode:new("combat")
function Modes.combat:init(window, combat)
if combat then
window.selectedCombat = combat
end
if not window.selectedCombat then
if #RM.Combats > 0 then
window.selectedCombat = RM.Combats[#RM.Combats]
end
end
if window.selectedCombat then
window:timerUpdate(window.selectedCombat.duration)
end
window:setTitle(L[window.settings.sort])
end
function Modes.combat:update(window)
if not window.selectedCombat then return end -- Update() is called on init
local data = window.selectedCombat:getPreparedPlayerData(window.settings.sort, window.showEnemies)
local rows = {}
local selfFound = false
local limit = math.min(data.count, #window.frames.rows)
local duration = math.max(window.selectedCombat.duration, 1)
for i = 1, limit do
local row = {}
local player = data.players[i + window.scrollOffset]
if RM.settings.alwaysShowPlayer then
if player.ref.detail.self then
selfFound = true
end
if i == limit and not selfFound then
for j = i + window.scrollOffset, data.count do
if data.players[j].ref.detail.self then
player = data.players[j]
i = j - window.scrollOffset
break
end
end
end
end
row.leftLabel = (RM.settings.showRankNumber and i + window.scrollOffset .. ". " or "") .. player.name
row.rightLabel = BuildFormat(NumberFormat(player.value), player.value / duration, player.value / math.max(data.total, 1) * 100)
row.color = RM.classColors[player.ref.detail.class] or {1, 1, 1}
row.value = player.value
row.tooltip = function()
return player.ref:getTooltip(window.settings.sort)
end
row.leftClick = function()
window:setMode("abilities", player.ref)
end
if player.ref.interactions then
row.middleClick = function()
window:setMode("interactions", player.ref)
end
end
table.insert(rows, row)
end
window:setGlobalLabel(data.total / duration)
return rows, data.count, data.max
end
function Modes.combat:rightClick(window)
if #RM.Combats > 0 then
window:setMode("combats")
end
end
function Modes.combat:getReportText(window)
if not window.selectedCombat then return end
local data = window.selectedCombat:getPreparedPlayerData(window.settings.sort, window.showEnemies)
local duration = math.max(window.selectedCombat.duration, 1)
local text = {}
table.insert(text, ("Target: %s ~ (%s)"):format(window.selectedCombat:getHostile():sub(0, 64), FormatSeconds(window.selectedCombat.duration)))
table.insert(text, ("--------------------"))
table.insert(text, ("Total %s: %s ~ (%s)"):format( window.settings.sort, NumberFormat(data.total), NumberFormat(data.total / duration) ))
for i = 1, math.min( data.count, RM.settings.report_lines ) do
local player = data.players[i]
if not player.ref.detail.isPet then
table.insert(text, ("%d) %s - %s (%s, %d%%) "):format( i, player.ref.detail.name:sub(0, 32), NumberFormat(player.value), NumberFormat(player.value / duration), math.round(player.value / data.total * 100, 2)))
end
end
return text
end
function Modes.combat:mouse4Click(window)
for i, combat in ipairs(RM.Combats) do
if combat == window.selectedCombat and i > 1 then
window:setMode("combat", RM.Combats[i - 1])
return
end
end
end
function Modes.combat:mouse5Click(window)
for i, combat in ipairs(RM.Combats) do
if combat == window.selectedCombat and i < #RM.Combats then
window:setMode("combat", RM.Combats[i + 1])
return
end
end
end
-- Mode: Interactions
Modes.interactions = Mode:new("interactions")
function Modes.interactions:init(window, player)
if player then
window.selectedPlayer = player
end
if window.selectedPlayer then
window:setTitle(L["%s: Interactions: %s"]:format(window.selectedPlayer.detail.name, L[window.settings.sort]))
end
end
function Modes.interactions:update(window)
if not window.selectedPlayer then
if window.selectedPlayerDetail then
self:findOwner(window)
end
if not window.selectedPlayer then
return
end
end
local data = window.selectedPlayer:getInteractions(window.settings.sort)
local duration = math.max(window.selectedCombat.duration, 1)
local rows = {}
local limit = math.min(data.count, #window.frames.rows)
for i = 1, limit do
local row = {}
local interaction = data.interactions[i + window.scrollOffset]
row.leftLabel = (RM.settings.showRankNumber and i + window.scrollOffset .. ". " or "") .. interaction.name
row.rightLabel = BuildFormat(NumberFormat(interaction.value), interaction.value / duration, interaction.value / data.total * 100)
row.color = RM.classColors[interaction.ref.detail.class] or {1, 1, 1}
row.value = interaction.value
row.leftClick = function()
window:setMode("interactionAbilities", interaction.ref, window.selectedPlayer)
end
table.insert(rows, row)
end
window:setGlobalLabel(data.total / duration)
return rows, data.count, data.max
end
function Modes.interactions:rightClick(window)
window:setMode("combat")
end
function Modes.interactions:findOwner(window)
local player = window.selectedCombat.players[window.selectedPlayerDetail]
if player then
window.selectedPlayer = player
window:setTitle(L["%s's Interactions: %s"]:format(player.detail.name, L[window.settings.sort]))
end
end
-- Mode: Interactions ability list
Modes.interactionAbilities = Mode:new("interactionAbilities")
function Modes.interactionAbilities:init(window, player, parent)
if player then
window.selectedPlayer = player
end
if window.selectedPlayer then
if parent then
window.selectedPlayerParent = parent
end
window:setTitle(("%s: %s: %s"):format(window.selectedPlayerParent.detail.name:sub(0, 6), window.selectedPlayer.detail.name:sub(0, 6), L[window.settings.sort]))
end
end
function Modes.interactionAbilities:update(window)
if not window.selectedPlayer then
if window.selectedPlayerDetail then
self:findOwner(window)
end
if not window.selectedPlayer then
return
end
end
local data = window.selectedPlayer:getInteractionAbilityData()
local duration = math.max(window.selectedCombat.duration, 1)
local rows = {}
local limit = math.min(data.count, #window.frames.rows)
for i = 1, limit do
-- total bar
if i == 1 and window.scrollOffset == 0 then
table.insert(rows, {
leftLabel = " " .. L["Total"],
rightLabel = NumberFormat(data.total),
value = data.max,
leftClick = function()
window:setMode("interactionAbility", window.selectedPlayer:createFakeAbility())
end
})
end
local row = {}
local index = window.scrollOffset > 0 and i + window.scrollOffset - 1 or i + window.scrollOffset
local ability = data.abilities[index]
row.icon = ability.ref.detail.icon
row.leftLabel = " " .. ability.ref.name
row.rightLabel = BuildFormat(NumberFormat(ability.value), ability.value / duration, ability.value / math.max(data.total, 1) * 100)
row.color = RM.abilityTypeColors[ability.ref.type]
row.value = ability.value
row.leftClick = function()
window:setMode("interactionAbility", ability.ref)
end
table.insert(rows, row)
end
window:setGlobalLabel(data.total / duration)
return rows, data.count + 1, data.max
end
function Modes.interactionAbilities:rightClick(window)
window:setMode("interactions", window.selectedPlayerParent)
end
function Modes.interactionAbilities:findOwner(window)
local player = window.selectedCombat.players[window.selectedPlayerDetail]
if player then
window.selectedPlayer = player
window:setTitle(("%s: %s"):format(player.detail.name, L[window.settings.sort]))
end
end
function Modes.interactionAbilities:onSortmodeChange(window, oldSortmode)
if window.settings.sort ~= oldSortmode then
window:setMode("interactions", window.selectedPlayerParent)
return false
end
return true
end
-- Mode: Interaction ability details
Modes.interactionAbility = Mode:new("interactionAbility")
function Modes.interactionAbility:init(window, ability)
if ability then
window.selectedAbility = ability
end
if window.selectedAbility then
window:setTitle(("%s: %s"):format(window.selectedPlayerParent.detail.name, window.selectedAbility.name))
end
end
function Modes.interactionAbility:update(window)
if not window.selectedAbility or not window.selectedPlayer then
self:findOwner(window)
if not window.selectedAbility then
return
end
end
local data = window.selectedAbility:getPreparedAbilityStatData(window.selectedCombat, window.settings.sort)
local rows = {}
local limit = math.min(#data, #window.frames.rows)
for i = 1, limit do
local row = {}
local stat = data[i + window.scrollOffset]
row.leftLabel = stat.name
row.rightLabel = stat.value
row.color = {0.7, 0.7, 0.7}
rows[i] = row
end
window:setGlobalLabel(window.selectedPlayerParent[window.settings.sort] / math.max(window.selectedCombat.duration, 1))
return rows, #data, 1
end
function Modes.interactionAbility:rightClick(window)
window:setMode("interactionAbilities")
end
function Modes.interactionAbility:findOwner(window)
if not window.selectedPlayer then
Modes.abilities:findOwner(window)
end
if window.selectedPlayer then
window:setMode("abilities", window.selectedPlayer)
end
end
function Modes.interactionAbility:onSortmodeChange(window, oldSortmode)
if window.settings.sort ~= oldSortmode then
window:setMode("interactions", window.selectedPlayerParent)
return false
end
return true
end
-- Mode: Combat list
Modes.combats = Mode:new("combats")
function Modes.combats:init(window)
window.rowCount = #RM.Combats
window.scrollOffset = math.max(window.rowCount - #window.frames.rows, 0)
window:setTitle(L["Combats"] .. ": " .. L[window.settings.sort])
end
function Modes.combats:update(window)
if not window.selectedCombat then return end
local rows = {}
local limit = math.min(#RM.Combats, #window.frames.rows)
local ncombats = 0
local maxvalue = 0
for i = 1, limit do
local row = {}
local combat = RM.Combats[i + window.scrollOffset]
if not RM.settings.showOnlyBoss or (combat.hasBoss or combat == RM.CurrentCombat or combat == RM.overallCombat) then
local stat = combat:getPreparedPlayerData(window.settings.sort, window.showEnemies).total / math.max(combat.duration, 1)
local hostile = combat:getHostile()
if stat > maxvalue then maxvalue = stat end
row.leftLabel = FormatSeconds(combat.duration) .. " " .. hostile
row.rightLabel = NumberFormat(math.floor(stat))
row.value = stat
row.leftClick = function()
window:setMode("combat", RM.Combats[i + window.scrollOffset]) end
ncombats = ncombats + 1
rows[ncombats] = row
end
end
window:setGlobalLabel(window.selectedCombat:getPreparedPlayerData(window.settings.sort, window.showEnemies).total / math.max(window.selectedCombat.duration, 1))
return rows, #RM.Combats, maxvalue
end
-- Mode: Ability list
Modes.abilities = Mode:new("abilities")
function Modes.abilities:init(window, player)
if player then
window.selectedPlayer = player
end
if window.selectedPlayer then
window:setTitle(("%s: %s"):format(window.selectedPlayer.detail.name, L[window.settings.sort]))
end
end
function Modes.abilities:update(window)
if not window.selectedPlayer then
if window.selectedPlayerDetail then
self:findOwner(window)
end
if not window.selectedPlayer then
return
end
end
local data = window.selectedPlayer:getPreparedAbilityData(window.settings.sort)
local duration = math.max(window.selectedCombat.duration, 1)
local rows = {}
local limit = math.min(data.count, #window.frames.rows)
for i = 1, limit do
-- total bar
if i == 1 and window.scrollOffset == 0 then
table.insert(rows, {
leftLabel = " " .. L["Total"],
rightLabel = NumberFormat(data.total),
value = data.max,
leftClick = function()
window:setMode("ability", window.selectedPlayer:createFakeAbility())
end
})
end
local row = {}
local index = window.scrollOffset > 0 and i + window.scrollOffset - 1 or i + window.scrollOffset
local ability = data.abilities[index]
row.icon = ability.ref.detail.icon
row.leftLabel = " " .. ability.ref.name
row.rightLabel = BuildFormat(NumberFormat(ability.value), ability.value / duration, ability.value / math.max(data.total, 1) * 100)
row.color = RM.abilityTypeColors[ability.ref.type]
row.value = ability.value
row.leftClick = function()
window:setMode("ability", ability.ref)
end
table.insert(rows, row)
end
window:setGlobalLabel(data.total / duration)
return rows, data.count + 1, data.max
end
function Modes.abilities:rightClick(window)
window:setMode("combat")
end