Skip to content

Commit

Permalink
Add more text options
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuller committed Mar 6, 2022
1 parent 9500c7b commit 6873d07
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 51 deletions.
6 changes: 6 additions & 0 deletions .pkgmeta
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
package-as: tullaCTC

externals:
libs/AceAddon-3.0: https://repos.wowace.com/wow/ace3/trunk/AceAddon-3.0
libs/AceDB-3.0: https://repos.wowace.com/wow/ace3/trunk/AceDB-3.0
libs/CallbackHandler-1.0: https://repos.wowace.com/wow/callbackhandler/trunk/CallbackHandler-1.0
libs/LibStub: https://repos.wowace.com/wow/libstub/tags/1.0
6 changes: 6 additions & 0 deletions embeds.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/">
<Script file="libs\LibStub\LibStub.lua"/>
<Include file="libs\CallbackHandler-1.0\CallbackHandler-1.0.xml"/>
<Include file="libs\AceAddon-3.0\AceAddon-3.0.xml"/>
<Include file="libs\AceDB-3.0\AceDB-3.0.xml"/>
</Ui>
193 changes: 144 additions & 49 deletions main.lua
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
local SECOND = 1
local MINUTE = SECOND * 60
local HOUR = MINUTE * 60

-- 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}
}
local AddonName, AddonTable = ...
local Addon = LibStub('AceAddon-3.0'):NewAddon(AddonTable, AddonName)
local DB_NAME = AddonName .. 'DB'
local DB_SCHEMA_VERSION = 1

local cooldowns = {}

Expand All @@ -38,39 +24,43 @@ local function updateText(cooldown)
return
end

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

for _, style in ipairs(STYLES) do
-- apply colors for the earliest value we're under
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, so that we know how long to
-- wait for the next style update
else
nextStyle = style
local theme, sleep = Addon:GetTheme(cd)
if not theme then
return
end

local tFontHeight = theme.fontScale * cd.fontHeight
local fontName, fontHeight, fontFlags = fs:GetFont()
if not (theme.fontName == fontName and fontHeight == tFontHeight and theme.fontFlags == fontFlags) then
if not fs:SetFont(theme.fontName, tFontHeight, theme.fontFlags) then
fs:SetFont(STANDARD_TEXT_FONT, tFontHeight, theme.fontFlags)
end
end

fs:SetTextColor(theme.r, theme.g, theme.b, theme.a)

local shadow = theme.shadow
fs:SetShadowColor(shadow.r, shadow.g, shadow.b, shadow.a)
fs:SetShadowOffset(shadow.x, shadow.y)

-- schedule the next update, if needed
local sleep = nextStyle and math.max(remain - nextStyle.duration, 0) or 0
if sleep > 0 then
if sleep and sleep > 0 then
C_Timer.After(sleep, cd.update)
end
end

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

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

Expand Down Expand Up @@ -100,24 +90,129 @@ local function setTimer(cooldown, start, duration)
end
end

local CooldownMT = getmetatable(ActionButton1Cooldown).__index
function Addon:OnInitialize()
-- initialize db
local db = LibStub('AceDB-3.0'):New(DB_NAME, self:GetDBDefaults(), DEFAULT)

hooksecurefunc(CooldownMT, 'SetCooldown', function(cd, start, duration)
if cd:IsForbidden() then
return
db.RegisterCallback(self, 'OnProfileChanged', 'OnProfileChanged')
db.RegisterCallback(self, 'OnProfileCopied', 'OnProfileChanged')
db.RegisterCallback(self, 'OnProfileReset', 'OnProfileChanged')

self.db = db

-- setup hooks
local cooldown_mt = getmetatable(ActionButton1Cooldown).__index

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

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

hooksecurefunc(cooldown_mt, '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)
end

function Addon:UpgradeDB()
local dbVersion = self.db.global.dbVersion

if dbVersion ~= DB_SCHEMA_VERSION then
self.db.global.dbVersion = DB_SCHEMA_VERSION
end

setTimer(cd, start or 0, duration or 0)
end)
local addonVersion = self.db.global.addonVersion
if addonVersion ~= GetAddOnMetadata(AddonName, 'Version') then
self.db.global.addonVersion = GetAddOnMetadata(AddonName, 'Version')
end
end

function Addon:OnProfileChanged()
self:Refresh()
end

function Addon:GetDBDefaults()
return {
profile = {
themes = {
['**'] = {
-- what font to use (an actual path)
fontName = STANDARD_TEXT_FONT,

-- NONE | OUTLINE | THICKOUTLINE | MONOCHROME
fontFlags = 'OUTLINE',

fontScale = 1,

-- text color
r = 1,
g = 1,
b = 1,
a = 1,

-- shadow color and offset
shadow = {
-- color
r = 1,
g = 1,
b = 1,
a = 0,

-- offset
x = 0,
y = 0
}
},

soon = {r = 1, g = 0, b = 0, fontScale = 1.5},
seconds = {r = 1, g = 1, b = 0},
minutes = {r = 1, g = 1, b = 1},
hours = {r = .7, g = .7, b = .7, fontScale = .75}
},

-- rules, in eval order
rules = {
{duration = 5, theme = "soon"},
{duration = 60, theme = "seconds"},
{duration = 60 * 60, theme = "minutes"},
{duration = math.huge, theme = "hours"}
}
}
}
end

hooksecurefunc(CooldownMT, 'SetCooldownDuration', function(cd)
if cd:IsForbidden() then
function Addon:GetTheme(cooldown)
local remain = cooldown.endTime - GetTime()
if remain <= 0 then
return
end

local start, duration = cd:GetCooldownTimes()
start = (start or 0) / 1000
duration = (duration or 0) / 1000
local nextRule
for _, rule in ipairs(self.db.profile.rules) do
if remain <= rule.duration then
if nextRule then
return self.db.profile.themes[rule.theme], remain - nextRule.duration
end

setTimer(cd, start, duration)
end)
return self.db.profile.themes[rule.theme], 0
else
nextRule = rule
end
end
end

function Addon:Refresh()
for cooldown in pairs(cooldowns) do
updateText(cooldown)
end
end
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# TullaCTC
# TullaCTC - Cooldown Text Customizer

Colorizes the built in Blizzard cooldown text based on time remaining.
4 changes: 3 additions & 1 deletion tullaCTC.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
## Interface-BCC: 20503
## Interface-Classic: 11402
## Title: tullaCTC
## Notes: Cooldown Text Colorizer
## Notes: Cooldown Text Customizer
## Author: Tuller
## Version: @version@
## SavedVariables: tullaCTCDB
embeds.xml
main.lua

0 comments on commit 6873d07

Please sign in to comment.