-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChronoBars_Gui.lua
1387 lines (1102 loc) · 39.4 KB
/
ChronoBars_Gui.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
--[[
====================================================
ChronoBars - buff, debuff, cooldown, totem tracker
Author: Ivan Leben
====================================================
--]]
local CB = ChronoBars;
--Bar and Group cache
--================================================================================
function ChronoBars.NewBar ()
local bar = nil;
local numBars = table.getn( CB.cache.bars );
--Check if any unused bars in cache
if (CB.cache.numUsedBars < numBars) then
CB.cache.numUsedBars = CB.cache.numUsedBars + 1;
bar = CB.cache.bars[ CB.cache.numUsedBars ];
else
--Create new bar if all bars used
CB.cache.numUsedBars = numBars + 1;
bar = CB.Bar_Create( "ChronoBars_Bar"..CB.cache.numUsedBars );
bar.cacheId = CB.cache.numUsedBars;
table.insert( CB.cache.bars, bar );
end
return bar;
end
function ChronoBars.NewGroup ()
local grp = nil;
local numGroups = table.getn( CB.cache.groups );
--Check if any unused groups in cache
if (CB.cache.numUsedGroups < numGroups) then
CB.cache.numUsedGroups = CB.cache.numUsedGroups + 1;
grp = CB.cache.groups[ CB.cache.numUsedGroups ];
else
--Create new group if all groups used
CB.cache.numUsedGroups = numGroups + 1;
grp = CB.Group_Create( "ChronoBars_Group"..CB.cache.numUsedGroups );
grp.cacheId = CB.cache.numUsedGroups;
table.insert( CB.cache.groups, grp );
end
return grp;
end
function ChronoBars.FreeBar (bar)
--Swap freed bar with last used bar and their ids
if (bar.cacheId < CB.cache.numUsedBars) then
local barId = bar.cacheId;
local lastId = CB.cache.numUsedBars;
local last = CB.cache.bars[ lastId ];
CB.cache.bars[ barId ] = last;
CB.cache.bars[ lastId ] = bar;
bar.cacheId = lastId;
last.cacheId = barId;
end
CB.cache.numUsedBars = CB.cache.numUsedBars - 1;
end
function ChronoBars.FreeGroup (grp)
--Swap freed group with last used group and their ids
if (grp.cacheId < CB.cache.numUsedGroups) then
local grpId = grp.cacheId;
local lastId = CB.cache.numUsedGroups;
local last = CB.cache.groups[ lastId ];
CB.cache.groups[ grpId ] = last;
CB.cache.groups[ lastId ] = grp;
grp.cacheId = lastId;
last.cacheId = grpId;
end
CB.cache.numUsedGroups = CB.cache.numUsedGroups - 1;
end
function ChronoBars.FreeAllBars ()
CB.cache.numUsedBars = 0;
end
function ChronoBars.FreeAllGroups ()
CB.cache.numUsedGroups = 0;
end
--Bar and Group hierarchy
--================================================================================
function ChronoBars.UI_AddGroup ()
local grp = CB.NewGroup();
table.insert( CB.groups, grp );
grp:Show();
return grp;
end
function ChronoBars.UI_AddBar (grp)
local bar = CB.NewBar();
table.insert( grp.bars, bar );
bar.removeInactive = false;
bar.group = grp;
bar:Show();
return bar;
end
function ChronoBars.UI_RemoveGroup (grp)
local numGroups = table.getn( CB.groups );
for g=1,numGroups do
if (CB.groups[g] == grp) then
CB.UI_RemoveAllBars( grp );
CB.FreeGroup( grp );
grp:Hide();
table.remove( CB.groups, g );
return;
end
end
end
function ChronoBars.UI_RemoveBar (bar)
local numBars = table.getn( bar.group.bars );
for b=1,numBars do
if (bar.group.bars[b] == bar) then
CB.FreeBar( bar );
bar:Hide();
table.remove( bar.group.bars, b );
return;
end
end
end
function ChronoBars.UI_RemoveAllBars (grp)
local numBars = table.getn( grp.bars );
for b=numBars,1,-1 do
CB.FreeBar( grp.bars[ b ] );
grp.bars[ b ]:Hide();
table.remove( grp.bars );
end
end
function ChronoBars.UI_RemoveAllGroups ()
local numGroups = table.getn( CB.groups );
for g=numGroups,1,-1 do
local numBars = table.getn( CB.groups[g].bars );
for b=numBars,1,-1 do
CB.groups[ g ].bars[ b ]:Hide();
table.remove( CB.groups[g].bars );
end
CB.groups[ g ]:Hide();
table.remove( CB.groups );
end
CB.FreeAllBars();
CB.FreeAllGroups();
end
function ChronoBars.UI_RemoveBarWhenInactive (bar)
bar.removeInactive = true;
end
function ChronoBars.UI_RemoveInactiveBars (grp)
local numBars = table.getn( grp.bars );
for b=numBars,1,-1 do
local bar = grp.bars[b];
if ((not bar.status.active)
and (not bar.status.animating)
and bar.removeInactive) then
CB.UI_RemoveBar( bar );
bar.removeInactive = false;
end
end
end
--Bar and group manipulation
--===========================================================================
function ChronoBars.Bar_OnMouseDown (bar, button)
if (button == "RightButton" and CB.designMode) then
CB.ShowBarConfig (bar);
end
end
function ChronoBars.BarIcon_OnMouseDown( icon, button )
CB.Bar_OnMouseDown( icon.bar, button );
end
function ChronoBars.Bar_OnDragStart (bar)
if (CB.designMode) then
bar.group:StartMoving();
end
end
function ChronoBars.Bar_OnDragStop (bar)
if (CB.designMode) then
bar.group:StopMovingOrSizing();
local x = bar.group:GetLeft();
local y = bar.group:GetBottom();
bar.group.settings.x = x - GetScreenWidth()/2;
bar.group.settings.y = y - GetScreenHeight()/2;
ChronoBars.UpdateBarSettings();
end
end
function ChronoBars.BarIcon_OnDragStart( icon )
CB.Bar_OnDragStart( icon.bar );
end
function ChronoBars.BarIcon_OnDragStop( icon )
CB.Bar_OnDragStop( icon.bar );
end
function ChronoBars.CreateSpark ( bar )
local spark = bar:CreateTexture( nil, "ARTWORK", nil, CB.LAYER_SPARK );
spark:SetTexture( "Interface\\CastingBar\\UI-CastingBar-Spark" );
spark:SetBlendMode( "ADD" );
spark:SetWidth( 32 );
spark:SetHeight( 60 );
return spark;
end
function ChronoBars.ApplySparkSettings(spark, settings, gsettings)
local h = CB.RoundToPixel( gsettings.height );
spark:SetWidth( settings.style.spark.width );
spark:SetHeight( h * settings.style.spark.height );
end
function ChronoBars.CreateNotch( bar )
local notch = bar:CreateTexture( nil, "ARTWORK", nil, CB.LAYER_NOTCH );
--notch:SetTexture("Interface\\AddOns\\ChronoBars\\Textures\\Notch.tga");
--notch:SetTexture("Interface\\AddOns\\ChronoBars\\Textures\\White.tga");
--notch:SetTexture("Interface\\AddOns\\ChronoBars\\Textures\\Notch2.tga");
notch:SetTexture("Interface\\AddOns\\ChronoBars\\Textures\\NotchLeft.tga");
--notch:SetTexture("Interface\\AddOns\\ChronoBars\\Textures\\NotchTriangle.tga");
notch:SetWidth( 2 );
notch:SetHeight( 10 );
return notch;
end
function ChronoBars.ApplyNotchSettings( notch, settings, gsettings)
local h = CB.RoundToPixel( gsettings.height );
local p = CB.RoundToPixel( gsettings.padding );
local c = settings.style.notch.color;
--local hh = (h - 2*p - 2) * settings.style.notch.height;
--notch:SetWidth( hh );
--notch:SetHeight( hh );
notch:SetWidth( settings.style.notch.width );
notch:SetHeight( (h - 2*p - 2) * settings.style.notch.height );
notch:SetGradientAlpha( "HORIZONTAL",
c.r, c.g, c.b, c.a,
c.r, c.g, c.b, c.a);
end
function ChronoBars.Bar_Create (name)
local bar = CreateFrame( "Frame", name );
local bg = bar:CreateTexture( nil, "BACKGROUND" );
bar.bg = bg;
local fg = bar:CreateTexture( nil, "ARTWORK", nil, CB.LAYER_FG );
bar.fg = fg;
local fgBlink = bar:CreateTexture( nil, "ARTWORK" );
bar.fgBlink = fgBlink;
local fgFade = bar:CreateTexture( nil, "ARTWORK", nil, CB.LAYER_FG_FADE);
bar.fgFade = fgFade;
local icon = CreateFrame( "Frame", name.."IconFrame" );
icon:SetParent( bar );
icon.bar = bar;
bar.icon = icon;
local iconBg = icon:CreateTexture( nil, "BACKGROUND" );
iconBg:SetAllPoints( icon );
icon.bg = iconBg;
local iconTex = icon:CreateTexture( nil, "ARTWORK", nil, 0 );
iconTex:SetAllPoints( icon );
icon.tex = iconTex;
local iconFade = icon:CreateTexture( nil, "ARTWORK", nil, 1 );
iconFade:SetAllPoints( icon );
iconFade:Hide();
icon.fade = iconFade;
local iconCd = CreateFrame("Cooldown", "CBIconCooldown", icon, "CooldownFrameTemplate");
iconCd:SetAllPoints( icon );
iconCd:Show();
icon.cd = iconCd;
local spark = CB.CreateSpark( bar );
bar.spark = spark;
-- Start with 2 notches for preview, more created on demand
bar.notches = {};
bar.notches[1] = CB.CreateNotch( bar );
bar.notches[2] = CB.CreateNotch( bar );
bar:SetPoint( "LEFT", 0,0 );
bar:SetPoint( "BOTTOM", 0,0 );
bar:SetWidth( 100 );
bar:SetHeight( 20 );
bar:Hide();
bar:EnableMouse( true );
bar:RegisterForDrag( "LeftButton" );
bar:SetScript( "OnDragStart", ChronoBars.Bar_OnDragStart );
bar:SetScript( "OnDragStop", ChronoBars.Bar_OnDragStop );
bar:SetScript( "OnMouseDown", ChronoBars.Bar_OnMouseDown );
bar.icon:EnableMouse( true );
bar.icon:RegisterForDrag( "LeftButton" );
bar.icon:SetScript( "OnDragStart", ChronoBars.BarIcon_OnDragStart );
bar.icon:SetScript( "OnDragStop", ChronoBars.BarIcon_OnDragStop );
bar.icon:SetScript( "OnMouseDown", ChronoBars.BarIcon_OnMouseDown );
bar.events = {};
return bar;
end
function ChronoBars.Bar_ApplySettings (bar, profile, groupId, barId)
--Get bar and group settings
local gsettings = profile.groups[ groupId ];
local settings = profile.groups[ groupId ].bars[ barId ];
--Store handy references
bar.groupId = groupId;
bar.barId = barId;
bar.gsettings = gsettings;
bar.settings = settings;
--Init bar animation
if (bar.anim == nil) then bar.anim = {} end
bar.anim.ratio = 0;
bar.anim.blink = 0;
bar.anim.fade = 0;
--Init bar status
if (bar.status == nil) then bar.status = {} end
bar.status.desc = nil;
bar.status.id = nil;
bar.status.name = nil;
bar.status.icon = nil;
bar.status.count = nil;
bar.status.maxCount = nil;
bar.status.target = nil;
bar.status.duration = nil;
bar.status.expires = nil;
bar.status.chargeDuration = nil;
bar.status.chargeExpires = nil;
bar.status.iconDuration = nil;
bar.status.iconStart = nil;
bar.status.iconUsable = true;
bar.status.left = 0.0;
bar.status.ratio = 0.0;
bar.status.active = false;
bar.status.deactivated = false;
bar.status.animating = true;
--Init effect status
CB.Bar_InitEffect( bar );
--Round graphics to actual pixels
local pad = CB.RoundToPixel( gsettings.padding );
local h = CB.RoundToPixel( gsettings.height );
local w = CB.RoundToPixel( gsettings.width );
--Fetch LibSharedMedia paths
local texPath = ChronoBars.LSM:Fetch( "statusbar", settings.style.lsmTexHandle );
if (not texPath) then texPath = ""; end
--Background
bar.bg:SetPoint( "BOTTOMLEFT", 0,0 );
bar.bg:SetPoint( "TOPRIGHT", 0,0 );
--Back and front color and texture
local b = settings.style.bgColor;
bar.bg:SetColorTexture( b.r, b.g, b.b, b.a );
local f = settings.style.fgColor;
bar.fg:SetHorizTile( true );
bar.fg:SetVertTile( false );
bar.fg:SetGradientAlpha( "HORIZONTAL", f.r,f.g,f.b,f.a, f.r,f.g,f.b,f.a );
bar.fgBlink:SetHorizTile( true );
bar.fgBlink:SetVertTile( false );
bar.fgBlink:SetGradientAlpha( "HORIZONTAL", f.r,f.g,f.b,0, f.r,f.g,f.b,0 );
if (settings.style.lsmTexHandle == "None") then
bar.fg:SetColorTexture( 1,1,1,1 );
bar.fgBlink:SetColorTexture( 1,1,1,1 );
else
bar.fg:SetTexture( texPath );
bar.fgBlink:SetTexture( texPath );
end
--TODO: allow choosing colour of charge fade
bar.fgFade:SetColorTexture( 0,0,0, 0.5 );
--Make foreground half-full
local maxW = (w - 2*pad);
local offWidth = maxW * 0.5;
bar.fg:ClearAllPoints();
bar.fgBlink:ClearAllPoints();
bar.fgFade:ClearAllPoints();
if (settings.style.fullSide == CB.SIDE_RIGHT) then
bar.fg:SetPoint( "BOTTOMLEFT", pad, pad );
bar.fg:SetPoint( "TOPRIGHT", -pad-offWidth, -pad );
bar.fgBlink:SetPoint( "BOTTOMLEFT", bar.fg, "BOTTOMRIGHT", 0,0 );
bar.fgBlink:SetPoint( "TOPRIGHT", -pad, -pad );
else
bar.fg:SetPoint( "BOTTOMLEFT", pad+offWidth, pad );
bar.fg:SetPoint( "TOPRIGHT", -pad, -pad );
bar.fgBlink:SetPoint( "BOTTOMLEFT", pad, pad );
bar.fgBlink:SetPoint( "TOPRIGHT", bar.fg, "TOPLEFT", 0,0 );
end
-- Cover some of the foreground as if the 2nd of 3 charges was recharging
if (settings.type == CB.EFFECT_TYPE_CHARGES and
settings.style.fillUp) then
if (settings.style.fullSide == CB.SIDE_RIGHT) then
bar.fgFade:SetPoint( "BOTTOMLEFT", bar.fg, "BOTTOMLEFT", maxW * 0.33, 0);
bar.fgFade:SetPoint( "TOPRIGHT", bar.fg, "TOPRIGHT", 0,0 );
else
bar.fgFade:SetPoint( "TOPRIGHT", bar.fg, "TOPRIGHT", -maxW * 0.33, 0 );
bar.fgFade:SetPoint( "BOTTOMLEFT", bar.fg, "BOTTOMLEFT", 0, 0);
end
bar.fgFade:Show();
else
bar.fgFade:Hide();
end
--Create layout table if missing
if (bar.prevFrame == nil) then
bar.prevFrame = {};
end
CB.Util_ClearTableKeys( bar.prevFrame );
--Icon
local isettings = settings.style.icon;
if (isettings.enabled) then
bar.icon:Show();
--Texture
local iconTex = bar.status.icon;
if (not iconTex) then iconTex = "Interface/Icons/INV_Misc_QuestionMark"; end
bar.icon.tex:SetTexture( iconTex );
--Zoom
if (isettings.zoom) then
local s = 0.08;
bar.icon.tex:SetTexCoord( s, 1-s, s, 1-s );
else
bar.icon.tex:SetTexCoord( 0,1,0,1 );
end
--Back color
local b = isettings.bgColor;
if (isettings.inherit) then b = settings.style.bgColor end
bar.icon.bg:SetColorTexture( b.r, b.g, b.b, b.a );
--Fade overlay
bar.icon.fade:SetColorTexture( 0,0,0, 0.5 );
bar.icon.fade:Hide();
--Reset last cooldown info
bar.icon.start = nil;
bar.icon.duration = nil;
--Size
local s = CB.RoundToPixel( isettings.size );
if (isettings.inherit) then s = h end
bar.icon:SetWidth( s );
bar.icon:SetHeight( s );
--Padding
local p = CB.RoundToPixel( isettings.padding );
if (isettings.inherit) then p = pad end
bar.icon.tex:ClearAllPoints();
bar.icon.tex:SetPoint( "BOTTOMLEFT", bar.icon, "BOTTOMLEFT", p, p );
bar.icon.tex:SetPoint( "TOPRIGHT", bar.icon, "TOPRIGHT", -p,-p );
--Position
bar.prevFrame[ isettings.position ] = bar.icon;
CB.PositionFrame( bar.icon, nil, bar.bg, nil, isettings.position, isettings.x, isettings.y, 0 );
else
bar.icon:Hide();
end
--Config text
local displayInfo = nil;
local displayCount = 0;
if (settings.type == CB.EFFECT_TYPE_CD) then
displayInfo = "CD";
displayCount = nil;
elseif (settings.type == CB.EFFECT_TYPE_USABLE) then
displayInfo = "Usable";
displayCount = nil;
end
--Create text table if missing
if (bar.text == nil) then
bar.text = {};
end
--Hide all text widgets
for t=1,table.getn(bar.text) do
bar.text[t]:Hide();
end
--Walk all the text settings
local numText = table.getn( settings.style.text );
for t=1,numText do
repeat
--Create new text if missing
if (t > table.getn( bar.text )) then
local newText = bar:CreateFontString( bar:GetName().."Text"..tostring(t) );
newText:SetDrawLayer("ARTWORK", CB.LAYER_TEXT);
newText:SetShadowOffset( 1, -1 );
newText:SetWordWrap( false );
newText:Hide();
table.insert( bar.text, newText );
end
--Store reference to settings
local tsettings = settings.style.text[t];
bar.text[t].settings = tsettings;
--Check if text enabled
if (tsettings.enabled)
then bar.text[t]:Show();
else break
end
--Font
local flags = nil;
if (tsettings.outline) then flags = "OUTLINE" end;
local fontPath = ChronoBars.LSM:Fetch( "font", tsettings.font );
if (not fontPath) then fontPath = "Fonts\\FRIZQT__.TTF" end;
bar.text[t]:SetFont( fontPath, tsettings.size, flags );
--Color
local tcol = tsettings.textColor;
bar.text[t]:SetTextColor( tcol.r, tcol.g, tcol.b, tcol.a );
--Shadow
local scol = tsettings.shadowColor;
bar.text[t]:SetShadowColor( scol.r, scol.g, scol.b, scol.a );
--Position
local prevFrame = bar.prevFrame[ tsettings.position ];
bar.prevFrame[ tsettings.position ] = bar.text[t];
CB.PositionFrame( bar.text[t], prevFrame, bar.bg, bar, tsettings.position, tsettings.x, tsettings.y, 5 );
--Maximum width
if (tsettings.width <= 0)
then bar.text[t]:SetWidth(0);
else bar.text[t]:SetWidth(tsettings.width);
end
--Text
CB.InitText( bar.text[t] );
CB.FormatText( bar.text[t], bar.status.name or bar.status.desc, displayCount, 0, 0, "Target Name", displayInfo );
until true
end
--Spark
if (settings.style.spark.enabled) then
CB.ApplySparkSettings(bar.spark, settings, gsettings);
bar.spark:Show();
if (settings.style.fullSide == CB.SIDE_RIGHT)
then bar.spark:SetPoint( "CENTER", bar.fg, "RIGHT", 0,0 );
else bar.spark:SetPoint( "CENTER", bar.fg, "LEFT", 0,0 );
end
else
bar.spark:Hide();
end
-- Charge notches
for t=1,table.getn(bar.notches) do
bar.notches[t]:Hide();
bar.notches[t]:ClearAllPoints();
end
if (settings.type == CB.EFFECT_TYPE_CHARGES and settings.style.notch.enabled) then
CB.ApplyNotchSettings(bar.notches[1], settings, gsettings);
CB.ApplyNotchSettings(bar.notches[2], settings, gsettings);
bar.notches[1]:Show();
bar.notches[2]:Show();
local n3 = CB.RoundToPixel(0.33 * maxW - bar.notches[1]:GetWidth()/2);
local n6 = CB.RoundToPixel(0.66 * maxW - bar.notches[1]:GetWidth()/2);
if (settings.style.fullSide == CB.SIDE_RIGHT) then
bar.notches[1]:SetPoint( "LEFT", bar.fg, "LEFT", n3, 0 );
bar.notches[2]:SetPoint( "LEFT", bar.fg, "LEFT", n6, 0 );
else
bar.notches[1]:SetPoint( "RIGHT", bar.fg, "RIGHT", -n3, 0 );
bar.notches[2]:SetPoint( "RIGHT", bar.fg, "RIGHT", -n6, 0 );
end
end
--Set half-transparent if disabled
if (settings.enabled)
then bar:SetAlpha( 1 );
else bar:SetAlpha( 0.5 );
end
--Enable for mouse events
bar:EnableMouse( true );
bar.icon:EnableMouse( true );
end
-- This function is called from Group_UpdateUI only on bars that are currently active (duration not nil)
-- The group will do that in every OnUpdate which runs as long as any of its bars are active
function ChronoBars.Bar_UpdateUI (bar, now, interval)
local p = CB.RoundToPixel( bar.gsettings.padding );
local w = CB.RoundToPixel( bar.gsettings.width );
local set = bar.settings;
--Animation
--===============================
--Animate ratio
local dRatio = interval * 3.0;
if (bar.status.ratio > bar.anim.ratio) then
--Slide up when refreshed
if (set.style.anim.up) then
bar.anim.ratio = bar.anim.ratio + dRatio;
if (bar.anim.ratio > bar.status.ratio) then
bar.anim.ratio = bar.status.ratio;
end
else bar.anim.ratio = bar.status.ratio end
elseif (bar.status.ratio < bar.anim.ratio) then
--Slide down when consumed
if (set.style.anim.down) then
bar.anim.ratio = bar.anim.ratio - dRatio;
if (bar.anim.ratio < bar.status.ratio) then
bar.anim.ratio = bar.status.ratio;
end
else bar.anim.ratio = bar.status.ratio end
end
--Find if should blink
local canBlink = false;
local blinkSpeed = 0.0;
if (bar.status.active) then
--Check if usability blinking applies
if (set.type == CB.EFFECT_TYPE_USABLE) then
if (set.style.anim.blinkUsable) then
canBlink = true;
blinkSpeed = 3.0;
end
--Check if bar does not have an infinite duration
elseif (bar.status.duration > 0) then
--Slow blink threshold is half bar or 5 seconds, whichever is smaller
local blinkSlow = 0.5 * bar.status.duration
if (blinkSlow > 5) then blinkSlow = 5 end;
--Fast blink threshold is always 1 second
local blinkFast = 1.0;
--Blink when bar time below threshold
if (set.style.anim.blinkFast and bar.status.left <= blinkFast) then
canBlink = true;
blinkSpeed = 10.0;
elseif (set.style.anim.blinkSlow and bar.status.left <= blinkSlow) then
canBlink = true;
blinkSpeed = 3.0;
end
end
end
--Animate blinking
if (canBlink) then
--Alpha is absolute of [1,-1] for back-and-forth animation
local dBlink = interval * blinkSpeed;
bar.anim.blink = bar.anim.blink - dBlink;
if (bar.anim.blink < -1.0) then
bar.anim.blink = 1;
end
--Infinite bar blinks full portion, other bars blink expired portion
elseif (bar.status.duration == 0)
then bar.anim.blink = 1;
else bar.anim.blink = 0;
end
--Animate fading (fade out when bar expires)
if (set.style.anim.fade and set.style.visibility ~= CB.VISIBLE_ALWAYS) then
if (bar.status.ratio == 0) then
local dFade = interval * 3.0;
bar.anim.fade = bar.anim.fade - dFade;
if (bar.anim.fade < 0.0) then
bar.anim.fade = 0;
end
else bar.anim.fade = 1; end
else bar.anim.fade = 1; end
--Bar is animating if time is left or animations aren't done yet
if (set.style.anim.fade and set.style.visibility ~= CB.VISIBLE_ALWAYS) then
bar.status.animating = (bar.anim.fade > 0.0);
elseif (set.style.anim.down) then
bar.status.animating = (bar.anim.ratio > 0.0);
else
bar.status.animating = (bar.status.ratio > 0.0);
end
--UI
--===============================
local maxW = w - 2 * p;
--Hide spark for no-duration and expired bars
if (bar.status.duration == 0 or bar.anim.ratio == 0) then
bar.spark:Hide();
else
if (set.style.spark.enabled) then
bar.spark:Show();
end
end
--Charge notches
if (set.type == CB.EFFECT_TYPE_CHARGES) then
-- Start by hiding all the notches
for t=1,table.getn(bar.notches) do
bar.notches[t]:Hide();
bar.notches[t]:ClearAllPoints();
end
-- Show a notch for each charge threshold between the first and the last
if (set.style.notch.enabled and bar.status.maxCount) then
local notchCount = bar.status.maxCount - 1;
for t=1,notchCount do
if (t > table.getn(bar.notches)) then
local notch = CB.CreateNotch( bar );
CB.ApplyNotchSettings(notch, bar.settings, bar.gsettings);
bar.notches[t] = notch;
end
local notch = bar.notches[t];
local notchOffset = CB.RoundToPixel(t * (maxW / bar.status.maxCount) - notch:GetWidth()/2);
if (set.style.fullSide == ChronoBars.SIDE_RIGHT) then
notch:SetPoint( "LEFT", bar.fg, "LEFT", notchOffset, 0 );
elseif (set.style.fullSide == ChronoBars.SIDE_LEFT) then
notch:SetPoint( "RIGHT", bar.fg, "RIGHT", -notchOffset, 0 );
end
notch:Show();
end
end
end
--Scale front to match ratio
local offW;
if (set.style.fillUp)
then offW = bar.anim.ratio * maxW;
else offW = (1.0 - bar.anim.ratio) * maxW;
end
if (set.style.fullSide == ChronoBars.SIDE_RIGHT) then
bar.fg:SetPoint( "TOPRIGHT", -p - offW, -p );
elseif (set.style.fullSide == ChronoBars.SIDE_LEFT) then
bar.fg:SetPoint( "BOTTOMLEFT", p + offW, p );
end
--Cover the next charge coming off cooldown with the foreground fade
if (set.type == CB.EFFECT_TYPE_CHARGES and bar.status.count and bar.status.maxCount) then
local chargeRatio = bar.status.count / bar.status.maxCount;
if (set.style.fullSide == ChronoBars.SIDE_RIGHT) then
bar.fgFade:SetPoint( "BOTTOMLEFT", bar.fg, "BOTTOMLEFT", maxW * chargeRatio, 0);
else
bar.fgFade:SetPoint( "TOPRIGHT", bar.fg, "TOPRIGHT", -maxW * chargeRatio, 0);
end
bar.fgFade:Show();
else
bar.fgFade:Hide();
end
--Get front color and blink alpha
local f = set.style.fgColor;
local blinkA = math.abs( bar.anim.blink );
-- Apply blink to foreground fade of the current charge
if (set.type == CB.EFFECT_TYPE_CHARGES) then
bar.fgFade:SetColorTexture( 0,0,0, (1 - blinkA) * 0.5 );
--Apply blink to full portion if infinite duration
elseif (bar.status.duration == 0) then
bar.fg:SetGradientAlpha( "HORIZONTAL",
f.r,f.g,f.b, blinkA * f.a,
f.r,f.g,f.b, blinkA * f.a );
--Apply blink to exhausted portion otherwise
else
bar.fgBlink:SetGradientAlpha( "HORIZONTAL",
f.r,f.g,f.b, 0.75 * blinkA * f.a,
f.r,f.g,f.b, 0.75 * blinkA * f.a );
end
--Set entire bar alpha to match fade
bar:SetAlpha( bar.anim.fade );
--Update bar icon
if (bar.status.icon) then
bar.icon.tex:SetTexture( bar.status.icon );
end
--Formatting input
local displayLeft = nil;
local displayDuration = nil;
local displayCount = nil;
local displayInfo = nil;
--Show time left and duration if active and not infinite,
if (bar.status.active and bar.status.duration > 0) then
displayLeft = bar.status.left;
displayDuration = bar.status.duration;
end
--Show count
if (bar.status.count ~= nil) then
displayCount = bar.status.count;
end
--Show usable/CD info
if (set.type == CB.EFFECT_TYPE_CD) then
displayInfo = "CD";
elseif (set.type == CB.EFFECT_TYPE_USABLE) then
displayInfo = "Usable";
end
--Format all text
for t=1,table.getn(set.style.text) do
if (set.style.text[t].enabled) then
CB.FormatText( bar.text[t], bar.status.name, displayCount,
displayLeft, displayDuration, bar.status.target, displayInfo );
end
end
--Disable mouse events
bar:EnableMouse( false );
bar.icon:EnableMouse( false );
end
-- This function is called by Bar_UpdateEffect on every event
function ChronoBars.Bar_UpdateIcon (bar)
-- It's important to only SetCooldown on the spinner widget when the values change, otherwise it unnecessarily flickers.
-- The widget template will continue to animate itself after SetCooldown.
if (bar.status.iconStart and bar.status.iconDuration and
bar.status.iconStart > 0 and bar.status.iconDuration > 0 and
(bar.status.iconStart ~= bar.icon.start or bar.status.iconDuration ~= bar.icon.duration)) then
--CB.Print("ICON CD UPDATE start " .. bar.status.iconStart .. " duration " .. bar.status.iconDuration);
bar.icon.cd:SetCooldown(bar.status.iconStart, bar.status.iconDuration, 1);
bar.icon.start = bar.status.iconStart;
bar.icon.duration = bar.status.iconDuration;
end
-- Add an extra fade behind the cooldown spinner when unusable
if (bar.status.iconUsable) then
bar.icon.fade:Hide();
else
bar.icon.fade:Show();
end
end
function ChronoBars_BarSmaller (a,b)
if (a.status.left ~= b.status.left) then
return a.status.left < b.status.left;
else
return a.barId < b.barId;
end
end
function ChronoBars_BarGreater (a,b)
if (a.status.left ~= b.status.left) then
return a.status.left > b.status.left;
else
return a.barId > b.barId;
end
end
function ChronoBars.Group_Create (name)
local grp = CreateFrame( "Frame", name, UIParent );
grp:SetPoint( "BOTTOMLEFT", UIParent, "BOTTOMLEFT", 0,0 );
grp:SetWidth( 2 );
grp:SetHeight( 2 );
grp:Hide();
local bg = grp:CreateTexture( nil, "BACKGROUND" );
grp.bg = bg;
grp:EnableMouse( true );
grp:SetMovable( true );
grp.bars = {};
grp.sortedBars = {};
return grp;
end
function ChronoBars.Group_UpdateBounds (grp, bar, L, R, B, T)
local barL = L;
local barR = R;
local barB = B;
local barT = T;
if (barL == nil) then
barL = bar;
barR = bar;
barB = bar;
barT = bar;
end
if (grp.settings.grow == ChronoBars.GROW_UP)
then barT = bar;
else barB = bar;
end
return barL, barR, barB, barT;
end
function ChronoBars.Group_ApplySettings (grp, profile, groupId)
--Get group settings
local settings = profile.groups[ groupId ];
--Store handy references
grp.groupId = groupId;
grp.settings = settings;
--Reset group update times
grp.initUpdate = false;
grp.nextUpdate = 0;
--Init complex variables
local x = CB.RoundToPixel( GetScreenWidth()/2 + settings.x );
local y = CB.RoundToPixel( GetScreenHeight()/2 + settings.y );
local w = CB.RoundToPixel( settings.width );
local h = CB.RoundToPixel( settings.height );
local s = CB.RoundToPixel( settings.spacing );
local m = CB.RoundToPixel( settings.margin );
local p = CB.RoundToPixel( settings.padding );