diff --git a/api/api.lua b/api/api.lua index d752ad30..6331768f 100644 --- a/api/api.lua +++ b/api/api.lua @@ -523,16 +523,15 @@ function pfUI.api.SetAutoPoint(frame, parent, spacing) end -- [ GetDefaultColors ] --- Queries the pfUI settings to get the default colors --- returns r,g,b,a,r,g,b,a (bg, border) -local color_cache = false -function pfUI.api.GetDefaultColors() - if not color_cache then - local br, bg, bb, ba = pfUI.api.strsplit(",", pfUI_config.appearance.border.background) - local er, eg, eb, ea = pfUI.api.strsplit(",", pfUI_config.appearance.border.color) - color_cache = { br, bg, bb, ba, er, eg, eb, ea } - end - return unpack(color_cache) +-- Queries the pfUI setting strings and extract its color codes +-- returns r,g,b,a +local color_cache = {} +function pfUI.api.GetStringColor(colorstr) + if not color_cache[colorstr] then + local r, g, b, a = pfUI.api.strsplit(",", colorstr) + color_cache[colorstr] = { r, g, b, a } + end + return unpack(color_cache[colorstr]) end -- [ Create Backdrop ] @@ -551,7 +550,9 @@ function pfUI.api.CreateBackdrop(f, inset, legacy, transp, backdropSetting) border = tonumber(pfUI_config.appearance.border.default) end - local br, bg, bb, ba, er, eg, eb, ea = pfUI.api.GetDefaultColors() + local br, bg, bb, ba = pfUI.api.GetStringColor(pfUI_config.appearance.border.background) + local er, eg, eb, ea = pfUI.api.GetStringColor(pfUI_config.appearance.border.color) + if transp then ba = transp end -- use legacy backdrop handling @@ -648,7 +649,7 @@ function pfUI.api.BarLayoutSize(bar,barsize,formfactor,iconsize,bordersize,visib if (visiblesize) and (visiblesize < barsize) then cols = math.min(cols,visiblesize) rows = math.min(math.ceil(visiblesize/cols),visiblesize) - end + end local width = (iconsize + bordersize*3) * cols - bordersize local height = (iconsize + bordersize*3) * rows - bordersize bar._size = {width,height} @@ -701,3 +702,28 @@ function pfUI.api.CreateAutohide(frame) end end) end + +-- [ GetColoredTime ] -- +-- 'remaining' the time in seconds that should be converted +-- return a colored string including a time unit (m/h/d) +function pfUI.api.GetColoredTimeString(remaining) + if not remaining then return "" end + if remaining > 99 * 60 * 60 then + local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.daycolor) + return "|cff" .. string.format("%02x%02x%02x", r*255, g*255, b*255) .. round(remaining / 60 / 60 / 24) .. "d" + elseif remaining > 99 * 60 then + local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.hourcolor) + return "|cff" .. string.format("%02x%02x%02x", r*255, g*255, b*255) .. round(remaining / 60 / 60) .. "h" + elseif remaining > 99 then + local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.minutecolor) + return "|cff" .. string.format("%02x%02x%02x", r*255, g*255, b*255) .. round(remaining / 60) .. "m" + elseif remaining <= 5 then + local r,g,b,a = pfUI.api.GetStringColor(C.appearance.cd.lowcolor) + return "|cff" .. string.format("%02x%02x%02x", r*255, g*255, b*255) .. round(remaining) + elseif remaining >= 0 then + local r, g, b, a = pfUI.api.GetStringColor(C.appearance.cd.normalcolor) + return "|cff" .. string.format("%02x%02x%02x", r*255, g*255, b*255) .. round(remaining) + else + return "" + end +end diff --git a/api/ui-widgets.lua b/api/ui-widgets.lua index 57ac9aad..fdae0551 100644 --- a/api/ui-widgets.lua +++ b/api/ui-widgets.lua @@ -118,8 +118,7 @@ end function pfUI.api.CreateScrollFrame(name, parent) local f = CreateFrame("ScrollFrame", name, parent) - - local br, bg, bb, ba = GetDefaultColors() + local br, bg, bb, ba = pfUI.api.GetStringColor(pfUI_config.appearance.border.background) f.Scroll = function(self, step) local current = self:GetVerticalScroll() local new = current + step*-25 diff --git a/modules/cooldown.lua b/modules/cooldown.lua index 038ba8c9..5a58103a 100644 --- a/modules/cooldown.lua +++ b/modules/cooldown.lua @@ -7,6 +7,31 @@ pfUI:RegisterModule("cooldown", function () local hourcolor = {strsplit(",", C.appearance.cd.hourcolor)} local daycolor = {strsplit(",", C.appearance.cd.daycolor)} + local function pfCooldownOnUpdate() + if not this:GetParent() then this:Hide() end + + -- avoid to set cooldowns on invalid frames + if this:GetParent() and this:GetParent():GetName() and _G[this:GetParent():GetName() .. "Cooldown"] then + if not _G[this:GetParent():GetName() .. "Cooldown"]:IsShown() then + this:Hide() + end + end + + if not this.next then this.next = GetTime() + .1 end + if this.next > GetTime() then return end + this.next = GetTime() + .1 + + -- fix own alpha value (should be inherited, but somehow isn't always) + this:SetAlpha(this:GetParent():GetAlpha()) + + local remaining = this.duration - (GetTime() - this.start) + if remaining >= 0 then + this.text:SetText(GetColoredTimeString(remaining)) + else + this:Hide() + end + end + local function pfCreateCoolDown(cooldown, start, duration) cooldown.cd = CreateFrame("Frame", "pfCooldownFrame", cooldown:GetParent()) cooldown.cd:SetAllPoints(cooldown:GetParent()) @@ -16,52 +41,7 @@ pfUI:RegisterModule("cooldown", function () cooldown.cd.text:SetFont(pfUI.font_unit, C.appearance.cd.font_size, "OUTLINE") cooldown.cd.text:SetPoint("CENTER", cooldown.cd, "CENTER", 0, 0) - cooldown.cd:SetScript("OnUpdate", function() - if not this:GetParent() then - this:Hide() - end - - if this:GetParent() and this:GetParent():GetName() and _G[this:GetParent():GetName() .. "Cooldown"] then - if not _G[this:GetParent():GetName() .. "Cooldown"]:IsShown() then - this:Hide() - end - end - - if not this.next then this.next = GetTime() + .1 end - if this.next > GetTime() then return end - this.next = GetTime() + .1 - - -- fix own alpha value (should be inherited, but isn't) - this:SetAlpha(this:GetParent():GetAlpha()) - - local remaining = this.duration - (GetTime() - this.start) - if remaining >= 0 then - local r, g, b, a = unpack(normalcolor) - local unit = "" - if remaining <= 3 then - r,g,b,a = unpack(lowcolor) - end - if remaining > 99 then - remaining = remaining / 60 - unit = "m" - r,g,b,a = unpack(minutecolor) - end - if remaining > 99 then - remaining = remaining / 60 - unit = "h" - r,g,b,a = unpack(hourcolor) - end - if remaining > 99 then - remaining = remaining / 24 - unit = "d" - r,g,b,a = unpack(daycolor) - end - this.text:SetText(round(remaining) .. unit) - this.text:SetTextColor(r,g,b,a) - else - this:Hide() - end - end) + cooldown.cd:SetScript("OnUpdate", pfCooldownOnUpdate) end -- hook