Gladdy-TBC/Modules/ArenaCountDown.lua

227 lines
7.4 KiB
Lua
Raw Normal View History

local str_find, pairs = string.find, pairs
2021-05-19 19:29:59 +02:00
local CreateFrame = CreateFrame
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,
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.countdown = -1
self.texturePath = "Interface\\AddOns\\Gladdy\\Images\\Countdown\\";
2021-05-19 19:29:59 +02:00
local ACDNumFrame = CreateFrame("Frame", "ACDNumFrame", UIParent)
self.ACDNumFrame = ACDNumFrame
2022-03-26 00:16:13 +01:00
self.ACDNumFrame:EnableMouse(false)
self.ACDNumFrame:SetHeight(Gladdy.db.arenaCountdownSize)
self.ACDNumFrame:SetWidth(Gladdy.db.arenaCountdownSize)
self.ACDNumFrame:SetPoint("CENTER", 0, 128)
self.ACDNumFrame:Hide()
2021-05-19 19:29:59 +02:00
2023-01-18 16:45:28 +01:00
local ACDNumTens = ACDNumFrame:CreateTexture("ACDNumTens", "OVERLAY")
2021-05-19 19:29:59 +02:00
self.ACDNumTens = ACDNumTens
2022-03-26 00:16:13 +01:00
self.ACDNumTens:SetWidth(Gladdy.db.arenaCountdownSize)
self.ACDNumTens:SetHeight(Gladdy.db.arenaCountdownSize)
self.ACDNumTens:SetPoint("CENTER", self.ACDNumFrame, "CENTER", -(Gladdy.db.arenaCountdownSize/8 + Gladdy.db.arenaCountdownSize/8/2), 0)
2021-05-19 19:29:59 +02:00
2023-01-18 16:45:28 +01:00
local ACDNumOnes = ACDNumFrame:CreateTexture("ACDNumOnes", "OVERLAY")
2021-05-19 19:29:59 +02:00
self.ACDNumOnes = ACDNumOnes
2022-03-26 00:16:13 +01:00
self.ACDNumOnes:SetWidth(Gladdy.db.arenaCountdownSize)
self.ACDNumOnes:SetHeight(Gladdy.db.arenaCountdownSize)
self.ACDNumOnes:SetPoint("CENTER", self.ACDNumFrame, "CENTER", (Gladdy.db.arenaCountdownSize/8 + Gladdy.db.arenaCountdownSize/8/2), 0)
2021-05-19 19:29:59 +02:00
2023-01-18 16:45:28 +01:00
local ACDNumOne = ACDNumFrame:CreateTexture("ACDNumOne", "OVERLAY")
2021-05-19 19:29:59 +02:00
self.ACDNumOne = ACDNumOne
2022-03-26 00:16:13 +01:00
self.ACDNumOne:SetWidth(Gladdy.db.arenaCountdownSize)
self.ACDNumOne:SetHeight(Gladdy.db.arenaCountdownSize)
self.ACDNumOne:SetPoint("CENTER", self.ACDNumFrame, "CENTER", 0, 0)
2021-05-19 19:29:59 +02: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")
self:SetScript("OnEvent", ACDFrame.OnEvent)
2021-05-17 16:49:54 +02:00
end
function ACDFrame:UpdateFrameOnce()
if Gladdy.db.countdown then
self:RegisterMessage("JOINED_ARENA")
self:RegisterMessage("ENEMY_SPOTTED")
self:RegisterMessage("UNIT_SPEC")
else
self:UnregisterAllMessages()
end
self.ACDNumFrame:SetFrameStrata(Gladdy.db.arenaCountdownFrameStrata)
self.ACDNumFrame:SetFrameLevel(Gladdy.db.arenaCountdownFrameLevel)
2022-03-26 00:16:13 +01:00
self.ACDNumFrame:SetHeight(Gladdy.db.arenaCountdownSize)
self.ACDNumFrame:SetWidth(Gladdy.db.arenaCountdownSize)
self.ACDNumFrame:SetPoint("CENTER", 0, 128)
self.ACDNumTens:SetWidth(Gladdy.db.arenaCountdownSize)
self.ACDNumTens:SetHeight(Gladdy.db.arenaCountdownSize)
self.ACDNumTens:SetPoint("CENTER", self.ACDNumFrame, "CENTER", -(Gladdy.db.arenaCountdownSize/8 + Gladdy.db.arenaCountdownSize/8/2), 0)
self.ACDNumOnes:SetWidth(Gladdy.db.arenaCountdownSize)
self.ACDNumOnes:SetHeight(Gladdy.db.arenaCountdownSize)
self.ACDNumOnes:SetPoint("CENTER", self.ACDNumFrame, "CENTER", (Gladdy.db.arenaCountdownSize/8 + Gladdy.db.arenaCountdownSize/8/2), 0)
self.ACDNumOne:SetWidth(Gladdy.db.arenaCountdownSize)
self.ACDNumOne:SetHeight(Gladdy.db.arenaCountdownSize)
self.ACDNumOne:SetPoint("CENTER", self.ACDNumFrame, "CENTER", 0, 0)
end
function ACDFrame:HideAll()
self.ACDNumFrame:Hide()
self.ACDNumTens:Hide()
self.ACDNumOnes:Hide()
self.ACDNumOne:Hide()
end
function ACDFrame:CreateTicker(countdown)
self.countdown = countdown
if self.ticker and not self.ticker:IsCancelled() then
self.ticker:Cancel()
end
self.ticker = C_Timer.NewTicker(1, ACDFrame.Ticker)
end
function ACDFrame.Ticker()
local self = ACDFrame
if (Gladdy.db.countdown) then
2022-03-25 22:34:04 +01:00
self.ACDNumFrame:Show()
if (self.countdown and self.countdown >= 10 and self.countdown <= 60) then
-- Display has 2 digits
local ones = self.countdown % 10
local tens = (self.countdown / 10) % 10
self.ACDNumOne:Hide()
self.ACDNumTens:Show()
self.ACDNumOnes:Show()
self.ACDNumTens:SetTexture(self.texturePath .. tens)
self.ACDNumOnes:SetTexture(self.texturePath .. ones)
self.ACDNumFrame:SetScale(0.7)
elseif (self.countdown and self.countdown < 10 and self.countdown > -1) then
-- Display has 1 digit
local path = self.countdown <= 0 and self.faction or self.countdown
self.ACDNumOne:Show()
self.ACDNumOne:SetTexture(self.texturePath .. path)
self.ACDNumOnes:Hide()
self.ACDNumTens:Hide()
self.ACDNumFrame:SetScale(1.0)
else
ACDFrame:HideAll()
if (self.countdown and self.countdown < -1) then
self.ticker:Cancel()
2021-05-19 19:29:59 +02:00
end
end
self.countdown = self.countdown and self.countdown - 1
2021-05-19 19:29:59 +02:00
else
ACDFrame:HideAll()
2021-05-24 12:41:21 +02:00
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:CreateTicker(nil)
2021-08-10 13:17:46 +02:00
self:RegisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL")
end
2021-05-19 19:29:59 +02:00
end
function ACDFrame:Reset()
if self.ticker and not self.ticker:IsCancelled() then
self.ticker:Cancel()
end
self.countdown = nil
self:UnregisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL")
ACDFrame:HideAll()
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 self.countdown and self.countdown == 0 then
return
2021-05-24 12:41:21 +02:00
end
self.countdown = k
2021-05-24 12:41:21 +02:00
end
2021-05-17 16:49:54 +02:00
end
end
2022-03-26 00:16:13 +01:00
function ACDFrame:TestOnce()
self:CreateTicker(30)
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",
disabled = function() return not Gladdy.db.countdown end,
2021-05-17 16:49:54 +02: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,
disabled = function() return not Gladdy.db.countdown end,
}),
arenaCountdownFrameLevel = Gladdy:option({
type = "range",
name = L["Frame Level"],
min = 0,
max = 500,
step = 1,
order = 7,
width = "full",
disabled = function() return not Gladdy.db.countdown end,
}),
2021-05-17 16:49:54 +02:00
}
end