-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
frame.lua
3943 lines (3314 loc) · 124 KB
/
frame.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 _, helpers = ...
local Aptechka = Aptechka
local config = AptechkaDefaultConfig
local pixelperfect = helpers.pixelperfect
local LSM = LibStub("LibSharedMedia-3.0")
LSM:Register("statusbar", "Gradient", [[Interface\AddOns\Aptechka\gradient.tga]])
LSM:Register("font", "AlegreyaSans-Medium", [[Interface\AddOns\Aptechka\AlegreyaSans-Medium.ttf]], GetLocale() ~= "enUS" and 15)
local APILevel = math.floor(select(4,GetBuildInfo())/10000)
local string_format = string.format
local GetSpellTexture = helpers.GetSpellTexture
--[[
DRAW LAYERS
2 shield icon border
0 shield icon texture
0 normal icon texture
0 corner indicators
0 text3 fontstring
-2 status bar bg
-2 debuff type texture
-4 absorb sidebar fg
-5 absorb sidebar bg
-5 absorb checkered fill
-5 incoming healing
-5 heal absorb checkered
-6 healthbar
-6 powerbar
-8 powerbar bg
-8 healthbar bg
]]
local FRAMELEVEL = helpers.FRAMELEVEL
Aptechka.Widget = {}
local dummy = function() end
local function WrapFrameAsWidget(frame)
if not frame.SetJob then frame.SetJob = dummy end
if not frame.StartTrace then frame.StartTrace = dummy end
return frame
end
local function InheritGlobalOptions(popts, gopts)
assert(gopts)
--[[
local gmt = getmetatable(gopts)
if not gmt then
local typeDefaults = Aptechka.Widget[gopts.type].default
gmt = { __index = typeDefaults }
setmetatable(gopts, gmt)
end
]]
if not popts then
return gopts
else
local mt = getmetatable(popts)
if not mt then
mt = { __index = gopts }
setmetatable(popts, mt)
end
mt.__index = gopts
end
return popts
end
function Aptechka:GetWidgetsOptions(name)
local gopts = Aptechka.db.global.widgetConfig[name]
if not gopts then return nil end
local popts = Aptechka.db.profile.widgetConfig and Aptechka.db.profile.widgetConfig[name]
return popts, gopts
end
function Aptechka:GetWidgetsOptionsOrCreate(name)
local popts, gopts = self:GetWidgetsOptions(name)
if not gopts then return nil end
if not popts then
Aptechka.util.MakeTables(Aptechka.db.profile, "widgetConfig", name)
popts = Aptechka.db.profile.widgetConfig[name]
end
return popts, gopts
end
function Aptechka:GetWidgetsOptionsMerged(name)
return InheritGlobalOptions(Aptechka:GetWidgetsOptions(name))
end
-- In case any new properties were added for a widget type,
-- fill the user-created ones with missing fields
function Aptechka:FixWidgetsAfterUpgrade()
local gconfig = self.db.global.widgetConfig
local defaultWidgets = AptechkaDefaultConfig.DefaultWidgets
local toRemove = {}
for name, gopts in pairs(gconfig) do
if not defaultWidgets[name] then
local wtype = gopts.type
if wtype then
local defaultOpts = Aptechka.Widget[wtype].default
for propertyName, value in pairs(defaultOpts) do
if gopts[propertyName] == nil then
gopts[propertyName] = defaultOpts[propertyName]
end
end
else
-- if it gets here that means it's a removed default widget, not a custom one
table.insert(toRemove, name)
end
end
end
for i, name in ipairs(toRemove) do
gconfig[name] = nil
end
end
local reverse = helpers.Reverse
local function AttachRegionToMask(region, parent, growth)
region:ClearAllPoints()
local mask, orientation, isReversed, p1, p2 = parent:GetSeparationRegionAttachmentPoints()
if not isReversed then growth = growth * -1 end
-- return points on the mask that currently separate health
if growth > 0 then -- region will grow in the same direction as mask
region:SetPoint(reverse(p1, orientation), mask, p1, 0, 0)
region:SetPoint(reverse(p2, orientation), mask, p2, 0, 0)
else -- opposite
region:SetPoint(p1, mask, p1, 0, 0)
region:SetPoint(p2, mask, p2, 0, 0)
end
end
local MakeBorder = function(self, tex, left, right, top, bottom, level)
local t = self:CreateTexture(nil,"BORDER",nil,level)
t:SetTexture(tex)
t:SetPoint("TOPLEFT", self, "TOPLEFT", left, -top)
t:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", -right, bottom)
return t
end
local CompositeBorder_Set = function(self, left, right, top, bottom)
local frame = self[5]
local ttop = self[1]
ttop:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, top)
ttop:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", right, 0)
local tright = self[2]
tright:SetPoint("TOPRIGHT", frame, "TOPRIGHT", right, 0)
tright:SetPoint("BOTTOMLEFT", frame, "BOTTOMRIGHT", 0, -bottom)
local tbot = self[3]
tbot:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, -bottom)
tbot:SetPoint("TOPLEFT", frame, "BOTTOMLEFT", -left, 0)
local tleft = self[4]
tleft:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", -left, 0)
tleft:SetPoint("TOPRIGHT", frame, "TOPLEFT", 0, top)
end
local CompositeBorder_SetColor = function(self, r,g,b,a)
local ttop = self[1]
ttop:SetVertexColor(r,g,b,a)
local tright = self[2]
tright:SetVertexColor(r,g,b,a)
local tbot = self[3]
tbot:SetVertexColor(r,g,b,a)
local tleft = self[4]
tleft:SetVertexColor(r,g,b,a)
end
local MakeCompositeBorder = function(frame, tex, left, right, top, bottom, drawLayer, level)
local ttop = frame:CreateTexture(nil, drawLayer, nil, level)
ttop:SetTexture(tex)
local tright = frame:CreateTexture(nil, drawLayer, nil, level)
tright:SetTexture(tex)
local tbot = frame:CreateTexture(nil, drawLayer, nil, level)
tbot:SetTexture(tex)
local tleft = frame:CreateTexture(nil, drawLayer, nil, level)
tleft:SetTexture(tex)
local border = { ttop, tright, tbot, tleft, frame }
border.parent = frame
border.Set = CompositeBorder_Set
border.SetColor = CompositeBorder_SetColor
border:Set(left, right, top, bottom)
border:SetColor(0,0,0, 1)
return border
end
local function GetSpellColor(job, caster, count)
local color
if caster ~= "player" and job.foreigncolor then
return unpack(job.foreigncolor)
elseif job.color then
return unpack(job.color)
elseif job.stackcolor then
return unpack(job.stackcolor[count])
end
return 1,1,1
end
local function GetSpellColorTable(job, caster, count)
local color
if caster ~= "player" and job.foreigncolor then
return job.foreigncolor
elseif job.stackcolor then
return job.stackcolor[count]
elseif job.color then
return job.color
end
return { 1,1,1 }
end
local function GetColor(job)
local r,g,b, a, tr,tg,tb
local c = job.color
r = c[1]
g = c[2]
b = c[3]
a = c[4] or 1
tr,tg,tb = r,g,b
return r,g,b, a, tr,tg,tb
end
local function GetTextColor(job)
if not job.textcolor then
return GetColor(job)
end
local r,g,b, a, tr,tg,tb
tr,tg,tb = unpack(job.textcolor)
local c = job.color
r = c[1]
g = c[2]
b = c[3]
a = c[4] or 1
return r,g,b, a, tr,tg,tb
end
local function GetClassOrTextColor(job, state)
local cc = (job.classcolor and state.classColor)
if not cc then return GetTextColor(job) end
local r,g,b, a, tr,tg,tb
r = cc[1]
g = cc[2]
b = cc[3]
a = 1
tr,tg,tb = r,g,b
return r,g,b, a, tr,tg,tb
end
local math_abs = math.abs
local function formatMissingHealth(mh)
local amh = math_abs(mh)
if amh < 1000 then
return "%d", mh
elseif amh < 10000 then
return "%.1fk", mh / 1000
else
return "%.0fk", mh / 1000
end
end
local function formatShorten(v)
local av = math_abs(v)
if av < 1000 then
return "%d", v
elseif av < 10000 then
return "%.1fk", v / 1000
else
return "%.0fk", v / 1000
end
end
local function formatShortenPositiveHealing(v)
if v < 1000 then
return "|cff00ff00+%d|r", v
elseif v < 10000 then
return "|cff00ff00+%.1fk|r", v / 1000
else
return "|cff00ff00+%.0fk|r", v / 1000
end
end
local TextFormatters = {
MISSING_VALUE_SHORT = function(cur, max)
return string_format(formatMissingHealth(cur-max))
end,
MISSING_HEALING_SHORT = function(cur, max, incomingHeal)
local diff = cur-max+incomingHeal
if diff < 0 then
return string_format(formatShorten(cur-max+incomingHeal))
else
return string_format(formatShortenPositiveHealing(cur-max+incomingHeal))
end
end,
VALUE = function(cur, max)
return cur
end,
VALUE_SHORT = function(cur, max)
return string_format(formatShorten(cur))
end,
PERCENTAGE = function(cur, max)
return string_format("%.0f%%", cur/max*100)
end,
PERCENTAGE_NOSIGN = function(cur, max)
return string_format("%.0f", cur/max*100)
end,
}
local function FormatText(job, ...)
local formattter = TextFormatters[job.formatType] or TextFormatters.VALUE
return formattter(...)
end
local contentNormalizers = {}
function contentNormalizers.HealthText(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
local incomingHeal
cur, max, incomingHeal = ...
text = FormatText(job, cur, max, incomingHeal)
r,g,b, a, tr,tg,tb = GetClassOrTextColor(job, state)
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
-- contentNormalizers.AbsorbText = contentNormalizers.HealthText
function contentNormalizers.INCOMING_HEAL(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
cur = ...
text = string_format("+%d", cur)
r,g,b, a, tr,tg,tb = GetTextColor(job)
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
local PowerBarColor = PowerBarColor
function contentNormalizers.POWERCOLOR(job, state, contentType, pname, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
local db = Aptechka.db.profile
local showPowerTypeColors = true
if showPowerTypeColors and (pname ~= "MANA" and pname ~= "NONE") then
local c = PowerBarColor[pname] -- getting default color from a globalr2
r,g,b = c.r, c.g, c.b
else
r,g,b = unpack(db.powerColor)
end
a = 1
text = job.text
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
function contentNormalizers.AURA(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
local duration, expirationTime, count1, icon1, spellID, caster = ...
count = count1
text = job.text or job.name
if job.infoType == "DURATION" and duration ~= 0 then
cur = duration
max = expirationTime
timerType = "TIMER"
elseif job.infoType == "COUNT" then
cur = count
max = job.maxCount or 5
text = count
end
icon = icon1
r,g,b = GetSpellColor(job, caster, count)
a, tr,tg,tb = 1,r,g,b
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
function contentNormalizers.TIMER(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
timerType = "FORWARD"
local startTime = ...
cur = startTime
text = job.text or job.name
r,g,b, a, tr,tg,tb = GetTextColor(job)
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
function contentNormalizers.Stagger(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
local stagger = state.stagger
text = stagger and string_format("%.0f%%", stagger*100) or ""
r,g,b = helpers.PercentColor(stagger)
a, tr,tg,tb = 1,r,g,b
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
function contentNormalizers.PROGRESS(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
local c, m, perc = ...
cur = c
max = m
r,g,b, a, tr,tg,tb = GetTextColor(job)
-- r,g,b = helpers.PercentColor(perc)
text = FormatText(job, cur, max)
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
function contentNormalizers.UnitName(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
text = state.name
local db = Aptechka.db.profile
local c = (db.nameColorByClass and state.classColor) or db.nameColor
r,g,b = unpack(c)
local m = db.nameColorMultiplier
r = r*m
g = g*m
b = b*m
a, tr,tg,tb = 1,r,g,b
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
function contentNormalizers.TEXTURE(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
texture, texCoords = ...
text = job.name
r,g,b = 1,1,1
a, tr,tg,tb = 1,r,g,b
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
local phaseIconCoords = {0.15625, 0.84375, 0.15625, 0.84375}
function contentNormalizers.PHASED(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
texture = "Interface\\TargetingFrame\\UI-PhasingIcon"
texCoords = phaseIconCoords
r,g,b, a, tr,tg,tb = GetTextColor(job)
text = job.name
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
function contentNormalizers.RESURRECTION(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
texture = "Interface\\RaidFrame\\Raid-Icon-Rez"
r,g,b, a, tr,tg,tb = GetTextColor(job)
text = job.name
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
local roleCoords = {
TANK = { 0, 19/64, 22/64, 41/64 },
HEALER = { 20/64, 39/64, 1/64, 20/64 },
}
local roleColors = {
TANK = { 0.4, 0.4, 1 },
HEALER = { 0.4, 1, 0.4 },
}
function contentNormalizers.ROLE(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
local role = ...
texture = "Interface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES"
texCoords = roleCoords[role]
text = role
r,g,b = unpack(roleColors[role])
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
local READY_CHECK_READY_TEXTURE = "Interface\\RaidFrame\\ReadyCheck-Ready"
local READY_CHECK_NOT_READY_TEXTURE = "Interface\\RaidFrame\\ReadyCheck-NotReady"
local READY_CHECK_WAITING_TEXTURE = "Interface\\RaidFrame\\ReadyCheck-Waiting"
function contentNormalizers.READY_CHECK(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
local status = ...
-- texCoords = "ATLAS"
if status == 'ready' then
texture = READY_CHECK_READY_TEXTURE
-- texture = "UI-LFG-ReadyMark"
r,g,b = 0,1,0
elseif status == 'notready' then
texture = READY_CHECK_NOT_READY_TEXTURE
-- texture = "UI-LFG-DeclineMark"
r,g,b = 1,0,0
elseif status == 'waiting' then
texture = READY_CHECK_WAITING_TEXTURE
-- texture = "UI-LFG-PendingMark"
r,g,b = 1,1,0
end
text = job.name
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
function contentNormalizers.OUTOFRANGE(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
a = ...
text = job.name
r,g,b = 1,1,1
tr,tg,tb = 1,1,1
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
local DT_TextureCoords = {
Magic = { 0.90234375, 0.97265625, 0.109375, 0.390625 },
Curse = { 0.02734375, 0.09765625, 0.609375, 0.890625 },
Poison = { 0.15234375, 0.22265625, 0.609375, 0.890625 },
Disease = { 0.27734375, 0.34765625, 0.609375, 0.890625 },
DANGER = { 0.52734375, 0.59765625, 0.109375, 0.390625 },
}
local DT_Icons = {
Magic = 135834,
Curse = 136130,
Poison = 132108,
Disease = 132100,
}
function contentNormalizers.DEBUFF_HIGHLIGHT(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
r,g,b, a, tr,tg,tb = GetColor(job)
text = "!!!"
texture = "Interface\\EncounterJournal\\UI-EJ-Icons"
icon = 132094
texCoords = DT_TextureCoords.DANGER
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
function contentNormalizers.TARGET_COUNT(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
count = ...
cur = count
max = 10
r,g,b, a, tr,tg,tb = GetTextColor(job)
text = count
-- texture = nil
icon = 458723
-- texCoords = nil
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
function contentNormalizers.DISPELTYPE(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
local debuffType, duration, expirationTime, count1, icon1, spellID, caster = ...
local color = helpers.DebuffTypeColors[debuffType]
cur = duration
max = expirationTime
timerType = "TIMER"
count = count1
r,g,b = unpack(color)
a, tr,tg,tb = 1,r,g,b
text = debuffType
texture = "Interface\\EncounterJournal\\UI-EJ-Icons"
icon = icon1 -- DT_Icons[debuffType]
texCoords = DT_TextureCoords[debuffType]
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
function contentNormalizers.CCEFFECT(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
local debuffType, duration, expirationTime, count1, icon1, spellID, caster = ...
debuffType = debuffType or "Physical"
local color = job.color or helpers.DebuffTypeColors[debuffType]
cur = duration
max = expirationTime
timerType = "TIMER"
count = count1
r,g,b = unpack(color)
a, tr,tg,tb = 1,r,g,b
text = job.text
texture = "Interface\\EncounterJournal\\UI-EJ-Icons"
icon = icon1 -- DT_Icons[debuffType]
texCoords = DT_TextureCoords[debuffType]
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
function contentNormalizers.LEADER(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
r,g,b, a, tr,tg,tb = GetTextColor(job)
text = "L"
texture = "Interface\\GroupFrame\\UI-Group-LeaderIcon"
icon = APILevel <= 3 and 132768 or 1670850
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
function contentNormalizers.CAST(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords, isReversed
local castType, name, duration, expirationTime, count1, icon1, spellID = ...
cur = duration
max = expirationTime
timerType = "TIMER"
count = count1
if castType == "CHANNEL" then
r,g,b = 0.8, 1, 0.3
isReversed = false
else
r,g,b = 1, 0.65, 0
isReversed = true
end
a, tr,tg,tb = 1,r,g,b
text = name
icon = icon1
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords, isReversed
end
local RaidTargetCoords = {
{ 0, 0.25, 0, 0.25, },
{ 0.25, 0.5, 0, 0.25 },
{ 0.5, 0.75, 0, 0.25 },
{ 0.75, 1, 0, 0.25 },
{ 0, 0.25, 0.25, 0.5 },
{ 0.25, 0.5, 0.25, 0.5 },
{ 0.5, 0.75, 0.25, 0.5 },
{ 0.75, 1, 0.25, 0.5 },
}
function contentNormalizers.RAIDTARGET(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
local raidTargetIndex = ...
r,g,b = 1,1,1
a, tr,tg,tb = 1,r,g,b
text = job.name
texture = "Interface\\TargetingFrame\\UI-RaidTargetingIcons"
texCoords = RaidTargetCoords[raidTargetIndex]
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
function contentNormalizers.Default(job, state, contentType, ...)
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
text = job.text or job.name
r,g,b, a, tr,tg,tb = GetTextColor(job)
return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords
end
local function NormalizeContent(job, state, contentType, ...)
local handler = contentNormalizers[contentType] or contentNormalizers["Default"]
return handler(job, state, contentType, ...)
end
function Aptechka:NormalizeWidgetContent(...)
NormalizeContent(...)
end
local function multiplyColor(mul, r,g,b,a)
return r*mul, g*mul, b*mul, a
end
local HealthBarSetColorFG = function(self, r,g,b,a, mul)
self:SetStatusBarColor(r*mul, g*mul, b*mul, a)
end
local HealthBarSetColorBG = function(self, r,g,b,a, mul)
self:SetVertexColor(r*mul, g*mul, b*mul, a)
end
local SetJob_HealthBar = function(self, job, state, contentType, ...)
local profile = Aptechka.db.profile
local r,g,b
local a = 1
local r2,g2,b2
-- TODO: Move to content handlers?
if contentType == "HealthBar" then
local isGradient = state.gradientHealthColor
local c1 = state.healthColor1
if not c1 then return end -- At some point during initialization health updates before colors are determined
if isGradient then
local c2 = state.healthColor2
local c3 = state.healthColor3
local progress = state.healthPercent or 1
progress = progress*1.2-0.2
r,g,b = helpers.GetGradientColor3(c1, c2, c3, progress)
else
r,g,b = unpack(c1)
end
if profile.useCustomBackgroundColor then
r2,g2,b2 = unpack(profile.customBackgroundColor)
else
r2,g2,b2 = r,g,b
end
else
local timerType, cur, max, count, icon, text, _,_,_, _, tr,tg,tb, texture, texCoords, isReversed
timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords, isReversed = NormalizeContent(job, state, contentType, ...)
r2,g2,b2 = r,g,b
end
if b then
local mulFG = profile.fgColorMultiplier or 1
local mulBG = profile.bgColorMultiplier or 0.2
local bgAlpha = profile.bgAlpha
self:SetColor(r,g,b,a,mulFG)
self.bg:SetColor(r2,g2,b2, bgAlpha,mulBG)
end
end
local SetJob_PowerBar = function(self, job, state, contentType, ...)
local profile = Aptechka.db.profile
local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords, isReversed = NormalizeContent(job, state, contentType, ...)
local r2,g2,b2
if profile.useCustomBackgroundColorPower then
r2,g2,b2 = unpack(profile.customBackgroundColorPower)
else
r2,g2,b2 = r,g,b
end
if b then
local mulFG = profile.fgColorMultiplier or 1
local mulBG = profile.bgColorMultiplier or 0.2
local bgAlpha = profile.bgAlpha
self:SetColor(r,g,b,a,mulFG)
self.bg:SetColor(r2,g2,b2, bgAlpha,mulBG)
end
end
local forcedStandardFillPowerTypes = {
RAGE = true,
FURY = true,
PAIN = true,
RUNIC_POWER = true,
INSANITY = true,
MAELSTROM = true,
LUNAR_POWER = true,
}
local PowerBar_OnPowerTypeChange = function(powerbar, powerType, hidePower)
local self = powerbar:GetParent()
local isInverted = Aptechka.db.profile.fgShowMissing
if not isInverted then
self.power:SetFillStyleLock(false)
self.power:SetFillStyle("STANDARD")
else
if forcedStandardFillPowerTypes[powerType] then
self.power:SetFillStyle("STANDARD")
self.power:SetFillStyleLock(true)
else
self.power:SetFillStyleLock(false)
self.power:SetFillStyle("REVERSE")
end
end
local isVertical = Aptechka.db.profile.healthOrientation == "VERTICAL"
if hidePower then
self.power.disabled = true
self.power:Hide()
-- self.power.powerType = "NONE"
if isVertical then
-- self.health:SetPoint("TOPLEFT", self, "TOPLEFT",0,0)
self.health:SetPoint("TOPRIGHT", self, "TOPRIGHT",0,0)
else
-- self.health:SetPoint("TOPLEFT", self, "TOPLEFT",0,0)
self.health:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT",0,0)
end
else
self.power.disabled = nil
self.power:Show()
-- self.power.powerType = powerType
if isVertical then
self.health:SetPoint("TOPLEFT", self, "TOPLEFT",0,0)
self.health:SetPoint("TOPRIGHT", self.power, "TOPLEFT",0,0)
else
self.health:SetPoint("TOPLEFT", self, "TOPLEFT",0,0)
self.health:SetPoint("BOTTOMLEFT", self.power, "TOPLEFT",0,0)
end
end
-- if self.healfeedbackpassive then
-- self.healfeedbackpassive:ClearAllPoints()
-- if self.power:IsShown() and Aptechka.db.profile.healthOrientation == "VERTICAL" then
-- self.healfeedbackpassive:SetPoint("TOPRIGHT", self.power, "TOPLEFT", 0,0)
-- else
-- self.healfeedbackpassive:SetPoint("TOPRIGHT", self, "TOPRIGHT", 0,0)
-- end
-- end
end
------------------------------------------------------------
-- Animations
------------------------------------------------------------
local Pulse_AnimOnFinished = function(self)
self.pulses = self.pulses + 1
local ag = self:GetParent()
if self.pulses > ag.maxpulses then
ag:Stop()
ag.done = true
end
end
local Pulse_AnimGroupOnPlay = function(ag)
ag.a2.pulses = 0
end
local Pulse_OnHide = function(self)
self.pulse.done = false
end
local function Pulse_PlayAnim(self, job)
if not self.pulse.done and not self.pulse:IsPlaying() then
if job.pulse == true then job.pulse = 10 end
self.pulse.maxpulses = job.pulse
self.pulse:Play()
end
end
local function AddPulseAnimation(f)
local pag = f:CreateAnimationGroup()
pag:SetLooping("REPEAT")
pag.maxpulses = 10
local pa1 = pag:CreateAnimation("Alpha")
pa1:SetFromAlpha(1)
pa1:SetToAlpha(0)
pa1:SetDuration(0.15)
pa1:SetOrder(1)
pag.a1 = pa1
local pa2 = pag:CreateAnimation("Alpha")
pa2:SetFromAlpha(0)
pa2:SetToAlpha(1)
pa2:SetDuration(0.15)
pa2:SetOrder(2)
pag.a2 = pa2
pa2:SetScript("OnFinished", Pulse_AnimOnFinished)
pag:SetScript("OnPlay", Pulse_AnimGroupOnPlay)
f:SetScript("OnHide", Pulse_OnHide)
f.pulse = pag
end
local BlinkAnimOnFinished = function(ag)
local widget = ag:GetParent()
local frame = widget:GetParent()
widget.traceJob = nil
Aptechka:UpdateWidget(frame, widget)
end
local function AddBlinkAnimation(f)
local bag = f:CreateAnimationGroup()
bag:SetLooping("NONE")
local ba1 = bag:CreateAnimation("Alpha")
ba1:SetFromAlpha(0)
ba1:SetToAlpha(1)
ba1:SetDuration(0.1)
ba1:SetOrder(1)
local ba2 = bag:CreateAnimation("Alpha")
ba2:SetFromAlpha(1)
ba2:SetToAlpha(0)
ba2:SetDuration(0.7)
ba2:SetOrder(2)
bag.a2 = ba2
bag:SetScript("OnFinished", BlinkAnimOnFinished)
f.blink = bag
end
local function MakeStartTraceForBlinkAnimation(func)
return function(self, job, ...)
if self.traceJob and self.traceJob.priority > job.priority then
return
end
self.traceJob = job
self:Show()
self.blink.a2:SetFromAlpha(1)
self.blink.a2:SetToAlpha(0)
local duration = job.fade or 0.7
self.blink.a2:SetDuration(duration)
func(self, job, ...)
-- local r,g,b,a = GetColor(job)
-- self.texture:SetVertexColor(r,g,b,a)
-- local scale = job.scale or 1
-- self:SetScale(scale)
if self.blink:IsPlaying() then
self.blink:Stop()
end
self.blink:Play()
end
end
local function AddSpinAnimation(f)
local rag = f:CreateAnimationGroup()
local r1 = rag:CreateAnimation("Rotation")
r1:SetDegrees(360)
r1:SetSmoothing("IN_OUT")
r1:SetDuration(1)
r1:SetOrder(1)
f.spin = rag
end
local function UpdateFramePoints(frame, parent, opts, w, h)
frame:ClearAllPoints()
-- frame:SetSize(w, h)
frame:SetWidth(w)
frame:SetHeight(h)
frame:SetPoint(opts.point, parent, opts.point, opts.x, opts.y)
end
-- This function is called from Reconf and by itself
-- handles disables between profile switches
local function CheckDisabled(widget, isDisabled)
local wasDisabled = widget.disabled
widget.disabled = isDisabled
if isDisabled then
widget:Hide()
-- elseif wasDisabled ~= isDisabled and wasDisabled ~= nil then
elseif wasDisabled == true then
local frame = widget:GetParent()
if frame.state then -- if parent is an actual untiframe and not just header
Aptechka:UpdateWidget(frame, widget)
end
end
end
----------------------------------------------------------------
-- Array
----------------------------------------------------------------
local SetJob_Array = function(hdr, job, state, contentType, ...)
local widgetState = state.widgets[hdr]
for i=1,hdr.maxChildren do
local widget = hdr.children[i]
local jobData = widgetState[i]
if jobData then
if not widget then -- dynamically create missing children
widget = hdr:Add()
end
local job = jobData.job
widget.previousJob = widget.currentJob
widget.currentJob = job
widget:SetJob(job, state, unpack(jobData))
widget:Show()
elseif widget then
widget.previousJob = widget.currentJob
widget.currentJob = nil
widget:Hide()
else
break
end
end
end
local function ArrayHeader_Arrange(hdr, startIndex)
local numChildren = #hdr.children
local gap = pixelperfect(1)
local point, relativeTo, relativePoint, _, _ = hdr:GetPoint(1)
local alignH = helpers.GetHorizontalAlignmentFromPoint(point)
local alignV = helpers.GetVerticalAlignmentFromPoint(point)
startIndex = startIndex or 1
for i=startIndex, numChildren do
local widget = hdr.children[i]
widget:ClearAllPoints()
if i == 1 then
widget:SetPoint(point, hdr, point, 0,0)
else
local growthDirection = hdr.growthDirection:upper()
local prevWidget = hdr.children[i-1]
if growthDirection == "DOWN" then
widget:SetPoint("TOP"..alignH, prevWidget, "BOTTOM"..alignH, 0, -gap)
elseif growthDirection == "LEFT" then
widget:SetPoint(alignV.."RIGHT", prevWidget, alignV.."LEFT", -gap, 0)
elseif growthDirection == "RIGHT" then
widget:SetPoint(alignV.."LEFT", prevWidget, alignV.."RIGHT", gap, 0)
else
widget:SetPoint("BOTTOM"..alignH, prevWidget, "TOP"..alignH, 0, gap)
end
end
end
end
local function ArrayHeader_Add(hdr)
-- if #hdr.children >= hdr.maxChildren then return end
local widget = Aptechka.Widget[hdr.childType].Create(hdr, nil, hdr.template)
table.insert(hdr.children, widget)
hdr:Arrange(#hdr.children)
return widget
end
-- When SetJob on header finds no active jobs it just hides the header
-- But .currentJob and .previousJob on the last child don't get updated
local function ArrayHeader_OnHide(hdr)
for i=1, #hdr.children do
local widget = hdr.children[i]
widget.previousJob = widget.currentJob
widget.currentJob = nil
widget:Hide()
end
end