-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.lua
1239 lines (1110 loc) · 40.2 KB
/
Core.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 cPointDisplay = LibStub("AceAddon-3.0"):NewAddon("cPointDisplay", "AceConsole-3.0", "AceEvent-3.0", "AceBucket-3.0")
local LSM = LibStub("LibSharedMedia-3.0")
local db
cPointDisplay.Types = {
["GENERAL"] = {
name = "General",
points = {
[1] = { name = "Combo Points", id = "cp", barcount = 5, fullcount = 5 },
[2] = { name = "Combo Points with Deeper Stratagem", id = "cp6", barcount = 6, fullcount = 6 },
}
},
["PALADIN"] = {
name = "Paladin",
points = {
[1] = { name = "Holy Power", id = "hp", barcount = 5, fullcount = 5 },
}
},
["WARLOCK"] = {
name = "Warlock",
points = {
[1] = { name = "Soul Shards", id = "ss", barcount = 5, fullcount = 5 },
[2] = { name = "Soul Shards Precise", id = "ssf", barcount = 5, fullcount = 5 },
}
},
["MAGE"] = {
name = "Mage",
points = {
[1] = { name = "Arcane Charges", id = "ac", barcount = 4, fullcount = 4},
[2] = { name = "Icicles", id = "ic", barcount = 5, fullcount = 5}
}
},
["MONK"] = {
name = "Monk",
points = {
[1] = { name = "Chi", id = "c5", barcount = 5, fullcount = 5 },
[2] = { name = "Chi with Ascension", id = "c6", barcount = 6, fullcount = 6 }
}
},
["SHAMAN"] = {
name = "Shaman",
points = {
[1] = { name = "Maelstrom Weapon", id = "mw", barcount = 10, fullcount = 5 }
}
},
["DEMONHUNTER"] = {
name = "Demon Hunter",
points = {
[1] = { name = "Soul Fragments", id = "sf", barcount = 5, fullcount = 5 }
}
}
}
local Types = cPointDisplay.Types
---- Spell Info table
local SpellInfo = {
["si"] = nil,
["bs"] = nil,
["lus"] = nil,
["lac"] = nil,
["al"] = nil,
["rsa"] = nil,
["fe"] = nil,
["ab"] = nil,
["ff"] = nil,
["sz"] = nil,
["vm"] = nil,
["eva"] = nil,
["deva"] = nil,
["ser"] = nil,
["bg"] = {[1] = nil, [2] = nil, [3] = nil},
["ant"] = nil,
["mw"] = nil,
["ls"] = nil,
["tw"] = nil,
["ws"] = nil,
["mco"] = nil,
["ts"] = nil,
["mc"] = nil,
["sa"] = nil,
["tb"] = nil,
}
---- Defaults
local defaults = {
profile = {
updatespeed = 8,
classcolor = {
enabled = false,
bg = {
empty = 0.15,
normal = 0.7,
max = 1,
},
border = {
empty = 0,
normal = 0,
max = 0,
},
spark = {
normal = 0.8,
max = 1,
},
},
-- CLASS/ID
["*"] = {
types = {
-- Point Display type
["*"] = {
enabled = true,
configmode = {
enabled = false,
count = 2,
},
general = {
hideui = false,
hideempty = false,
hidein = {
vehicle = false,
spec = 1,
},
direction = {
vertical = false,
reverse = false,
},
showatzero = false,
},
position = {
parent = "UIParent",
anchorto = "CENTER",
anchorfrom = "CENTER",
x = 0,
y = 0,
framelevel = {
strata = "MEDIUM",
level = 2,
},
},
bgpanel = {
enabled = false,
size = {
width = 150,
height = 12,
},
bg = {
texture = "Solid",
color = {r = 0.37, g = 0.37, b = 0.37, a = 1},
},
border = {
texture = "Solid",
edgesize = 1,
inset = 0,
color = {r = 0, g = 0, b = 0, a = 1},
},
},
bars = {
["*"] = {
position = {
gap = -1,
xofs = 0,
yofs = 0,
},
size = {
width = 25,
height = 8,
},
bg = {
empty = {
texture = "Solid",
color = {r = 0.14, g = 0.14, b = 0.14, a = 1},
},
full = {
texture = "Solid",
color = {r = 0.7, g = 0.7, b = 0.7, a = 1},
maxcolor = {r = 1, g = 1, b = 1, a = 1},
},
},
border = {
empty = {
texture = "Solid",
edgesize = 1,
inset = 0,
color = {r = 0, g = 0, b = 0, a = 1},
},
full = {
texture = "Solid",
edgesize = 1,
inset = 0,
color = {r = 0, g = 0, b = 0, a = 1},
maxcolor = {r = 0, g = 0, b = 0, a = 1},
},
},
spark = {
enabled = false,
position = {
x = 0,
y = 0,
},
size = {
width = 32,
height = 18,
},
bg = {
texture = "",
color = {r = 0.8, g = 0.8, b = 0.8, a = 1},
maxcolor = {r = 1, g = 1, b = 1, a = 1},
},
},
},
},
combatfader = {
enabled = false,
opacity = {
incombat = 1,
hurt = .7,
target = .7,
outofcombat = .3,
},
},
},
},
},
},
}
-- Point Display tables
local Frames = {}
local Borders = {}
local BG = {}
-- Points
local Points = {}
local PointsChanged = {}
local ClassColors
local ClassColorBarTable = {}
local LoggedIn = false
local PlayerClass
local PlayerSpec
local ValidClasses
-- Combat Fader
local CFFrame = CreateFrame("Frame")
local FadeTime = 0.25
local CFStatus = nil
-- Power 'Full' check
local power_check = {
MANA = function()
return UnitPower("player", 0) < UnitPowerMax("player", 0)
end,
RAGE = function()
return UnitPower("player", 1) > 0
end,
ENERGY = function()
return UnitPower("player", 3) < UnitPowerMax("player", 3)
end,
RUNICPOWER = function()
return UnitPower("player", 6) > 0
end,
}
-- Fade frame
local function FadeIt(self, NewOpacity)
local CurrentOpacity = self:GetAlpha()
if NewOpacity > CurrentOpacity then
UIFrameFadeIn(self, FadeTime, CurrentOpacity, NewOpacity)
elseif NewOpacity < CurrentOpacity then
UIFrameFadeOut(self, FadeTime, CurrentOpacity, NewOpacity)
end
end
-- Determine new opacity values for frames
function cPointDisplay:FadeFrames()
for ic,vc in pairs(Types) do
for it,vt in ipairs(Types[ic].points) do
local NewOpacity
local tid = Types[ic].points[it].id
-- Retrieve opacity/visibility for current status
NewOpacity = 1
if db[ic].types[tid].combatfader.enabled then
if CFStatus == "DISABLED" then
NewOpacity = 1
elseif CFStatus == "INCOMBAT" then
NewOpacity = db[ic].types[tid].combatfader.opacity.incombat
elseif CFStatus == "TARGET" then
NewOpacity = db[ic].types[tid].combatfader.opacity.target
elseif CFStatus == "HURT" then
NewOpacity = db[ic].types[tid].combatfader.opacity.hurt
elseif CFStatus == "OUTOFCOMBAT" then
NewOpacity = db[ic].types[tid].combatfader.opacity.outofcombat
end
-- Fade Frame
FadeIt(Frames[ic][tid].bgpanel.frame, NewOpacity)
else
-- Combat Fader disabled for this frame
if Frames[ic][tid].bgpanel.frame:GetAlpha() < 1 then
FadeIt(Frames[ic][tid].bgpanel.frame, NewOpacity)
end
end
end
end
cPointDisplay:UpdatePointDisplay("ENABLE")
end
function cPointDisplay:UpdateCFStatus()
local OldStatus = CFStatus
-- Combat Fader based on status
if UnitAffectingCombat("player") then
CFStatus = "INCOMBAT"
elseif UnitExists("target") then
CFStatus = "TARGET"
elseif UnitHealth("player") < UnitHealthMax("player") then
CFStatus = "HURT"
else
local _, power_token = UnitPowerType("player")
local func = power_check[power_token]
if func and func() then
CFStatus = "HURT"
else
CFStatus = "OUTOFCOMBAT"
end
end
if CFStatus ~= OldStatus then cPointDisplay:FadeFrames() end
end
function cPointDisplay:UpdateCombatFader()
CFStatus = nil
cPointDisplay:UpdateCFStatus()
end
-- On combat state change
function cPointDisplay:CombatFaderCombatState()
-- If in combat, then don't worry about health/power events
if UnitAffectingCombat("player") then
CFFrame:UnregisterEvent("UNIT_HEALTH")
CFFrame:UnregisterEvent("UNIT_POWER_UPDATE")
CFFrame:UnregisterEvent("UNIT_DISPLAYPOWER")
else
CFFrame:RegisterEvent("UNIT_HEALTH")
CFFrame:RegisterEvent("UNIT_POWER_UPDATE")
CFFrame:RegisterEvent("UNIT_DISPLAYPOWER")
end
end
-- Register events for Combat Fader status
function cPointDisplay:UpdateCombatFaderEnabled()
CFFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
CFFrame:RegisterEvent("PLAYER_TARGET_CHANGED")
CFFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
CFFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
CFFrame:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_REGEN_ENABLED" or event == "PLAYER_REGEN_DISABLED" then
cPointDisplay:CombatFaderCombatState()
cPointDisplay:UpdateCFStatus()
elseif event == "UNIT_HEALTH" or event == "UNIT_POWER_UPDATE" or event == "UNIT_DISPLAYPOWER" then
local unit = ...
if unit == "player" then
cPointDisplay:UpdateCFStatus()
end
elseif event == "PLAYER_TARGET_CHANGED" then
cPointDisplay:UpdateCFStatus()
elseif event == "PLAYER_ENTERING_WORLD" then
cPointDisplay:CombatFaderCombatState()
cPointDisplay:UpdateCombatFader()
end
end)
cPointDisplay:UpdateCombatFader()
cPointDisplay:FadeFrames()
end
local function SetEmptyBarTextures(ic, it, tid, i)
local cc = ClassColorBarTable[ic]
local dbc = db[ic].types[tid].bars[i]
Frames[ic][tid].bars[i].bg:SetTexture(BG[ic][tid].bars[i].empty)
Frames[ic][tid].bars[i].border:SetBackdrop({bgFile = "", edgeFile = Borders[ic][tid].bars[i].empty, edgeSize = dbc.border.empty.edgesize, tile = false, tileSize = 0, insets = {left = 0, right = 0, top = 0, bottom = 0}})
Frames[ic][tid].bars[i].border:SetHeight(dbc.size.height - dbc.border.empty.inset)
Frames[ic][tid].bars[i].border:SetWidth(dbc.size.width - dbc.border.empty.inset)
if db.classcolor.enabled then
Frames[ic][tid].bars[i].bg:SetVertexColor(cc.bg.empty.r, cc.bg.empty.g, cc.bg.empty.b, dbc.bg.empty.color.a)
Frames[ic][tid].bars[i].border:SetBackdropBorderColor(cc.border.empty.r, cc.border.empty.g, cc.border.empty.b, dbc.border.empty.color.a)
else
Frames[ic][tid].bars[i].bg:SetVertexColor(dbc.bg.empty.color.r, dbc.bg.empty.color.g, dbc.bg.empty.color.b, dbc.bg.empty.color.a)
Frames[ic][tid].bars[i].border:SetBackdropBorderColor(dbc.border.empty.color.r, dbc.border.empty.color.g, dbc.border.empty.color.b, dbc.border.empty.color.a)
end
end
local function SetPartialBarTextures(ic, it, tid, i, partial)
local cc = ClassColorBarTable[ic]
local dbc = db[ic].types[tid].bars[i]
local toColorize = partial
for j = 0, 8 do
Frames[ic][tid].bars[i].subbars[j].frame:Show()
-- BG
Frames[ic][tid].bars[i].subbars[j].bg:SetTexture(BG[ic][tid].bars[i].full)
-- Colors
if j < toColorize then
Frames[ic][tid].bars[i].subbars[j].frame:Show()
if db.classcolor.enabled then Frames[ic][tid].bars[i].subbars[j].bg:SetVertexColor(cc.bg.normal.r, cc.bg.normal.g, cc.bg.normal.b, dbc.bg.full.color.a)
else Frames[ic][tid].bars[i].subbars[j].bg:SetVertexColor(dbc.bg.full.color.r, dbc.bg.full.color.g, dbc.bg.full.color.b, dbc.bg.full.color.a) end
else
Frames[ic][tid].bars[i].subbars[j].frame:Hide()
if db.classcolor.enabled then Frames[ic][tid].bars[i].subbars[j].bg:SetVertexColor(cc.bg.max.r, cc.bg.max.g, cc.bg.max.b, dbc.bg.full.maxcolor.a)
else Frames[ic][tid].bars[i].subbars[j].bg:SetVertexColor(dbc.bg.full.maxcolor.r, dbc.bg.full.maxcolor.g, dbc.bg.full.maxcolor.b, dbc.bg.full.maxcolor.a) end
end
end
end
local function SetPointBarTextures(ic, it, tid, i, points)
local cc = ClassColorBarTable[ic]
local dbc = db[ic].types[tid].bars[i]
-- BG
Frames[ic][tid].bars[i].bg:SetTexture(BG[ic][tid].bars[i].full)
-- Border
Frames[ic][tid].bars[i].border:SetBackdrop({bgFile = "", edgeFile = Borders[ic][tid].bars[i].full, edgeSize = dbc.border.full.edgesize, tile = false, tileSize = 0, insets = {left = 0, right = 0, top = 0, bottom = 0}})
Frames[ic][tid].bars[i].border:SetHeight(dbc.size.height - dbc.border.full.inset)
Frames[ic][tid].bars[i].border:SetWidth(dbc.size.width - dbc.border.full.inset)
-- Colors
if points < Types[ic].points[it].fullcount then
if db.classcolor.enabled then
Frames[ic][tid].bars[i].bg:SetVertexColor(cc.bg.normal.r, cc.bg.normal.g, cc.bg.normal.b, dbc.bg.full.color.a)
Frames[ic][tid].bars[i].border:SetBackdropBorderColor(cc.border.normal.r, cc.border.normal.g, cc.border.normal.b, dbc.border.full.color.a)
else
Frames[ic][tid].bars[i].bg:SetVertexColor(dbc.bg.full.color.r, dbc.bg.full.color.g, dbc.bg.full.color.b, dbc.bg.full.color.a)
Frames[ic][tid].bars[i].border:SetBackdropBorderColor(dbc.border.full.color.r, dbc.border.full.color.g, dbc.border.full.color.b, dbc.border.full.color.a)
end
else
if db.classcolor.enabled then
Frames[ic][tid].bars[i].bg:SetVertexColor(cc.bg.max.r, cc.bg.max.g, cc.bg.max.b, dbc.bg.full.maxcolor.a)
Frames[ic][tid].bars[i].border:SetBackdropBorderColor(cc.border.max.r, cc.border.max.g, cc.border.max.b, dbc.bg.full.maxcolor.a)
else
Frames[ic][tid].bars[i].bg:SetVertexColor(dbc.bg.full.maxcolor.r, dbc.bg.full.maxcolor.g, dbc.bg.full.maxcolor.b, dbc.bg.full.maxcolor.a)
Frames[ic][tid].bars[i].border:SetBackdropBorderColor(dbc.border.full.maxcolor.r, dbc.border.full.maxcolor.g, dbc.border.full.maxcolor.b, dbc.border.full.maxcolor.a)
end
end
-- Spark
if dbc.spark.enabled then
Frames[ic][tid].bars[i].spark.frame:Show()
Frames[ic][tid].bars[i].spark.bg:SetTexture(BG[ic][tid].bars[i].spark)
if points < Types[ic].points[it].barcount then
-- Normal color
if db.classcolor.enabled then
Frames[ic][tid].bars[i].spark.bg:SetVertexColor(cc.spark.normal.r, cc.spark.normal.g, cc.spark.normal.b, dbc.spark.bg.color.a)
else
Frames[ic][tid].bars[i].spark.bg:SetVertexColor(dbc.spark.bg.color.r, dbc.spark.bg.color.g, dbc.spark.bg.color.b, dbc.spark.bg.color.a)
end
else
-- Max color
if db.classcolor.enabled then
Frames[ic][tid].bars[i].spark.bg:SetVertexColor(cc.spark.max.r, cc.spark.max.g, cc.spark.max.b, dbc.spark.bg.maxcolor.a)
else
Frames[ic][tid].bars[i].spark.bg:SetVertexColor(dbc.spark.bg.maxcolor.r, dbc.spark.bg.maxcolor.g, dbc.spark.bg.maxcolor.b, dbc.spark.bg.maxcolor.a)
end
end
else
Frames[ic][tid].bars[i].spark.frame:Hide()
end
end
-- Update Point Bars
local function HideAtIndex(ic, it, tid, i)
if db[ic].types[tid].general.hideempty then
-- Hide "empty" bar
Frames[ic][tid].bars[i].frame:Hide()
else
-- Show bar and set textures to "Empty"
Frames[ic][tid].bars[i].frame:Show()
SetEmptyBarTextures(ic, it, tid, i)
end
-- Hide the "Spark"
Frames[ic][tid].bars[i].spark.frame:Hide()
if #Frames[ic][tid].bars[i].subbars > 0 then
for j = 0, 8 do Frames[ic][tid].bars[i].subbars[j].frame:Hide() end
end
end
function cPointDisplay:UpdatePointDisplay(...)
local UpdateList
if ... == "ENABLE" then
-- Update everything
UpdateList = Types
else
UpdateList = ValidClasses
end
-- Cycle through all Types that need updating
for ic,vc in pairs(UpdateList) do
-- Cycle through all Point Displays in current Type
if Types[ic] then
for it,vt in ipairs(Types[ic].points) do
local tid = Types[ic].points[it].id
-- Do we hide the Display
if ((Points[tid] == 0 and not db[ic].types[tid].general.showatzero)
or (Points[tid] == nil)
or (ic ~= PlayerClass and ic ~= "GENERAL") -- Not my class
or ((PlayerClass ~= "ROGUE" and (PlayerClass ~= "DRUID" and PlayerSpec ~= 1)) and (ic == "GENERAL") and not UnitHasVehicleUI("player")) -- Impossible to have Combo Points
or (db[ic].types[tid].general.hidein.vehicle and UnitHasVehicleUI("player")) -- Hide in vehicle
or ((db[ic].types[tid].general.hidein.spec - 1) == PlayerSpec)) -- Hide in spec
and not db[ic].types[tid].configmode.enabled then -- Not in config mode
-- Hide Display
Frames[ic][tid].bgpanel.frame:Hide()
else
-- Update the Display
-- Update Bars if their Points have changed
if PointsChanged[tid] then
if Points[tid] == nil then Points[tid] = 0 end
local points = Points[tid];
if tid == "ssf" then points = points / 10 end
for i = 1, Types[ic].points[it].barcount do
if points > i - 1 and points < i and tid == "ssf" then
--- Show bar and set texture to "Partial"
HideAtIndex(ic, it, tid, i)
Frames[ic][tid].bars[i].frame:Show()
SetPartialBarTextures(ic, it, tid, i, Points[tid] - (10 * (i - 1)))
elseif points >= i then
-- Show bar and set textures to "Full"
Frames[ic][tid].bars[i].frame:Show()
SetPointBarTextures(ic, it, tid, i, points)
if #Frames[ic][tid].bars[i].subbars > 0 then
for j = 0, 8 do Frames[ic][tid].bars[i].subbars[j].frame:Hide() end
end
else
HideAtIndex(ic, it, tid, i)
end
end
-- Show the Display
Frames[ic][tid].bgpanel.frame:Show()
-- Flag as having been changed
PointsChanged[tid] = false
end
end
end
end
end
end
local function GetBuffCount(Spell, ...)
if not Spell then return end
local unit = ... or "player"
for i = 1, 255 do
local name, _, count, _, _, _, _, _, _, id = UnitAura(unit, i, "HELPFUL")
if not name then return end
if Spell == id or Spell == name then
if (count == nil) then count = 0 end
return count
end
end
return 0
end
function cPointDisplay:GetPoints(CurClass, CurType)
local NewPoints
-- General
if CurClass == "GENERAL" then
-- Combo Points
if (CurType == "cp") or (CurType == "cp6") then
if (UnitHasVehicleUI("player") and UnitHasVehiclePlayerFrameUI("player")) then
NewPoints = GetComboPoints("vehicle")
if (NewPoints == 0) then
NewPoints = GetComboPoints("vehicle", "vehicle")
end
else
local maxcp = UnitPowerMax("player", 4)
if (CurType == "cp" and maxcp == 5) or
(CurType == "cp6" and maxcp == 6) then
NewPoints = UnitPower("player", 4)
end
end
end
-- Paladin
elseif CurClass == "PALADIN" then
-- Holy Power
if CurType == "hp" then
NewPoints = UnitPower("player", Enum.PowerType.HolyPower)
end
-- Monk
elseif CurClass == "MONK" and PlayerSpec == 3 then -- chi is only for windwalkers
-- Chi
local maxchi = UnitPowerMax("player", Enum.PowerType.Chi)
if (CurType == "c5" and maxchi == 5) or
(CurType == "c6" and maxchi == 6) then
NewPoints = UnitPower("player", Enum.PowerType.Chi)
end
-- Warlock
elseif CurClass == "WARLOCK" then
-- Soul Shards
NewPoints = UnitPower("player", Enum.PowerType.SoulShards, CurType == "ssf")
-- Mage
elseif CurClass == "MAGE" then
-- Arcane Charges
if CurType == "ac" and PlayerSpec == SPEC_MAGE_ARCANE then
NewPoints = UnitPower("player", Enum.PowerType.ArcaneCharges)
-- Icicles
elseif CurType == "ic" and PlayerSpec == 3 then
NewPoints = GetBuffCount(205473) -- Icicle buff id
end
-- Shaman
elseif CurClass == "SHAMAN" then
if CurType == "mw" and PlayerSpec == 2 then
NewPoints = GetBuffCount(344179) -- Maelstrom Weapon buff id
end
-- Demon Hunter
elseif CurClass == "DEMONHUNTER" then
if CurType == "sf" and PlayerSpec == 2 then
NewPoints = GetBuffCount(203981) -- Soul Fragments buff id
end
end
Points[CurType] = NewPoints
end
-- Update all valid Point Displays
function cPointDisplay:UpdatePoints(...)
if not LoggedIn then return end
local HasChanged = false
local Enable = ...
local UpdateList
if ... == "ENABLE" then
-- Update everything
UpdateList = Types
else
UpdateList = ValidClasses
end
-- ENABLE update: Config Mode / Reset displays
if Enable == "ENABLE" then
HasChanged = true
for ic,vc in pairs(Types) do
for it,vt in ipairs(Types[ic].points) do
local tid = Types[ic].points[it].id
PointsChanged[tid] = true
if ( db[ic].types[tid].enabled and db[ic].types[tid].configmode.enabled ) then
-- If Enabled and Config Mode is on, then set points
Points[tid] = db[ic].types[tid].configmode.count
else
Points[tid] = 0
end
end
end
end
-- Normal update: Cycle through valid classes
for ic,vc in pairs(UpdateList) do
-- Cycle through point types for current class
if Types[ic] then
for it,vt in ipairs(Types[ic].points) do
local tid = Types[ic].points[it].id
if (db[ic].types[tid].enabled and not db[ic].types[tid].configmode.enabled) then
-- Retrieve new point count
local OldPoints = Points[tid]
cPointDisplay:GetPoints(ic, tid)
if Points[tid] ~= OldPoints then
-- Points have changed, flag for updating
HasChanged = true
PointsChanged[tid] = true
end
end
end
end
end
-- Update Point Displays
if HasChanged then cPointDisplay:UpdatePointDisplay(Enable) end
end
-- Enable a Point Display
function cPointDisplay:EnablePointDisplay(c, t)
cPointDisplay:UpdatePoints("ENABLE")
end
-- Disable a Point Display
function cPointDisplay:DisablePointDisplay(c, t)
-- Set to 0 points
Points[t] = 0
PointsChanged[t] = true
-- Update Point Displays
cPointDisplay:UpdatePointDisplay("ENABLE")
end
-- Update frame positions/sizes
function cPointDisplay:UpdatePosition()
for ic,vc in pairs(Types) do
for it,vt in ipairs(Types[ic].points) do
local tid = Types[ic].points[it].id
---- BG Panel
local Parent = _G[db[ic].types[tid].position.parent]
if not Parent then Parent = UIParent end
Frames[ic][tid].bgpanel.frame:SetParent(Parent)
Frames[ic][tid].bgpanel.frame:ClearAllPoints()
Frames[ic][tid].bgpanel.frame:SetPoint(db[ic].types[tid].position.anchorfrom, Parent, db[ic].types[tid].position.anchorto, db[ic].types[tid].position.x, db[ic].types[tid].position.y)
Frames[ic][tid].bgpanel.frame:SetFrameStrata(db[ic].types[tid].position.framelevel.strata)
Frames[ic][tid].bgpanel.frame:SetFrameLevel(db[ic].types[tid].position.framelevel.level)
Frames[ic][tid].bgpanel.frame:SetWidth(db[ic].types[tid].bgpanel.size.width)
Frames[ic][tid].bgpanel.frame:SetHeight(db[ic].types[tid].bgpanel.size.height)
Frames[ic][tid].bgpanel.border:SetFrameStrata(db[ic].types[tid].position.framelevel.strata)
Frames[ic][tid].bgpanel.border:SetFrameLevel(db[ic].types[tid].position.framelevel.level + 1)
Frames[ic][tid].bgpanel.border:SetHeight(db[ic].types[tid].bgpanel.size.height - db[ic].types[tid].bgpanel.border.inset)
Frames[ic][tid].bgpanel.border:SetWidth(db[ic].types[tid].bgpanel.size.width - db[ic].types[tid].bgpanel.border.inset)
---- Anchor
Frames[ic][tid].anchor.frame:SetParent(Parent)
Frames[ic][tid].anchor.frame:ClearAllPoints()
Frames[ic][tid].anchor.frame:SetPoint(db[ic].types[tid].position.anchorfrom, Parent, db[ic].types[tid].position.anchorto, db[ic].types[tid].position.x, db[ic].types[tid].position.y)
Frames[ic][tid].anchor.frame:SetFrameStrata(db[ic].types[tid].position.framelevel.strata)
Frames[ic][tid].anchor.frame:SetFrameLevel(db[ic].types[tid].position.framelevel.level)
Frames[ic][tid].anchor.frame:SetWidth(db[ic].types[tid].bgpanel.size.width)
Frames[ic][tid].anchor.frame:SetHeight(db[ic].types[tid].bgpanel.size.height)
---- Point Bars
local IsVert, IsRev = db[ic].types[tid].general.direction.vertical, db[ic].types[tid].general.direction.reverse
local XPos, YPos, CPRatio, TWidth, THeight
local Positions = {}
local CPSize = {}
-- Get total Width and Height of Point Display, and the size of each Bar
TWidth = 0
THeight = 0
for i = 1, Types[ic].points[it].barcount do
if IsVert then
CPSize[i] = db[ic].types[tid].bars[i].size.height + db[ic].types[tid].bars[i].position.gap
THeight = THeight + db[ic].types[tid].bars[i].size.height + db[ic].types[tid].bars[i].position.gap
else
CPSize[i] = db[ic].types[tid].bars[i].size.width + db[ic].types[tid].bars[i].position.gap
TWidth = TWidth + db[ic].types[tid].bars[i].size.width + db[ic].types[tid].bars[i].position.gap
end
end
-- Calculate position of each Bar
for i = 1, Types[ic].points[it].barcount do
local CurPos = 0
local TVal
-- Get appropriate total to compare each Bar against
if IsVert then
TVal = THeight
else
TVal = TWidth
end
-- Add up position of each Bar in sequence
if i == 1 then
CurPos = (CPSize[i] / 2) - (TVal / 2)
else
for j = 1, i-1 do
CurPos = CurPos + CPSize[j]
end
CurPos = CurPos + (CPSize[i] / 2) - (TVal / 2)
end
-- Found Position of Bar
Positions[i] = CurPos
end
-- Position each Bar
for i = 1, Types[ic].points[it].barcount do
local XOfs = db[ic].types[tid].bars[i].position.xofs
local YOfs = db[ic].types[tid].bars[i].position.yofs
local RevMult = 1
if IsRev then RevMult = -1 end
Frames[ic][tid].bars[i].frame:SetParent(Frames[ic][tid].bgpanel.frame)
Frames[ic][tid].bars[i].frame:ClearAllPoints()
if IsVert then
XPos = 0
YPos = Positions[i] * RevMult
else
XPos = Positions[i] * RevMult
YPos = 0
end
Frames[ic][tid].bars[i].frame:SetPoint("CENTER", Frames[ic][tid].bgpanel.frame, "CENTER", XPos + XOfs, YPos + YOfs)
Frames[ic][tid].bars[i].frame:SetFrameStrata(db[ic].types[tid].position.framelevel.strata)
Frames[ic][tid].bars[i].frame:SetFrameLevel(db[ic].types[tid].position.framelevel.level + 2)
Frames[ic][tid].bars[i].frame:SetWidth(db[ic].types[tid].bars[i].size.width)
Frames[ic][tid].bars[i].frame:SetHeight(db[ic].types[tid].bars[i].size.height)
Frames[ic][tid].bars[i].border:SetFrameStrata(db[ic].types[tid].position.framelevel.strata)
Frames[ic][tid].bars[i].border:SetFrameLevel(db[ic].types[tid].position.framelevel.level + 4)
Frames[ic][tid].bars[i].spark.frame:SetParent(Frames[ic][tid].bars[i].frame)
Frames[ic][tid].bars[i].spark.frame:ClearAllPoints()
Frames[ic][tid].bars[i].spark.frame:SetPoint("CENTER", Frames[ic][tid].bars[i].frame, "CENTER", db[ic].types[tid].bars[i].spark.position.x, db[ic].types[tid].bars[i].spark.position.y)
Frames[ic][tid].bars[i].spark.frame:SetFrameStrata(db[ic].types[tid].position.framelevel.strata)
Frames[ic][tid].bars[i].spark.frame:SetFrameLevel(db[ic].types[tid].position.framelevel.level + 5)
Frames[ic][tid].bars[i].spark.frame:SetWidth(db[ic].types[tid].bars[i].spark.size.width)
Frames[ic][tid].bars[i].spark.frame:SetHeight(db[ic].types[tid].bars[i].spark.size.height)
if #Frames[ic][tid].bars[i].subbars > 0 then
for j = 0, 8 do
local XSOfs = 0
local YSOfs = 0
local fillStart = { "LEFT", "RIGHT", "TOP", "BOTTOM" }
if IsVert then
YSOfs = j * (db[ic].types[tid].bars[i].size.height / 9) * RevMult
if IsRev then fillStart = "TOP" else fillStart = "BOTTOM" end
else
XSOfs = j * (db[ic].types[tid].bars[i].size.width / 9) * RevMult
if IsRev then fillStart = "RIGHT" else fillStart = "LEFT" end
end
Frames[ic][tid].bars[i].subbars[j].frame:SetParent(Frames[ic][tid].bars[i].frame)
Frames[ic][tid].bars[i].subbars[j].frame:ClearAllPoints()
Frames[ic][tid].bars[i].subbars[j].frame:SetPoint(fillStart, Frames[ic][tid].bars[i].frame, fillStart, XSOfs, YSOfs)
Frames[ic][tid].bars[i].subbars[j].frame:SetFrameStrata(Frames[ic][tid].bars[i].frame:GetFrameStrata())
Frames[ic][tid].bars[i].subbars[j].frame:SetFrameLevel(Frames[ic][tid].bars[i].frame:GetFrameLevel() + 1)
if IsVert then
Frames[ic][tid].bars[i].subbars[j].frame:SetWidth(db[ic].types[tid].bars[i].size.width)
Frames[ic][tid].bars[i].subbars[j].frame:SetHeight(db[ic].types[tid].bars[i].size.height / 9)
else
Frames[ic][tid].bars[i].subbars[j].frame:SetWidth(db[ic].types[tid].bars[i].size.width / 9)
Frames[ic][tid].bars[i].subbars[j].frame:SetHeight(db[ic].types[tid].bars[i].size.height)
end
end
end
end
end
end
end
-- Update BG Panel textures
function cPointDisplay:UpdateBGPanelTextures()
local BorderA
local BGA
for ic,vc in pairs(Types) do
for it,vt in ipairs(Types[ic].points) do
local tid = Types[ic].points[it].id
-- Border
if db[ic].types[tid].bgpanel.enabled then BorderA = db[ic].types[tid].bgpanel.border.color.a else BorderA = 0 end
Frames[ic][tid].bgpanel.border:SetBackdrop({bgFile = "", edgeFile = Borders[ic][tid].bgpanel, edgeSize = db[ic].types[tid].bgpanel.border.edgesize, tile = false, tileSize = 0, insets = {left = 0, right = 0, top = 0, bottom = 0}})
Frames[ic][tid].bgpanel.border:SetBackdropBorderColor(db[ic].types[tid].bgpanel.border.color.r, db[ic].types[tid].bgpanel.border.color.g, db[ic].types[tid].bgpanel.border.color.b, BorderA)
-- BG
if db[ic].types[tid].bgpanel.enabled then BGA = db[ic].types[tid].bgpanel.bg.color.a else BGA = 0 end
Frames[ic][tid].bgpanel.bg:SetTexture(BG[ic][tid].bgpanel)
Frames[ic][tid].bgpanel.bg:SetVertexColor(db[ic].types[tid].bgpanel.bg.color.r, db[ic].types[tid].bgpanel.bg.color.g, db[ic].types[tid].bgpanel.bg.color.b, BGA)
end
end
end
-- Retrieve SharedMedia backgound
local function RetrieveBackground(background)
background = LSM:Fetch("background", background, true)
return background
end
local function VerifyBackground(background)
local newbackground = ""
if background and strlen(background) > 0 then
newbackground = RetrieveBackground(background)
if background ~= "None" then
if not newbackground then
print("Background "..background.." was not found in SharedMedia.")
newbackground = ""
end
end
end
return newbackground
end
-- Retrieve SharedMedia border
local function RetrieveBorder(border)
border = LSM:Fetch("border", border, true)
return border
end
local function VerifyBorder(border)
local newborder = ""
if border and strlen(border) > 0 then
newborder = RetrieveBorder(border)
if border ~= "None" then
if not newborder then
print("Border "..border.." was not found in SharedMedia.")
newborder = ""
end
end
end
return newborder
end
-- Retrieve Border/Background textures and store in tables
function cPointDisplay:GetTextures()
for ic,vc in pairs(Types) do
for it,vt in ipairs(Types[ic].points) do
local tid = Types[ic].points[it].id
Borders[ic][tid].bgpanel = VerifyBorder(db[ic].types[tid].bgpanel.border.texture)
BG[ic][tid].bgpanel = VerifyBackground(db[ic].types[tid].bgpanel.bg.texture)
for i = 1, Types[ic].points[it].barcount do
Borders[ic][tid].bars[i].empty = VerifyBorder(db[ic].types[tid].bars[i].border.empty.texture)
Borders[ic][tid].bars[i].full = VerifyBorder(db[ic].types[tid].bars[i].border.full.texture)
BG[ic][tid].bars[i].empty = VerifyBackground(db[ic].types[tid].bars[i].bg.empty.texture)
BG[ic][tid].bars[i].full = VerifyBackground(db[ic].types[tid].bars[i].bg.full.texture)
BG[ic][tid].bars[i].spark = VerifyBackground(db[ic].types[tid].bars[i].spark.bg.texture)
end
end
end
end
function cPointDisplay:GetClassColors()
local CurClassColor
for k,v in pairs(Types) do
tinsert(ClassColorBarTable, k)
if k == "GENERAL" then
CurClassColor = {r = 1, g = 1, b = 1}
else
CurClassColor = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[k] or RAID_CLASS_COLORS[k]
end
ClassColorBarTable[k] = {
bg = {
empty = {r = db.classcolor.bg.empty * CurClassColor.r, g = db.classcolor.bg.empty * CurClassColor.g, b = db.classcolor.bg.empty * CurClassColor.b},
normal = {r = db.classcolor.bg.normal * CurClassColor.r, g = db.classcolor.bg.normal * CurClassColor.g, b = db.classcolor.bg.normal * CurClassColor.b},
max = {r = db.classcolor.bg.max * CurClassColor.r, g = db.classcolor.bg.max * CurClassColor.g, b = db.classcolor.bg.max * CurClassColor.b},
},
border = {
empty = {r = db.classcolor.border.empty * CurClassColor.r, g = db.classcolor.border.empty * CurClassColor.g, b = db.classcolor.border.empty * CurClassColor.b},
normal = {r = db.classcolor.border.normal * CurClassColor.r, g = db.classcolor.border.normal * CurClassColor.g, b = db.classcolor.border.normal * CurClassColor.b},
max = {r = db.classcolor.border.max * CurClassColor.r, g = db.classcolor.border.max * CurClassColor.g, b = db.classcolor.border.max * CurClassColor.b},
},
spark = {
normal = {r = db.classcolor.spark.normal * CurClassColor.r, g = db.classcolor.spark.normal * CurClassColor.g, b = db.classcolor.spark.normal * CurClassColor.b},
max = {r = db.classcolor.spark.max * CurClassColor.r, g = db.classcolor.spark.max * CurClassColor.g, b = db.classcolor.spark.max * CurClassColor.b},
},
}
end
end
-- Frame Creation
local function CreateFrames()
for ic,vc in pairs(Types) do
for it,vt in ipairs(Types[ic].points) do
local tid = Types[ic].points[it].id
-- BG Panel
local FrameName = "cPointDisplay_Frames_"..tid
Frames[ic][tid].bgpanel.frame = CreateFrame("Frame", FrameName, UIParent, BackdropTemplateMixin and "BackdropTemplate")
Frames[ic][tid].bgpanel.bg = Frames[ic][tid].bgpanel.frame:CreateTexture(nil, "ARTWORK")
Frames[ic][tid].bgpanel.bg:SetAllPoints(Frames[ic][tid].bgpanel.frame)
Frames[ic][tid].bgpanel.border = CreateFrame("Frame", nil, UIParent, BackdropTemplateMixin and "BackdropTemplate")
Frames[ic][tid].bgpanel.border:SetParent(Frames[ic][tid].bgpanel.frame)
Frames[ic][tid].bgpanel.border:ClearAllPoints()
Frames[ic][tid].bgpanel.border:SetPoint("CENTER", Frames[ic][tid].bgpanel.frame, "CENTER", 0, 0)
Frames[ic][tid].bgpanel.frame:Hide()
-- Anchor Panel
local AnchorFrameName = "cPointDisplay_Frames_"..tid.."_avAanchor"
Frames[ic][tid].anchor.frame = CreateFrame("Frame", AnchorFrameName, UIParent, BackdropTemplateMixin and "BackdropTemplate")
-- Point bars
for i = 1, Types[ic].points[it].barcount do
local BarFrameName = "cPointDisplay_Frames_"..tid.."_bar"..tostring(i)
Frames[ic][tid].bars[i].frame = CreateFrame("Frame", BarFrameName, UIParent, BackdropTemplateMixin and "BackdropTemplate")
Frames[ic][tid].bars[i].bg = Frames[ic][tid].bars[i].frame:CreateTexture(nil, "ARTWORK")
Frames[ic][tid].bars[i].bg:SetAllPoints(Frames[ic][tid].bars[i].frame)
Frames[ic][tid].bars[i].border = CreateFrame("Frame", nil, UIParent, BackdropTemplateMixin and "BackdropTemplate")
Frames[ic][tid].bars[i].border:SetParent(Frames[ic][tid].bars[i].frame)
Frames[ic][tid].bars[i].border:ClearAllPoints()
Frames[ic][tid].bars[i].border:SetPoint("CENTER", Frames[ic][tid].bars[i].frame, "CENTER", 0, 0)
Frames[ic][tid].bars[i].frame:Show()
if tid == "ssf" then
for j = 0, 8 do
local SubBarSubFrameName = "cPointDisplay_Frames_"..tid.."_bar"..tostring(i).."_sub"..tostring(j)
Frames[ic][tid].bars[i].subbars[j] = {frame = nil, bg = nil}
Frames[ic][tid].bars[i].subbars[j].frame = CreateFrame("Frame", SubBarSubFrameName, UIParent, BackdropTemplateMixin and "BackdropTemplate")
Frames[ic][tid].bars[i].subbars[j].bg = Frames[ic][tid].bars[i].subbars[j].frame:CreateTexture(nil, "ARTWORK")
Frames[ic][tid].bars[i].subbars[j].bg:SetAllPoints(Frames[ic][tid].bars[i].subbars[j].frame)