Skip to content

Commit

Permalink
Initial Import
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuller committed Feb 27, 2022
0 parents commit ad5fc34
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Windows image file caches
Thumbs.db

# Folder config file
Desktop.ini

# Mac folder info
.DS_Store

# packager artifacts
.release
1 change: 1 addition & 0 deletions .pkgmeta
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-as: tullaCTC
115 changes: 115 additions & 0 deletions main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
local DAY = 86400
local MINUTE = 60
local SECOND = 1

local SETTINGS = {
{duration = 5.5 * SECOND, r = 1, g = 0, b = 0, a = 1},
{duration = 90.5 * SECOND, r = 1, g = 1, b = 0, a = 1},
{duration = DAY, r = 1, g = 1, b = 1, a = 1},
{duration = math.huge, r = 0.5, g = 0.5, b = 0.5, a = 1}
}

local cooldowns = {}

local function getFontStringFromRegions(...)
for i = 1, select("#", ...) do
local region = select(i, ...)

if region:GetObjectType() == "FontString" then
return region
end
end
end

local function updateText(cooldown)
local cd = cooldowns[cooldown]

-- no text, quit early
local fs = cd.fontString
if not fs and fs:GetText() ~= "" then
return
end

local remain = cd.endTime - GetTime()
local prev = nil

for _, setting in ipairs(SETTINGS) do
-- apply colors for the earliest value we're under
if remain <= setting.duration then
fs:SetTextColor(setting.r, setting.g, setting.b, setting.a)
break
-- and keep track of the previous one for scheduling updates
else
prev = setting
end
end

-- schedule the next update, if we need to
if prev then
local sleep = math.max(remain - prev.duration, 0)

if sleep > 0 then
C_Timer.After(sleep, cd.update)
end
end
end

-- setup initial data when we first wee a cooldown
setmetatable(cooldowns, {
__index = function(t, k)
local fontString = getFontStringFromRegions(k:GetRegions())

local v = {
update = function()
updateText(k)
end,
fontString = fontString,
endTime = 0
}

t[k] = v

return v
end
})

-- hooks
local function setTimer(cooldown, start, duration)
-- skip zero duration cooldowns
if start <= 0 or duration <= 0 then
return
end

local endTime = start + duration

-- both the wow api and addons (especially auras) have a habit of resetting
-- cooldowns every time there's an update to an aura we chack and do nothing
-- if there's an exact start/duration match
if cooldowns[cooldown].endTime ~= endTime then
cooldowns[cooldown].endTime = endTime

updateText(cooldown)
end
end

local CooldownMT = getmetatable(ActionButton1Cooldown).__index

hooksecurefunc(CooldownMT, 'SetCooldown', function(cd, start, duration)
if cd:IsForbidden() then
return
end

setTimer(cd, start or 0, duration or 0)
end)

hooksecurefunc(CooldownMT, 'SetCooldownDuration', function(cd)
if cd:IsForbidden() then
return
end

local start, duration = cd:GetCooldownTimes()
start = (start or 0) / 1000
duration = (duration or 0) / 1000

setTimer(cd, start, duration)
end)
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# TullaCT

Colorizes the built in Action Bar cooldown text based on time remaining
8 changes: 8 additions & 0 deletions tullaCTC.toc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Interface: 90200
## Interface-BCC: 20502
## Interface-Classic: 11402
## Title: tullaCTC
## Notes: Cooldown Text Colorizer
## Author: Tuller
## Version: @version@
main.lua

0 comments on commit ad5fc34

Please sign in to comment.