View Single Post
05-08-14, 11:55 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by cokedrivers View Post
Ive seen DBM have a count down stays bar show. But I'm just looking for a numeric count down nothing dance.

Ill look threw DBM maybe I can find how they get the timer info.
DBM just hardcodes it at 40 seconds; AFAIK there is no API function to get the remaining time.

Code:
local PROPOSAL_DURATION = 40

local frame = CreateFrame("Frame", nil, LFGDungeonReadyPopup)
frame:SetPoint("TOP", LFGDungeonReadyPopup, "BOTTOM", 0, -5)
frame:SetSize(20, 20) -- doesn't actually matter, just needs nonzero dimensions

local text = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
text:SetPoint("TOP")

local t = PROPOSAL_DURATION
frame:SetScript("OnUpdate", function(self, elapsed)
     t = t - elapsed
     text:SetText(floor(t + 0.5))
end)

frame:RegisterEvent("LFG_PROPOSAL_SHOW")
frame:SetScript("OnEvent", function(self, event)
     if event == "LFG_PROPOSAL_SHOW" then
          t = PROPOSAL_DURATION
          self:Show()
     else
          self:Hide()
     end
end)
If you wanted a status bar (complete with gradient coloring) instead:

Code:
local PROPOSAL_DURATION = 40

local bar = CreateFrame("StatusBar", nil, LFGDungeonReadyPopup)
bar:SetPoint("TOPLEFT", LFGDungeonReadyPopup, "BOTTOMLEFT", 0, -5)
bar:SetPoint("TOPRIGHT", LFGDungeonReadyPopup, "BOTTOMRIGHT", 0, -5)
bar:SetHeight(5)
bar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
bar:SetMinMaxValues(0, PROPOSAL_DURATION)

local spark = bar:CreateTexture(nil, "OVERLAY")
spark:SetPoint("CENTER", bar:GetStatusBarTexture(), "LEFT")
spark:SetSize(5, 8) -- height should be about 2.5x width
spark:SetAlpha(0.5)
spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
spark:SetBlendMode("ADD")

local t = PROPOSAL_DURATION
local HALF_POINT = PROPOSAL_DURATION / 2
bar:SetScript("OnUpdate", function(self, elapsed)
     t = t - elapsed
     self:SetValue(t)
     if t > HALF_POINT then
          self:SetStatusBarColor(1, t / PROPOSAL_DURATION, 0)
     else
          self:SetStatusBarColor(1 - (t / PROPOSAL_DURATION), 1, 0)
     end
end)

frame:RegisterEvent("LFG_PROPOSAL_SHOW")
frame:SetScript("OnEvent", function(self, event)
     if event == "LFG_PROPOSAL_SHOW" then
          t = PROPOSAL_DURATION
          self:Show()
     else
          self:Hide()
     end
end)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 05-09-14 at 12:03 AM.
  Reply With Quote