-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSkada.lua
More file actions
2501 lines (2148 loc) · 67.7 KB
/
Copy pathSkada.lua
File metadata and controls
2501 lines (2148 loc) · 67.7 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 _, addon = ...
local Skada = LibStub("AceAddon-3.0"):NewAddon(addon, "Skada", "AceTimer-3.0", "AceEvent-3.0", "LibNotify-1.0")
_G.Skada = Skada
local L = LibStub("AceLocale-3.0"):GetLocale("Skada", true)
local acd = LibStub("AceConfigDialog-3.0")
local icon = LibStub("LibDBIcon-1.0", true)
local media = LibStub("LibSharedMedia-3.0")
local lds = LibStub("LibDualSpec-1.0", true)
local dataobj = LibStub("LibDataBroker-1.1"):NewDataObject("Skada", {
label = "Skada",
type = "data source",
icon = "Interface\\Icons\\Spell_Lightning_LightningBolt01",
text = "n/a"
})
InterfaceOptions_AddCategory = InterfaceOptions_AddCategory
if not InterfaceOptions_AddCategory then
InterfaceOptions_AddCategory = function(frame, addOn, position)
frame.OnCommit = frame.okay;
frame.OnDefault = frame.default;
frame.OnRefresh = frame.refresh;
if frame.parent then
local category = Settings.GetCategory(frame.parent);
local subcategory, layout = Settings.RegisterCanvasLayoutSubcategory(category, frame, frame.name, frame.name);
subcategory.ID = frame.name;
return subcategory, category;
else
local category, layout = Settings.RegisterCanvasLayoutCategory(frame, frame.name, frame.name);
category.ID = frame.name;
Settings.RegisterAddOnCategory(category);
return category;
end
end
end
function Skada:GetSpellIcon(spellId)
-- Use cached version from SecretValueHelper for performance
return self.SecretHelper:GetSpellIcon(spellId)
end
function Skada:GetGameVersion()
local version = floor((floor(select(4, GetBuildInfo())) / 10000))
return version
end
local popup
-- Aliases
local tsort, tinsert, tremove = table.sort, table.insert, table.remove
local next, pairs, ipairs, type = next, pairs, ipairs, type
-- bit.band no longer needed with Native API
-- Check if the player is in a PvP instance (battleground or arena).
local function IsInPVP()
local _, instanceType = IsInInstance()
return instanceType == "pvp" or instanceType == "arena"
end
-- Returns the group type (i.e., "party" or "raid") and the size of the group.
function Skada:GetGroupTypeAndCount()
local groupType
local count = GetNumGroupMembers()
-- Modern API detection with Classic Era support
if IsInRaid() then
groupType = "raid"
elseif IsInGroup() then -- Works in both Retail and Classic
groupType = "party"
-- Maintain Classic-era behavior where count includes player
count = count > 0 and count - 1 or 0
end
return groupType, count
end
do
popup = CreateFrame("Frame", nil, UIParent, "BackdropTemplate")
popup:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
tile = true, tileSize = 0, edgeSize = 1,
insets = { left = 0, right = 0, top = 0, bottom = 0 }
})
popup:SetBackdropColor(0.05, 0.05, 0.05, 0.9)
popup:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
popup:SetSize(300, 120)
popup:SetPoint("CENTER", UIParent, "CENTER")
popup:SetFrameStrata("TOOLTIP")
popup:Hide()
popup:EnableKeyboard(true)
popup:SetScript("OnKeyDown", function(self, key)
if GetBindingFromClick(key) == "TOGGLEGAMEMENU" then
popup:SetPropagateKeyboardInput(false) -- swallow escape
popup:Hide()
end
end)
local text = popup:CreateFontString(nil, "ARTWORK", "GameFontNormal")
text:SetPoint("TOP", popup, "TOP", 0, -25)
text:SetText(L["Do you want to reset Skada?"])
local accept = CreateFrame("Button", nil, popup, "BackdropTemplate")
accept:SetSize(100, 30)
accept:SetPoint("BOTTOMLEFT", popup, "BOTTOMLEFT", 40, 20)
accept:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
edgeSize = 1,
})
accept:SetBackdropColor(0.1, 0.4, 0.1, 0.8)
accept:SetBackdropBorderColor(0.2, 0.6, 0.2, 1)
local acceptText = accept:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
acceptText:SetPoint("CENTER")
acceptText:SetText(L["Yes"])
accept:SetScript("OnEnter", function(self) self:SetBackdropColor(0.2, 0.5, 0.2, 1) end)
accept:SetScript("OnLeave", function(self) self:SetBackdropColor(0.1, 0.4, 0.1, 0.8) end)
accept:SetScript("OnClick", function(f)
Skada:Reset()
f:GetParent():Hide()
end)
local close = CreateFrame("Button", nil, popup, "BackdropTemplate")
close:SetSize(100, 30)
close:SetPoint("BOTTOMRIGHT", popup, "BOTTOMRIGHT", -40, 20)
close:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
edgeSize = 1,
})
close:SetBackdropColor(0.4, 0.1, 0.1, 0.8)
close:SetBackdropBorderColor(0.6, 0.2, 0.2, 1)
local closeText = close:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
closeText:SetPoint("CENTER")
closeText:SetText(L["No"])
close:SetScript("OnEnter", function(self) self:SetBackdropColor(0.5, 0.2, 0.2, 1) end)
close:SetScript("OnLeave", function(self) self:SetBackdropColor(0.4, 0.1, 0.1, 0.8) end)
close:SetScript("OnClick", function(f) f:GetParent():Hide() end)
function Skada:ShowPopup()
popup:SetPropagateKeyboardInput(true)
popup:Show()
end
end
-- Keybindings
BINDING_HEADER_Skada = "Skada"
BINDING_NAME_SKADA_TOGGLE = L["Toggle window"]
BINDING_NAME_SKADA_RESET = L["Reset"]
BINDING_NAME_SKADA_NEWSEGMENT = L["Start new segment"]
-- The current set
Skada.current = nil
-- The total set
Skada.total = nil
-- The last set
Skada.last = nil
-- Modes - these are modules, really. Modeules?
local modes = {}
-- Pet tracking handled by Native API
-- No local pet/player tables needed
-- Flag marking if we need an update.
local changed = true
-- Flag for if we were in a party/raid.
local wasinparty = nil
-- By default we just use RAID_CLASS_COLORS as class colors.
Skada.classcolors = RAID_CLASS_COLORS
-- The selected data feed.
local selectedfeed = nil
-- A list of data feeds available. Modules add to it.
local feeds = {}
-- Our windows.
local windows = {}
-- Our display providers.
Skada.displays = {}
function Skada:GetWindows()
return windows
end
local function find_mode(name)
for i, mode in ipairs(modes) do
if mode:GetName() == name then
return mode
end
end
end
-- Our window type.
local Window = {}
local mt = { __index = Window }
function Window:new()
return setmetatable({
-- The selected mode and set
selectedmode = nil,
selectedset = nil,
-- Mode and set to return to after combat.
restore_mode = nil,
restore_set = nil,
usealt = true,
-- Our dataset.
dataset = {},
-- Metadata about our dataset.
metadata = {},
-- Our display provider.
display = nil,
-- Our mode traversing history.
history = {},
-- Flag for window-specific changes.
changed = false,
}, mt)
end
function Window:AddOptions()
local db = self.db
local options = {
type = "group",
name = function() return db.name end,
args = {
rename = {
type = "input",
name = L["Rename window"],
desc = L["Enter the name for the window."],
get = function() return db.name end,
set = function(win, val)
if val ~= db.name and val ~= "" then
local oldname = db.name
db.name = val
Skada.options.args.windows.args[val] = Skada.options.args.windows.args[oldname]
Skada.options.args.windows.args[oldname] = nil
end
end,
order = 1,
},
locked = {
type = "toggle",
name = L["Lock window"],
desc = L["Locks the bar window in place."],
order = 2,
get = function() return db.barslocked end,
set = function()
db.barslocked = not db.barslocked
Skada:ApplySettings()
end,
},
delete = {
type = "execute",
name = L["Delete window"],
desc = L["Deletes the chosen window."],
order = 20,
width = "full",
confirm = function() return "Are you sure you want to delete this window?" end,
func = function() Skada:DeleteWindow(db.name) end,
},
}
}
options.args.switchoptions = {
type = "group",
name = L["Mode switching"],
order = 4,
args = {
modeincombat = {
type = "select",
name = L["Combat mode"],
desc = L["Automatically switch to set 'Current' and this mode when entering combat."],
values = function()
local modes = {}
modes[""] = L["None"]
for i, mode in ipairs(Skada:GetModes()) do
modes[mode:GetName()] = mode:GetName()
end
return modes
end,
get = function() return db.modeincombat end,
set = function(win, mode) db.modeincombat = mode end,
order = 21,
},
wipemode = {
type = "select",
name = L["Wipe mode"],
desc = L["Automatically switch to set 'Current' and this mode after a wipe."],
values = function()
local modes = {}
modes[""] = L["None"]
for i, mode in ipairs(Skada:GetModes()) do
modes[mode:GetName()] = mode:GetName()
end
return modes
end,
get = function() return db.wipemode end,
set = function(win, mode) db.wipemode = mode end,
order = 21,
},
returnaftercombat = {
type = "toggle",
name = L["Return after combat"],
desc = L["Return to the previous set and mode after combat ends."],
order = 23,
get = function() return db.returnaftercombat end,
set = function() db.returnaftercombat = not db.returnaftercombat end,
disabled = function() return db.returnaftercombat == nil end,
},
}
}
self.display:AddDisplayOptions(self, options.args)
Skada.options.args.windows.args[self.db.name] = options
end
-- Sets a slave window for this window. This window will also be updated on view updates.
function Window:SetChild(window)
self.child = window
end
function Window:destroy()
self.dataset = nil
if self.display and self.display.Destroy then
self.display:Destroy(self)
end
local name = self.db.name or Skada.windowdefaults.name
Skada.options.args.windows.args[name] = nil -- remove from options
end
function Window:SetDisplay(name)
-- Don't do anything if nothing actually changed.
if name ~= self.db.display or self.display == nil then
if self.display then
-- Destroy old display.
self.display:Destroy(self)
end
-- Set new display.
self.db.display = name
self.display = Skada.displays[self.db.display]
-- Add options. Replaces old options.
self:AddOptions()
end
end
-- Tells window to update the display of its dataset, using its display provider.
function Window:UpdateDisplay()
-- Fetch max value if our mode has not done this itself.
if not self.metadata.maxvalue then
self.metadata.maxvalue = 0
for i, data in ipairs(self.dataset) do
if data.id then
local val = Skada:SafeNumber(data.value)
if val > self.metadata.maxvalue then
self.metadata.maxvalue = val
end
end
end
end
-- Display it.
if self.display and self.display.Update then
self.display:Update(self)
end
self:set_mode_title()
end
-- Called before dataset is updated.
function Window:UpdateInProgress()
for i, data in ipairs(self.dataset) do
if data.ignore then -- ensure total bar icon is cleared before bar is recycled
data.icon = nil
end
data.id = nil
data.ignore = nil
end
end
function Window:Show()
self.display:Show(self)
end
function Window:Hide()
self.display:Hide(self)
end
function Window:IsShown()
return self.display:IsShown(self)
end
function Window:Reset()
for i, data in ipairs(self.dataset) do
wipe(data)
end
end
function Window:Wipe()
-- Clear dataset.
self:Reset()
-- Clear display.
if self.display and self.display.Wipe then
self.display:Wipe(self)
end
if self.child then
self.child:Wipe()
end
end
-- If selectedset is "current", returns current set if we are in combat, otherwise returns the last set.
function Window:get_selected_set()
return Skada:find_set(self.selectedset)
end
-- Sets up the mode view.
function Window:DisplayMode(mode)
self:Wipe()
self.selectedplayer = nil
self.selectedmode = mode
self.metadata = wipe(self.metadata or {})
-- Apply mode's metadata.
if mode.metadata then
for key, value in pairs(mode.metadata) do
self.metadata[key] = value
end
end
self.changed = true
self:set_mode_title() -- in case data sets are empty
if self.child then
self.child:DisplayMode(mode)
end
Skada:UpdateDisplay(false)
end
local numsetfmts = 8
local function SetLabelFormat(name, starttime, endtime, fmt)
fmt = fmt or Skada.db.profile.setformat
local namelabel = name
if fmt < 1 or fmt > numsetfmts then fmt = 3 end
local timelabel = ""
if starttime and endtime and fmt > 1 then
local duration = SecondsToTimeAbbrev(endtime - starttime)
-- translate locale time abbreviations, whose escape sequences are not legal in chat
Skada.getsetlabel_fs = Skada.getsetlabel_fs or UIParent:CreateFontString(nil, "ARTWORK", "ChatFontNormal")
Skada.getsetlabel_fs:SetText(duration)
duration = "(" .. Skada.getsetlabel_fs:GetText() .. ")"
if fmt == 2 then
timelabel = duration
elseif fmt == 3 then
timelabel = date("%H:%M", starttime) .. " " .. duration
elseif fmt == 4 then
timelabel = date("%I:%M", starttime) .. " " .. duration
elseif fmt == 5 then
timelabel = date("%H:%M", starttime) .. " - " .. date("%H:%M", endtime)
elseif fmt == 6 then
timelabel = date("%I:%M", starttime) .. " - " .. date("%I:%M", endtime)
elseif fmt == 7 then
timelabel = date("%H:%M:%S", starttime) .. " - " .. date("%H:%M:%S", endtime)
elseif fmt == 8 then
timelabel = date("%H:%M", starttime) .. " - " .. date("%H:%M", endtime) .. " " .. duration
end
end
local comb
if #namelabel == 0 or #timelabel == 0 then
comb = namelabel .. timelabel
elseif timelabel:match("^%p") then
comb = namelabel .. " " .. timelabel
else
comb = namelabel .. ": " .. timelabel
end
-- provide both the combined label and the separated name/time labels
return comb, namelabel, timelabel
end
function Skada:SetLabelFormats() -- for config option display
local ret = {}
local start = 1000007900
for i = 1, numsetfmts do
ret[i] = SetLabelFormat("Hogger", start, start + 380, i)
end
return ret
end
function Skada:GetSetLabel(set) -- return a nicely-formatted label for a set
if not set then return "" end
-- Prefer the encounter name (e.g. "Hogger") when the Native API provides one;
-- fall back to the session's generic name or "Unknown".
-- Use type() to guard against secret values during combat — type() is safe
-- to call on secrets, and a secret value will not be "string".
local name = set.name or "Unknown"
local encounter = set.encounterName
if type(encounter) == "string" and encounter ~= "" then
name = encounter
end
-- Handle Native API session fields (capital T)
local startTime = set.startTime or set.starttime
local endTime = set.endTime or set.endtime or time()
return SetLabelFormat(name, startTime, endTime)
end
function Window:set_mode_title()
if not self.selectedmode or not self.selectedset then return end
local name = tostring(self.selectedmode.title or self.selectedmode:GetName())
-- save window settings for RestoreView after reload
self.db.set = self.selectedset
local savemode = name
if self.history[1] then -- can't currently preserve a nested mode, use topmost one
savemode = self.history[1].title or self.history[1]:GetName()
end
self.db.mode = savemode
if self.db.titleset then
local setname
if self.selectedset == "current" then
setname = L["Current"]
-- Append encounter name if the Native API session has one.
-- Use type() to avoid crashing on secret values during combat.
local set = self:get_selected_set()
local encounter = set and set.encounterName
if type(encounter) == "string" and encounter ~= "" then
setname = setname .. " (" .. encounter .. ")"
end
elseif self.selectedset == "total" then
setname = L["Total"]
local set = self:get_selected_set()
local encounter = set and set.encounterName
if type(encounter) == "string" and encounter ~= "" then
setname = setname .. " (" .. encounter .. ")"
end
else
local set = self:get_selected_set()
if set then
setname = Skada:GetSetLabel(set)
end
end
if setname then
name = tostring(name) .. ": " .. tostring(setname)
end
end
self.metadata.title = name
if self.display and self.display.SetTitle then
self.display:SetTitle(self, name)
end
end
local function sort_modes()
tsort(modes, function(a, b)
if Skada.db.profile.sortmodesbyusage and Skada.db.profile.modeclicks then
-- Most frequest usage order
return (Skada.db.profile.modeclicks[a:GetName()] or 0) > (Skada.db.profile.modeclicks[b:GetName()] or 0)
else
-- Alphabetic order
return a:GetName() < b:GetName()
end
end)
end
local function click_on_mode(win, id, label, button)
if button == "LeftButton" then
local mode = find_mode(id)
if mode then
-- Store number of clicks on modes, for automatic sorting.
if Skada.db.profile.sortmodesbyusage then
if not Skada.db.profile.modeclicks then
Skada.db.profile.modeclicks = {}
end
Skada.db.profile.modeclicks[id] = (Skada.db.profile.modeclicks[id] or 0) + 1
sort_modes()
end
win:DisplayMode(mode)
end
elseif button == "RightButton" then
win:RightClick()
end
end
-- Sets up the mode list.
function Window:DisplayModes(settime)
self.history = wipe(self.history or {})
self:Wipe()
self.selectedplayer = nil
self.selectedmode = nil
self.metadata = wipe(self.metadata or {})
self.metadata.title = L["Skada: Modes"]
-- Find the selected set
-- With Native API, we only have "current" and "total" sessions
-- Historical sessions are managed by WoW's API
if settime == "current" or settime == "total" then
self.selectedset = settime
else
-- Try to parse as session ID
local sessionId = tonumber(settime)
if sessionId then
self.selectedset = settime -- Store as string session ID
else
-- Default to current
self.selectedset = "current"
end
end
self.metadata.click = click_on_mode
self.metadata.maxvalue = 1
self.metadata.sortfunc = function(a, b) return a.name < b.name end
if self.display and self.display.SetTitle then
self.display:SetTitle(self, self.metadata.title)
end
self.changed = true
if self.child then
self.child:DisplayModes(settime)
end
Skada:UpdateDisplay(false)
end
local function click_on_set(win, id, label, button)
if button == "LeftButton" then
win:DisplayModes(id)
elseif button == "RightButton" then
win:RightClick()
end
end
-- Sets up the set list.
function Window:DisplaySets()
self.history = wipe(self.history or {})
self:Wipe()
self.metadata = wipe(self.metadata or {})
self.selectedplayer = nil
self.selectedmode = nil
self.selectedset = nil
self.metadata.title = L["Skada: Fights"]
if self.display and self.display.SetTitle then
self.display:SetTitle(self, self.metadata.title)
end
self.metadata.click = click_on_set
self.metadata.maxvalue = 1
-- self.metadata.sortfunc = function(a,b) return a.name < b.name end
self.changed = true
if self.child then
self.child:DisplaySets()
end
Skada:UpdateDisplay(false)
end
-- Default "right-click" behaviour in case no special click function is defined:
-- 1) If there is a mode traversal history entry, go to the last mode.
-- 2) Go to modes list if we are in a mode.
-- 3) Go to set list.
function Window:RightClick(group, button)
if self.selectedmode then
-- If mode traversal history exists, go to last entry, else mode list.
if #self.history > 0 then
self:DisplayMode(tremove(self.history))
else
self:DisplayModes(self.selectedset)
end
elseif self.selectedset then
self:DisplaySets()
end
end
function Skada:tcopy(to, from, ...)
for k, v in pairs(from) do
local skip = false
if ... then
for i, j in ipairs(...) do
if j == k then
skip = true
break
end
end
end
if not skip then
if type(v) == "table" then
to[k] = {}
Skada:tcopy(to[k], v, ...)
else
to[k] = v
end
end
end
end
function Skada:CreateWindow(name, db, display)
local isnew = false
if not db then
isnew = true
db = {}
self:tcopy(db, Skada.windowdefaults)
tinsert(self.db.profile.windows, db)
end
if display then
db.display = display
end
-- Migrate old settings.
if not db.barbgcolor then
db.barbgcolor = { r = 0.3, g = 0.3, b = 0.3, a = 0.6 }
end
if not db.buttons then
db.buttons = { menu = true, reset = true, report = true, mode = true, segment = true }
end
if not db.scale then
db.scale = 1
end
if not db.version then
-- On changes that needs updates to window data structure, increment version in defaults and handle it after this bit.
db.version = 1
end
local window = Window:new()
window.db = db
window.db.name = name
if self.displays[window.db.display] then
-- Set the window's display and call it's Create function.
window:SetDisplay(window.db.display or "bar")
window.display:Create(window, isnew)
tinsert(windows, window)
-- Set initial view, set list.
window:DisplaySets()
if isnew and find_mode(L["Damage"]) then
-- Default mode for new windows - will not fail if mode is disabled.
self:RestoreView(window, "current", L["Damage"])
elseif window.db.set or window.db.mode then
-- Restore view.
self:RestoreView(window, window.db.set, window.db.mode)
end
else
-- This window's display is missing.
self:Print("Window '" ..
name .. "' was not loaded because its display module, '" .. window.db.display .. "' was not found.")
end
self:ApplySettings()
return window
end
-- Deleted named window from our windows table, and also from db.
function Skada:DeleteWindow(name)
for i, win in ipairs(windows) do
if win.db.name == name then
win:destroy()
wipe(tremove(windows, i))
end
end
for i, win in ipairs(self.db.profile.windows) do
if win.name == name then
tremove(self.db.profile.windows, i)
end
end
end
function Skada:Print(msg)
print("|cFF33FF99Skada|r: " .. msg)
end
function Skada:Debug(...)
if not Skada.db.profile.debug then return end
local msg = ""
for i = 1, select("#", ...) do
local val = select(i, ...)
local v
-- Safe conversion for debug output
if issecretvalue and issecretvalue(val) then
v = string.format("%s", val)
else
v = tostring(val)
end
if #msg > 0 then
msg = msg .. ", "
end
msg = msg .. v
end
print("|cFF33FF99Skada Debug|r: " .. msg)
end
local function slashHandler(param)
local reportusage =
"/skada report [raid|party|instance|guild|officer|say] [current||total|set_num] [mode] [max_lines]"
if param == "cpu" then
local funcs = {}
UpdateAddOnCPUUsage()
for k, v in pairs(Skada) do
if type(v) == "function" then
local usage, calls = GetFunctionCPUUsage(v, true)
--local info = debug.getinfo(v, "n")
tinsert(funcs, { ["name"] = k, ["usage"] = usage, ["calls"] = calls })
end
end
tsort(funcs, function(a, b) return a.usage > b.usage end)
for i, func in ipairs(funcs) do
print(func.name .. '\t' .. func.usage .. ' (' .. func.calls .. ')')
if i > 10 then
break
end
end
elseif param == "test" then
Skada:Notify("test")
elseif param == "reset" then
Skada:Reset()
-- newsegment command removed - with Native API, sessions are managed by WoW
elseif param == "toggle" then
Skada:ToggleWindow()
elseif param == "debug" then
Skada.db.profile.debug = not Skada.db.profile.debug
Skada:Print("Debug mode " ..
(Skada.db.profile.debug and ("|cFF00FF00" .. L["ENABLED"] .. "|r") or ("|cFFFF0000" .. L["DISABLED"] .. "|r")))
elseif param == "config" then
Skada:OpenOptions()
elseif param:sub(1, 6) == "report" then
local chan = (IsInGroup(LE_PARTY_CATEGORY_INSTANCE) and "instance") or
(IsInRaid() and "raid") or
(IsInGroup() and "party") or
"say"
local set = "current"
local report_mode_name = L["Damage"]
local w1, w2, w3, w4 = param:match("^%s*(%w*)%s*(%w*)%s*([^%d]-)%s*(%d*)%s*$", 7)
if w1 and #w1 > 0 then
chan = string.lower(w1)
end
if w2 and #w2 > 0 then
w2 = tonumber(w2) or w2:lower()
if Skada:find_set(w2) then
set = w2
end
end
if w3 and #w3 > 0 then
w3 = strtrim(w3)
w3 = strtrim(w3, "'\"[]()") -- strip optional quoting
if find_mode(w3) then
report_mode_name = w3
end
end
local max = tonumber(w4) or 10
if chan == "instance" then chan = "instance_chat" end
if chan == "say" or chan == "guild" or chan == "raid" or chan == "party" or chan == "officer" or chan == "instance_chat" then
Skada:Report(chan, "preset", report_mode_name, set, max)
else
Skada:Print("Usage:")
Skada:Print(("%-20s"):format(reportusage))
end
else
Skada:Print("Usage:")
Skada:Print(("%-20s"):format(reportusage))
Skada:Print(("%-20s"):format("/skada reset"))
Skada:Print(("%-20s"):format("/skada toggle"))
Skada:Print(("%-20s"):format("/skada debug"))
Skada:Print(("%-20s"):format("/skada config"))
end
end
local function sendchat(msg, chan, chantype)
if chantype == "self" then
-- To self.
Skada:Print(msg)
elseif chantype == "channel" then
-- To channel.
SendChatMessage(msg, "CHANNEL", nil, chan)
elseif chantype == "preset" then
-- To a preset channel id (say, guild, etc).
SendChatMessage(msg, string.upper(chan))
elseif chantype == "whisper" then
-- To player.
SendChatMessage(msg, "WHISPER", nil, chan)
elseif chantype == "bnet" then
BNSendWhisper(chan, msg)
end
end
function Skada:Report(channel, chantype, report_mode_name, report_set_name, max, window)
if chantype == "channel" then
local list = { GetChannelList() }
for i = 1, #list, 3 do
if Skada.db.profile.report.channel == list[i + 1] then
channel = list[i]
break
end
end
end
local report_table
local report_set
local report_mode
if not window then
report_mode = find_mode(report_mode_name)
report_set = Skada:find_set(report_set_name)
if report_set == nil then
return
end
-- Create a temporary fake window.
report_table = Window:new()
-- Tell our mode to populate our dataset.
report_mode:Update(report_table, report_set)
else
report_table = window
report_set = window:get_selected_set()
report_mode = window.selectedmode
end
if not report_set then
Skada:Print(L["There is nothing to report."])
return
end
-- Sort our temporary table according to value unless ordersort is set.
if not report_table.metadata.ordersort then
tsort(report_table.dataset, Skada.valueid_sort)
end
-- Title
sendchat(
string.format(L["Skada: %s for %s:"], report_mode.title or report_mode:GetName(), Skada:GetSetLabel(report_set)),
channel, chantype)
-- For each item in dataset, print label and valuetext.
local nr = 1
for i, data in ipairs(report_table.dataset) do
if data.id then
local label = data.reportlabel or (data.spellid and C_Spell.GetSpellLink(data.spellid)) or data.label
local value = data.valuetext or data.valueText1
if report_mode.metadata and report_mode.metadata.showspots then
sendchat(("%2u. %s %s"):format(nr, label, value), channel, chantype)
else
sendchat(("%s %s"):format(label, value), channel, chantype)
end
nr = nr + 1
end
if nr > max then