2021-05-24 12:41:21 +02:00
|
|
|
local floor, str_len, tostring, str_sub, str_find, pairs = math.floor, string.len, tostring, string.sub, string.find, pairs
|
2021-05-19 19:29:59 +02:00
|
|
|
local CreateFrame = CreateFrame
|
2021-05-24 12:41:21 +02:00
|
|
|
local GetTime = GetTime
|
2021-05-17 16:49:54 +02:00
|
|
|
|
|
|
|
local Gladdy = LibStub("Gladdy")
|
|
|
|
local L = Gladdy.L
|
2021-05-24 12:41:21 +02:00
|
|
|
local ACDFrame = Gladdy:NewModule("Arena Countdown", nil, {
|
2021-05-17 16:49:54 +02:00
|
|
|
countdown = true,
|
2022-01-12 20:21:53 +01:00
|
|
|
arenaCountdownSize = 256,
|
|
|
|
arenaCountdownFrameStrata = "HIGH",
|
|
|
|
arenaCountdownFrameLevel = 50,
|
2021-05-17 16:49:54 +02:00
|
|
|
})
|
|
|
|
|
2021-05-19 19:29:59 +02:00
|
|
|
function ACDFrame:OnEvent(event, ...)
|
|
|
|
self[event](self, ...)
|
|
|
|
end
|
|
|
|
|
2021-05-17 16:49:54 +02:00
|
|
|
function ACDFrame:Initialize()
|
2021-06-15 09:05:32 +02:00
|
|
|
self.locale = Gladdy:GetArenaTimer()
|
2021-05-17 16:49:54 +02:00
|
|
|
self.hidden = false
|
|
|
|
self.countdown = -1
|
|
|
|
self.texturePath = "Interface\\AddOns\\Gladdy\\Images\\Countdown\\";
|
|
|
|
|
2021-05-19 19:29:59 +02:00
|
|
|
local ACDNumFrame = CreateFrame("Frame", "ACDNumFrame", UIParent)
|
|
|
|
ACDNumFrame:EnableMouse(false)
|
2021-08-10 13:17:46 +02:00
|
|
|
ACDNumFrame:SetHeight(512)
|
|
|
|
ACDNumFrame:SetWidth(512)
|
|
|
|
ACDNumFrame:SetPoint("CENTER", 0, 256)
|
2022-01-25 20:03:17 +01:00
|
|
|
ACDNumFrame:Hide()
|
2021-05-19 19:29:59 +02:00
|
|
|
self.ACDNumFrame = ACDNumFrame
|
|
|
|
|
|
|
|
local ACDNumTens = ACDNumFrame:CreateTexture("ACDNumTens", "HIGH")
|
|
|
|
ACDNumTens:SetWidth(256)
|
2021-08-10 13:17:46 +02:00
|
|
|
ACDNumTens:SetHeight(256)
|
2021-09-03 01:39:21 +02:00
|
|
|
ACDNumTens:SetPoint("CENTER", ACDNumFrame, "CENTER", -50, 0)
|
2021-05-19 19:29:59 +02:00
|
|
|
self.ACDNumTens = ACDNumTens
|
|
|
|
|
|
|
|
local ACDNumOnes = ACDNumFrame:CreateTexture("ACDNumOnes", "HIGH")
|
|
|
|
ACDNumOnes:SetWidth(256)
|
2021-08-10 13:17:46 +02:00
|
|
|
ACDNumOnes:SetHeight(256)
|
2021-09-03 01:39:21 +02:00
|
|
|
ACDNumOnes:SetPoint("CENTER", ACDNumFrame, "CENTER", 50, 0)
|
2021-05-19 19:29:59 +02:00
|
|
|
self.ACDNumOnes = ACDNumOnes
|
|
|
|
|
|
|
|
local ACDNumOne = ACDNumFrame:CreateTexture("ACDNumOne", "HIGH")
|
|
|
|
ACDNumOne:SetWidth(256)
|
2021-08-10 13:17:46 +02:00
|
|
|
ACDNumOne:SetHeight(256)
|
2021-05-19 19:29:59 +02:00
|
|
|
ACDNumOne:SetPoint("CENTER", ACDNumFrame, "CENTER", 0, 0)
|
|
|
|
self.ACDNumOne = ACDNumOne
|
|
|
|
|
2022-02-15 22:59:21 +01:00
|
|
|
if Gladdy.db.countdown then
|
|
|
|
self:RegisterMessage("JOINED_ARENA")
|
|
|
|
self:RegisterMessage("ENEMY_SPOTTED")
|
|
|
|
self:RegisterMessage("UNIT_SPEC")
|
|
|
|
end
|
2021-08-10 13:17:46 +02:00
|
|
|
self.faction = UnitFactionGroup("player")
|
2021-05-17 16:49:54 +02:00
|
|
|
end
|
|
|
|
|
2022-01-12 20:21:53 +01:00
|
|
|
function ACDFrame:UpdateFrameOnce()
|
2022-02-15 22:59:21 +01:00
|
|
|
if Gladdy.db.countdown then
|
|
|
|
self:RegisterMessage("JOINED_ARENA")
|
|
|
|
self:RegisterMessage("ENEMY_SPOTTED")
|
|
|
|
self:RegisterMessage("UNIT_SPEC")
|
|
|
|
else
|
|
|
|
self:UnregisterAllMessages()
|
|
|
|
end
|
2022-01-12 20:21:53 +01:00
|
|
|
self.ACDNumFrame:SetFrameStrata(Gladdy.db.arenaCountdownFrameStrata)
|
|
|
|
self.ACDNumFrame:SetFrameLevel(Gladdy.db.arenaCountdownFrameLevel)
|
|
|
|
end
|
|
|
|
|
2021-05-19 19:29:59 +02:00
|
|
|
function ACDFrame.OnUpdate(self, elapse)
|
|
|
|
if (self.countdown > 0 and Gladdy.db.countdown) then
|
|
|
|
self.hidden = false;
|
2022-03-25 22:34:04 +01:00
|
|
|
self.ACDNumFrame:Show()
|
2021-05-19 19:29:59 +02:00
|
|
|
if ((floor(self.countdown) ~= floor(self.countdown - elapse)) and (floor(self.countdown - elapse) >= 0)) then
|
|
|
|
local str = tostring(floor(self.countdown - elapse));
|
|
|
|
|
2021-08-10 13:17:46 +02:00
|
|
|
if (str_len(str) == 2) then
|
2021-05-19 19:29:59 +02:00
|
|
|
-- Display has 2 digits
|
|
|
|
self.ACDNumOne:Hide();
|
|
|
|
self.ACDNumTens:Show();
|
|
|
|
self.ACDNumOnes:Show();
|
|
|
|
|
|
|
|
self.ACDNumTens:SetTexture(self.texturePath .. str_sub(str, 0, 1));
|
|
|
|
self.ACDNumOnes:SetTexture(self.texturePath .. str_sub(str, 2, 2));
|
|
|
|
self.ACDNumFrame:SetScale(0.7)
|
|
|
|
elseif (str_len(str) == 1) then
|
|
|
|
-- Display has 1 digit
|
2021-08-10 13:17:46 +02:00
|
|
|
local numStr = str_sub(str, 0, 1)
|
|
|
|
local path = numStr == "0" and self.faction or numStr
|
2021-05-19 19:29:59 +02:00
|
|
|
self.ACDNumOne:Show();
|
2021-08-10 13:17:46 +02:00
|
|
|
self.ACDNumOne:SetTexture(self.texturePath .. path);
|
2021-05-19 19:29:59 +02:00
|
|
|
self.ACDNumOnes:Hide();
|
|
|
|
self.ACDNumTens:Hide();
|
|
|
|
self.ACDNumFrame:SetScale(1.0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self.countdown = self.countdown - elapse;
|
|
|
|
else
|
|
|
|
self.hidden = true;
|
2022-01-25 20:03:17 +01:00
|
|
|
self.ACDNumFrame:Hide()
|
2021-05-19 19:29:59 +02:00
|
|
|
self.ACDNumTens:Hide();
|
|
|
|
self.ACDNumOnes:Hide();
|
|
|
|
self.ACDNumOne:Hide();
|
2021-05-17 16:49:54 +02:00
|
|
|
end
|
2021-05-24 12:41:21 +02:00
|
|
|
if (GetTime() > self.endTime) then
|
|
|
|
self:SetScript("OnUpdate", nil)
|
|
|
|
end
|
2021-05-17 16:49:54 +02:00
|
|
|
end
|
|
|
|
|
2021-05-19 19:29:59 +02:00
|
|
|
function ACDFrame:JOINED_ARENA()
|
2021-08-10 13:17:46 +02:00
|
|
|
if Gladdy.db.countdown then
|
|
|
|
self:RegisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL")
|
|
|
|
self:SetScript("OnEvent", ACDFrame.OnEvent)
|
|
|
|
self.endTime = GetTime() + 70
|
|
|
|
self:SetScript("OnUpdate", ACDFrame.OnUpdate)
|
|
|
|
end
|
2021-05-19 19:29:59 +02:00
|
|
|
end
|
|
|
|
|
2021-05-24 12:41:21 +02:00
|
|
|
function ACDFrame:ENEMY_SPOTTED()
|
2021-08-10 13:17:46 +02:00
|
|
|
if not Gladdy.frame.testing then
|
|
|
|
ACDFrame:Reset()
|
|
|
|
end
|
2021-05-24 12:41:21 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ACDFrame:UNIT_SPEC()
|
2021-08-10 13:17:46 +02:00
|
|
|
if not Gladdy.frame.testing then
|
|
|
|
ACDFrame:Reset()
|
|
|
|
end
|
2021-05-24 12:41:21 +02:00
|
|
|
end
|
|
|
|
|
2021-05-17 16:49:54 +02:00
|
|
|
function ACDFrame:CHAT_MSG_BG_SYSTEM_NEUTRAL(msg)
|
2021-05-24 12:41:21 +02:00
|
|
|
for k,v in pairs(self.locale) do
|
|
|
|
if str_find(msg, v) then
|
|
|
|
if k == 0 then
|
|
|
|
ACDFrame:Reset()
|
|
|
|
else
|
|
|
|
self.countdown = k
|
|
|
|
end
|
|
|
|
end
|
2021-05-17 16:49:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ACDFrame:UpdateFrame()
|
2021-05-19 19:29:59 +02:00
|
|
|
self.ACDNumFrame:SetHeight(Gladdy.db.arenaCountdownSize)
|
|
|
|
self.ACDNumFrame:SetWidth(Gladdy.db.arenaCountdownSize)
|
|
|
|
self.ACDNumFrame:SetPoint("CENTER", 0, 128)
|
2021-05-17 16:49:54 +02:00
|
|
|
|
2021-05-19 19:29:59 +02:00
|
|
|
self.ACDNumTens:SetWidth(Gladdy.db.arenaCountdownSize)
|
2021-08-10 13:17:46 +02:00
|
|
|
self.ACDNumTens:SetHeight(Gladdy.db.arenaCountdownSize)
|
2021-05-19 19:29:59 +02:00
|
|
|
self.ACDNumTens:SetPoint("CENTER", self.ACDNumFrame, "CENTER", -(Gladdy.db.arenaCountdownSize/8 + Gladdy.db.arenaCountdownSize/8/2), 0)
|
2021-05-17 16:49:54 +02:00
|
|
|
|
2021-05-19 19:29:59 +02:00
|
|
|
self.ACDNumOnes:SetWidth(Gladdy.db.arenaCountdownSize)
|
2021-08-10 13:17:46 +02:00
|
|
|
self.ACDNumOnes:SetHeight(Gladdy.db.arenaCountdownSize)
|
2021-05-19 19:29:59 +02:00
|
|
|
self.ACDNumOnes:SetPoint("CENTER", self.ACDNumFrame, "CENTER", (Gladdy.db.arenaCountdownSize/8 + Gladdy.db.arenaCountdownSize/8/2), 0)
|
2021-05-17 16:49:54 +02:00
|
|
|
|
2021-05-19 19:29:59 +02:00
|
|
|
self.ACDNumOne:SetWidth(Gladdy.db.arenaCountdownSize)
|
2021-08-10 13:17:46 +02:00
|
|
|
self.ACDNumOne:SetHeight(Gladdy.db.arenaCountdownSize)
|
2021-05-19 19:29:59 +02:00
|
|
|
self.ACDNumOne:SetPoint("CENTER", self.ACDNumFrame, "CENTER", 0, 0)
|
2021-05-17 16:49:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ACDFrame:Test()
|
|
|
|
self.countdown = 30
|
2021-05-19 19:29:59 +02:00
|
|
|
self:JOINED_ARENA()
|
2021-05-17 16:49:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ACDFrame:Reset()
|
2021-05-24 12:41:21 +02:00
|
|
|
self.endTime = 0
|
2021-05-17 16:49:54 +02:00
|
|
|
self.countdown = 0
|
2021-05-19 19:29:59 +02:00
|
|
|
self:UnregisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL")
|
|
|
|
self:SetScript("OnUpdate", nil)
|
|
|
|
self.hidden = true;
|
2022-01-12 02:25:40 +01:00
|
|
|
self.ACDNumFrame:Hide()
|
2021-05-19 19:29:59 +02:00
|
|
|
self.ACDNumTens:Hide();
|
|
|
|
self.ACDNumOnes:Hide();
|
|
|
|
self.ACDNumOne:Hide();
|
2021-05-17 16:49:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ACDFrame:GetOptions()
|
|
|
|
return {
|
|
|
|
headerArenaCountdown = {
|
|
|
|
type = "header",
|
|
|
|
name = L["Arena Countdown"],
|
|
|
|
order = 2,
|
|
|
|
},
|
|
|
|
countdown = Gladdy:option({
|
|
|
|
type = "toggle",
|
2021-05-24 12:41:21 +02:00
|
|
|
name = L["Enabled"],
|
2021-05-17 16:49:54 +02:00
|
|
|
desc = L["Turns countdown before the start of an arena match on/off."],
|
|
|
|
order = 3,
|
|
|
|
width = "full",
|
|
|
|
}),
|
|
|
|
arenaCountdownSize = Gladdy:option({
|
|
|
|
type = "range",
|
|
|
|
name = L["Size"],
|
|
|
|
order = 4,
|
|
|
|
min = 64,
|
|
|
|
max = 512,
|
|
|
|
step = 16,
|
2021-06-15 09:05:32 +02:00
|
|
|
width = "full",
|
2022-02-15 22:59:21 +01:00
|
|
|
disabled = function() return not Gladdy.db.countdown end,
|
2021-05-17 16:49:54 +02:00
|
|
|
}),
|
2022-01-12 20:21:53 +01:00
|
|
|
headerAuraLevel = {
|
|
|
|
type = "header",
|
|
|
|
name = L["Frame Strata and Level"],
|
|
|
|
order = 5,
|
|
|
|
},
|
|
|
|
arenaCountdownFrameStrata = Gladdy:option({
|
|
|
|
type = "select",
|
|
|
|
name = L["Frame Strata"],
|
|
|
|
order = 6,
|
|
|
|
values = Gladdy.frameStrata,
|
|
|
|
sorting = Gladdy.frameStrataSorting,
|
2022-02-15 22:59:21 +01:00
|
|
|
disabled = function() return not Gladdy.db.countdown end,
|
2022-01-12 20:21:53 +01:00
|
|
|
}),
|
|
|
|
arenaCountdownFrameLevel = Gladdy:option({
|
|
|
|
type = "range",
|
|
|
|
name = L["Frame Level"],
|
|
|
|
min = 0,
|
|
|
|
max = 500,
|
|
|
|
step = 1,
|
|
|
|
order = 7,
|
|
|
|
width = "full",
|
2022-02-15 22:59:21 +01:00
|
|
|
disabled = function() return not Gladdy.db.countdown end,
|
2022-01-12 20:21:53 +01:00
|
|
|
}),
|
2021-05-17 16:49:54 +02:00
|
|
|
}
|
|
|
|
end
|