cooldown: new cooldown mechanism

This commit is contained in:
shagu
2016-11-26 00:53:51 +01:00
parent d63c6a68d8
commit 94001b41da
3 changed files with 53 additions and 51 deletions
+45 -49
View File
@@ -1,71 +1,67 @@
pfUI:RegisterModule("cooldown", function ()
function CooldownFrame_SetTimer(this, start, duration, enable)
if not this then return end
-- disable animation
this:SetPosition(1,1,1)
local function pfCreateCoolDown(cooldown, start, duration)
cooldown.cd = CreateFrame("Frame", "pfCooldownFrame", cooldown:GetParent())
cooldown.cd:SetAllPoints(cooldown:GetParent())
cooldown.cd:SetFrameLevel(cooldown.cd:GetFrameLevel() + 1)
if ( start > 0 and duration > tonumber(pfUI_config.global.cooldown_min) and enable > 0) then
this.start = start
this.duration = duration
this.stopping = 0
this:SetSequence(0)
cooldown.cd.text = cooldown.cd:CreateFontString("pfCooldownFrameText", "OVERLAY")
cooldown.cd.text:SetFont("Interface\\AddOns\\pfUI\\fonts\\" .. pfUI_config.global.font_square .. ".ttf", pfUI_config.global.font_size, "OUTLINE")
cooldown.cd.text:SetPoint("CENTER", cooldown.cd, "CENTER", 0, 1)
if not this.cd then
this.cd = CreateFrame("Frame")
this.cd:SetAllPoints(this)
cooldown.cd:SetScript("OnUpdate", function()
if not getglobal(this:GetParent():GetName() .. "Cooldown"):IsShown() then this:Hide() end
if not this.next then this.next = GetTime() + .1 end
if this.next > GetTime() then return end
this.next = GetTime() + .1
this.cd.back = this.cd:CreateTexture(nil,"BACKGROUND")
this.cd.back:SetTexture(0,0,0,1)
this.cd.back:SetAlpha(.5)
this.cd.back:SetParent(this)
this.cd.back:SetAllPoints(this)
this.cd.text = this.cd:CreateFontString("Status", "HIGH", "GameFontNormal")
this.cd.text:SetFont("Interface\\AddOns\\pfUI\\fonts\\" .. pfUI_config.global.font_square .. ".ttf", pfUI_config.global.font_size, "OUTLINE")
this.cd.text:ClearAllPoints()
this.cd.text:SetParent(this)
this.cd.text:SetAllPoints(this)
this.cd.text:SetJustifyH("CENTER")
this.cd.text:SetFontObject(GameFontWhite)
end
this:Show()
else
this:Hide()
if this.cd then this.cd:Hide() end
end
end
function CooldownFrame_OnUpdateModel()
if this.start and this.duration then
local remaining = this.duration - (GetTime() - this.start)
-- disable GCD notify
if (remaining >= 0 and this.duration > tonumber(pfUI_config.global.cooldown_min)) then
this.cd:Show()
if remaining >= 0 then
local unit = ""
local color = "|cffffffff"
if remaining > 99 then
remaining = remaining / 60
unit = "m"
color = "|cff" .. pfUI_config.appearance.cd.mincolor
end
if remaining > 99 then
remaining = remaining / 60
unit = "h"
color = "|cff" .. pfUI_config.appearance.cd.hourcolor
end
this.cd.text:SetText(ceil(remaining)..unit)
if remaining > 99 then
remaining = remaining / 24
unit = "d"
color = "|cff" .. pfUI_config.appearance.cd.daycolor
end
this.text:SetText(color .. round(remaining) .. unit)
else
this:Hide()
this.cd:Hide()
this.stopping = 1
end
end
end)
end
function CooldownFrame_OnAnimFinished()
if ( this.stopping == 1 ) then
this:Hide()
this.cd:Hide()
-- hook
if not pfCooldownFrame_SetTimer then pfCooldownFrame_SetTimer = CooldownFrame_SetTimer end
function CooldownFrame_SetTimer(this, start, duration, enable)
-- realign all cooldown frames
if this:GetParent():GetWidth() / 36 > 0 then
this:SetScale(this:GetParent():GetWidth() / 36)
this:SetPoint("TOPLEFT", this:GetParent(), "TOPLEFT", 0, 0)
this:SetPoint("BOTTOMRIGHT", this:GetParent(), "BOTTOMRIGHT", 1, -1)
end
-- print time as text on cooldown frames
if ( start > 0 and duration > tonumber(pfUI_config.appearance.cd.threshold) and enable > 0) then
if( not this.cd ) then
pfCreateCoolDown(this, start, duration)
end
this.cd.start = start
this.cd.duration = duration
this.cd:Show()
elseif(this.cd) then
this.cd:Hide();
end
pfCooldownFrame_SetTimer(this, start, duration, enable)
end
end)