-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLockInRageBar.lua
More file actions
364 lines (318 loc) · 12.1 KB
/
Copy pathLockInRageBar.lua
File metadata and controls
364 lines (318 loc) · 12.1 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
--[[
LockIn Rage Bar v1.0.0
Hosted by Toxic Army (https://www.toxicarmy.com)
Clean Warrior rage bar with proc thresholds.
Gray < 60 rage "you're rage starved"
Yellow 60-79 "approach safe spend"
Green 80-99 "you're capped soon, dump it"
Flash 100 "stop sitting on rage"
Pairs with LockInProcCore. Same family. Same philosophy:
install, play, no setup needed.
Slash commands:
/lockinragebar test show with fake rage values
/lockinragebar unlock drag to reposition / resize
/lockinragebar lock save position
/lockinragebar reset restore defaults
/lockinragebar status debug info
/lirb short alias
]]
local ADDON_NAME = "LockInRageBar"
local POWER_TYPE_RAGE = Enum and Enum.PowerType and Enum.PowerType.Rage or 1
local addon = CreateFrame("Frame", ADDON_NAME .. "Frame", UIParent)
------------------------------------------------------------
-- Defaults / SavedVariables
------------------------------------------------------------
local DEFAULTS = {
posX = 0,
posY = -200,
width = 240,
height = 22,
locked = true,
showText = true,
flashAtCap = true,
thresholdMid = 60,
thresholdHigh = 80,
-- color stops (RGBA 0-1)
colorLow = { 0.45, 0.45, 0.50, 1.0 },
colorMid = { 0.95, 0.85, 0.20, 1.0 },
colorHigh = { 0.20, 0.95, 0.40, 1.0 },
colorCap = { 1.00, 0.30, 0.30, 1.0 },
bgAlpha = 0.55,
}
local DB
local function InitDB()
LockInRageBarDB = LockInRageBarDB or {}
for k, v in pairs(DEFAULTS) do
if LockInRageBarDB[k] == nil then
LockInRageBarDB[k] = v
end
end
DB = LockInRageBarDB
end
------------------------------------------------------------
-- Frame construction
------------------------------------------------------------
local container, bar, bgTex, textLabel, flashAnim
local function ColorForRage(rage, max)
local pct = (max > 0) and (rage / max * 100) or 0
if pct >= 100 then
return DB.colorCap
elseif pct >= DB.thresholdHigh then
return DB.colorHigh
elseif pct >= DB.thresholdMid then
return DB.colorMid
end
return DB.colorLow
end
local function BuildFrame()
container = CreateFrame("Frame", ADDON_NAME .. "Container", UIParent, "BackdropTemplate")
container:SetSize(DB.width, DB.height)
container:SetPoint("CENTER", UIParent, "CENTER", DB.posX, DB.posY)
container:SetFrameStrata("MEDIUM")
container:SetFrameLevel(10)
container:SetMovable(true)
container:RegisterForDrag("LeftButton")
container:SetScript("OnDragStart", function(self)
if not DB.locked then self:StartMoving() end
end)
container:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
local _, _, _, x, y = self:GetPoint()
DB.posX = x
DB.posY = y
end)
container:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
edgeSize = 1,
})
container:SetBackdropColor(0, 0, 0, DB.bgAlpha)
container:SetBackdropBorderColor(0, 0, 0, 0.85)
-- Filling status bar
bar = CreateFrame("StatusBar", nil, container)
bar:SetPoint("TOPLEFT", container, "TOPLEFT", 1, -1)
bar:SetPoint("BOTTOMRIGHT", container, "BOTTOMRIGHT", -1, 1)
bar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
bar:SetMinMaxValues(0, 100)
bar:SetValue(0)
-- Tick marks at thresholds
local function AddTick(atPct)
local tick = container:CreateTexture(nil, "OVERLAY")
tick:SetColorTexture(1, 1, 1, 0.35)
tick:SetSize(1, DB.height - 2)
tick:SetPoint("LEFT", container, "LEFT", 1 + (DB.width - 2) * (atPct / 100), 0)
return tick
end
container.tickMid = AddTick(DB.thresholdMid)
container.tickHigh = AddTick(DB.thresholdHigh)
-- Text overlay
textLabel = container:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
textLabel:SetPoint("CENTER", container, "CENTER")
textLabel:SetText("0 / 100")
-- Flash animation when capped
flashAnim = container:CreateAnimationGroup()
flashAnim:SetLooping("REPEAT")
local fadeOut = flashAnim:CreateAnimation("Alpha")
fadeOut:SetFromAlpha(1.0)
fadeOut:SetToAlpha(0.55)
fadeOut:SetDuration(0.35)
fadeOut:SetOrder(1)
local fadeIn = flashAnim:CreateAnimation("Alpha")
fadeIn:SetFromAlpha(0.55)
fadeIn:SetToAlpha(1.0)
fadeIn:SetDuration(0.35)
fadeIn:SetOrder(2)
end
------------------------------------------------------------
-- Update logic
------------------------------------------------------------
local lastFlashState = false
local function UpdateBar()
if not bar then return end
local rage = UnitPower("player", POWER_TYPE_RAGE)
local maxRage = UnitPowerMax("player", POWER_TYPE_RAGE)
if maxRage <= 0 then maxRage = 100 end
bar:SetMinMaxValues(0, maxRage)
bar:SetValue(rage)
local color = ColorForRage(rage, maxRage)
bar:SetStatusBarColor(unpack(color))
if DB.showText then
textLabel:SetText(rage .. " / " .. maxRage)
textLabel:Show()
else
textLabel:Hide()
end
-- Flash at cap
local atCap = (rage >= maxRage)
if atCap and DB.flashAtCap then
if not lastFlashState then
flashAnim:Play()
lastFlashState = true
end
else
if lastFlashState then
flashAnim:Stop()
container:SetAlpha(1)
lastFlashState = false
end
end
end
local function ApplyGeometry()
if not container then return end
container:ClearAllPoints()
container:SetPoint("CENTER", UIParent, "CENTER", DB.posX, DB.posY)
container:SetSize(DB.width, DB.height)
-- reposition tick marks if width changes
if container.tickMid and container.tickHigh then
container.tickMid:ClearAllPoints()
container.tickMid:SetPoint("LEFT", container, "LEFT", 1 + (DB.width - 2) * (DB.thresholdMid / 100), 0)
container.tickHigh:ClearAllPoints()
container.tickHigh:SetPoint("LEFT", container, "LEFT", 1 + (DB.width - 2) * (DB.thresholdHigh / 100), 0)
container.tickMid:SetSize(1, DB.height - 2)
container.tickHigh:SetSize(1, DB.height - 2)
end
end
------------------------------------------------------------
-- Class gate + init
------------------------------------------------------------
local function Initialize()
InitDB()
local _, class = UnitClass("player")
if class ~= "WARRIOR" then
addon:UnregisterAllEvents()
return
end
BuildFrame()
ApplyGeometry()
UpdateBar()
end
------------------------------------------------------------
-- Events
------------------------------------------------------------
addon:RegisterEvent("PLAYER_LOGIN")
addon:RegisterEvent("UNIT_POWER_FREQUENT")
addon:RegisterEvent("UNIT_MAXPOWER")
addon:RegisterEvent("PLAYER_ENTERING_WORLD")
addon:SetScript("OnEvent", function(_, event, unit)
if event == "PLAYER_LOGIN" then
Initialize()
return
end
if not container then return end
if event == "PLAYER_ENTERING_WORLD" then
UpdateBar()
return
end
if (event == "UNIT_POWER_FREQUENT" or event == "UNIT_MAXPOWER") and unit == "player" then
UpdateBar()
end
end)
------------------------------------------------------------
-- Slash commands
------------------------------------------------------------
SLASH_LOCKINRAGEBAR1 = "/lockinragebar"
SLASH_LOCKINRAGEBAR2 = "/lirb"
local testRunning = false
local testValue = 0
local testTimer
SlashCmdList["LOCKINRAGEBAR"] = function(msg)
msg = string.lower(msg or "")
if msg == "test" then
if not container then
print("|cff00ff00LockIn Rage Bar:|r not initialized — are you a Warrior?")
return
end
testRunning = not testRunning
if testRunning then
testValue = 0
-- Sweep 0 -> 100 -> 0 every 4s
testTimer = C_Timer.NewTicker(0.1, function()
testValue = testValue + 5
if testValue > 100 then testValue = 0 end
bar:SetMinMaxValues(0, 100)
bar:SetValue(testValue)
local color = ColorForRage(testValue, 100)
bar:SetStatusBarColor(unpack(color))
if DB.showText then textLabel:SetText(testValue .. " / 100") end
if testValue >= 100 and DB.flashAtCap then
if not flashAnim:IsPlaying() then flashAnim:Play() end
else
if flashAnim:IsPlaying() then
flashAnim:Stop()
container:SetAlpha(1)
end
end
end)
print("|cff00ff00LockIn Rage Bar:|r test mode ON. /lockinragebar test again to stop.")
else
if testTimer then testTimer:Cancel() end
UpdateBar()
print("|cff00ff00LockIn Rage Bar:|r test mode OFF.")
end
elseif msg == "unlock" then
DB.locked = false
container:SetBackdropBorderColor(0.4, 0.9, 0.4, 1.0)
print("|cff00ff00LockIn Rage Bar:|r unlocked. Drag to reposition. /lockinragebar lock when done.")
elseif msg == "lock" then
DB.locked = true
container:SetBackdropBorderColor(0, 0, 0, 0.85)
print("|cff00ff00LockIn Rage Bar:|r locked. Position saved.")
elseif msg == "reset" then
for k, v in pairs(DEFAULTS) do DB[k] = v end
ApplyGeometry()
UpdateBar()
print("|cff00ff00LockIn Rage Bar:|r reset to defaults.")
elseif msg == "text" then
DB.showText = not DB.showText
UpdateBar()
print("|cff00ff00LockIn Rage Bar:|r text " .. (DB.showText and "ON" or "OFF"))
elseif msg == "flash" then
DB.flashAtCap = not DB.flashAtCap
if not DB.flashAtCap and flashAnim:IsPlaying() then
flashAnim:Stop()
container:SetAlpha(1)
end
print("|cff00ff00LockIn Rage Bar:|r flash-at-cap " .. (DB.flashAtCap and "ON" or "OFF"))
elseif msg:match("^width ") then
local n = tonumber(msg:match("^width (%d+)"))
if n and n >= 80 and n <= 800 then
DB.width = n
ApplyGeometry()
print("|cff00ff00LockIn Rage Bar:|r width = " .. n)
else
print("|cff00ff00LockIn Rage Bar:|r width must be 80-800, e.g. /lockinragebar width 240")
end
elseif msg:match("^height ") then
local n = tonumber(msg:match("^height (%d+)"))
if n and n >= 8 and n <= 80 then
DB.height = n
ApplyGeometry()
print("|cff00ff00LockIn Rage Bar:|r height = " .. n)
else
print("|cff00ff00LockIn Rage Bar:|r height must be 8-80, e.g. /lockinragebar height 22")
end
elseif msg == "status" then
local rage = UnitPower("player", POWER_TYPE_RAGE)
local maxRage = UnitPowerMax("player", POWER_TYPE_RAGE)
print("|cff00ff00LockIn Rage Bar v1.0.0|r")
print(" Rage: " .. rage .. " / " .. maxRage)
print(" Position: x=" .. DB.posX .. " y=" .. DB.posY)
print(" Size: " .. DB.width .. "x" .. DB.height)
print(" Thresholds: mid=" .. DB.thresholdMid .. " high=" .. DB.thresholdHigh)
print(" Locked: " .. tostring(DB.locked))
print(" Show text: " .. tostring(DB.showText))
print(" Flash at cap: " .. tostring(DB.flashAtCap))
else
print("|cff00ff00LockIn Rage Bar|r commands:")
print(" /lockinragebar test toggle test sweep")
print(" /lockinragebar unlock drag to reposition")
print(" /lockinragebar lock save position")
print(" /lockinragebar text toggle rage text label")
print(" /lockinragebar flash toggle flash-at-cap")
print(" /lockinragebar width <N> set bar width (80-800)")
print(" /lockinragebar height <N> set bar height (8-80)")
print(" /lockinragebar reset restore defaults")
print(" /lockinragebar status debug info")
print(" /lirb short alias")
end
end