-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNugEnergy.lua
2380 lines (2161 loc) · 85.9 KB
/
NugEnergy.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 addonName, ns = ...
local spenderFeedback = true
local doFadeOut = true
local fadeAfter = 5
local fadeTime = 1
local onlyText = false
local shouldBeFull = false
local isFull = true
local isVertical
local APILevel = math.floor(select(4,GetBuildInfo())/10000)
local isClassic = APILevel <= 4
local GetSpecialization = isClassic and function() return 1 end or _G.GetSpecialization
local GetNumSpecializations = isClassic and function() return 1 end or _G.GetNumSpecializations
local GetSpecializationInfo = isClassic and function() return nil end or _G.GetSpecializationInfo
NugEnergy = CreateFrame("StatusBar","NugEnergy",UIParent)
NugEnergy:SetScript("OnEvent", function(self, event, ...)
-- print(event, unpack{...})
return self[event](self, event, ...)
end)
local LSM = LibStub("LibSharedMedia-3.0")
LSM:Register("statusbar", "Glamour7", [[Interface\AddOns\NugEnergy\statusbar.tga]])
LSM:Register("statusbar", "Glamour7NoArt", [[Interface\AddOns\NugEnergy\statusbar3.tga]])
LSM:Register("statusbar", "NugEnergyVertical", [[Interface\AddOns\NugEnergy\vstatusbar.tga]])
LSM:Register("font", "OpenSans Bold", [[Interface\AddOns\NugEnergy\OpenSans-Bold.ttf]], GetLocale() ~= "enUS" and 15)
local getStatusbar = function() return LSM:Fetch("statusbar", NugEnergy.db.profile.textureName) end
local getFont = function() return LSM:Fetch("font", NugEnergy.db.profile.fontName) end
-- local getStatusbar = function() return [[Interface\AddOns\NugEnergy\statusbar.tga]] end
-- local getFont = function() return [[Interface\AddOns\NugEnergy\Emblem.ttf]] end
local L = setmetatable({}, {
__index = function(t, k)
-- print(string.format('L["%s"] = ""',k:gsub("\n","\\n")));
return k
end,
__call = function(t,k) return t[k] end,
})
NugEnergy.L = L
NugEnergy:RegisterEvent("PLAYER_LOGIN")
local UnitPower = UnitPower
local math_modf = math.modf
local math_abs = math.abs
local math_max = math.max
local PowerFilter
local PowerTypeIndex
local ForcedToShow
local GetPower = UnitPower
local GetPowerMax = UnitPowerMax
local execute = false
local execute_range = nil
local upvalueInCombat = nil
local EPT = Enum.PowerType
local Enum_PowerType_Insanity = EPT.Insanity
local Enum_PowerType_Energy = EPT.Energy
local Enum_PowerType_RunicPower = EPT.RunicPower
local Enum_PowerType_LunarPower = EPT.LunarPower
local Enum_PowerType_Focus = EPT.Focus
local class = select(2,UnitClass("player"))
local UnitAura = UnitAura
local ColorArray = function(color) return {color.r, color.g, color.b} end
local defaults = {
global = {
classConfig = {
ROGUE = { "EnergyRogue", "EnergyRogue", "EnergyRogue" },
DRUID = { "ShapeshiftDruid", "ShapeshiftDruid", "ShapeshiftDruid", "ShapeshiftDruid" },
PALADIN = { "Disabled", "Disabled", "Disabled" },
MONK = { "EnergyBrewmaster", "Disabled", "EnergyWindwalker" },
WARLOCK = { "Disabled", "Disabled", "Disabled" },
DEMONHUNTER = { "FuryDemonHunter", "FuryDemonHunter" },
DEATHKNIGHT = { "RunicPowerDeathstrike", "RunicPower", "RunicPower" },
MAGE = { "MageMana", "Disabled", "Disabled" },
WARRIOR = { "RageWarriorExecute", "RageWarriorExecute", "RageWarriorExecute" },
SHAMAN = { "Maelstrom", "Disabled", "Disabled" },
HUNTER = { "Focus", "Focus", "Focus" },
PRIEST = { "Disabled", "Disabled", "Insanity" },
EVOKER = { "Disabled", "Disabled", "Disabled" },
},
},
profile = {
point = "CENTER",
x = 0, y = 0,
marks = {},
focus = true,
rage = true,
mana = false,
energy = true,
fury = true,
shards = false,
runic = true,
balance = true,
insanity = true,
maelstrom = true,
-- powerTypeColors = true,
-- focusColor = true
hideText = false,
hideBar = false,
enableClassicTicker = true,
spenderFeedback = not isClassic,
borderType = "2PX",
smoothing = true,
smoothingSpeed = 6, -- 1 - 8
width = 100,
height = 30,
normalColor = { 0.9, 0.1, 0.1 }, --1
altColor = { 0.9, 0.168, 0.43 }, -- for dispatch and meta 2
useMaxColor = true,
maxColor = { 131/255, 0.2, 0.2 }, --max color 3
lowColor = { 141/255, 31/255, 62/255 }, --low color 4
enableColorByPowerType = false,
powerTypeColors = {
["ENERGY"] = ColorArray(PowerBarColor["ENERGY"]),
["FOCUS"] = ColorArray(PowerBarColor["FOCUS"]),
["RAGE"] = ColorArray(PowerBarColor["RAGE"]),
["RUNIC_POWER"] = ColorArray(PowerBarColor["RUNIC_POWER"]),
["LUNAR_POWER"] = ColorArray(PowerBarColor["LUNAR_POWER"]),
["BALANCE"] = ColorArray(PowerBarColor["LUNAR_POWER"]),
["FURY"] = ColorArray(PowerBarColor["FURY"]),
["INSANITY"] = ColorArray(PowerBarColor["INSANITY"]),
["MAELSTROM"] = ColorArray(PowerBarColor["MAELSTROM"]),
["MANA"] = ColorArray(PowerBarColor["MANA"]),
},
textureName = "Glamour7",
fontName = "OpenSans Bold",
fontSize = 25,
textAlign = "END",
textOffsetX = 0,
textOffsetY = 0,
textColor = {1,1,1, isClassic and 0.8 or 0.3},
textOutline = "", -- can be "OUTLINE" or empty string
outOfCombatAlpha = 0,
isVertical = false,
twEnabled = true,
twColor = { 0.15, 0.9, 0.4 }, -- tick window color
twEnabledCappedOnly = true,
twStart = 0.9,
twLength = 0.4,
twCrossfade = 0.15,
twChangeColor = true,
soundName = "none",
soundNameCustom = "Interface\\AddOns\\YourSound.mp3",
soundChannel = "SFX",
}
}
if APILevel <= 3 then
defaults.global.classConfig = {
ROGUE = { "EnergyRogue", "EnergyRogue", "EnergyRogue" },
DRUID = { "ShapeshiftDruidClassic", "ShapeshiftDruidClassic", "ShapeshiftDruidClassic", "ShapeshiftDruidClassic" },
PALADIN = { "Disabled", "Disabled", "Disabled" },
MONK = { "Disabled", "Disabled", "Disabled" },
WARLOCK = { "Disabled", "Disabled", "Disabled" },
DEMONHUNTER = { "Disabled", "Disabled" },
DEATHKNIGHT = { "RunicPower", "RunicPower", "RunicPower" },
MAGE = { "Disabled", "Disabled", "Disabled" },
WARRIOR = { "RageWarriorClassic", "RageWarriorClassic", "RageWarriorClassic" },
SHAMAN = { "Disabled", "Disabled", "Disabled" },
HUNTER = { "Disabled", "Disabled", "Disabled" },
PRIEST = { "Disabled", "Disabled", "Disabled" },
}
end
if APILevel == 4 then
defaults.global.classConfig = {
ROGUE = { "EnergyRogue", "EnergyRogue", "EnergyRogue" },
DRUID = { "ShapeshiftDruid", "ShapeshiftDruid", "ShapeshiftDruid", "ShapeshiftDruid" },
PALADIN = { "Disabled", "Disabled", "Disabled" },
MONK = { "Disabled", "Disabled", "Disabled" },
WARLOCK = { "Disabled", "Disabled", "Disabled" },
DEMONHUNTER = { "Disabled", "Disabled" },
DEATHKNIGHT = { "RunicPower", "RunicPower", "RunicPower" },
MAGE = { "Disabled", "Disabled", "Disabled" },
WARRIOR = { "RageWarrior", "RageWarrior", "RageWarrior" },
SHAMAN = { "Disabled", "Disabled", "Disabled" },
HUNTER = { "Focus", "Focus", "Focus" },
PRIEST = { "Disabled", "Disabled", "Disabled" },
}
end
local normalColor = defaults.profile.normalColor
local lowColor = defaults.profile.lowColor
local maxColor = defaults.profile.maxColor
local free_marks = {}
local pmult = 1
local function pixelperfect(size)
return floor(size/pmult + 0.5)*pmult
end
function NugEnergy.PLAYER_LOGIN(self,event)
_G.NugEnergyDB = _G.NugEnergyDB or {}
self:DoMigrations(NugEnergyDB)
self.db = LibStub("AceDB-3.0"):New("NugEnergyDB", defaults, "Default") -- Create a DB using defaults and using a shared default profile
-- NugEnergyDB = self.db
-- SetupDefaults(NugEnergyDB, defaults)
local res = GetCVar("gxWindowedResolution")
if res then
local w,h = string.match(res, "(%d+)x(%d+)")
pmult = (768/h) / UIParent:GetScale()
end
NugEnergy:UpdateUpvalues()
NugEnergy:Initialize()
SLASH_NUGENERGY1= "/nugenergy"
SLASH_NUGENERGY2= "/nen"
SlashCmdList["NUGENERGY"] = self.SlashCmd
local f = CreateFrame('Frame', nil, SettingsPanel or InterfaceOptionsFrame)
f:SetScript('OnShow', function(self)
self:SetScript('OnShow', nil)
if not NugEnergy.optionsPanel then
NugEnergy.optionsPanel = NugEnergy:CreateGUI()
end
end)
end
function NugEnergy:UpdateUpvalues()
isVertical = NugEnergy.db.profile.isVertical
onlyText = NugEnergy.db.profile.hideBar
spenderFeedback = NugEnergy.db.profile.spenderFeedback
if APILevel <= 2 then
self.ticker.UpdateUpvalues()
end
end
local function FindAura(unit, spellID, filter)
for i=1, 100 do
-- rank will be removed in bfa
local name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, nameplateShowPersonal, auraSpellID = UnitAura(unit, i, filter)
if not name then return nil end
if spellID == auraSpellID then
return name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, nameplateShowPersonal, auraSpellID
end
end
end
local GetPowerBy5 = function(unit)
local p = UnitPower(unit)
local pmax = UnitPowerMax(unit)
-- p, p2, execute, shine, capped, insufficient
return p, math_modf(p/5)*5, nil, nil, p == pmax, nil
end
local RageBarGetPower = function(shineZone, cappedZone, minLimit, throttleText)
return function(unit)
local p = UnitPower(unit, PowerTypeIndex)
local pmax = UnitPowerMax(unit, PowerTypeIndex)
local shine = shineZone and (p >= pmax-shineZone)
-- local state
-- if p >= pmax-10 then state = "CAPPED" end
-- if GetSpecialization() == 3 p < 60 pmax-10
local capped = p >= pmax-cappedZone
local p2 = throttleText and math_modf(p/5)*5
return p, p2, execute, shine, capped, (minLimit and p < minLimit)
end
end
local ManaBarGetPower = function(shineZone, cappedZone, minLimit, throttleText)
return function(unit)
local p = UnitPower(unit, PowerTypeIndex)
local pmax = UnitPowerMax(unit, PowerTypeIndex)
local p2 = math.floor(p/pmax*100)
return p, p2
end
end
function NugEnergy.Initialize(self)
-- self:RegisterEvent("UNIT_POWER_UPDATE")
-- self:RegisterEvent("UNIT_MAXPOWER")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self.PLAYER_REGEN_ENABLED = self.UPDATE_STEALTH
self.PLAYER_REGEN_DISABLED = self.UPDATE_STEALTH
if not self.initialized then
self:Create()
self.eventProxy = CreateFrame("Frame", nil, self)
self.eventProxy:SetScript("OnEvent", function(proxy, event, ...)
return proxy[event](self, event, ...)
end)
self.flags = setmetatable({}, {
__index = function(t,k)
return NugEnergy.db.profile[k]
end
})
-- flags = self.flags
self.initialized = true
self:SetNormalColor()
end
self:RegisterEvent("SPELLS_CHANGED")
self:SPELLS_CHANGED()
self:UPDATE_STEALTH()
self:UpdateEnergy()
return true
end
function NugEnergy.UNIT_POWER_UPDATE(self,event,unit,powertype)
if powertype == PowerFilter then self:UpdateEnergy() end
end
NugEnergy.UNIT_POWER_FREQUENT = NugEnergy.UNIT_POWER_UPDATE
function NugEnergy.UpdateEnergy(self, elapsed)
local p, p2, _, shine, capped, insufficient = GetPower("player")
local wasFull = isFull
isFull = p == GetPowerMax("player", PowerTypeIndex)
if isFull ~= wasFull then
NugEnergy:UPDATE_STEALTH(nil, true)
end
p2 = p2 or p
self.text:SetText(p2)
if not onlyText then
if shine and upvalueInCombat then
-- self.glow:Show()
if not self.glow:IsPlaying() then self.glow:Play() end
else
-- self.glow:Hide()
self.glow:Stop()
end
local c
if capped then
c = maxColor
self.glowanim:SetDuration(0.15)
elseif execute then
c = NugEnergy.db.profile.altColor
self.glowanim:SetDuration(0.3)
elseif insufficient then
c = lowColor
self.glowanim:SetDuration(0.3)
else
c = normalColor
self.glowanim:SetDuration(0.3)
end
self:SetColor(unpack(c))
if APILevel <= 2 and PowerTypeIndex == Enum_PowerType_Energy then
self:ColorTickWindow(capped, c)
end
self:SetValue(p)
--if self.marks[p] then self:PlaySpell(self.marks[p]) end
if self.marks[p] then self.marks[p].shine:Play() end
end
end
NugEnergy.Update = NugEnergy.UpdateEnergy
NugEnergy.__UpdateEnergy = NugEnergy.UpdateEnergy
-- local idleSince = nil
-- function NugEnergy.UpdateEclipseEnergy(self)
-- local p = UnitPower( "player", SPELL_POWER_ECLIPSE )
-- local mp = UnitPowerMax( "player", SPELL_POWER_ECLIPSE )
-- local absp = math.abs(p)
-- self.text:SetText(absp)
-- if not onlyText then
-- if p <= 0 then
-- self:SetStatusBarColor(unpack(lunar))
-- self.bg:SetVertexColor(lunar[1]*.5,lunar[2]*.5,lunar[3]*.5)
-- else
-- self:SetStatusBarColor(unpack(solar))
-- self.bg:SetVertexColor(solar[1]*.5,solar[2]*.5,solar[3]*.5)
-- end
-- self:SetValue(absp)
-- end
-- if p == 0 and not UnitAffectingCombat("player") then
-- if not idleSince then
-- idleSince = GetTime()
-- else
-- if idleSince < GetTime()-3 then
-- self:Hide()
-- idleSince = nil
-- end
-- end
-- else
-- idleSince = nil
-- end
-- end
function NugEnergy:Disable()
PowerFilter = nil
PowerTypeIndex = nil
self:UnregisterEvent("UNIT_POWER_UPDATE")
self:UnregisterEvent("UNIT_MAXPOWER")
self:UnregisterEvent("PLAYER_REGEN_DISABLED")
self:Hide()
end
function NugEnergy.UNIT_HEALTH(self, event, unit)
if unit ~= "target" then return end
local uhm = UnitHealthMax(unit)
if uhm == 0 then uhm = 1 end
if execute_range then
execute = UnitHealth(unit)/uhm < execute_range
else
execute = false
end
self:UpdateEnergy()
end
function NugEnergy.PLAYER_TARGET_CHANGED(self,event)
if UnitExists('target') then
self.UNIT_HEALTH(self,event,"target")
end
end
-- function NugEnergy.UNIT_MAXPOWER(self)
-- self:SetMinMaxValues(0,GetPowerMax("player", PowerTypeIndex))
-- if not self.marks then return end
-- for _, mark in pairs(self.marks) do
-- mark:Update()
-- end
-- end
local fader = CreateFrame("Frame", nil, NugEnergy)
NugEnergy.fader = fader
local HideTimer = function(self, time)
self.OnUpdateCounter = (self.OnUpdateCounter or 0) + time
if self.OnUpdateCounter < fadeAfter then return end
local nen = self:GetParent()
local p = fadeTime - ((self.OnUpdateCounter - fadeAfter) / fadeTime)
-- if p < 0 then p = 0 end
-- local ooca = NugEnergy.db.profile.outOfCombatAlpha
-- local a = ooca + ((1 - ooca) * p)
local pA = NugEnergy.db.profile.outOfCombatAlpha
local rA = 1 - NugEnergy.db.profile.outOfCombatAlpha
local a = pA + (p*rA)
if a < 0 then a = 0 end
nen:SetAlpha(a)
if self.OnUpdateCounter >= fadeAfter + fadeTime then
if nen:GetAlpha() <= 0.03 then
nen:Hide()
end
NugEnergy:StopHiding()
self.OnUpdateCounter = 0
end
end
function NugEnergy:StartHiding()
self:Show()
if (not self.hiding) then
fader:SetScript("OnUpdate", HideTimer)
fader.OnUpdateCounter = 0
self.hiding = true
end
end
function NugEnergy:StopHiding()
-- if self.hiding then
fader:SetScript("OnUpdate", nil)
fader.OnUpdateCounter = 0
self.hiding = false
-- end
end
function NugEnergy.UPDATE_STEALTH(self, event, fromUpdateEnergy)
self:UpdateVisibility()
end
function NugEnergy:UpdateVisibility()
if self.isDisabled then self:Hide(); return end
local inCombat = UnitAffectingCombat("player")
upvalueInCombat = inCombat
if (inCombat or
((class == "ROGUE" or class == "DRUID") and IsStealthed() and (self.ticker.isEnabled or (shouldBeFull and not isFull))) or
ForcedToShow)
and PowerFilter
then
-- self:UNIT_MAXPOWER()
self:UpdateEnergy()
self:StopHiding()
self:SetAlpha(1)
self:Show()
elseif doFadeOut and self:IsVisible() and self:GetAlpha() > NugEnergy.db.profile.outOfCombatAlpha and PowerFilter then
self:StartHiding()
elseif NugEnergy.db.profile.outOfCombatAlpha > 0 and PowerFilter then
self:SetAlpha(NugEnergy.db.profile.outOfCombatAlpha)
self:Show()
else
self:Hide()
end
end
function NugEnergy.ReconfigureMarks(self)
-- local spec_marks = NugEnergy.db.profile_Character.marks[GetSpecialization() or 0]
-- for at, frame in pairs(NugEnergy.marks) do
-- frame:Hide()
-- table.insert(free_marks, frame)
-- NugEnergy.marks[at] = nil
-- -- print("Hiding", at)
-- end
-- for at in pairs(spec_marks) do
-- -- print("Showing", at)
-- NugEnergy:CreateMark(at)
-- end
-- -- NugEnergy:RealignMarks()
end
local function rgb2hsv (r, g, b)
local rabs, gabs, babs, rr, gg, bb, h, s, v, diff, diffc, percentRoundFn
rabs = r
gabs = g
babs = b
v = math.max(rabs, gabs, babs)
diff = v - math.min(rabs, gabs, babs);
diffc = function(c) return (v - c) / 6 / diff + 1 / 2 end
-- percentRoundFn = function(num) return math.floor(num * 100) / 100 end
if (diff == 0) then
h = 0
s = 0
else
s = diff / v;
rr = diffc(rabs);
gg = diffc(gabs);
bb = diffc(babs);
if (rabs == v) then
h = bb - gg;
elseif (gabs == v) then
h = (1 / 3) + rr - bb;
elseif (babs == v) then
h = (2 / 3) + gg - rr;
end
if (h < 0) then
h = h + 1;
elseif (h > 1) then
h = h - 1;
end
end
return h, s, v
end
local function hsv2rgb(h,s,v)
local r,g,b
local i = math.floor(h * 6);
local f = h * 6 - i;
local p = v * (1 - s);
local q = v * (1 - f * s);
local t = v * (1 - (1 - f) * s);
local rem = i % 6
if rem == 0 then
r = v; g = t; b = p;
elseif rem == 1 then
r = q; g = v; b = p;
elseif rem == 2 then
r = p; g = v; b = t;
elseif rem == 3 then
r = p; g = q; b = v;
elseif rem == 4 then
r = t; g = p; b = v;
elseif rem == 5 then
r = v; g = p; b = q;
end
return r,g,b
end
local function hsv_shift(src, hm,sm,vm)
local r,g,b = unpack(src)
local h,s,v = rgb2hsv(r,g,b)
-- rollover on hue
local h2 = h + hm
if h2 < 0 then h2 = h2 + 1 end
if h2 > 1 then h2 = h2 - 1 end
local s2 = s + sm
if s2 < 0 then s2 = 0 end
if s2 > 1 then s2 = 1 end
local v2 = v + vm
if v2 < 0 then v2 = 0 end
if v2 > 1 then v2 = 1 end
local r2,g2,b2 = hsv2rgb(h2, s2, v2)
return r2, g2, b2
end
local colorOverride = nil
-- local cor, cog, cob = 1,1,1
function NugEnergy:DisableColorOverride()
colorOverride = nil
end
function NugEnergy:SetColorOverride(r,g,b)
colorOverride = {r,g,b}
self:SetNormalColor()
end
function NugEnergy:SetNormalColor()
if colorOverride then
normalColor = colorOverride
lowColor = { hsv_shift(normalColor, -0.07, -0.22, -0.3) }
maxColor = { hsv_shift(normalColor, 0, -0.3, -0.4) }
elseif NugEnergy.db.profile.enableColorByPowerType and PowerFilter then
normalColor = NugEnergy.db.profile.powerTypeColors[PowerFilter]
lowColor = { hsv_shift(normalColor, -0.07, -0.22, -0.3) }
maxColor = { hsv_shift(normalColor, 0, -0.3, -0.4) }
else
normalColor = NugEnergy.db.profile.normalColor
lowColor = NugEnergy.db.profile.lowColor
maxColor = NugEnergy.db.profile.maxColor
end
if not NugEnergy.db.profile.useMaxColor then
maxColor = normalColor
end
end
function NugEnergy:Resize()
local f = self
local width = NugEnergy.db.profile.width
local height = NugEnergy.db.profile.height
local text = f.text
if isVertical then
height, width = width, height
f:SetWidth(width)
f:SetHeight(height)
f:SetOrientation("VERTICAL")
if not onlyText then
f.spark:ClearAllPoints()
f.spark:SetWidth(width)
f.spark:SetHeight(width*2)
f.spark:SetTexCoord(1,1,0,1,1,0,0,0)
end
text:ClearAllPoints()
local textAlign = NugEnergy.db.profile.textAlign
if textAlign == "END" then
text:SetPoint("TOP", f, "TOP", 0+NugEnergy.db.profile.textOffsetX, 0+NugEnergy.db.profile.textOffsetY)
text:SetJustifyV("TOP")
elseif textAlign == "CENTER" then
text:SetPoint("CENTER", f, "CENTER", 0+NugEnergy.db.profile.textOffsetX, 0+NugEnergy.db.profile.textOffsetY)
text:SetJustifyV("MIDDLE")
elseif textAlign == "START" then
text:SetPoint("BOTTOM", f, "BOTTOM", 0+NugEnergy.db.profile.textOffsetX, 0+NugEnergy.db.profile.textOffsetY)
text:SetJustifyV("BOTTOM")
end
text:SetJustifyH("CENTER")
else
f:SetWidth(width)
f:SetHeight(height)
f:SetOrientation("HORIZONTAL")
if not onlyText then
f.spark:ClearAllPoints()
f.spark:SetTexCoord(0,1,0,1)
f.spark:SetWidth(height*2)
f.spark:SetHeight(height)
end
text:ClearAllPoints()
local textAlign = NugEnergy.db.profile.textAlign
if textAlign == "END" then
text:SetPoint("RIGHT", f, "RIGHT", -7+NugEnergy.db.profile.textOffsetX, -2+NugEnergy.db.profile.textOffsetY)
text:SetJustifyH("RIGHT")
elseif textAlign == "CENTER" then
text:SetPoint("CENTER", f, "CENTER", 0+NugEnergy.db.profile.textOffsetX, -2+NugEnergy.db.profile.textOffsetY)
text:SetJustifyH("CENTER")
elseif textAlign == "START" then
text:SetPoint("LEFT", f, "LEFT", 7+NugEnergy.db.profile.textOffsetX, -2+NugEnergy.db.profile.textOffsetY)
text:SetJustifyH("LEFT")
end
text:SetJustifyV("MIDDLE")
end
if not onlyText then
f.spentBar:ClearAllPoints()
self:UpdateEnergy()
local tex = getStatusbar()
f:SetStatusBarTexture(tex)
f.bg:SetTexture(tex)
f.spentBar:SetTexture(tex)
f.spentBar:SetWidth(width)
f.spentBar:SetHeight(height)
end
end
function NugEnergy:ResizeText()
local text = self.text
local font = getFont()
local fontSize = NugEnergy.db.profile.fontSize
text:SetFont(font,fontSize, NugEnergy.db.profile.textOutline)
local r,g,b,a = unpack(NugEnergy.db.profile.textColor)
text:SetTextColor(r,g,b)
text:SetAlpha(a)
if NugEnergy.db.profile.hideText then
text:Hide()
else
text:Show()
end
end
local SparkSetValue = function(self, v)
local min, max = self:GetMinMaxValues()
local total = max-min
local p
if total == 0 then
p = 0
else
p = (v-min)/(max-min)
if p > 1 then p = 1 end
end
local len = p*self:GetWidth()
self.spark:SetPoint("CENTER", self, "LEFT", len, 0)
return self:NormalSetValue(v)
end
function NugEnergy:UpdateFrameBorder()
local borderType = NugEnergy.db.profile.borderType
if self.border then self.border:Hide() end
if self.backdrop then self.backdrop:Hide() end
if borderType == "2PX" then
self.backdrop = self.backdrop or self:CreateTexture(nil, "BACKGROUND", nil, -2)
local backdrop = self.backdrop
local offset = pixelperfect(2)
backdrop:SetTexture("Interface\\BUTTONS\\WHITE8X8")
backdrop:SetVertexColor(0,0,0, 0.5)
backdrop:SetPoint("TOPLEFT", -offset, offset)
backdrop:SetPoint("BOTTOMRIGHT", offset, -offset)
backdrop:Show()
elseif borderType == "1PX" then
self.backdrop = self.backdrop or self:CreateTexture(nil, "BACKGROUND", nil, -2)
local backdrop = self.backdrop
local offset = pixelperfect(1)
backdrop:SetTexture("Interface\\BUTTONS\\WHITE8X8")
backdrop:SetVertexColor(0,0,0, 1)
backdrop:SetPoint("TOPLEFT", -offset, offset)
backdrop:SetPoint("BOTTOMRIGHT", offset, -offset)
backdrop:Show()
elseif borderType == "TOOLTIP" then
self.border = self.border or CreateFrame("Frame", nil, self, BackdropTemplateMixin and "BackdropTemplate")
local border = self.border
border:SetPoint("TOPLEFT", -3, 3)
border:SetPoint("BOTTOMRIGHT", 3, -3)
border:SetBackdrop({
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16,
-- insets = {left = -5, right = -5, top = -5, bottom = -5},
})
border:SetBackdropBorderColor(0.55,0.55,0.55)
border:Show()
elseif borderType == "STATUSBAR" then
self.border = self.border or CreateFrame("Frame", nil, self, BackdropTemplateMixin and "BackdropTemplate")
local border = self.border
border:SetPoint("TOPLEFT", -2, 3)
border:SetPoint("BOTTOMRIGHT", 2, -3)
border:SetBackdrop({
edgeFile = "Interface\\AddOns\\NugEnergy\\border_statusbar", edgeSize = 8, tileEdge = false,
})
border:SetBackdropBorderColor(1,1,1)
border:Show()
elseif borderType == "3PX" then
self.border = self.border or CreateFrame("Frame", nil, self, BackdropTemplateMixin and "BackdropTemplate")
local border = self.border
border:SetPoint("TOPLEFT", -2, 2)
border:SetPoint("BOTTOMRIGHT", 2, -2)
border:SetBackdrop({
edgeFile = "Interface\\AddOns\\NugEnergy\\border_3px", edgeSize = 8, tileEdge = false,
})
border:SetBackdropBorderColor(0.4,0.4,0.4)
border:Show()
end
end
function NugEnergy.Create(self)
local f = self
local width = NugEnergy.db.profile.width
local height = NugEnergy.db.profile.height
if isVertical then
height, width = width, height
f:SetOrientation("VERTICAL")
end
f:SetWidth(width)
f:SetHeight(height)
if not onlyText then
self:UpdateFrameBorder()
local tex = getStatusbar()
f:SetStatusBarTexture(tex)
-- f:GetStatusBarTexture():SetDrawLayer("ARTWORK", 3)
local bg = f:CreateTexture(nil,"BACKGROUND")
bg:SetTexture(tex)
bg:SetAllPoints(f)
f.bg = bg
local spark = f:CreateTexture(nil, "ARTWORK", nil, 4)
spark:SetBlendMode("ADD")
spark:SetTexture([[Interface\AddOns\NugEnergy\spark.tga]])
if isVertical then
spark:SetSize(f:GetWidth(), f:GetWidth()*2)
spark:SetTexCoord(1,1,0,1,1,0,0,0)
else
spark:SetSize(f:GetHeight()*2, f:GetHeight())
end
spark:SetPoint("CENTER", f, "TOP",0,0)
f.spark = spark
local spentBar = f:CreateTexture(nil, "ARTWORK", nil, 7)
-- spentBar:SetTexture([[Interface\AddOns\NugEnergy\white.tga]])
spentBar:SetTexture(tex)
-- spentBar:SetVertexColor(unpack(color))
spentBar:SetHeight(height*1)
spentBar:SetWidth(width)
spentBar.SetColor = function(self, r1,g1,b1)
local r = math.min(1, r1 + 0.15)
local g = math.min(1, g1 + 0.15)
local b = math.min(1, b1 + 0.15)
self:SetVertexColor(r,g,b)
end
-- spentBar:SetBlendMode("ADD")
spentBar:SetPoint("LEFT", f, "LEFT",0,0)
spentBar:SetAlpha(0)
f.spentBar = spentBar
f.SetColor = function(self, r,g,b,a)
self:SetStatusBarColor(r,g,b,a)
self.bg:SetVertexColor(r*0.3,g*0.3,b*0.3)
self.spark:SetVertexColor(r,g,b)
-- self.spentBar:SetColor(r,g,b)
self.spentBar:SetVertexColor(r,g,b)
end
local color = NugEnergy.db.profile.normalColor
f:SetColor(unpack(color))
f.OriginalSetValue = f.OriginalSetValue or f.SetValue
self:UpdateBarEffects()
local trail = spentBar:CreateAnimationGroup()
-- local sa1 = trail:CreateAnimation("Alpha")
-- sa1:SetFromAlpha(0)
-- sa1:SetToAlpha(1)
-- sa1:SetSmoothing("OUT")
-- sa1:SetDuration(0.1)
-- sa1:SetOrder(1)
local sa2 = trail:CreateAnimation("Alpha")
sa2:SetFromAlpha(1)
sa2:SetToAlpha(0)
-- sa2:SetSmoothing("IN")
sa2:SetDuration(0.6)
sa2:SetOrder(1)
-- local ta1 = trail:CreateAnimation("Translation")
-- ta1:SetOffset(0, 8)
-- ta1:SetSmoothing("OUT")
-- ta1:SetDuration(0.2)
-- ta1:SetOrder(1)
-- local ta1 = trail:CreateAnimation("Translation")
-- ta1:SetOffset(0, -38)
-- ta1:SetSmoothing("IN")
-- ta1:SetDuration(0.20)
-- ta1:SetOrder(2)
f.trail = trail
f.marks = {}
-- f:UNIT_MAXPOWER()
-- NEW MARKS
-- for p in pairs(NugEnergy.db.profile_Character.marks) do
-- self:CreateMark(p)
-- end
NugEnergy:ReconfigureMarks()
-- local glow = f:CreateTexture(nil,"OVERLAY")
-- glow:SetAllPoints(f)
-- glow:SetTexture([[Interface\AddOns\NugEnergy\white.tga]])
-- glow:SetAlpha(0)
-- local ag = glow:CreateAnimationGroup()
-- ag:SetLooping("BOUNCE")
-- local a1 = ag:CreateAnimation("Alpha")
-- a1:SetChange(0.1)
-- a1:SetDuration(0.2)
-- a1:SetOrder(1)
local at = CreateFrame("Frame", nil, f, BackdropTemplateMixin and "BackdropTemplate")
local border_backdrop = {
edgeFile = "Interface\\Addons\\NugEnergy\\glow", tileEdge = true, edgeSize = 16,
-- insets = {left = -16, right = -16, top = -16, bottom = -16},
}
at:SetBackdrop(border_backdrop)
at:SetSize(64, 64)
at:SetFrameStrata("BACKGROUND")
at:SetBackdropBorderColor(1,0,0)
at:SetPoint("TOPLEFT", -16, 16)
at:SetPoint("BOTTOMRIGHT", 16, -16)
at:SetAlpha(0)
f.alertFrame = at
local sag = at:CreateAnimationGroup()
sag:SetLooping("BOUNCE")
local sa1 = sag:CreateAnimation("Alpha")
sa1:SetFromAlpha(0)
sa1:SetToAlpha(1)
sa1:SetDuration(0.3)
sa1:SetOrder(1)
-- local sa2 = sag:CreateAnimation("Alpha")
-- sa2:SetChange(-1)
-- sa2:SetDuration(0.5)
-- sa2:SetSmoothing("OUT")
-- sa2:SetOrder(2)
--
-- f.shine = sag
self.glow = sag
self.glowanim = sa1
-- self.glowtex = glow
--~ -- MARKS
--~ local f2 = CreateFrame("Frame",nil,f)
--~ f2:SetWidth(height)--*.8
--~ f2:SetHeight(height)
--~ f2:SetBackdrop(backdrop)
--~ f2:SetBackdropColor(0,0,0,0.5)
--~ f2:SetAlpha(0)
--~ --f2:SetFrameStrata("BACKGROUND") --fall behind energy bar
--~ local icon = f2:CreateTexture(nil,"BACKGROUND")
--~ icon:SetTexCoord(.07, .93, .07, .93)
--~ icon:SetAllPoints(f2)
--~
--~ --local sht = f2:CreateTexture(nil,"OVERLAY")
--~ --sht:SetTexture([[Interface\AddOns\NugEnergy\white.tga]])
--~ --sht:SetAlpha(0.3)
--~ --sht:SetAllPoints(f)
--~ f2:SetPoint("RIGHT",f,"LEFT",-2,0)
--~
--~ local ag = f2:CreateAnimationGroup()
--~ local a1 = ag:CreateAnimation("Alpha")
--~ a1:SetChange(1)
--~ a1:SetDuration(0.3)
--~ a1:SetOrder(1)
--~
--~ local a2 = ag:CreateAnimation("Alpha")
--~ a2:SetChange(-1)
--~ a2:SetDuration(0.7)
--~ a2:SetOrder(2)
--~
--~ f.icon = icon
--~ f.ag = ag
--~
--~ f.PlaySpell = function(self,spellID)
--~ self.icon:SetTexture(select(3,GetSpellInfo(spellID)))
--~ self.ag:Play()