arena countdown refactor
This commit is contained in:
parent
e01b86e1e6
commit
67edecf8d1
@ -1,5 +1,5 @@
|
|||||||
local select, floor, str_len, tostring, str_sub, str_find = select, math.floor, string.len, tostring, string.sub, string.find
|
local floor, str_len, tostring, str_sub, str_find = math.floor, string.len, tostring, string.sub, string.find
|
||||||
local IsInInstance = IsInInstance
|
local CreateFrame = CreateFrame
|
||||||
|
|
||||||
local Gladdy = LibStub("Gladdy")
|
local Gladdy = LibStub("Gladdy")
|
||||||
local L = Gladdy.L
|
local L = Gladdy.L
|
||||||
@ -8,87 +8,88 @@ local ACDFrame = Gladdy:NewModule("Countdown", nil, {
|
|||||||
arenaCountdownSize = 256
|
arenaCountdownSize = 256
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function ACDFrame:OnEvent(event, ...)
|
||||||
|
self[event](self, ...)
|
||||||
|
end
|
||||||
|
|
||||||
function ACDFrame:Initialize()
|
function ACDFrame:Initialize()
|
||||||
self.hidden = false
|
self.hidden = false
|
||||||
self.countdown = -1
|
self.countdown = -1
|
||||||
self.texturePath = "Interface\\AddOns\\Gladdy\\Images\\Countdown\\";
|
self.texturePath = "Interface\\AddOns\\Gladdy\\Images\\Countdown\\";
|
||||||
ACDFrame:RegisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL")
|
|
||||||
ACDFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
|
local ACDNumFrame = CreateFrame("Frame", "ACDNumFrame", UIParent)
|
||||||
|
ACDNumFrame:EnableMouse(false)
|
||||||
|
ACDNumFrame:SetHeight(256)
|
||||||
|
ACDNumFrame:SetWidth(256)
|
||||||
|
ACDNumFrame:SetPoint("CENTER", 0, 128)
|
||||||
|
ACDNumFrame:Show()
|
||||||
|
self.ACDNumFrame = ACDNumFrame
|
||||||
|
|
||||||
|
local ACDNumTens = ACDNumFrame:CreateTexture("ACDNumTens", "HIGH")
|
||||||
|
ACDNumTens:SetWidth(256)
|
||||||
|
ACDNumTens:SetHeight(128)
|
||||||
|
ACDNumTens:SetPoint("CENTER", ACDNumFrame, "CENTER", -48, 0)
|
||||||
|
self.ACDNumTens = ACDNumTens
|
||||||
|
|
||||||
|
local ACDNumOnes = ACDNumFrame:CreateTexture("ACDNumOnes", "HIGH")
|
||||||
|
ACDNumOnes:SetWidth(256)
|
||||||
|
ACDNumOnes:SetHeight(128)
|
||||||
|
ACDNumOnes:SetPoint("CENTER", ACDNumFrame, "CENTER", 48, 0)
|
||||||
|
self.ACDNumOnes = ACDNumOnes
|
||||||
|
|
||||||
|
local ACDNumOne = ACDNumFrame:CreateTexture("ACDNumOne", "HIGH")
|
||||||
|
ACDNumOne:SetWidth(256)
|
||||||
|
ACDNumOne:SetHeight(128)
|
||||||
|
ACDNumOne:SetPoint("CENTER", ACDNumFrame, "CENTER", 0, 0)
|
||||||
|
self.ACDNumOne = ACDNumOne
|
||||||
|
|
||||||
|
self:RegisterMessage("JOINED_ARENA")
|
||||||
end
|
end
|
||||||
|
|
||||||
function ACDFrame:OnEvent(event, ...)
|
function ACDFrame.OnUpdate(self, elapse)
|
||||||
-- functions created in "object:method"-style have an implicit first parameter of "self", which points to object
|
if (self.countdown > 0 and Gladdy.db.countdown) then
|
||||||
self[event](self, ...) -- route event parameters to LoseControl:event methods
|
self.hidden = false;
|
||||||
end
|
|
||||||
ACDFrame:SetScript("OnEvent", ACDFrame.OnEvent)
|
|
||||||
|
|
||||||
|
if ((floor(self.countdown) ~= floor(self.countdown - elapse)) and (floor(self.countdown - elapse) >= 0)) then
|
||||||
|
local str = tostring(floor(self.countdown - elapse));
|
||||||
|
|
||||||
local ACDNumFrame = CreateFrame("Frame", "ACDNumFrame", UIParent)
|
if (floor(self.countdown - elapse) == 0) then
|
||||||
ACDNumFrame:SetHeight(256)
|
self.ACDNumTens:Hide();
|
||||||
ACDNumFrame:SetWidth(256)
|
self.ACDNumOnes:Hide();
|
||||||
ACDNumFrame:SetPoint("CENTER", 0, 128)
|
self.ACDNumOne:Hide();
|
||||||
ACDNumFrame:Show()
|
elseif (str_len(str) == 2) then
|
||||||
|
-- Display has 2 digits
|
||||||
|
self.ACDNumOne:Hide();
|
||||||
|
self.ACDNumTens:Show();
|
||||||
|
self.ACDNumOnes:Show();
|
||||||
|
|
||||||
local ACDNumTens = ACDNumFrame:CreateTexture("ACDNumTens", "HIGH")
|
self.ACDNumTens:SetTexture(self.texturePath .. str_sub(str, 0, 1));
|
||||||
ACDNumTens:SetWidth(256)
|
self.ACDNumOnes:SetTexture(self.texturePath .. str_sub(str, 2, 2));
|
||||||
ACDNumTens:SetHeight(128)
|
self.ACDNumFrame:SetScale(0.7)
|
||||||
ACDNumTens:SetPoint("CENTER", ACDNumFrame, "CENTER", -48, 0)
|
elseif (str_len(str) == 1) then
|
||||||
|
-- Display has 1 digit
|
||||||
local ACDNumOnes = ACDNumFrame:CreateTexture("ACDNumOnes", "HIGH")
|
self.ACDNumOne:Show();
|
||||||
ACDNumOnes:SetWidth(256)
|
self.ACDNumOne:SetTexture(self.texturePath .. str_sub(str, 0, 1));
|
||||||
ACDNumOnes:SetHeight(128)
|
self.ACDNumOnes:Hide();
|
||||||
ACDNumOnes:SetPoint("CENTER", ACDNumFrame, "CENTER", 48, 0)
|
self.ACDNumTens:Hide();
|
||||||
|
self.ACDNumFrame:SetScale(1.0)
|
||||||
local ACDNumOne = ACDNumFrame:CreateTexture("ACDNumOne", "HIGH")
|
|
||||||
ACDNumOne:SetWidth(256)
|
|
||||||
ACDNumOne:SetHeight(128)
|
|
||||||
ACDNumOne:SetPoint("CENTER", ACDNumFrame, "CENTER", 0, 0)
|
|
||||||
|
|
||||||
function ACDFrame:PLAYER_ENTERING_WORLD()
|
|
||||||
|
|
||||||
local instanceType = select(2, IsInInstance())
|
|
||||||
if (( instanceType == "arena" )) then
|
|
||||||
ACDFrame:SetScript("OnUpdate", function(self, elapse)
|
|
||||||
if (self.countdown > 0 and Gladdy.db.countdown) then
|
|
||||||
self.hidden = false;
|
|
||||||
|
|
||||||
if ((floor(self.countdown) ~= floor(self.countdown - elapse)) and (floor(self.countdown - elapse) >= 0)) then
|
|
||||||
local str = tostring(floor(self.countdown - elapse));
|
|
||||||
|
|
||||||
if (floor(self.countdown - elapse) == 0) then
|
|
||||||
ACDNumTens:Hide();
|
|
||||||
ACDNumOnes:Hide();
|
|
||||||
ACDNumOne:Hide();
|
|
||||||
elseif (str_len(str) == 2) then
|
|
||||||
-- Display has 2 digits
|
|
||||||
ACDNumOne:Hide();
|
|
||||||
ACDNumTens:Show();
|
|
||||||
ACDNumOnes:Show();
|
|
||||||
|
|
||||||
ACDNumTens:SetTexture(self.texturePath .. str_sub(str, 0, 1));
|
|
||||||
ACDNumOnes:SetTexture(self.texturePath .. str_sub(str, 2, 2));
|
|
||||||
ACDNumFrame:SetScale(0.7)
|
|
||||||
elseif (str_len(str) == 1) then
|
|
||||||
-- Display has 1 digit
|
|
||||||
ACDNumOne:Show();
|
|
||||||
ACDNumOne:SetTexture(self.texturePath .. str_sub(str, 0, 1));
|
|
||||||
ACDNumOnes:Hide();
|
|
||||||
ACDNumTens:Hide();
|
|
||||||
ACDNumFrame:SetScale(1.0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.countdown = self.countdown - elapse;
|
|
||||||
else
|
|
||||||
self.hidden = true;
|
|
||||||
ACDNumTens:Hide();
|
|
||||||
ACDNumOnes:Hide();
|
|
||||||
ACDNumOne:Hide();
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end)
|
self.countdown = self.countdown - elapse;
|
||||||
|
else
|
||||||
|
self.hidden = true;
|
||||||
|
self.ACDNumTens:Hide();
|
||||||
|
self.ACDNumOnes:Hide();
|
||||||
|
self.ACDNumOne:Hide();
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ACDFrame:JOINED_ARENA()
|
||||||
|
self:RegisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL")
|
||||||
|
self:SetScript("OnEvent", ACDFrame.OnEvent)
|
||||||
|
self:SetScript("OnUpdate", ACDFrame.OnUpdate)
|
||||||
|
end
|
||||||
|
|
||||||
function ACDFrame:CHAT_MSG_BG_SYSTEM_NEUTRAL(msg)
|
function ACDFrame:CHAT_MSG_BG_SYSTEM_NEUTRAL(msg)
|
||||||
if (str_find(msg, "L'ar\195\168ne ouvre ses portes dans 60 secondes !")) then
|
if (str_find(msg, "L'ar\195\168ne ouvre ses portes dans 60 secondes !")) then
|
||||||
self.countdown = 61
|
self.countdown = 61
|
||||||
@ -129,29 +130,36 @@ function ACDFrame:CHAT_MSG_BG_SYSTEM_NEUTRAL(msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ACDFrame:UpdateFrame()
|
function ACDFrame:UpdateFrame()
|
||||||
ACDNumFrame:SetHeight(Gladdy.db.arenaCountdownSize)
|
self.ACDNumFrame:SetHeight(Gladdy.db.arenaCountdownSize)
|
||||||
ACDNumFrame:SetWidth(Gladdy.db.arenaCountdownSize)
|
self.ACDNumFrame:SetWidth(Gladdy.db.arenaCountdownSize)
|
||||||
ACDNumFrame:SetPoint("CENTER", 0, 128)
|
self.ACDNumFrame:SetPoint("CENTER", 0, 128)
|
||||||
|
|
||||||
ACDNumTens:SetWidth(Gladdy.db.arenaCountdownSize)
|
self.ACDNumTens:SetWidth(Gladdy.db.arenaCountdownSize)
|
||||||
ACDNumTens:SetHeight(Gladdy.db.arenaCountdownSize/2)
|
self.ACDNumTens:SetHeight(Gladdy.db.arenaCountdownSize/2)
|
||||||
ACDNumTens:SetPoint("CENTER", ACDNumFrame, "CENTER", -(Gladdy.db.arenaCountdownSize/8 + Gladdy.db.arenaCountdownSize/8/2), 0)
|
self.ACDNumTens:SetPoint("CENTER", self.ACDNumFrame, "CENTER", -(Gladdy.db.arenaCountdownSize/8 + Gladdy.db.arenaCountdownSize/8/2), 0)
|
||||||
|
|
||||||
ACDNumOnes:SetWidth(Gladdy.db.arenaCountdownSize)
|
self.ACDNumOnes:SetWidth(Gladdy.db.arenaCountdownSize)
|
||||||
ACDNumOnes:SetHeight(Gladdy.db.arenaCountdownSize/2)
|
self.ACDNumOnes:SetHeight(Gladdy.db.arenaCountdownSize/2)
|
||||||
ACDNumOnes:SetPoint("CENTER", ACDNumFrame, "CENTER", (Gladdy.db.arenaCountdownSize/8 + Gladdy.db.arenaCountdownSize/8/2), 0)
|
self.ACDNumOnes:SetPoint("CENTER", self.ACDNumFrame, "CENTER", (Gladdy.db.arenaCountdownSize/8 + Gladdy.db.arenaCountdownSize/8/2), 0)
|
||||||
|
|
||||||
ACDNumOne:SetWidth(Gladdy.db.arenaCountdownSize)
|
self.ACDNumOne:SetWidth(Gladdy.db.arenaCountdownSize)
|
||||||
ACDNumOne:SetHeight(Gladdy.db.arenaCountdownSize/2)
|
self.ACDNumOne:SetHeight(Gladdy.db.arenaCountdownSize/2)
|
||||||
ACDNumOne:SetPoint("CENTER", ACDNumFrame, "CENTER", 0, 0)
|
self.ACDNumOne:SetPoint("CENTER", self.ACDNumFrame, "CENTER", 0, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ACDFrame:Test()
|
function ACDFrame:Test()
|
||||||
self.countdown = 30
|
self.countdown = 30
|
||||||
|
self:JOINED_ARENA()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ACDFrame:Reset()
|
function ACDFrame:Reset()
|
||||||
self.countdown = 0
|
self.countdown = 0
|
||||||
|
self:UnregisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL")
|
||||||
|
self:SetScript("OnUpdate", nil)
|
||||||
|
self.hidden = true;
|
||||||
|
self.ACDNumTens:Hide();
|
||||||
|
self.ACDNumOnes:Hide();
|
||||||
|
self.ACDNumOne:Hide();
|
||||||
end
|
end
|
||||||
|
|
||||||
function ACDFrame:GetOptions()
|
function ACDFrame:GetOptions()
|
||||||
|
Loading…
Reference in New Issue
Block a user