forked from Mapkov2/Midnight-Simple-Auras
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSA_Bars.lua
More file actions
507 lines (436 loc) · 17.2 KB
/
MSA_Bars.lua
File metadata and controls
507 lines (436 loc) · 17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
-- ########################################################
-- MSA_Bars.lua v2 - Progress Bar Display
--
-- Layout options:
-- barShowIcon = true/false
-- barIconPos = "LEFT" / "RIGHT" / "TOP" / "BOTTOM"
-- barFillDir = "LR" / "RL" / "BT" / "TB"
-- TB/BT -> vertical bar (btn width/height swap)
--
-- Secret-safe: issecretvalue guards on all timing reads.
-- ########################################################
local GetTime = GetTime
local type, tonumber = type, tonumber
-----------------------------------------------------------
-- Defaults
-----------------------------------------------------------
local DEF_W = 200
local DEF_H = 22
local DEF_TEX = "Interface\\TargetingFrame\\UI-StatusBar"
local SPARK_W = 14
-----------------------------------------------------------
-- Visible bars + 60fps ticker
-----------------------------------------------------------
local visBars = {}
local barCount = 0
local ticker = CreateFrame("Frame", "MSWA_BarTicker", UIParent)
ticker:Hide()
ticker:SetScript("OnUpdate", function(self)
local now = GetTime()
local any = false
for btn in pairs(visBars) do
local bd = btn._msaBar
if bd and bd.frame and bd.frame:IsShown() then
any = true
local exp, dur = bd._exp or 0, bd._dur or 0
if dur > 0 and exp > 0 then
local rem = exp - now
if rem < 0 then rem = 0 end
local pct = rem / dur
if pct > 1 then pct = 1 end
bd.bar:SetValue(pct)
-- Spark
if bd.spark and bd._showSpark then
if pct > 0.01 and pct < 0.99 then
bd.spark:ClearAllPoints()
if bd._isVert then
-- Vertical: spark along Y
local h = bd.bar:GetHeight()
if bd._reversed then
-- TB: fills top->bottom, spark moves down
bd.spark:SetPoint("CENTER", bd.bar, "TOP", 0, -(h * pct))
else
-- BT: fills bottom->top, spark moves up
bd.spark:SetPoint("CENTER", bd.bar, "BOTTOM", 0, h * pct)
end
else
-- Horizontal
local w = bd.bar:GetWidth()
if bd._reversed then
-- RL: fills right->left, spark moves left
bd.spark:SetPoint("CENTER", bd.bar, "RIGHT", -(w * pct), 0)
else
-- LR: fills left->right
bd.spark:SetPoint("CENTER", bd.bar, "LEFT", w * pct, 0)
end
end
bd.spark:Show()
else
bd.spark:Hide()
end
elseif bd.spark then
bd.spark:Hide()
end
if bd.timerFS and bd._showTimer then
bd.timerFS:SetText(MSWA_FormatTimer(rem, bd._showDecimal))
end
-- Conditional text color (matches icon system tc2)
if bd._tc2Enabled and bd.timerFS then
local condActive = false
if bd._tc2Cond == "TIMER_BELOW" then
condActive = rem <= bd._tc2Val and rem > 0
elseif bd._tc2Cond == "TIMER_ABOVE" then
condActive = rem >= bd._tc2Val
end
if condActive then
bd.timerFS:SetTextColor(bd._tc2R, bd._tc2G, bd._tc2B, 1)
else
bd.timerFS:SetTextColor(bd._baseTextR or 1, bd._baseTextG or 1, bd._baseTextB or 1, 1)
end
end
else
bd.bar:SetValue(1)
if bd.spark then bd.spark:Hide() end
if bd.timerFS then bd.timerFS:SetText("") end
end
else
visBars[btn] = nil
barCount = barCount - 1
end
end
if not any then barCount = 0; self:Hide() end
end)
-----------------------------------------------------------
-- EnsureBar: create elements (no anchoring - done in Layout)
-----------------------------------------------------------
function MSWA_EnsureBar(btn)
if btn._msaBar then return btn._msaBar end
local bd = { _exp = 0, _dur = 0, _showTimer = true, _isVert = false, _reversed = false }
local f = CreateFrame("Frame", nil, btn, "BackdropTemplate")
f:SetAllPoints(btn)
f:SetFrameLevel(btn:GetFrameLevel() + 2)
bd.frame = f
-- Border + BG
bd.border = f:CreateTexture(nil, "BACKGROUND", nil, -2)
bd.border:SetPoint("TOPLEFT", -1, 1)
bd.border:SetPoint("BOTTOMRIGHT", 1, -1)
bd.border:SetColorTexture(0, 0, 0, 0.95)
bd.bg = f:CreateTexture(nil, "BACKGROUND", nil, -1)
bd.bg:SetAllPoints(f)
bd.bg:SetColorTexture(0.06, 0.06, 0.06, 0.85)
-- Icon elements (positioned in Layout)
bd.iconBG = f:CreateTexture(nil, "ARTWORK")
bd.iconBG:SetColorTexture(0, 0, 0, 0.9)
bd.iconTex = f:CreateTexture(nil, "ARTWORK", nil, 1)
bd.iconTex:SetTexCoord(0.07, 0.93, 0.07, 0.93)
-- StatusBar (positioned in Layout)
bd.bar = CreateFrame("StatusBar", nil, f)
bd.bar:SetMinMaxValues(0, 1)
bd.bar:SetValue(1)
bd.bar:SetStatusBarTexture(DEF_TEX)
bd.bar:SetStatusBarColor(0.9, 0.7, 0.0)
bd.barBG = bd.bar:CreateTexture(nil, "BACKGROUND")
bd.barBG:SetAllPoints()
bd.barBG:SetTexture(DEF_TEX)
bd.barBG:SetVertexColor(0.12, 0.12, 0.12, 0.7)
-- Spark
bd.spark = bd.bar:CreateTexture(nil, "OVERLAY")
bd.spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
bd.spark:SetBlendMode("ADD")
bd.spark:Hide()
-- Name text
bd.nameFS = bd.bar:CreateFontString(nil, "OVERLAY")
bd.nameFS:SetFont(STANDARD_TEXT_FONT, 11, "OUTLINE")
bd.nameFS:SetWordWrap(false)
-- Timer text
bd.timerFS = bd.bar:CreateFontString(nil, "OVERLAY")
bd.timerFS:SetFont(STANDARD_TEXT_FONT, 11, "OUTLINE")
-- Stack text
bd.stackFS = f:CreateFontString(nil, "OVERLAY")
bd.stackFS:SetFont(STANDARD_TEXT_FONT, 10, "OUTLINE")
bd.stackFS:SetJustifyH("RIGHT")
bd.stackFS:SetTextColor(1, 0.82, 0)
bd.stackFS:Hide()
f:Hide()
btn._msaBar = bd
return bd
end
-----------------------------------------------------------
-- Layout: position icon + bar based on settings
-- Called every ApplyStyle (settings may have changed)
-----------------------------------------------------------
local function ApplyLayout(bd, s)
local showIcon = (s.barShowIcon ~= false)
local iconPos = s.barIconPos or "LEFT"
local fillDir = s.barFillDir or "LR"
local isVert = (fillDir == "TB" or fillDir == "BT")
local reversed = (fillDir == "RL" or fillDir == "TB")
bd._isVert = isVert
bd._reversed = reversed
local bw = tonumber(s.barWidth) or DEF_W
local bh = tonumber(s.barHeight) or DEF_H
-- For vertical bars: swap so barWidth = narrow, barHeight = tall
local btnW, btnH
if isVert then
btnW = bh -- narrow dimension
btnH = bw -- tall dimension
else
btnW = bw
btnH = bh
end
bd._btnW = btnW
bd._btnH = btnH
-- Icon size
local pad = 2
local icoSz
if isVert then
icoSz = btnW - (pad * 2)
else
icoSz = btnH - (pad * 2)
end
if icoSz < 4 then icoSz = 4 end
-- Clear all dynamic anchors
bd.iconTex:ClearAllPoints()
bd.iconBG:ClearAllPoints()
bd.bar:ClearAllPoints()
bd.nameFS:ClearAllPoints()
bd.timerFS:ClearAllPoints()
bd.stackFS:ClearAllPoints()
-- StatusBar orientation + fill
if isVert then
bd.bar:SetOrientation("VERTICAL")
else
bd.bar:SetOrientation("HORIZONTAL")
end
if bd.bar.SetReverseFill then
bd.bar:SetReverseFill(reversed)
end
-- Icon
if showIcon then
bd.iconTex:SetSize(icoSz, icoSz)
bd.iconBG:SetSize(icoSz + 2, icoSz + 2)
bd.iconTex:Show()
bd.iconBG:Show()
local f = bd.frame
if iconPos == "RIGHT" then
bd.iconTex:SetPoint("TOPRIGHT", f, "TOPRIGHT", -pad, -pad)
bd.iconBG:SetPoint("CENTER", bd.iconTex, "CENTER", 0, 0)
bd.bar:SetPoint("TOPLEFT", f, "TOPLEFT", pad, -(pad+1))
bd.bar:SetPoint("BOTTOMRIGHT", bd.iconTex, "BOTTOMLEFT", -3, -1)
elseif iconPos == "TOP" then
bd.iconTex:SetPoint("TOPLEFT", f, "TOPLEFT", pad, -pad)
bd.iconBG:SetPoint("CENTER", bd.iconTex, "CENTER", 0, 0)
bd.bar:SetPoint("TOPLEFT", bd.iconTex, "BOTTOMLEFT", -1, -3)
bd.bar:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -pad, pad)
elseif iconPos == "BOTTOM" then
bd.iconTex:SetPoint("BOTTOMLEFT", f, "BOTTOMLEFT", pad, pad)
bd.iconBG:SetPoint("CENTER", bd.iconTex, "CENTER", 0, 0)
bd.bar:SetPoint("TOPLEFT", f, "TOPLEFT", pad, -(pad+1))
bd.bar:SetPoint("BOTTOMRIGHT", bd.iconTex, "TOPRIGHT", 1, 3)
else -- LEFT (default)
bd.iconTex:SetPoint("TOPLEFT", f, "TOPLEFT", pad, -pad)
bd.iconBG:SetPoint("CENTER", bd.iconTex, "CENTER", 0, 0)
bd.bar:SetPoint("TOPLEFT", bd.iconTex, "TOPRIGHT", 3, -1)
bd.bar:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -pad, pad)
end
bd.stackFS:SetPoint("BOTTOMRIGHT", bd.iconTex, "BOTTOMRIGHT", 0, 0)
else
-- No icon
bd.iconTex:Hide()
bd.iconBG:Hide()
bd.bar:SetPoint("TOPLEFT", bd.frame, "TOPLEFT", pad, -(pad+1))
bd.bar:SetPoint("BOTTOMRIGHT", bd.frame, "BOTTOMRIGHT", -pad, pad)
bd.stackFS:SetPoint("BOTTOMRIGHT", bd.bar, "BOTTOMRIGHT", -2, 2)
end
-- Spark size
if bd.spark then
if isVert then
bd.spark:SetSize(btnW * 1.6, SPARK_W)
-- Rotate spark for vertical (90deg)
bd.spark:SetTexCoord(1, 0, 0, 0, 1, 1, 0, 1)
else
bd.spark:SetSize(SPARK_W, btnH * 1.6)
bd.spark:SetTexCoord(0, 0, 0, 1, 1, 0, 1, 1) -- default
end
end
-- Text anchoring
if isVert then
-- Vertical: name top, timer bottom (both centered)
bd.nameFS:SetPoint("TOP", bd.bar, "TOP", 0, -3)
bd.nameFS:SetPoint("LEFT", bd.bar, "LEFT", 2, 0)
bd.nameFS:SetPoint("RIGHT", bd.bar, "RIGHT", -2, 0)
bd.nameFS:SetJustifyH("CENTER")
bd.timerFS:SetPoint("BOTTOM", bd.bar, "BOTTOM", 0, 3)
bd.timerFS:SetJustifyH("CENTER")
else
-- Horizontal: name left, timer right
bd.nameFS:SetPoint("LEFT", bd.bar, "LEFT", 4, 0)
bd.nameFS:SetPoint("RIGHT", bd.bar, "RIGHT", -45, 0)
bd.nameFS:SetJustifyH("LEFT")
bd.timerFS:SetPoint("RIGHT", bd.bar, "RIGHT", -4, 0)
bd.timerFS:SetJustifyH("RIGHT")
end
end
-----------------------------------------------------------
-- ApplyStyle: colors, font, texture + layout
-----------------------------------------------------------
local function ApplyStyle(bd, s, db)
-- Layout first (sets orientation, anchors, sizes)
ApplyLayout(bd, s)
-- BG
bd.bg:SetColorTexture(0.06, 0.06, 0.06, tonumber(s.barBgAlpha) or 0.85)
-- Texture MUST be set BEFORE color (SetStatusBarTexture
-- replaces the fill region and can reset vertex color)
local tex = s.barTexture or DEF_TEX
bd.bar:SetStatusBarTexture(tex)
bd.barBG:SetTexture(tex)
-- Re-assert MinMaxValues after orientation change
bd.bar:SetMinMaxValues(0, 1)
-- Color (AFTER texture so it sticks)
local c = s.barColor
if c and type(c) == "table" then
bd.bar:SetStatusBarColor(c.r or 0.9, c.g or 0.7, c.b or 0.0, c.a or 1)
else
bd.bar:SetStatusBarColor(0.9, 0.7, 0.0)
end
-- Toggles
bd._showTimer = (s.barShowTimer ~= false)
bd._showSpark = (s.barShowSpark ~= false)
bd._showDecimal = (s.showDecimal == true)
if bd.timerFS then if bd._showTimer then bd.timerFS:Show() else bd.timerFS:Hide() end end
if bd.nameFS then if s.barShowName ~= false then bd.nameFS:Show() else bd.nameFS:Hide() end end
-- Font: same resolution chain as icon text system
-- Face: per-aura textFontKey -> global fontKey -> DEFAULT
local fontKey = (s and s.textFontKey) or (db and db.fontKey) or "DEFAULT"
local fp = MSWA_GetFontPathFromKey and MSWA_GetFontPathFromKey(fontKey) or STANDARD_TEXT_FONT
-- Size: barFontSize (explicit override) -> textFontSize -> db.textFontSize -> 12
local fs = tonumber(s.barFontSize) or tonumber(s.textFontSize) or tonumber(db and db.textFontSize) or 12
-- Vertical bars with narrow width: smaller font
if bd._isVert and (bd._btnW or 22) < 30 then
fs = fs - 2
if fs < 7 then fs = 7 end
end
bd.nameFS:SetFont(fp, fs, "OUTLINE")
bd.timerFS:SetFont(fp, fs, "OUTLINE")
-- Text color: same chain as icon system (textColor per-aura -> global)
local tc = (s and s.textColor) or (db and db.textColor)
local tr, tg, tb = 1, 1, 1
if tc then tr = tonumber(tc.r) or 1; tg = tonumber(tc.g) or 1; tb = tonumber(tc.b) or 1 end
bd.nameFS:SetTextColor(tr, tg, tb, 1)
bd.timerFS:SetTextColor(tr, tg, tb, 1)
-- Store for conditional coloring updates from ticker
bd._baseTextR = tr
bd._baseTextG = tg
bd._baseTextB = tb
-- Conditional text color 2 config (cached for ticker use)
if s and s.textColor2Enabled and s.textColor2 then
bd._tc2Enabled = true
bd._tc2Cond = s.textColor2Cond or "TIMER_BELOW"
bd._tc2Val = tonumber(s.textColor2Value) or 5
bd._tc2R = tonumber(s.textColor2.r) or 1
bd._tc2G = tonumber(s.textColor2.g) or 0
bd._tc2B = tonumber(s.textColor2.b) or 0
else
bd._tc2Enabled = false
end
end
-----------------------------------------------------------
-- ShowBar
-----------------------------------------------------------
local function ShowBar(btn, bd, s, db)
ApplyStyle(bd, s, db)
-- Resize btn (layout already computed dimensions)
btn:SetSize(bd._btnW or DEF_W, bd._btnH or DEF_H)
-- Copy texture
local tex = btn.icon:GetTexture()
if tex then bd.iconTex:SetTexture(tex) end
-- Hide icon-mode elements
btn.icon:SetAlpha(0)
if btn.cooldown then
btn.cooldown:SetAlpha(0)
if btn.cooldown.SetHideCountdownNumbers then btn.cooldown:SetHideCountdownNumbers(true) end
end
if btn.count then btn.count:Hide() end
if btn.stackText then btn.stackText:Hide() end
if btn.border then btn.border:SetAlpha(0) end
bd.frame:Show()
if not visBars[btn] then
visBars[btn] = true
barCount = barCount + 1
end
ticker:Show()
end
-----------------------------------------------------------
-- MSWA_HideBar / CleanupBar / IsBarMode
-----------------------------------------------------------
function MSWA_HideBar(btn)
local bd = btn._msaBar
if bd and bd.frame then bd.frame:Hide() end
if visBars[btn] then
visBars[btn] = nil
barCount = barCount - 1
if barCount <= 0 then barCount = 0; ticker:Hide() end
end
btn.icon:SetAlpha(1)
if btn.cooldown then
btn.cooldown:SetAlpha(1)
if btn.cooldown.SetHideCountdownNumbers then btn.cooldown:SetHideCountdownNumbers(false) end
end
if btn.border then btn.border:SetAlpha(1) end
end
function MSWA_CleanupBar(btn)
if btn._msaBar then MSWA_HideBar(btn) end
end
function MSWA_IsBarMode(s)
return s and s.displayType == "BAR"
end
-----------------------------------------------------------
-- MSWA_UpdateBarDisplay
-----------------------------------------------------------
function MSWA_UpdateBarDisplay(btn, s, db, info)
if not MSWA_IsBarMode(s) then
if btn._msaBar and btn._msaBar.frame and btn._msaBar.frame:IsShown() then
MSWA_HideBar(btn)
end
return false
end
local bd = MSWA_EnsureBar(btn)
ShowBar(btn, bd, s, db)
if bd.nameFS then bd.nameFS:SetText(info.name or "") end
if info.isActive ~= false then
bd.frame:SetAlpha(btn:GetAlpha())
if info.isSecret then
bd._exp = 0; bd._dur = 0
else
local e = tonumber(info.expires) or 0
local d = tonumber(info.duration) or 0
if d > 0 and e > 0 then
bd._exp = e; bd._dur = d
else
bd._exp = 0; bd._dur = 0
end
end
bd.iconTex:SetDesaturated(false)
bd.iconTex:SetAlpha(1)
bd.bar:SetAlpha(1)
bd.barBG:SetAlpha(0.7)
else
bd._exp = 0; bd._dur = 0
bd.iconTex:SetDesaturated(true)
bd.iconTex:SetAlpha(0.6)
bd.bar:SetValue(0)
bd.bar:SetAlpha(0.3)
bd.barBG:SetAlpha(0.3)
if bd.spark then bd.spark:Hide() end
if bd.timerFS then bd.timerFS:SetText("") end
bd.frame:SetAlpha(tonumber(info.absentAlpha) or 0.45)
end
if bd.stackFS then
if info.stacks and info.stacks ~= "" then
bd.stackFS:SetText(info.stacks); bd.stackFS:Show()
else
bd.stackFS:SetText(""); bd.stackFS:Hide()
end
end
return true
end