-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathPlater_CastColorPanels.lua
2308 lines (1961 loc) · 100 KB
/
Plater_CastColorPanels.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 Plater = Plater
local addonId, platerInternal = ...
local GameCooltip = GameCooltip2
---@type detailsframework
local DF = DetailsFramework
local GetSpellInfo = GetSpellInfo or function(spellID) if not spellID then return nil end local si = C_Spell.GetSpellInfo(spellID) if si then return si.name, nil, si.iconID, si.castTime, si.minRange, si.maxRange, si.spellID, si.originalIconID end end
local _
---@alias spellid number
---@alias soundpath string
local bitAnd = bit.band
local unpack = table.unpack or _G.unpack
--localization
local LOC = DF.Language.GetLanguageTable(addonId)
local LibSharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0")
--get templates
local options_text_template = DF:GetTemplate("font", "OPTIONS_FONT_TEMPLATE")
local options_dropdown_template = DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")
local options_switch_template = DF:GetTemplate("switch", "OPTIONS_CHECKBOX_TEMPLATE")
local options_slider_template = DF:GetTemplate("slider", "OPTIONS_SLIDER_TEMPLATE")
local options_button_template = DF:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE")
local dropdownStatusBarTexture = platerInternal.Defaults.dropdownStatusBarTexture
local dropdownStatusBarColor = platerInternal.Defaults.dropdownStatusBarColor
local colorNoValue = {1, 1, 1, 0.5}
local dropdownIconColor = {1, 1, 1, .6}
local scrollRefreshCallback
local DB_CAST_COLORS
---@type table<spellid, soundpath>
local DB_CAST_AUDIOCUES
local DB_NPCIDS_CACHE
local DB_CAPTURED_SPELLS
local DB_CAPTURED_CASTS
local CONST_INDEX_ENABLED = 1
local CONST_INDEX_COLOR = 2
local CONST_INDEX_NAME = 3
local CONST_CASTINFO_ENABLED = 1
local CONST_CASTINFO_COLOR = 2
local CONST_CASTINFO_SPELLID = 3
local CONST_CASTINFO_SPELLNAME = 4
local CONST_CASTINFO_SPELLICON = 5
local CONST_CASTINFO_SOURCENAME = 6
local CONST_CASTINFO_NPCID = 7
local CONST_CASTINFO_NPCLOCATION = 8
local CONST_CASTINFO_ENCOUNTERNAME = 9
local CONST_CASTINFO_CUSTOMSPELLNAME = 10
local spellIndicators = {
["edited_name"] = {
texture = [[Interface\AddOns\Plater\images\spell_indicators_1]],
coords = {0, 0.125, 0, 1},
scale = 1,
shown = false,
id = "edited_name",
width = 12,
height = 12,
name = "Name Changed Indicator",
alpha = 1,
type = "spell_indicators",
},
["edited_audio"] = {
texture = [[Interface\AddOns\Plater\images\spell_indicators_1]],
coords = {0.125, 0.25, 0, 1},
scale = 1,
shown = false,
id = "edited_audio",
width = 12,
height = 12,
name = "Audio Changed Indicator",
alpha = 1,
type = "spell_indicators",
},
["edited_color"] = {
texture = [[Interface\AddOns\Plater\images\spell_indicators_1]],
coords = {0.25, 0.375, 0, 1},
scale = 1,
shown = false,
id = "edited_color",
width = 12,
height = 12,
name = "Color Changed Indicator",
alpha = 1,
type = "spell_indicators",
},
["edited_script"] = {
texture = [[Interface\AddOns\Plater\images\spell_indicators_1]],
coords = {0.375, 0.5, 0, 1},
scale = 1,
shown = false,
id = "edited_script",
width = 12,
height = 12,
name = "Script Changed Indicator",
alpha = 1,
type = "spell_indicators",
},
}
local on_refresh_db = function()
local profile = Plater.db.profile
DB_CAST_AUDIOCUES = profile.cast_audiocues
DB_CAST_COLORS = profile.cast_colors
DB_NPCIDS_CACHE = profile.npc_cache
DB_CAPTURED_SPELLS = PlaterDB.captured_spells
DB_CAPTURED_CASTS = PlaterDB.captured_casts
DB_CAPTURED_CASTS[116] = {npcID = 188027}
end
Plater.RegisterRefreshDBCallback(on_refresh_db)
function platerInternal.Data.GetSpellRenameData(spellId)
if (spellId) then
local spellTable = Plater.db.profile.cast_colors[spellId]
if (spellTable) then
--index 3 is the spell name renamed by the user
return spellTable[3]
end
else
return Plater.db.profile.cast_colors
end
end
function platerInternal.Data.GetSpellColorData(spellId)
if (spellId) then
local spellTable = Plater.db.profile.cast_colors[spellId]
if (spellTable) then
--index 2 is the color
return spellTable[2]
end
else
return Plater.db.profile.cast_colors
end
end
function platerInternal.Data.SetSpellRenameData(spellId, newName)
if (spellId) then
local spellTable = Plater.db.profile.cast_colors[spellId]
if (spellTable) then
spellTable[1] = true --index one is the enabled flag
spellTable[3] = newName --index 3 is the spell name renamed by the user
else
Plater.db.profile.cast_colors[spellId] = {true, "white", newName}
end
end
end
function platerInternal.Data.SetSpellColorData(spellId, color)
if (spellId) then
local spellTable = Plater.db.profile.cast_colors[spellId]
if (spellTable) then
--index 2 is the color
spellTable[1] = true
spellTable[2] = color
else
Plater.db.profile.cast_colors[spellId] = {true, color, ""}
end
end
end
function Plater.GetSpellCustomColor(spellId) --exposed
local customColorTable = Plater.db.profile.cast_colors[spellId]
if (customColorTable) then
return customColorTable[2] and (customColorTable[2] ~= "white") and customColorTable[2] or nil
end
end
--priority for user cast color >> can't interrupt color >> script color
function Plater.SetCastBarColorForScript(castBar, canUseScriptColor, scriptColor, envTable) --exposed
--user set cast bar color into the Cast Colors tab in the options panel
local colorByUser = Plater.GetSpellCustomColor(envTable._SpellID)
if (colorByUser) then
castBar:SetColor(Plater:ParseColors(colorByUser))
return
end
--don't change the color of non-interruptible casts
if (not envTable._CanInterrupt) then
castBar:SetColor(Plater:ParseColors(Plater.db.profile.cast_statusbar_color_nointerrupt))
return
end
--if is interruptible and don't have a custom user color, set the script color
if (canUseScriptColor and scriptColor) then
if (type(scriptColor) == "table" or (type(scriptColor) == "string") and DF:IsHtmlColor(scriptColor)) then
castBar:SetColor(Plater:ParseColors(scriptColor))
end
end
end
function Plater.CreateCastColorOptionsFrame(castColorFrame)
local castFrame = CreateFrame("frame", castColorFrame:GetName() .. "ColorFrame", castColorFrame)
castFrame:SetPoint("topleft", castColorFrame, "topleft", 5, -140)
castFrame:SetSize(1060, 495)
castColorFrame:HookScript("OnHide", function()
GameCooltip:Hide()
end)
--options
local scroll_width = 1050
local scroll_height = 442
local scroll_lines = 20
local scroll_line_height = 20
local backdrop_color = {.2, .2, .2, 0.2}
local backdrop_color_on_enter = {.8, .8, .8, 0.4}
local y = -20
local headerY = y - 20
local scrollY = headerY - 15
----platerInternal.optionsYStart or
local luaeditor_border_color = {0, 0, 0, 1}
local importbox_size = {620, 300}
local buttons_size = {120, 20}
DB_CAST_COLORS = Plater.db.profile.cast_colors
DB_NPCIDS_CACHE = Plater.db.profile.npc_cache --[npcId] = {npc name, npc zone}
DB_CAPTURED_CASTS = PlaterDB.captured_casts --[spellId] = {[npcID] = 000000}
DB_CAPTURED_SPELLS = PlaterDB.captured_spells --[spellId] = {[npcID] = 000000}
--header
local headerTable = {
{text = "", width = 40}, --1
{text = "", width = 20}, --2
{text = "Spell Id", width = 50}, --3
{text = "Spell Name", width = 140}, --4
{text = "Rename To", width = 110}, --5
{text = "Npc Name", width = 110}, --6
{text = "Send To Raid", width = 80}, --7
{text = "Play Sound", width = 110}, --8
{text = "Color", width = 110}, --9
{text = "Add Animation", width = 270}, --10
}
local headerOptions = {
padding = 2,
}
castFrame.Header = DF:CreateHeader(castFrame, headerTable, headerOptions)
castFrame.Header:SetPoint("topleft", castFrame, "topleft", 5, headerY+5)
--store npcID = checkbox object
--this is used when selecting the color from the dropdown, it'll automatically enable the color and need to set the checkbox to checked for feedback
castFrame.CheckBoxCache = {}
--line scripts
local line_onenter = function(self)
if (castColorFrame.lastLineEntered) then
castColorFrame.lastLineEntered:SetBackdropColor(unpack (castColorFrame.lastLineEntered.backdrop_color or backdrop_color))
end
GameCooltip:Hide()
self:SetBackdropColor (unpack (backdrop_color_on_enter or backdrop_color))
if (self.spellId) then
GameTooltip:SetOwner (self, "ANCHOR_TOPLEFT")
GameTooltip:SetSpellByID (self.spellId)
GameTooltip:AddLine (" ")
GameTooltip:Show()
castColorFrame.latestSpellId = self.spellId
castColorFrame.optionsFrame.previewCastBar.UpdateAppearance()
castColorFrame.SelectScriptForSpellId(self.spellId)
castColorFrame.currentSpellId = self.spellId
end
end
local line_onleave = function(self)
--self:SetBackdropColor(unpack (self.backdrop_color or backdrop_color))
GameTooltip:Hide()
castColorFrame.lastLineEntered = self
--castColorFrame.currentSpellId = nil
end
local widget_onenter = function(self)
local line = self:GetParent()
line:GetScript ("OnEnter")(line)
end
local widget_onleave = function(self)
local line = self:GetParent()
line:GetScript ("OnLeave")(line)
end
local oneditfocusgained_spellid = function(self, capsule)
self:HighlightText (0)
end
local oneditfocuslost = function(self)
self:HighlightText(0, 0)
end
local refresh_line_color = function(self, color)
color = color or backdrop_color
local r, g, b = DF:ParseColors(color)
local a = 0.2
self:SetBackdropColor (r, g, b, a)
self.backdrop_color = self.backdrop_color or {}
self.backdrop_color[1] = r
self.backdrop_color[2] = g
self.backdrop_color[3] = b
self.backdrop_color[4] = a
self.ColorDropdown:Select (color)
end
local onToggleEnabled = function(self, spellId, state)
if (not DB_CAST_COLORS[spellId]) then
DB_CAST_COLORS[spellId] = {false, "blue"}
end
DB_CAST_COLORS[spellId][CONST_INDEX_ENABLED] = state
--clean the refresh scroll cache
castFrame.spellsScroll.CachedTable = nil
castFrame.spellsScroll.SearchCachedTable = nil
if (state) then
self:GetParent():RefreshColor(DB_CAST_COLORS[spellId][CONST_INDEX_COLOR])
castColorFrame.latestSpellId = spellId
castColorFrame.optionsFrame.previewCastBar.UpdateAppearance()
else
self:GetParent():RefreshColor()
end
Plater.RefreshDBLists()
Plater.UpdateAllNameplateColors()
Plater.ForceTickOnAllNameplates()
castFrame.RefreshScroll(0)
end
--audio cues
local line_select_audio_dropdown = function (self, spellId, audioFilePath)
--current audio selected for this spellId
if (IsShiftKeyDown()) then
local oldAudioFilePath = DB_CAST_AUDIOCUES[spellId]
if (oldAudioFilePath and oldAudioFilePath ~= audioFilePath) then
--if the shift key is pressed, change the audio of all casts with its old audio the new audio selected
for thisSpellId, filePathForSpellId in pairs(DB_CAST_AUDIOCUES) do
if (filePathForSpellId == oldAudioFilePath) then
DB_CAST_AUDIOCUES[thisSpellId] = audioFilePath
end
end
castFrame.spellsScroll.CachedTable = nil
castFrame.RefreshScroll(0)
end
else
DB_CAST_AUDIOCUES[spellId] = audioFilePath
castFrame.spellsScroll.CachedTable = nil
castFrame.RefreshScroll(0)
end
end
local audioFileNameToCueName = {}
local audioCueSort = function(t1, t2)
if (t1[4] and not t2[4]) then
return true
elseif (not t1[4] and t2[4]) then
return false
elseif (t1[4] and t2[4]) then
return t1[3] < t2[3]
else
return t1[3] < t2[3]
end
end
---@param self df_dropdown
local createAudioCueList = function(self, fullRefresh)
if (castFrame.AudioCueListCache and not fullRefresh) then
--return
end
local audioCueList = {
{
label = " no audio",
value = nil,
color = colorNoValue,
statusbar = [[Interface\Tooltips\UI-Tooltip-Background]],
statusbarcolor = {.1, .1, .1, .92},
icon = [[Interface\AddOns\Plater\media\audio_cue_icon]],
iconcolor = {1, 1, 1, .4},
onclick = line_select_audio_dropdown
}
}
local cuesInUse = {}
for spellId, cueFile in pairs(DB_CAST_AUDIOCUES) do
cuesInUse[cueFile] = true
end
local audioCues = _G.LibStub:GetLibrary("LibSharedMedia-3.0"):HashTable("sound")
local audioListInOrder = {}
for cueName, cueFile in pairs(audioCues) do
audioListInOrder[#audioListInOrder+1] = {cueName, cueFile, cueName:lower(), cuesInUse[cueFile] or false}
audioFileNameToCueName[cueFile] = cueName
end
table.sort(audioListInOrder, audioCueSort)
--table.sort(audioListInOrder, function(t1, t2) return t1[3] < t2[3] end) --alphabetical
--table.sort(audioListInOrder, function(t1, t2) return t1[4] > t2[4] end) --in use
local currentSelected = self:GetValue()
if (type(currentSelected) == "string") then
currentSelected = currentSelected
else
currentSelected = nil
end
for i = 1, #audioListInOrder do
local cueName, cueFile, lowerName, cueInUse = unpack(audioListInOrder[i])
local desc
if (currentSelected) then
local currentSelectedCueName = audioFileNameToCueName[currentSelected]
desc = "Hold Shift to change the sound of all casts with the audio |cFFFFFF00" .. currentSelectedCueName .. "|r to |cFFFFDD00" .. cueName .. "|r."
else
desc = nil
end
audioCueList[#audioCueList+1] = {
label = " " .. cueName,
value = cueFile,
audiocue = cueFile,
color = "white",
statusbar = dropdownStatusBarTexture,
statusbarcolor = cueInUse and {.3, .3, .3, .8} or dropdownStatusBarColor,
iconcolor = dropdownIconColor,
icon = [[Interface\AddOns\Plater\media\audio_cue_icon]],
onclick = line_select_audio_dropdown,
desc = desc, --
}
end
castFrame.AudioCueListCache = audioCueList
end
local line_refresh_audio_dropdown = function(self)
createAudioCueList(self, true)
return castFrame.AudioCueListCache
end
--cast color
local line_select_color_dropdown = function (self, spellId, color)
local bNeedRefresh = false
if (color == platerInternal.RemoveColor) then
if (DB_CAST_COLORS[spellId]) then
DB_CAST_COLORS[spellId] = nil
local enableColorCheckbox = castFrame.CheckBoxCache[spellId]
if (enableColorCheckbox) then
enableColorCheckbox:SetValue(false)
end
end
else
if (not DB_CAST_COLORS[spellId]) then
DB_CAST_COLORS[spellId] = {true, "blue", ""}
end
local bOldColorWasEnabled = self.colorTable and self.colorTable[1]
local oldColorName = self.colorTable and self.colorTable[2]
DB_CAST_COLORS[spellId][CONST_INDEX_ENABLED] = true
DB_CAST_COLORS[spellId][CONST_INDEX_COLOR] = color
--if the shift key is pressed, change the color of all castbars with this color
if (IsShiftKeyDown() and bOldColorWasEnabled and type(oldColorName) == "string") then
for thisSpellId, castColorTable in pairs(DB_CAST_COLORS) do
if (castColorTable[1] and castColorTable[2] == oldColorName) then
castColorTable[2] = color
bNeedRefresh = true
end
end
end
local enableColorCheckbox = castFrame.CheckBoxCache[spellId]
if (enableColorCheckbox) then
enableColorCheckbox:SetValue(true)
end
end
--clean the refresh scroll cache
castFrame.spellsScroll.CachedTable = nil
castFrame.spellsScroll.SearchCachedTable = nil
self:GetParent():RefreshColor(color)
Plater.RefreshDBLists()
Plater.ForceTickOnAllNameplates()
--o que é esses dois caches
castFrame.cachedColorTable = nil
castFrame.cachedColorTableNameplate = nil
castFrame.RefreshScroll(0)
castColorFrame.latestSpellId = spellId
castColorFrame.optionsFrame.previewCastBar.UpdateAppearance()
if (bNeedRefresh) then
--refresh the scrollbox showing all the spell colors
castFrame.spellsScroll:Refresh()
end
end
local line_refresh_color_dropdown = function(self)
local colorEnabledIndexOnDB = 1
local colorIndexOnDB = 2
return platerInternal.RefreshColorDropdown(castFrame, self, DB_CAST_COLORS, line_select_color_dropdown, "spellId", colorEnabledIndexOnDB, colorIndexOnDB)
end
--line
local scroll_createline = function (self, index) --~create
local line = CreateFrame ("button", "$parentLine" .. index, self, BackdropTemplateMixin and "BackdropTemplate")
line:SetPoint ("topleft", self, "topleft", 1, -((index-1)*(scroll_line_height+1)) - 1)
line:SetSize (scroll_width - 3, scroll_line_height)
line:SetScript ("OnEnter", line_onenter)
line:SetScript ("OnLeave", line_onleave)
line.RefreshColor = refresh_line_color
line:SetBackdrop({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
line:SetBackdropColor(unpack (backdrop_color))
DF:Mixin (line, DF.HeaderFunctions)
local indicatorsSettings = {
icon_width = 16,
icon_height = 16,
show_text = false,
stack_text = true,
cooldown_swipe_enabled = false,
surpress_blizzard_cd_timer = true,
show_cooldown = false,
stack_text_color = {1, 1, 0, 1},
swipe_brightness = 0,
}
local spellIndicatorsFrame = DF:CreateIconRowGeneric(line, "$parentIndicators", indicatorsSettings)
spellIndicatorsFrame:SetSize(16, 16)
line.IconRow = spellIndicatorsFrame
--spell icon
local spellIconTexture = DF:CreateImage(line, "", scroll_line_height-2, scroll_line_height-2)
spellIconTexture:SetTexCoord(.1, .9, .1, .9)
line.spellIconTexture = spellIconTexture
--spell Id
local spellIdEntry = DF:CreateTextEntry(line, function()end, headerTable[3].width, 20, "spellIdEntry", nil, nil, DF:GetTemplate("dropdown", "PLATER_DROPDOWN_OPTIONS"))
spellIdEntry:SetHook("OnEditFocusGained", oneditfocusgained_spellid)
spellIdEntry:SetHook("OnEditFocusLost", oneditfocuslost)
spellIdEntry:SetJustifyH("left")
--spell Name
local spellNameEntry = DF:CreateTextEntry(line, function()end, headerTable[4].width, 20, "spellNameEntry", nil, nil, DF:GetTemplate("dropdown", "PLATER_DROPDOWN_OPTIONS"))
spellNameEntry:SetHook("OnEditFocusGained", oneditfocusgained_spellid)
spellNameEntry:SetHook("OnEditFocusLost", oneditfocuslost)
spellNameEntry:SetJustifyH("left")
local spellRenameEntry = DF:CreateTextEntry(line, function()end, headerTable[5].width, 20, "spellRenameEntry", nil, nil, DF:GetTemplate("dropdown", "PLATER_DROPDOWN_OPTIONS"))
spellRenameEntry:SetHook("OnEditFocusGained", oneditfocusgained_spellid)
spellRenameEntry:SetJustifyH("left")
spellRenameEntry:SetHook("OnEditFocusLost", function(widget, capsule, text)
local castColors = Plater.db.profile.cast_colors
local spellId = capsule.spellId
capsule.text = castColors[spellId] and castColors[spellId][CONST_INDEX_NAME] or ""
end)
spellRenameEntry:SetHook("OnEnterPressed", function(widget, capsule, text)
local castColors = Plater.db.profile.cast_colors
local spellId = capsule.spellId
local castColor = castColors[spellId]
if (text == "") then
if (castColor) then
castColor[CONST_INDEX_NAME] = ""
end
else
if (castColor) then
castColor[CONST_INDEX_NAME] = text
else
castColors[spellId] = {true, "white", text}
end
end
Plater.UpdateAllPlates()
end)
--npc name
local npcNameEntry = DF:CreateTextEntry(line, function()end, headerTable[6].width, 20, "npcNameEntry", nil, nil, DF:GetTemplate("dropdown", "PLATER_DROPDOWN_OPTIONS"))
npcNameEntry:SetHook("OnEditFocusGained", oneditfocusgained_spellid)
npcNameEntry:SetHook("OnEditFocusLost", oneditfocuslost)
npcNameEntry:SetJustifyH("left")
--npc Id
--local npcIdLabel = DF:CreateLabel(line, "", 10, "white", nil, "npcIdLabel")
--send to raid button
local sendToRaidButton = DF:CreateButton(line, function()end, headerTable[7].width - 15, 20, "Send to Raid", -1, nil, nil, nil, nil, nil, DF:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate("font", "PLATER_BUTTON"))
line.sendToRaidButton = sendToRaidButton
--location
--local npcLocationLabel = DF:CreateLabel(line, "", 10, "white", nil, "npcLocationLabel")
local selectAudioDropdown = DF:CreateDropDown(line, line_refresh_audio_dropdown, 1, headerTable[8].width - 1, 20, "SelectAudioDropdown", nil, DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
selectAudioDropdown:SetFrameLevel(line:GetFrameLevel()+2)
--encounter
local encounterNameLabel = DF:CreateLabel(line, "", 10, "white", nil, "encounterNameLabel") --not in use, got replaced by spell name rename
--color enabled check box
local enabledCheckBox = DF:CreateSwitch(line, onToggleEnabled, true, _, _, _, _, "EnabledCheckbox", "$parentEnabledToggle" .. index, _, _, _, nil, DF:GetTemplate("switch", "OPTIONS_CHECKBOX_BRIGHT_TEMPLATE"))
enabledCheckBox:SetAsCheckBox()
--color dropdown
local colorDropdown = DF:CreateDropDown(line, line_refresh_color_dropdown, 1, headerTable[8].width - 1, 20, "ColorDropdown", nil, DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
colorDropdown:SetFrameLevel(line:GetFrameLevel()+2)
enabledCheckBox:SetHook ("OnEnter", widget_onenter)
enabledCheckBox:SetHook ("OnLeave", widget_onleave)
spellIdEntry:SetHook ("OnEnter", widget_onenter)
spellIdEntry:SetHook ("OnLeave", widget_onleave)
spellNameEntry:SetHook ("OnEnter", widget_onenter)
spellNameEntry:SetHook ("OnLeave", widget_onleave)
spellRenameEntry:SetHook ("OnEnter", widget_onenter)
spellRenameEntry:SetHook ("OnLeave", widget_onleave)
colorDropdown:SetHook ("OnEnter", widget_onenter)
colorDropdown:SetHook ("OnLeave", widget_onleave)
selectAudioDropdown:SetHook("OnEnter", widget_onenter)
selectAudioDropdown:SetHook("OnLeave", widget_onleave)
line:AddFrameToHeaderAlignment (spellIndicatorsFrame)
line:AddFrameToHeaderAlignment (spellIconTexture)
line:AddFrameToHeaderAlignment (spellIdEntry)
line:AddFrameToHeaderAlignment (spellNameEntry)
line:AddFrameToHeaderAlignment (spellRenameEntry)
line:AddFrameToHeaderAlignment (npcNameEntry)
line:AddFrameToHeaderAlignment (sendToRaidButton)
--line:AddFrameToHeaderAlignment (npcIdLabel)
line:AddFrameToHeaderAlignment (selectAudioDropdown)
--line:AddFrameToHeaderAlignment (encounterNameLabel)
line:AddFrameToHeaderAlignment (enabledCheckBox)
colorDropdown:SetPoint("left", enabledCheckBox, "right", 2, 0)
--line:AddFrameToHeaderAlignment (colorDropdown)
line:AlignWithHeader (castFrame.Header, "left")
return line
end
--> build scripts preview to add the cast to a script
local scriptPreviewFrame = CreateFrame("frame", castFrame:GetName() .. "ScriptPreviewPanel", castFrame, "BackdropTemplate")
local spFrame = scriptPreviewFrame
spFrame:SetPoint("topright", castFrame, "topright", 23, -56)
spFrame:SetPoint("bottomright", castFrame, "bottomright", -10, 35)
spFrame:SetWidth(250)
spFrame:SetFrameLevel(castFrame:GetFrameLevel()+10)
DF:ApplyStandardBackdrop(spFrame)
spFrame:SetBackdropBorderColor(0, 0, 0, 0)
spFrame:EnableMouse(true)
local CONST_PREVIEW_SPELLID = 116
local allPreviewFrames = {}
castColorFrame.allPreviewFrames = allPreviewFrames
--receives a spellId and verify if this spellId is a trigger of any script
local hasScriptWithPreviewSpellId = function(spellId)
local previewSpellId = spellId or CONST_PREVIEW_SPELLID
local defaultCastScripts = platerInternal.Scripts.DefaultCastScripts
local GetScriptObjectByName = platerInternal.Scripts.GetScriptObjectByName
local find = DF.table.find
for i = 1, #defaultCastScripts do
local scriptName = defaultCastScripts[i]
---@type scriptdata
local scriptObject = GetScriptObjectByName(scriptName)
if (scriptObject) then
local index = find(scriptObject.SpellIds, previewSpellId)
if (index) then
return true
end
end
end
end
local castBarPreviewTexture = "" --[[Interface\AddOns\Plater\Images\cast_bar_scripts_preview]]
local eachCastBarButtonHeight = PlaterOptionsPanelContainerCastColorManagementColorFrameScriptPreviewPanel:GetHeight() / #platerInternal.Scripts.DefaultCastScripts
local scriptsToShow = {}
for i = 1, #platerInternal.Scripts.DefaultCastScripts do
local scriptName = platerInternal.Scripts.DefaultCastScripts[i]
local scriptObject = platerInternal.Scripts.GetScriptObjectByName(scriptName)
if (scriptObject) then
scriptsToShow[#scriptsToShow + 1] = scriptName
end
end
for i = 1, #scriptsToShow do
local scriptName = scriptsToShow[i]
---@type scriptdata
local scriptObject = platerInternal.Scripts.GetScriptObjectByName(scriptName)
if (scriptObject) then
local previewFrame = CreateFrame("button", nil, spFrame, BackdropTemplateMixin and "BackdropTemplate")
previewFrame:SetSize(spFrame:GetWidth()-5, eachCastBarButtonHeight) --270
previewFrame:SetPoint("topleft", spFrame, "topleft", 5, (-eachCastBarButtonHeight * (i - 1)) -5)
DF:ApplyStandardBackdrop(previewFrame)
previewFrame.scriptName = scriptName
local scriptNameText = previewFrame:CreateFontString(nil, "overlay", "GameFontNormal")
scriptNameText:SetPoint("topright", previewFrame, "topright", -2, -1)
scriptNameText:SetJustifyH("right")
scriptNameText:SetText(scriptName)
scriptNameText:SetAlpha(0.75)
DF:SetFontSize(scriptNameText, 9)
previewFrame.scriptNameText = scriptNameText
local widthEnd = 282/512
local textureHeight = 46.54 --increasing reduces the preview texture height
local scriptPreviewTexture = previewFrame:CreateTexture(nil, "overlay", nil, 3)
--scriptPreviewTexture:SetTexture(castBarPreviewTexture)
scriptPreviewTexture:SetTexture(scriptObject.Icon)
--scriptPreviewTexture:SetTexCoord(0, widthEnd, textureHeight * (i-1) / 512, textureHeight * i / 512)
scriptPreviewTexture:SetPoint("topleft", previewFrame, "topleft", 1, -1)
scriptPreviewTexture:SetSize(100, eachCastBarButtonHeight)
scriptPreviewTexture:SetTexCoord(0.1, 0.9, 0.1, 0.9)
--scriptPreviewTexture:SetPoint("bottomright", previewFrame, "bottomright", -1, 1)
scriptPreviewTexture:SetAlpha(1)
--scriptPreviewTexture:SetBlendMode("ADD")
local scriptPreviewTexture2 = previewFrame:CreateTexture(nil, "overlay", nil, 2)
scriptPreviewTexture2:SetTexture(castBarPreviewTexture)
scriptPreviewTexture2:SetTexCoord(0, widthEnd, textureHeight * (i-1) / 512, textureHeight * i / 512)
scriptPreviewTexture2:SetPoint("topleft", previewFrame, "topleft", 1, -1)
scriptPreviewTexture2:SetPoint("bottomright", previewFrame, "bottomright", -1, 1)
scriptPreviewTexture2:SetAlpha(0.2)
scriptPreviewTexture2:SetBlendMode("ADD")
previewFrame.selectedHighlight = scriptPreviewTexture2
local selectedScript = previewFrame:CreateTexture(nil, "overlay", nil, 1)
selectedScript:SetPoint("topleft", previewFrame, "topleft", 0, 0)
selectedScript:SetPoint("bottomright", previewFrame, "bottomright", 0, 0)
selectedScript:SetTexture([[Interface\AddOns\Plater\images\overlay_indicator_3]])
selectedScript:SetAlpha(0.3)
selectedScript:Hide()
previewFrame.selectedScript = selectedScript
platerInternal.Scripts.RemoveSpellFromScriptTriggers(scriptObject, CONST_PREVIEW_SPELLID)
previewFrame:EnableMouse(false)
allPreviewFrames[#allPreviewFrames+1] = previewFrame
previewFrame:SetScript("OnEnter", function(castBar)
GameCooltip:Reset()
GameCooltip:AddLine("Script:", previewFrame.scriptName)
GameCooltip:AddLine("Click to use this animation when the cast start")
GameCooltip:AddLine("Having enemy npcs near you, make their nameplates to preview this animation")
local scriptObject = platerInternal.Scripts.GetScriptObjectByName(previewFrame.scriptName)
if (scriptObject) then
GameCooltip:AddLine(" ")
GameCooltip:AddLine(scriptObject.Desc, "", 1, "yellow")
end
GameCooltip:SetOption("FixedWidth", 320)
GameCooltip:SetOwner(previewFrame)
GameCooltip:Show(previewFrame)
previewFrame:SetBackdropBorderColor(1, .7, .1, 1)
spFrame.StartCastBarPreview(previewFrame)
end)
previewFrame:SetScript("OnLeave", function(castBar)
GameCooltip:Hide()
previewFrame:SetBackdropBorderColor(0, 0, 0, 0)
spFrame.StopCastBarPreview(previewFrame)
end)
previewFrame:SetScript("OnClick", function() --~onclick õnclick
local spellId = castColorFrame.currentSpellId
local scriptName = previewFrame.scriptName
local scriptObject = platerInternal.Scripts.GetScriptObjectByName(scriptName)
if (scriptObject) then
--already have this trigger?
local index = DF.table.find(scriptObject.SpellIds, spellId)
if (index) then
spFrame.RemoveTriggerFromAllScriptsBySpellID(spellId)
else
spFrame.RemoveTriggerFromAllScriptsBySpellID(spellId)
platerInternal.Scripts.AddSpellToScriptTriggers(scriptObject, spellId)
end
castColorFrame.SelectScriptForSpellId(spellId)
castFrame.RefreshScroll()
end
end)
end
end
function castColorFrame.SelectScriptForSpellId(spellId)
local foundScriptWithThisSpellId = false
for i = 1, #platerInternal.Scripts.DefaultCastScripts do
local scriptName = platerInternal.Scripts.DefaultCastScripts[i]
local scriptObject = platerInternal.Scripts.GetScriptObjectByName(scriptName)
if (scriptObject) then
local hasTrigger = platerInternal.Scripts.DoesScriptHasTrigger(scriptObject, spellId)
if (hasTrigger) then
for o = 1, #allPreviewFrames do
local previewFrame = allPreviewFrames[o]
if (previewFrame.scriptName == scriptName) then
previewFrame.selectedScript:Show()
previewFrame.scriptNameText:SetAlpha(0.9)
previewFrame.selectedHighlight:Show()
foundScriptWithThisSpellId = true
else
previewFrame.selectedScript:Hide()
previewFrame.scriptNameText:SetAlpha(0.75)
previewFrame.selectedHighlight:Hide()
end
end
end
end
end
--no script has been found using this spellId as trigger
if (not foundScriptWithThisSpellId) then
for o = 1, #allPreviewFrames do
local previewFrame = allPreviewFrames[o]
previewFrame.selectedScript:Hide()
previewFrame.scriptNameText:SetAlpha(0.75)
previewFrame.selectedHighlight:Hide()
end
end
end
function spFrame.StartCastBarPreview(previewFrame)
if (Plater.IsTestRunning) then
Plater.StopCastBarTest()
end
local scriptName = previewFrame.scriptName
local scriptObject = platerInternal.Scripts.GetScriptObjectByName(scriptName)
if (scriptObject) then
spFrame.RemovePreviewTriggerFromAllScripts()
platerInternal.Scripts.AddSpellToScriptTriggers(scriptObject, CONST_PREVIEW_SPELLID)
Plater.StartCastBarTest(true, 2)
end
end
--on leave castBar area
function spFrame.StopCastBarPreview(previewFrame)
Plater.StopCastBarTest()
local scriptName = previewFrame.scriptName
local scriptObject = platerInternal.Scripts.GetScriptObjectByName(scriptName)
if (not scriptObject) then
Plater:Msg("[StopCastBarPreview] script not found:", scriptName)
return
end
spFrame.RemovePreviewTriggerFromAllScripts()
end
function spFrame.RemoveTriggerFromAllScriptsBySpellID(spellId)
spellId = spellId or CONST_PREVIEW_SPELLID
local noRecompile = true
local scriptData = Plater.db.profile.script_data
local spellRemoved = false
for i, scriptObject in pairs(scriptData) do
platerInternal.Scripts.RemoveSpellFromScriptTriggers(scriptObject, spellId, noRecompile)
spellRemoved = true
end
if (spellRemoved) then
Plater.WipeAndRecompileAllScripts("script")
end
end
function spFrame.RemovePreviewTriggerFromAllScripts()
for i = 1, #platerInternal.Scripts.DefaultCastScripts do
local scriptName = platerInternal.Scripts.DefaultCastScripts[i]
local scriptObject = platerInternal.Scripts.GetScriptObjectByName(scriptName)
if (scriptObject) then
platerInternal.Scripts.RemoveSpellFromScriptTriggers(scriptObject, CONST_PREVIEW_SPELLID)
end
end
end
spFrame:HookScript("OnShow", function()
if (not spFrame.LoopPreviewTimer) then
--spFrame.LoopPreviewTimer = DF.Schedules.NewTicker(2, startCasting)
end
end)
spFrame.OnHide = function()
if (Plater.IsTestRunning) then
C_Timer.After(0.05, spFrame.OnHide)
else
spFrame.RemovePreviewTriggerFromAllScripts()
end
end
spFrame:HookScript("OnHide", function()
spFrame.OnHide()
end)
------------------------------------------------------------------------------------------------------------
--> build the ~options panel
local optionsFrame = CreateFrame("frame", "PlaterCCastsOptionsPanel", castFrame, "BackdropTemplate")
optionsFrame:SetPoint("topright", castFrame, "topright", 28, -56)
optionsFrame:SetPoint("bottomright", castFrame, "bottomright", 0, 18)
optionsFrame:SetWidth(250)
optionsFrame:SetFrameLevel(castFrame:GetFrameLevel()+20)
optionsFrame:Hide() --hidden by default
DF:ApplyStandardBackdrop(optionsFrame)
--optionsFrame:SetBackdropBorderColor(0, 0, 0, 0)
optionsFrame:EnableMouse(true)
local onChangeOption = function()
--when a setting if changed
Plater.RefreshDBUpvalues()
Plater.UpdateAllPlates()
optionsFrame.previewCastBar.UpdateAppearance()
end
local layerNames = {
"Background",
"Artwork",
"Overlay",
}
local buildLayerMenu = function()
local t = {}
for i = 1, #layerNames do
tinsert (t, {
label = layerNames[i],
value = layerNames[i],
onclick = function (_, _, value)
Plater.db.profile.cast_color_settings.layer = value
onChangeOption()
end
})
end
return t
end
--anchor table
local anchorNames = Plater.AnchorNames
local build_anchor_side_table = function()
local t = {}
for i = 1, 13 do
tinsert (t, {
label = anchorNames[i],
value = i,
onclick = function (_, _, value)
Plater.db.profile.cast_color_settings.anchor.side = value
onChangeOption()
end
})
end
return t
end
local optionsTable = {
{
type = "toggle",
get = function() return Plater.db.profile.cast_color_settings.enabled end,
set = function (self, fixedparam, value)
Plater.db.profile.cast_color_settings.enabled = value
end,
name = "Enable Original Cast Color",
desc = "Show a small indicator showing the original color of the cast.",
childrenids = {"alpha", "width", "height_offset", "layer", "anchor", "x", "y"},
children_follow_enabled = true,
},
{
type = "range",