Quantcast

now using setformatted text, and added more blue

Tuller [08-27-10 - 20:43]
now using setformatted text, and added more blue
Filename
tullaCC/cc.lua
tullaCC/tullaCC.toc
diff --git a/tullaCC/cc.lua b/tullaCC/cc.lua
index 7ae8e81..9998f21 100644
--- a/tullaCC/cc.lua
+++ b/tullaCC/cc.lua
@@ -9,17 +9,24 @@
 --constants!
 OmniCC = OmniCC or true --hack to work around detection from other addons for OmniCC
 local ICON_SIZE = 36 --the normal size for an icon (don't change this)
+local DAY, HOUR, MINUTE = 86400, 3600, 60 --used for formatting text
+local DAYISH, HOURISH, MINUTEISH = 3600 * 23.5, 60 * 59.5, 59.5 --used for formatting text at transition points
+local HALFDAYISH, HALFHOURISH, HALFMINUTEISH = DAY/2 + 0.5, HOUR/2 + 0.5, MINUTE/2 + 0.5 --used for calculating next update times
+
+--configuration settings
 local FONT_FACE = STANDARD_TEXT_FONT --what font to use
 local FONT_SIZE = 18 --the base font size to use at a scale of 1
 local FONT_COLOR = {1, 0.92, 0}
 local MIN_SCALE = 0.5 --the minimum scale we want to show cooldown counts at, anything below this will be hidden
 local MIN_DURATION = 3 --the minimum duration to show cooldown text for
-local DAY, HOUR, MINUTE = 86400, 3600, 60 --used for formatting text
-local DAYISH, HOURISH, MINUTEISH = 3600 * 23.5, 60 * 59.5, 59.5 --used for formatting text at transition points
-local HALFDAYISH, HALFHOURISH, HALFMINUTEISH = DAY/2 + 0.5, HOUR/2 + 0.5, MINUTE/2 + 0.5 --used for calculating next update times
+local EXPIRING_DURATION = 5 --the minimum number of seconds a cooldown must be to use to display in the expiring format
+local EXPIRING_FORMAT = '|cffff0000%d|r' --format for timers that are soon to expire
+local SECONDS_FORMAT = '|cffffff00%d|r' --format for timers that have seconds remaining
+local MINUTES_FORMAT = '|cffffffff%dm|r' --format for timers that have minutes remaining
+local HOURS_FORMAT = '|cff66ffff%dh|r' --format for timers that have hours remaining
+local DAYS_FORMAT = '|cff6666ff%dh|r' --format for timers that have days remaining

 --local bindings!
-local format = string.format
 local floor = math.floor
 local min = math.min
 local round = function(x) return floor(x + 0.5) end
@@ -30,22 +37,20 @@ local function getTimeText(s)
 	--format text as seconds when at 90 seconds or below
 	if s < MINUTEISH then
 		local seconds = round(s)
-		if seconds > 5 then
-			return format('|cffffff00%d|r', seconds), s - (seconds - 0.51)
-		end
-		return format('|cffff0000%d|r', seconds), s - (seconds - 0.51)
+		local formatString = seconds > EXPIRING_DURATION and SECONDS_FORMAT or EXPIRING_FORMAT
+		return formatString, seconds, s - (seconds - 0.51)
 	--format text as minutes when below an hour
 	elseif s < HOURISH then
 		local minutes = round(s/MINUTE)
-		return format('|cffffffff%dm|r', minutes), minutes > 1 and (s - (minutes*MINUTE - HALFMINUTEISH)) or (s - MINUTEISH)
+		return MINUTES_FORMAT, minutes, minutes > 1 and (s - (minutes*MINUTE - HALFMINUTEISH)) or (s - MINUTEISH)
 	--format text as hours when below a day
 	elseif s < DAYISH then
 		local hours = round(s/HOUR)
-		return format('|cffccccff%dh|r', hours), hours > 1 and (s - (hours*HOUR - HALFHOURISH)) or (s - HOURISH)
+		return HOURS_FORMAT, hours, hours > 1 and (s - (hours*HOUR - HALFHOURISH)) or (s - HOURISH)
 	--format text as days
 	else
 		local days = round(s/DAY)
-		return format('|cffcccccc%dd|r', days), days > 1 and (s - (days*DAY - HALFDAYISH)) or (s - DAYISH)
+		return DAYS_FORMAT, days,  days > 1 and (s - (days*DAY - HALFDAYISH)) or (s - DAYISH)
 	end
 end

@@ -94,8 +99,8 @@ local function Timer_OnUpdate(self, elapsed)
 				self.text:SetText('')
 				self.nextUpdate  = 1
 			else
-				local time, nextUpdate = getTimeText(remain)
-				self.text:SetText(time)
+				local formatStr, time, nextUpdate = getTimeText(remain)
+				self.text:SetFormattedText(formatStr, time)
 				self.nextUpdate = nextUpdate
 			end
 		else
@@ -128,7 +133,7 @@ local function Timer_Create(cd)
 end

 --hook the SetCooldown method of all cooldown frames
---ActionButton1Cooldown is used here since its likely to always exist
+--ActionButton1Cooldown is used here since its likely to always exist
 --and I'd rather not create my own cooldown frame to preserve a tiny bit of memory
 hooksecurefunc(getmetatable(ActionButton1Cooldown).__index, 'SetCooldown', function(cd, start, duration)
 	--start timer
diff --git a/tullaCC/tullaCC.toc b/tullaCC/tullaCC.toc
index 4942c86..ebf7fbd 100644
--- a/tullaCC/tullaCC.toc
+++ b/tullaCC/tullaCC.toc
@@ -2,5 +2,5 @@
 ## Title: tullaCooldownCount
 ## Notes: Adds text to cooldowns
 ## Author: Tuller
-## Version: 1.3
+## Version: 1.4
 cc.lua
\ No newline at end of file