-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathModuleCore.lua
More file actions
1236 lines (1135 loc) · 39.8 KB
/
ModuleCore.lua
File metadata and controls
1236 lines (1135 loc) · 39.8 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
-- localization
local LM = LibStub("AceLocale-3.0"):GetLocale("ArcHUD_Module")
local AceConfig = LibStub("AceConfig-3.0")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local AceConfigRegistry = LibStub("AceConfigRegistry-3.0")
-- Debug levels
local d_warn = 1
local d_info = 2
local d_notice = 3
local _
-- Set libraries
ArcHUD:SetDefaultModuleLibraries("AceEvent-3.0")
ArcHUD.modulePrototype = {
parent = ArcHUD
}
local basePowerTypeIsEmpty = {
[Enum.PowerType.Rage] = true,
[Enum.PowerType.RunicPower] = true,
[Enum.PowerType.Insanity] = true,
[Enum.PowerType.Fury] = true,
[Enum.PowerType.Pain] = true,
[Enum.PowerType.LunarPower] = true,
[Enum.PowerType.Maelstrom] = true
}
----------------------------------------------
-- Debug function uses the core :Debug function
----------------------------------------------
function ArcHUD.modulePrototype:Debug(level, msg, ...)
if(self.parent.LevelDebug) then
self.parent:LevelDebug(level, "["..self.name.."] "..msg, ...)
end
end
----------------------------------------------
-- Initialize config options
----------------------------------------------
function ArcHUD.modulePrototype:InitConfigOptions()
if (self.isCustom) then
-- Custom buff module
self:Debug(d_notice, "Initializing custom buff module options")
-- Register options
if (self.optionsTable and type(self.optionsTable) == "table") then
self.parent:AddCustomModuleOptionsTable(self.name, self.optionsTable)
end
elseif (self.defaults and type(self.defaults) == "table") then
-- Add defaults to ArcHUD defaults table
self:Debug(d_notice, "Acquiring ring DB namespace")
self.db = self.parent.db:RegisterNamespace(self.name, self.defaults)
if(not self.db) then
self:Debug(d_warn, "Failed to acquire DB namespace")
end
-- Register options
if (self.optionsTable and type(self.optionsTable) == "table") then
self.parent:AddModuleOptionsTable(self.name, self.optionsTable)
end
end
end
----------------------------------------------
-- Enabling/Disabling
----------------------------------------------
function ArcHUD.modulePrototype:OnInitialize()
-- Prevent double-initialization
-- This might happen for custom modules loaded after the ADDON_LOADED event
if (self.isInitialized) then return end
self.isInitialized = true
if(self.Initialize) then
self:Initialize()
self:Debug(d_notice, "Ring initialized")
self:RegisterMessage("ARCHUD_MODULE_ENABLE")
self:RegisterMessage("ARCHUD_MODULE_UPDATE")
else
self:Debug(d_warn, "Missing Initialize(). Aborting")
return
end
self:InitConfigOptions()
-- Add metadata for module if it doesn't exist
if(not self.version) then
self.version = self.parent.version
end
if(not self.author) then
self.author = self.parent.author
end
if(not self.date) then
self.date = self.parent.date
end
-- Check for necessary alpha updates
if (not self.noAutoAlpha) then
self:RegisterTimer("CheckAlpha", ArcHUD.modulePrototype.CheckAlpha, 0.1, self, true)
end
self:Debug(d_info, "Ring loaded")
end
----------------------------------------------
-- OnEnable
----------------------------------------------
function ArcHUD.modulePrototype:OnEnable()
if(self.db.profile.Enabled) then
if(self.disableEvents and (not self.disableEvents.option or self.disableEvents.option and self.db.profile[self.disableEvents.option])) then
self:Debug(d_notice, "Disabling events:")
for k,v in ipairs(self.disableEvents) do
local f = getglobal(v.frame)
if(f) then
self:Debug(d_notice, "- Frame '"..f:GetName().."':")
for _, event in pairs(v.events) do
self:Debug(d_notice, " * "..event)
f:UnregisterEvent(event)
end
if(v.hide and f:IsVisible()) then
self:Debug(d_notice, "- Frame '"..f:GetName().."' hiding")
f:Hide()
end
end
end
self.eventsDisabled = TRUE
end
if (self.OnModuleEnable) then
self:OnModuleEnable()
else
self:Debug(d_info, "Ring "..self:GetName().." has no OnModuleEnable() handler")
end
self:ARCHUD_MODULE_UPDATE("ARCHUD_MODULE_UPDATE", self:GetName())
self:RegisterMessage("ARCHUD_MODULE_DISABLE")
self:RegisterMessage("ARCHUD_MODULE_UPDATE")
self:Debug(d_info, "Ring enabled")
else
self:Debug(d_notice, "Ring disabled as per user setting")
self:Disable()
end
end
----------------------------------------------
-- OnDisable
----------------------------------------------
function ArcHUD.modulePrototype:OnDisable()
--self:Debug(d_info, "Disabling ring")
if(self.disableEvents and self.eventsDisabled) then
self:Debug(d_notice, "Re-enabling events:")
for k,v in ipairs(self.disableEvents) do
local f = getglobal(v.frame)
if(f) then
--self:Debug(d_notice, "- Frame '"..f:GetName().."':")
for _, event in pairs(v.events) do
self:Debug(d_notice, " * "..event)
f:RegisterEvent(event)
end
end
end
self.eventsDisabled = FALSE
end
if(self.f) then
self.f:Hide()
end
self:StopRingTimers()
if(self.OnModuleDisable) then
self:OnModuleDisable()
end
if (not self.deleted) then
self:RegisterMessage("ARCHUD_MODULE_ENABLE")
self:RegisterMessage("ARCHUD_MODULE_UPDATE")
end
self:Debug(d_info, "Ring disabled")
end
----------------------------------------------
-- ARCHUD_MODULE_ENABLE
----------------------------------------------
function ArcHUD.modulePrototype:ARCHUD_MODULE_ENABLE()
self:Enable()
end
----------------------------------------------
-- ARCHUD_MODULE_DISABLE
----------------------------------------------
function ArcHUD.modulePrototype:ARCHUD_MODULE_DISABLE()
self:Disable()
end
----------------------------------------------
-- ARCHUD_MODULE_UPDATE
----------------------------------------------
function ArcHUD.modulePrototype:ARCHUD_MODULE_UPDATE(message, module)
--self:Debug(1, "ARCHUD_MODULE_UPDATE("..tostring(message)..", "..tostring(module))
if(module == self:GetName()) then
if(self.db.profile.Enabled and not self:IsEnabled()) then
self:Enable()
elseif(not self.db.profile.Enabled and self:IsEnabled()) then
self:Disable()
elseif(self.db.profile.Enabled and self:IsEnabled()) then
if (not self.f) then
self.parent:LevelDebug(d_warn, "Frame for "..module.." not defined")
return
end
if(self.f.BG) then
if(self.db.profile.Outline) then
self.f.BG:Show()
else
self.f.BG:Hide()
end
end
if(not self.options.nocolor) then
self.ColorMode = self.db.profile.ColorMode or "custom"
end
if self.name ~= "Anchors" then
self:AttachRing() -- default frame
if self.frames then -- any additional frames
for i,v in ipairs(self.frames) do
self:AttachRing(v)
end
end
end
if(self.OnModuleUpdate) then
--self:Debug(d_notice, "Updating ring")
self:OnModuleUpdate()
end
end
end
end
----------------------------------------------
-- Ring frame creation and setup
----------------------------------------------
function ArcHUD.modulePrototype:CreateRing(hasBG, parent)
-- Create frame
local f = CreateFrame("Frame", "ArcHUD_"..self:GetName().."_Ring", parent, "ArcHUDRingTemplate")
f.module = self
if not hasBG then
f.BG:Hide()
f.oldBG = f.BG -- if needed later again
f.BG = nil
end
return f
end
----------------------------------------------
-- Anchor ring frame according to config
----------------------------------------------
function ArcHUD.modulePrototype:AttachRing(ring)
if (not ring) then
ring = self.f
end
local oldValue = ring.endValue
ring:SetValue(0)
-- Clear all points for the ring
ring:ClearAllPoints()
if(self.db.profile.Side == 1) then
-- Attach to left side
if self.db.profile.InnerAnchor then
ring:SetScale(0.6)
ring:SetPoint("TOPLEFT", self.parent:GetModule("Anchors").Left, "LEFT", self.db.profile.Level * -9, 90)
else
ring:SetScale(1)
ring:SetPoint("TOPLEFT", self.parent:GetModule("Anchors").Left, "TOPLEFT", self.db.profile.Level * -15, 0)
end
if(ring.BG) then
ring.BG:SetReversed(false)
end
ring:SetReversed(false)
else
-- Attach to right side
if self.db.profile.InnerAnchor then
ring:SetScale(0.6)
ring:SetPoint("TOPLEFT", self.parent:GetModule("Anchors").Right, "LEFT", self.db.profile.Level * 9, 90)
else
ring:SetScale(1)
ring:SetPoint("TOPRIGHT", self.parent:GetModule("Anchors").Right, "TOPRIGHT", self.db.profile.Level * 15, 0)
end
if(ring.BG) then
ring.BG:SetReversed(true)
end
ring:SetReversed(true)
end
if(ring.BG) then
ring.BG:SetAngle(180)
end
-- separators
if (self.db.profile.ShowSeparators) then
ring.showSeparators = true
end
ring:RefreshSeparators()
ring:SetValue(oldValue)
end
----------------------------------------------
-- CreateFontString
----------------------------------------------
function ArcHUD.modulePrototype:CreateFontString(parent, layer, size, fontsize, justify, color, point)
local fs = parent:CreateFontString(nil, layer)
local width, height = unpack(size)
fs:SetWidth(width)
fs:SetHeight(height)
fs:SetFont("Fonts\\"..LM["FONT"], fontsize, "OUTLINE")
if(color) then
fs:SetTextColor(unpack(color))
end
fs:SetJustifyH(justify)
fs:SetPoint(unpack(point))
fs:Show()
return fs
end
----------------------------------------------
-- CreateTexture
----------------------------------------------
function ArcHUD.modulePrototype:CreateTexture(parent, layer, size, texture, point)
local t = parent:CreateTexture(nil, layer)
local width, height = unpack(size)
t:SetWidth(width)
t:SetHeight(height)
if(texture) then
t:SetTexture(texture)
end
if(point) then
t:SetPoint(unpack(point))
end
t:Show()
return t
end
-----------------------------------------------------------
-- Update of alpha value for all frames
--
-- alpha - Alpha value to set
-- alpha2 - If not nil and ring not full/empty, use alpha2 instead of alpha
-- In 12.0.0+, values may be secret - protect operations
-----------------------------------------------------------
function ArcHUD.modulePrototype:SetFramesAlpha(alpha, alpha2, invertCurve)
if (self.frames) then
-- module with multiple frames
for i,f in pairs(self.frames) do
-- Check if values are secret (12.0.0+)
local maxValueSecret = ArcHUD.isMidnight and issecretvalue and issecretvalue(f.maxValue)
local startValueSecret = ArcHUD.isMidnight and issecretvalue and issecretvalue(f.startValue)
local endValueSecret = ArcHUD.isMidnight and issecretvalue and issecretvalue(f.endValue)
if maxValueSecret or f.isHidden then
f:SetRingAlpha(0)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(0) end
elseif not maxValueSecret and (f.maxValue == 0) then
f:SetRingAlpha(0)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(0) end
elseif (alpha2) then
-- In Midnight, use CurveObject to determine alpha based on percentage
-- The ring frame values are kept at 1/0 (not secret), so we must check actual unit health/power
if ArcHUD.isMidnight and self.unit and (self.isHealth or self.isPower) then
local unit = self.unit
if not self.alphaCurve then
-- Create Step curve: alpha2 for < 0.999, alpha for >= 1.0
self.alphaCurve = C_CurveUtil.CreateCurve()
if self.alphaCurve then
self.alphaCurve:SetType(Enum.LuaCurveType.Step)
-- Store alpha values in the module for reuse
self.alphaCurve.alpha2 = alpha2
self.alphaCurve.alpha = alpha
-- Add points immediately when creating the curve
self.alphaCurve:AddPoint(0.9999, alpha2)
self.alphaCurve:AddPoint(1.0, alpha)
end
end
if self.alphaCurve then
-- Update curve points if alpha values changed
if self.alphaCurve.alpha2 ~= alpha2 or self.alphaCurve.alpha ~= alpha then
self.alphaCurve:ClearPoints()
self.alphaCurve:AddPoint(0.9999, alpha2)
self.alphaCurve:AddPoint(1.0, alpha)
self.alphaCurve.alpha2 = alpha2
self.alphaCurve.alpha = alpha
end
end
if invertCurve then
if not self.invertedAlphaCurve then
-- Create Step curve: alpha2 for < 0.999, alpha for >= 1.0
self.invertedAlphaCurve = C_CurveUtil.CreateCurve()
if self.invertedAlphaCurve then
self.invertedAlphaCurve:SetType(Enum.LuaCurveType.Step)
-- Store alpha values in the module for reuse
self.invertedAlphaCurve.alpha2 = alpha2
self.invertedAlphaCurve.alpha = alpha
-- Add points immediately when creating the curve
self.invertedAlphaCurve:AddPoint(0.001, alpha2)
self.invertedAlphaCurve:AddPoint(0.000, alpha)
end
end
if self.invertedAlphaCurve then
-- Update curve points if alpha values changed
if self.invertedAlphaCurve.alpha2 ~= alpha2 or self.invertedAlphaCurve.alpha ~= alpha then
self.invertedAlphaCurve:ClearPoints()
self.invertedAlphaCurve:AddPoint(0.001, alpha2)
self.invertedAlphaCurve:AddPoint(0.000, alpha)
self.invertedAlphaCurve.alpha2 = alpha2
self.invertedAlphaCurve.alpha = alpha
end
end
end
-- Determine if this is health or power
if self.isHealth then
-- Use UnitHealthPercent with curve
if self.alphaCurve then
local secretAlpha
if invertCurve then
secretAlpha = UnitHealthPercent(unit, true, self.invertedAlphaCurve)
else
secretAlpha = UnitHealthPercent(unit, true, self.alphaCurve)
end
-- Check if secretAlpha is not nil (0 is a valid value, so check ~= nil)
if secretAlpha ~= nil then
f:SetRingAlpha(secretAlpha)
if f.statusBarArc then
f.statusBarArc:SetAlpha(secretAlpha)
end
else
f:SetRingAlpha(alpha2)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha2) end
end
else
f:SetRingAlpha(alpha2)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha2) end
end
elseif self.isPower then
-- Use UnitPowerPercent with curve
local powerType = self.powerType or UnitPowerType(unit)
if self.alphaCurve then
local secretAlpha
if invertCurve then
secretAlpha = UnitPowerPercent(unit, powerType, nil, self.invertedAlphaCurve)
else
secretAlpha = UnitPowerPercent(unit, powerType, nil, self.alphaCurve)
end
-- Check if secretAlpha is not nil (0 is a valid value, so check ~= nil)
if secretAlpha ~= nil then
f:SetRingAlpha(secretAlpha)
if f.statusBarArc then
f.statusBarArc:SetAlpha(secretAlpha)
end
else
f:SetRingAlpha(alpha2)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha2) end
end
else
f:SetRingAlpha(alpha2)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha2) end
end
else
-- Not health or power - fallback
f:SetRingAlpha(alpha2)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha2) end
end
elseif not startValueSecret and not maxValueSecret and not endValueSecret then
-- Legacy: check ring frame values directly
if(f.startValue < f.maxValue or math.floor(f.startValue) ~= math.floor(f.endValue)) then
f:SetRingAlpha(alpha2)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha2) end
elseif(self.f.startValue == self.f.maxValue) then
f:SetRingAlpha(alpha)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha) end
end
else
-- Values are secret but not in Midnight health/power mode - fallback
f:SetRingAlpha(alpha2)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha2) end
end
else
-- No alpha2: set alpha directly (e.g., when in combat)
-- Force instant update to ensure it works even if previous alpha was secret
f:SetRingAlpha(alpha, true)
-- Also sync StatusBar alpha if it exists (Midnight mode)
if ArcHUD.isMidnight and f.statusBarArc then
f.statusBarArc:SetAlpha(alpha)
end
end
end
elseif (self.f) then
-- single/no frame
local f = self.f
-- Check if values are secret (12.0.0+)
local maxValueSecret = ArcHUD.isMidnight and issecretvalue and issecretvalue(f.maxValue)
local startValueSecret = ArcHUD.isMidnight and issecretvalue and issecretvalue(f.startValue)
local endValueSecret = ArcHUD.isMidnight and issecretvalue and issecretvalue(f.endValue)
if maxValueSecret or f.isHidden then
f:SetRingAlpha(0)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(0) end
elseif not maxValueSecret and (f.maxValue == 0) then
f:SetRingAlpha(0)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(0) end
elseif (alpha2) then
if ArcHUD.isMidnight then
if not self.alphaCurve then
-- Create Step curve: alpha2 for < 0.999, alpha for >= 1.0
self.alphaCurve = C_CurveUtil.CreateCurve()
if self.alphaCurve then
self.alphaCurve:SetType(Enum.LuaCurveType.Step)
-- Store alpha values in the module for reuse
self.alphaCurve.alpha2 = alpha2
self.alphaCurve.alpha = alpha
-- Add points immediately when creating the curve
self.alphaCurve:AddPoint(0.9999, alpha2)
self.alphaCurve:AddPoint(1.0, alpha)
end
end
if self.alphaCurve then
-- Update curve points if alpha values changed
if self.alphaCurve.alpha2 ~= alpha2 or self.alphaCurve.alpha ~= alpha then
self.alphaCurve:ClearPoints()
self.alphaCurve:AddPoint(0.9999, alpha2)
self.alphaCurve:AddPoint(1.0, alpha)
self.alphaCurve.alpha2 = alpha2
self.alphaCurve.alpha = alpha
end
end
if invertCurve then
if not self.invertedAlphaCurve then
-- Create Step curve: alpha2 for < 0.999, alpha for >= 1.0
self.invertedAlphaCurve = C_CurveUtil.CreateCurve()
if self.invertedAlphaCurve then
self.invertedAlphaCurve:SetType(Enum.LuaCurveType.Step)
-- Store alpha values in the module for reuse
self.invertedAlphaCurve.alpha2 = alpha2
self.invertedAlphaCurve.alpha = alpha
-- Add points immediately when creating the curve
self.invertedAlphaCurve:AddPoint(0.001, alpha2)
self.invertedAlphaCurve:AddPoint(0.000, alpha)
end
end
if self.invertedAlphaCurve then
-- Update curve points if alpha values changed
if self.invertedAlphaCurve.alpha2 ~= alpha2 or self.invertedAlphaCurve.alpha ~= alpha then
self.invertedAlphaCurve:ClearPoints()
self.invertedAlphaCurve:AddPoint(0.001, alpha2)
self.invertedAlphaCurve:AddPoint(0.000, alpha)
self.invertedAlphaCurve.alpha2 = alpha2
self.invertedAlphaCurve.alpha = alpha
end
end
end
end
-- In Midnight, use CurveObject to determine alpha based on percentage
-- The ring frame values are kept at 1/0 (not secret), so we must check actual unit health/power
if ArcHUD.isMidnight and self.unit and (self.isHealth or self.isPower) then
local unit = self.unit
-- Determine if this is health or power
if self.isHealth then
-- Use UnitHealthPercent with curve
if self.alphaCurve then
local secretAlpha
if invertCurve then
secretAlpha = UnitHealthPercent(unit, true, self.invertedAlphaCurve)
else
secretAlpha = UnitHealthPercent(unit, true, self.alphaCurve)
end
-- Check if secretAlpha is not nil (0 is a valid value, so check ~= nil)
if secretAlpha ~= nil then
f:SetRingAlpha(secretAlpha)
if f.statusBarArc then
f.statusBarArc:SetAlpha(secretAlpha)
end
else
f:SetRingAlpha(alpha2)
end
else
f:SetRingAlpha(alpha2)
end
elseif self.isPower then
-- Use UnitPowerPercent with curve
local powerType = self.powerType or UnitPowerType(unit)
if self.alphaCurve then
local secretAlpha
if invertCurve then
secretAlpha = UnitPowerPercent(unit, powerType, nil, self.invertedAlphaCurve)
else
secretAlpha = UnitPowerPercent(unit, powerType, nil, self.alphaCurve)
end
-- Check if secretAlpha is not nil (0 is a valid value, so check ~= nil)
if secretAlpha ~= nil then
f:SetRingAlpha(secretAlpha)
if f.statusBarArc then
f.statusBarArc:SetAlpha(secretAlpha)
end
else
f:SetRingAlpha(alpha2)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha2) end
end
else
f:SetRingAlpha(alpha2)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha2) end
end
else
-- Not health or power - fallback
f:SetRingAlpha(alpha2)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha2) end
end
elseif not startValueSecret and not maxValueSecret and not endValueSecret then
-- Legacy: check ring frame values directly
if(f.startValue < f.maxValue or math.floor(f.startValue) ~= math.floor(f.endValue)) then
f:SetRingAlpha(alpha2)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha2) end
elseif(self.f.startValue == self.f.maxValue) then
f:SetRingAlpha(alpha)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha) end
end
else
-- Determine if this is health or power
if self.isHealth then
-- Use UnitHealthPercent with curve
if self.alphaCurve then
local secretAlpha
if invertCurve then
secretAlpha = UnitHealthPercent(unit, true, self.invertedAlphaCurve)
else
secretAlpha = UnitHealthPercent(unit, true, self.alphaCurve)
end
-- Check if secretAlpha is not nil (0 is a valid value, so check ~= nil)
if secretAlpha ~= nil then
f:SetRingAlpha(secretAlpha)
if f.statusBarArc then
f.statusBarArc:SetAlpha(secretAlpha)
end
else
f:SetRingAlpha(alpha2)
end
else
f:SetRingAlpha(alpha2)
end
elseif self.isPower then
-- Use UnitPowerPercent with curve
local powerType = self.powerType or UnitPowerType(unit)
if self.alphaCurve then
local secretAlpha
if invertCurve then
secretAlpha = UnitPowerPercent(unit, powerType, nil, self.invertedAlphaCurve)
else
secretAlpha = UnitPowerPercent(unit, powerType, nil, self.alphaCurve)
end
-- Check if secretAlpha is not nil (0 is a valid value, so check ~= nil)
if secretAlpha ~= nil then
f:SetRingAlpha(secretAlpha)
if f.statusBarArc then
f.statusBarArc:SetAlpha(secretAlpha)
end
else
f:SetRingAlpha(alpha2)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha2) end
end
else
f:SetRingAlpha(alpha2)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha2) end
end
else
-- Not health or power - fallback
f:SetRingAlpha(alpha2)
if ArcHUD.isMidnight and f.statusBarArc then f.statusBarArc:SetAlpha(alpha2) end
end
end
else
-- No alpha2: set alpha directly (e.g., when in combat)
-- Force instant update to ensure it works even if previous alpha was secret
f:SetRingAlpha(alpha, true)
-- Also sync StatusBar alpha if it exists (Midnight mode)
if ArcHUD.isMidnight and f.statusBarArc then
f.statusBarArc:SetAlpha(alpha)
end
end
end
end
-----------------------------------------------------------
-- Trigger update of alpha value (e.g. on entering combat)
-----------------------------------------------------------
function ArcHUD.modulePrototype:CheckAlpha()
if (self.noAutoAlpha) then
self:Debug(1, "CheckAlpha(): noAutoAlpha, but CheckAlpha timer started!")
return
end
local AH_profile = self.parent.db.profile
local isInCombat = false
local me = self:GetName()
local unit = self.unit or "player"
if (unit == "pet") then
isInCombat = self.parent.PetIsInCombat
else
isInCombat = self.parent.PlayerIsInCombat
end
-- 1: Fade out when rings are full, regardless of combat status
-- 2: Always fade out when out of combat, regardless of ring status
-- 3: Fade out when out of combat or rings are full (default)
local RingVisibility = self.db.profile.RingVisibility -- ring config
if (RingVisibility == nil) then
RingVisibility = AH_profile.RingVisibility -- global config
end
if (RingVisibility == 1 or RingVisibility == 3) then
-- Check if maxValue is secret (12.0.0+)
local maxValueSecret = ArcHUD.isMidnight and issecretvalue and issecretvalue(self.f.maxValue)
local startValueSecret = ArcHUD.isMidnight and issecretvalue and issecretvalue(self.f.startValue)
local endValueSecret = ArcHUD.isMidnight and issecretvalue and issecretvalue(self.f.endValue)
if (RingVisibility == 3 and isInCombat) then
if (not UnitExists(unit)) or (self.isPower and (UnitIsDead(unit) or (not maxValueSecret and self.f.maxValue == 0))) then
self.f:SetRingAlpha(0)
elseif (self.isHealth and UnitIsDead(unit)) then
self.f:SetRingAlpha(AH_profile.FadeFull)
else
-- all other frames
self:SetFramesAlpha(AH_profile.FadeIC)
end
else
local powerTypeId, _ = self.powerType or UnitPowerType(unit)
-- powerTypeId: 1 = rage, 6 = runic_power, 17 = fury
if (self.isPower and (unit ~= "pet") and basePowerTypeIsEmpty[powerTypeId] and (not maxValueSecret and self.f.maxValue > 0)) then
if ArcHUD.isMidnight then
self:SetFramesAlpha(AH_profile.FadeFull, AH_profile.FadeOOC, true)
elseif not startValueSecret and not endValueSecret then
if(math.floor(self.f.startValue) > 0 or math.floor(self.f.startValue) ~= math.floor(self.f.endValue)) then
self.f:SetRingAlpha(AH_profile.FadeOOC)
elseif(math.floor(self.f.startValue) == 0) then
self.f:SetRingAlpha(AH_profile.FadeFull)
end
else
self:SetFramesAlpha(AH_profile.FadeFull, AH_profile.FadeOOC, true)
end
else
if (not UnitExists(unit)) or (self.isPower and (UnitIsDead(unit) or (not maxValueSecret and self.f.maxValue == 0))) then
self.f:SetRingAlpha(0)
if ArcHUD.isMidnight and self.f.statusBar then self.f.statusBar:SetAlpha(0) end
elseif (self.isHealth and UnitIsDead(unit)) then
self.f:SetRingAlpha(AH_profile.FadeFull)
else
-- all other frames
self:SetFramesAlpha(AH_profile.FadeFull, AH_profile.FadeOOC)
end
end
end
elseif (RingVisibility == 2) then
-- Check if maxValue is secret (12.0.0+)
local maxValueSecret = ArcHUD.isMidnight and issecretvalue and issecretvalue(self.f.maxValue)
if ((not UnitExists(unit)) or (self.isPower and (UnitIsDead(unit) or (not maxValueSecret and self.f.maxValue == 0)))) then
self.f:SetRingAlpha(0)
elseif (self.isHealth and UnitIsDead(unit)) then
self.f:SetRingAlpha(AH_profile.FadeFull)
else
-- all other frames
if(isInCombat) then
self:SetFramesAlpha(AH_profile.FadeIC)
else
self:SetFramesAlpha(AH_profile.FadeFull)
end
end
end
end
----------------------------------------------
-- Start ring timers (filling and alpha check)
----------------------------------------------
function ArcHUD.modulePrototype:StartRingTimers()
if (self.frames) then
-- module with multiple frames
for i,f in pairs(self.frames) do
f.fillUpdate:Play()
end
elseif (self.f) then
-- module with single or no frame
self.f.fillUpdate:Play()
end
if (not self.noAutoAlpha) then
self:StartTimer("CheckAlpha")
end
end
----------------------------------------------
-- Stop ring timers
----------------------------------------------
function ArcHUD.modulePrototype:StopRingTimers()
if (self.frames) then
-- module with multiple frames
for i,f in pairs(self.frames) do
f.fillUpdate:Stop()
end
elseif (self.f) then
-- module with single or no frame
self.f.fillUpdate:Stop()
end
self:StopTimer("CheckAlpha")
end
----------------------------------------------
-- color_switch
----------------------------------------------
local color_switch = {
friendfoe = {
[1] = function(self) return self.db.profile.ColorFriend end,
[2] = function(self) return self.db.profile.ColorFoe end,
},
manabar = {
[0] = function(self) return self.db.profile.ColorMana end,
[1] = function(self) return self.db.profile.ColorRage end,
[2] = function(self) return self.db.profile.ColorFocus end,
[3] = function(self) return self.db.profile.ColorEnergy end,
[6] = function(self) return self.db.profile.ColorRunic end,
}
}
----------------------------------------------
-- UpdateColor
----------------------------------------------
function ArcHUD.modulePrototype:UpdateColor(color)
if(color and type(color) == "table") then
self.f:UpdateColor(color)
elseif(color and type(color) == "number") then
if(self.options.hasfriendfoe) then
-- Friend / Foe = 1 / 2
if(color_switch.friendfoe[color]) then
self.f:UpdateColor(color_switch.friendfoe[color](self))
end
elseif(self.options.hasmanabar) then
-- Mana / Rage / Focus / Energy / Runic = 0 / 1 / 2 / 3 / 6
if(color_switch.manabar[color]) then
self.f:UpdateColor(color_switch.manabar[color](self))
elseif(PowerBarColor[color]) then
self.f:UpdateColor(PowerBarColor[color])
end
end
else
if (self.ColorMode == "fade") then return end
self.f:UpdateColor(self.db.profile.Color)
end
end
----------------------------------------------
-- Return power bar color
----------------------------------------------
function ArcHUD.modulePrototype:GetPowerBarColor(powerType)
if (color_switch.manabar[powerType]) then
return color_switch.manabar[powerType](self)
else
return PowerBarColor[powerType]
end
end
----------------------------------------------
-- Return power bar color (for text, thus readable colors)
----------------------------------------------
function ArcHUD.modulePrototype:GetPowerBarColorText(powerType)
if (powerType == 0) then
return { r = 0.00, g = 1.00, b = 1.00 }
elseif (color_switch.manabar[powerType]) then
return color_switch.manabar[powerType](self)
else
return PowerBarColor[powerType]
end
end
----------------------------------------------
-- Register a timer
----------------------------------------------
function ArcHUD.modulePrototype:RegisterTimer(name, callback, delay, arg, repeating)
self.parent:RegisterTimer(self.name..name, callback, delay, arg, repeating)
end
----------------------------------------------
-- Start a registered timer
----------------------------------------------
function ArcHUD.modulePrototype:StartTimer(name)
self.parent:StartTimer(self.name..name)
end
----------------------------------------------
-- Stop a registered timer
----------------------------------------------
function ArcHUD.modulePrototype:StopTimer(name)
self.parent:StopTimer(self.name..name)
end
----------------------------------------------
-- Register a unit event (not supported by AceEvent)
-- Requires a module frame (module.f)
----------------------------------------------
function ArcHUD.modulePrototype:RegisterUnitEvent(event, callback, unit)
if (not self.f) then
self:Debug(1, "No frame to register a unit event on!")
return
end
if (not self.f.unitEvents) then
self.f.unitEvents = {}
end
if (self.f.unitEvents[event]) then
self:Debug(1, "Unit event %s already registered!", tostring(event))
return
end
if (not callback) then
callback = event
end
if (not unit) then
unit = self.unit
end
local unit2 = nil
if (unit == "player") then
unit2 = "vehicle"
end
self.f.unitEvents[event] = { cb = callback, module = self }
if (self.f.RegisterUnitEvent) then
-- introduced in WoW 5.x
self.f:RegisterUnitEvent(event, unit, unit2)
else
-- for backward compatibility (WoW 4.x)
self:RegisterEvent(event, callback)
end
end
----------------------------------------------
-- Unregister a unit event (not supported by AceEvent)
----------------------------------------------
function ArcHUD.modulePrototype:UnregisterUnitEvent(event)
if (not self.f) then
self:Debug(1, "No frame to unregister a unit event from!")
return
end
if (not self.f.unitEvents) then
self:Debug(1, "UnregisterUnitEvent(): No unit events registered yet!")
return
end
if (not self.f.unitEvents[event]) then
self:Debug(1, "UnregisterUnitEvent(): Unit event %s not registered!", tostring(event))
return
end
self.f:UnregisterEvent(event)
self.f.unitEvents[event] = nil
end
----------------------------------------------
-- Create standard module options
----------------------------------------------
function ArcHUD.modulePrototype:CreateStandardModuleOptions(order)
local t
local name
if (self.isCustom) then
name = self.db.profile.BuffName .. " (" .. self.db.profile.Unit .. ")"
else
name = LM[self:GetName()]
end
self.optionsTable = {
type = "group",
name = name,
order = order or 100,
args = {
header = {
type = "header",
name = "v" .. self.version,
order = 0,
},
enabled = {