Quantcast
WoWInterface: SVN - fernir_UI - Rev 2 - /omnicc.lua

WoWInterface SVN fernir_UI

[/] [omnicc.lua] - Rev 2

Compare with Previous | Blame | View Log

local settings = oUF_Settings
local font = settings.font
local format = string.format
local floor = math.floor

local OmniCC_Settings = {
   FontSize = 13,                         -- Font size for frames of NormalizedSize, will be scaled for other sizes
   NormalizedSize = 31,                   -- At this frame width font will have 100% size
   ChangeColorTime = 5,                   -- Time in seconds when text color will be changed
   longR = 0.8, -- Color for cooldowns longer than ChangeColorTime. More info: http://www.wowwiki.com/API_FontString_SetTextColor
   longG = 0.8,
   longB = 0.8,
   shortR = 1,  -- Color for cooldowns shorter than ChangeColorTime.
   shortG = 0.2,
   shortB = 0.2,
   Point = {"BOTTOM", 0, -2}, -- Where to place cooldown text. More info: http://www.wowwiki.com/API_Region_SetPoint
}

local function GetFormattedTime(s)
    if s >= 3600 then
                return format('%dh', floor(s/3600 + 0.5)), s % 3600
        elseif s >= 60 then
                return format('%dm', floor(s/60 + 0.5)), s % 60
        end
        return floor(s + 0.5), s - floor(s)
end

local function Timer_OnUpdate(self, elapsed)
        if self.text:IsShown() then
                if self.nextUpdate > 0 then
                        self.nextUpdate = self.nextUpdate - elapsed
                else
                        local remain = self.duration - (GetTime() - self.start)
                        if floor(remain + 0.5) > 0 then
                                local time, nextUpdate = GetFormattedTime(remain)
                                self.text:SetText(time)
                                self.nextUpdate = nextUpdate
                if(floor(remain + 0.5) > OmniCC_Settings.ChangeColorTime) then
                    self.text:SetTextColor(OmniCC_Settings.longR, OmniCC_Settings.longG, OmniCC_Settings.longB)
                else
                    self.text:SetTextColor(OmniCC_Settings.shortR, OmniCC_Settings.shortG, OmniCC_Settings.shortB)
                end
                        else
                                self.text:Hide()
                        end
                end
        end
end

local function Timer_Create(self)
        if self:GetParent() then
    local realsize = self:GetParent():GetWidth() * OmniCC_Settings.FontSize / OmniCC_Settings.NormalizedSize
    if(realsize>8) then
        local text = self:CreateFontString(nil, "OVERLAY")
        text:SetPoint(unpack(OmniCC_Settings.Point))
        text:SetJustifyH("CENTER")
        text:SetFont(font, realsize, "THINOUTLINE")
        self.text = text
        self:SetScript("OnUpdate", Timer_OnUpdate)

        return text
    end
        end
end

local function Timer_Start(self, start, duration)
        self.start = start
        self.duration = duration
        self.nextUpdate = 0

        local text = self.text or Timer_Create(self)
        if text then
                text:Show()
        end
end

local methods = getmetatable(ActionButton1Cooldown).__index
hooksecurefunc(methods, "SetCooldown", function(self, start, duration)
        if(start>0 and duration>3) then
                Timer_Start(self, start, duration)
        else
                local text = self.text
                if text then
                        text:Hide()
                end
        end
end)

Compare with Previous | Blame