mirror of
https://github.com/brues-code/pfUI.git
synced 2026-09-28 10:26:02 +00:00
api: cache color values for time strings
This commit is contained in:
+53
-15
@@ -1212,26 +1212,64 @@ end
|
||||
-- [ GetColoredTime ] --
|
||||
-- 'remaining' the time in seconds that should be converted
|
||||
-- return a colored string including a time unit (m/h/d)
|
||||
local color_day, color_hour, color_minute, color_low, color_normal
|
||||
function pfUI.api.GetColoredTimeString(remaining)
|
||||
if not remaining then return "" end
|
||||
if remaining > 356400 then -- Show days if remaining is > 99 Hours (99 * 60 * 60)
|
||||
local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.daycolor)
|
||||
return pfUI.api.rgbhex(r,g,b) .. round(remaining / 86400) .. "|rd"
|
||||
elseif remaining > 5940 then -- Show hours if remaining is > 99 Minutes (99 * 60)
|
||||
local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.hourcolor)
|
||||
return pfUI.api.rgbhex(r,g,b) .. round(remaining / 3600) .. "|rh"
|
||||
elseif remaining > 99 then -- Show minutes if remaining is > 99 Seconds (99)
|
||||
local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.minutecolor)
|
||||
return pfUI.api.rgbhex(r,g,b) .. round(remaining / 60) .. "|rm"
|
||||
|
||||
-- Show days if remaining is > 99 Hours (99 * 60 * 60)
|
||||
if remaining > 356400 then
|
||||
if not color_day then
|
||||
local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.daycolor)
|
||||
color_day = pfUI.api.rgbhex(r,g,b)
|
||||
end
|
||||
|
||||
return color_day .. round(remaining / 86400) .. "|rd"
|
||||
|
||||
-- Show hours if remaining is > 99 Minutes (99 * 60)
|
||||
elseif remaining > 5940 then
|
||||
if not color_hour then
|
||||
local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.hourcolor)
|
||||
color_hour = pfUI.api.rgbhex(r,g,b)
|
||||
end
|
||||
|
||||
return color_hour .. round(remaining / 3600) .. "|rh"
|
||||
|
||||
-- Show minutes if remaining is > 99 Seconds (99)
|
||||
elseif remaining > 99 then
|
||||
if not color_minute then
|
||||
local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.minutecolor)
|
||||
color_minute = pfUI.api.rgbhex(r,g,b)
|
||||
end
|
||||
|
||||
return color_minute .. round(remaining / 60) .. "|rm"
|
||||
|
||||
-- Show milliseconds on low
|
||||
elseif remaining <= 5 and pfUI_config.appearance.cd.milliseconds == "1" then
|
||||
local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.lowcolor)
|
||||
return pfUI.api.rgbhex(r,g,b) .. string.format("%.1f", round(remaining,1))
|
||||
if not color_low then
|
||||
local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.lowcolor)
|
||||
color_low = pfUI.api.rgbhex(r,g,b)
|
||||
end
|
||||
|
||||
return color_low .. string.format("%.1f", round(remaining,1))
|
||||
|
||||
-- Show seconds on low
|
||||
elseif remaining <= 5 then
|
||||
local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.lowcolor)
|
||||
return pfUI.api.rgbhex(r,g,b) .. round(remaining)
|
||||
if not color_low then
|
||||
local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.lowcolor)
|
||||
color_low = pfUI.api.rgbhex(r,g,b)
|
||||
end
|
||||
|
||||
return color_low .. round(remaining)
|
||||
|
||||
-- Show seconds on normal
|
||||
elseif remaining >= 0 then
|
||||
local r, g, b, a = pfUI.api.GetStringColor(C.appearance.cd.normalcolor)
|
||||
return pfUI.api.rgbhex(r,g,b) .. round(remaining)
|
||||
if not color_normal then
|
||||
local r, g, b, a = pfUI.api.GetStringColor(C.appearance.cd.normalcolor)
|
||||
color_normal = pfUI.api.rgbhex(r,g,b)
|
||||
end
|
||||
return color_normal .. round(remaining)
|
||||
|
||||
-- Return empty
|
||||
else
|
||||
return ""
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user