From ad5fc34a73a9e61fa47de0bcc6b6bcd42517fa16 Mon Sep 17 00:00:00 2001 From: Jason Greer Date: Sun, 27 Feb 2022 15:15:24 -0500 Subject: [PATCH 1/2] Initial Import --- .gitattributes | 2 + .gitignore | 11 +++++ .pkgmeta | 1 + main.lua | 115 +++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 3 ++ tullaCTC.toc | 8 ++++ 6 files changed, 140 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .pkgmeta create mode 100644 main.lua create mode 100644 readme.md create mode 100644 tullaCTC.toc diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..105a7d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Windows image file caches +Thumbs.db + +# Folder config file +Desktop.ini + +# Mac folder info +.DS_Store + +# packager artifacts +.release \ No newline at end of file diff --git a/.pkgmeta b/.pkgmeta new file mode 100644 index 0000000..8710a91 --- /dev/null +++ b/.pkgmeta @@ -0,0 +1 @@ +package-as: tullaCTC diff --git a/main.lua b/main.lua new file mode 100644 index 0000000..64bd212 --- /dev/null +++ b/main.lua @@ -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) diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..8485fe6 --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +# TullaCT + +Colorizes the built in Action Bar cooldown text based on time remaining \ No newline at end of file diff --git a/tullaCTC.toc b/tullaCTC.toc new file mode 100644 index 0000000..9b6650e --- /dev/null +++ b/tullaCTC.toc @@ -0,0 +1,8 @@ +## Interface: 90200 +## Interface-BCC: 20502 +## Interface-Classic: 11402 +## Title: tullaCTC +## Notes: Cooldown Text Colorizer +## Author: Tuller +## Version: @version@ +main.lua From ae6ab17c2088147dbf4c79e006870ebe29fa6d27 Mon Sep 17 00:00:00 2001 From: Jason Greer Date: Sun, 27 Feb 2022 15:29:48 -0500 Subject: [PATCH 2/2] add some todos for later --- main.lua | 46 +++++++++++++++++++++++++++------------------- readme.md | 2 +- tullaCTC.toc | 2 +- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/main.lua b/main.lua index 64bd212..5f3eb7b 100644 --- a/main.lua +++ b/main.lua @@ -1,11 +1,19 @@ -local DAY = 86400 -local MINUTE = 60 local SECOND = 1 +local MINUTE = SECOND * 60 +local HOUR = MINUTE * 60 -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}, +-- TODO: move to saved settings +local STYLES = { + -- 10s or less + {duration = 10 * SECOND, r = 1, g = 0, b = 0, a = 1}, + + -- 90s + {duration = 90 * SECOND, r = 1, g = 1, b = 0, a = 1}, + + -- hours + {duration = HOUR, r = 1, g = 1, b = 1, a = 1}, + + -- default case {duration = math.huge, r = 0.5, g = 0.5, b = 0.5, a = 1} } @@ -31,26 +39,25 @@ local function updateText(cooldown) end local remain = cd.endTime - GetTime() - local prev = nil + local nextStyle = nil - for _, setting in ipairs(SETTINGS) do + for _, style in ipairs(STYLES) 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) + if remain <= style.duration then + fs:SetTextColor(style.r, style.g, style.b, style.a) + -- TODO: font/scale should be easy to apply, too break - -- and keep track of the previous one for scheduling updates + -- and keep track of the previous one, so that we know how long to + -- wait for the next style update else - prev = setting + nextStyle = style 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 + -- schedule the next update, if needed + local sleep = nextStyle and math.max(remain - nextStyle.duration, 0) or 0 + if sleep > 0 then + C_Timer.After(sleep, cd.update) end end @@ -80,6 +87,7 @@ local function setTimer(cooldown, start, duration) return end + -- TODO: test excluding GCD for perf/memory usage reasons local endTime = start + duration -- both the wow api and addons (especially auras) have a habit of resetting diff --git a/readme.md b/readme.md index 8485fe6..de57d86 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,3 @@ # TullaCT -Colorizes the built in Action Bar cooldown text based on time remaining \ No newline at end of file +Colorizes the built in cooldown text based on time remaining. diff --git a/tullaCTC.toc b/tullaCTC.toc index 9b6650e..41b083d 100644 --- a/tullaCTC.toc +++ b/tullaCTC.toc @@ -1,5 +1,5 @@ ## Interface: 90200 -## Interface-BCC: 20502 +## Interface-BCC: 20503 ## Interface-Classic: 11402 ## Title: tullaCTC ## Notes: Cooldown Text Colorizer