-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCooldownCount.lua
More file actions
235 lines (206 loc) · 7.36 KB
/
CooldownCount.lua
File metadata and controls
235 lines (206 loc) · 7.36 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
local addonName = ...
-- Config defaults
CooldownCountConfig = CooldownCountConfig or {
enabled = true,
fontSize = 14,
fontOutline = "OUTLINE",
fontColor = { 1, 0.82, 0 }, -- gold
position = "BOTTOMRIGHT", -- anchor point on button
posX = -2, -- offset X
posY = 2, -- offset Y
minCooldown = 1.5, -- only show cooldowns > this
updateInterval = 0.2, -- update frequency
bartenderEnabled = true, -- enable Bartender bars
}
local CC = CreateFrame("Frame")
local trackedButtons = {}
-- Standard action bar button prefixes
local standardButtonPrefixes = {
"ActionButton",
"MultiBarBottomLeftButton",
"MultiBarBottomRightButton",
"MultiBarRightButton",
"MultiBarLeftButton",
"BonusActionButton",
"MultiBar5Button",
"MultiBar6Button",
"MultiBar7Button",
}
-- Bartender button prefixes (bars 1-10, 12 buttons each)
local bartenderButtonPrefixes = {
"BT4Button", -- Bartender uses BT4Button + bar number + button number pattern
}
local function ensureFontOnButton(btn)
if not btn or trackedButtons[btn] then return end
local fs = btn:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
fs:SetPoint(CooldownCountConfig.position, btn, CooldownCountConfig.position,
CooldownCountConfig.posX, CooldownCountConfig.posY)
fs:SetJustifyH("RIGHT")
local fontPath, _, _ = fs:GetFont()
fs:SetFont(fontPath, CooldownCountConfig.fontSize, CooldownCountConfig.fontOutline)
local color = CooldownCountConfig.fontColor
fs:SetTextColor(color[1], color[2], color[3])
fs:Hide()
btn.CooldownCount = fs
trackedButtons[btn] = true
end
-- Scan standard action bar buttons
local function scanStandardButtons()
for _, prefix in ipairs(standardButtonPrefixes) do
for i = 1, 12 do
local btn = _G[prefix .. i]
if btn then
ensureFontOnButton(btn)
end
end
end
end
-- Scan Bartender bars (if enabled)
local function scanBartenderButtons()
if not CooldownCountConfig.bartenderEnabled then return end
-- Bartender4 uses a naming pattern like BT4Button1_1 (bar 1, button 1)
for bar = 1, 10 do
for btn = 1, 12 do
local btnName = "BT4Button" .. bar .. "_" .. btn
local button = _G[btnName]
if button then
ensureFontOnButton(button)
end
end
end
end
-- Initial scan on load
scanStandardButtons()
scanBartenderButtons()
-- Hook for dynamic button creation
-- Instead, hook OnShow for all tracked buttons
local function hookButtonOnShow(btn)
if btn and not btn.CooldownCountOnShowHooked then
btn:HookScript("OnShow", function(self)
ensureFontOnButton(self)
end)
btn.CooldownCountOnShowHooked = true
end
end
-- After creating/tracking a button, hook its OnShow
local oldEnsureFontOnButton = ensureFontOnButton
ensureFontOnButton = function(btn)
oldEnsureFontOnButton(btn)
hookButtonOnShow(btn)
end
-- Hook Bartender's button initialization if available
if Bartender4 then
local origBT4Update = Bartender4.ActionBar.UpdateButton
if origBT4Update then
Bartender4.ActionBar.UpdateButton = function(self, button, ...)
origBT4Update(self, button, ...)
ensureFontOnButton(button)
end
end
end
-- Format cooldown time
local function formatTime(t)
if not t then return "" end
if t >= 3600 then
return string.format("%dh", math.floor(t / 3600 + 0.5))
elseif t >= 60 then
return string.format("%dm", math.floor(t / 60 + 0.5))
else
return tostring(math.floor(t + 0.5))
end
end
local updateThrottle = 0
CC:SetScript("OnUpdate", function(self, elapsed)
if not CooldownCountConfig.enabled then return end
updateThrottle = updateThrottle + elapsed
if updateThrottle < CooldownCountConfig.updateInterval then return end
updateThrottle = 0
for btn, _ in pairs(trackedButtons) do
if btn and btn:IsShown() and btn.action then
local actionType, id, subType = GetActionInfo(btn.action)
local start, duration, enable
if actionType == "item" and id then
start, duration, enable = GetItemCooldown(id)
else
start, duration, enable = GetActionCooldown(btn.action)
end
if start and duration and duration > CooldownCountConfig.minCooldown and (enable == nil or enable ~= 0) then
local remain = start + duration - GetTime()
if remain > 0 then
if not btn.CooldownCount then ensureFontOnButton(btn) end
btn.CooldownCount:SetText(formatTime(remain))
btn.CooldownCount:Show()
else
if btn.CooldownCount then btn.CooldownCount:Hide() end
end
else
if btn.CooldownCount then btn.CooldownCount:Hide() end
end
end
end
end)
-- Slash commands
SLASH_COOLDOWNCOUNT1 = "/ccount"
SlashCmdList["COOLDOWNCOUNT"] = function(msg)
msg = msg:lower():trim()
if msg == "toggle" then
CooldownCountConfig.enabled = not CooldownCountConfig.enabled
if not CooldownCountConfig.enabled then
for btn, _ in pairs(trackedButtons) do
if btn.CooldownCount then btn.CooldownCount:Hide() end
end
end
print("CooldownCount: " .. (CooldownCountConfig.enabled and "enabled" or "disabled"))
elseif msg:match("^fontsize%s+%d+$") then
local size = tonumber(msg:match("%d+"))
if size and size >= 8 and size <= 32 then
CooldownCountConfig.fontSize = size
-- Refresh all fonts
for btn, _ in pairs(trackedButtons) do
if btn.CooldownCount then
local fontPath, _, _ = btn.CooldownCount:GetFont()
btn.CooldownCount:SetFont(fontPath, CooldownCountConfig.fontSize, CooldownCountConfig.fontOutline)
end
end
print("CooldownCount font size set to " .. size)
else
print("Font size must be between 8 and 32")
end
elseif msg:match("^color%s+%d+%s+%d+%s+%d+$") then
local r, g, b = msg:match("(%d+)%s+(%d+)%s+(%d+)")
r, g, b = tonumber(r) / 255, tonumber(g) / 255, tonumber(b) / 255
if r >= 0 and r <= 1 and g >= 0 and g <= 1 and b >= 0 and b <= 1 then
CooldownCountConfig.fontColor = { r, g, b }
-- Refresh all font colors
for btn, _ in pairs(trackedButtons) do
if btn.CooldownCount then
btn.CooldownCount:SetTextColor(r, g, b)
end
end
print(string.format("CooldownCount color set to RGB(%.2f, %.2f, %.2f)", r, g, b))
else
print("Color values must be 0-255")
end
elseif msg == "bartender on" then
CooldownCountConfig.bartenderEnabled = true
scanBartenderButtons()
print("CooldownCount Bartender support enabled")
elseif msg == "bartender off" then
CooldownCountConfig.bartenderEnabled = false
print("CooldownCount Bartender support disabled")
elseif msg == "status" then
print("=== CooldownCount Status ===")
print("Enabled: " .. tostring(CooldownCountConfig.enabled))
print("Font Size: " .. CooldownCountConfig.fontSize)
print("Font Outline: " .. CooldownCountConfig.fontOutline)
print("Bartender: " .. tostring(CooldownCountConfig.bartenderEnabled))
print("Tracked Buttons: " .. tostring(#trackedButtons))
else
print("=== CooldownCount Commands ===")
print("/ccount toggle - Enable/disable counters")
print("/ccount fontsize <8-32> - Set font size")
print("/ccount color <0-255> <0-255> <0-255> - Set RGB color")
print("/ccount bartender on|off - Enable/disable Bartender bars")
print("/ccount status - Show current config")
end
end