local addonName, addon = ...
local L, MyRegion
local RegionTimes = {
[1] = {
startTime = 1710482400,
totalDuration = 18000,
A = {
duration = 7200,
interval = 3600,
eventtime = 600,
},
B = {
duration = 10200,
},
},
[2] = {
startTime = 1670331660,
A = {
duration = 900,
interval = 5400,
},
},
}
local Localizations = {
enUS = {
Waiting = "|cFFDEB887Trial of the Elements:%s\nbefore the start: %s%s|r",
Running = "|cFF35BE21Trial of the Elements:%s\n%s%s until completion|r",
Timer2Interval = "Every hour", -- Added English text for timer 2 interval
Timer2EventTime = "10 minutes", -- Added English text for timer 2 event time
},
deDE = {
Waiting = "|cFFDEB887Prüfung der Elemente:%s\nvor dem Anfang: %s%s|r",
Running = "|cFF35BE21Prüfung der Elemente:%s\n%s%s bis zur Fertigstellung|r",
Timer2Interval = "|c1C7BCEFFTolles Fest durch:|r", -- Added German text for timer 2 interval
Timer2EventTime = "|cFF35BE21Das große Fest steht vor der Tür:|r", -- Added German text for timer 2 event time
},
}
------------------------------------------------------------------------------------------------------
-- These might be converted to Saved Variables so each character can determine
-- wether or not to play a sound, the alert times and colors and sound to play.
-- If so then most of the code below will have to move into an event handler for
-- the PLAYER_LOGIN or PLAYER_ENTERING_WORLD event.
local defaults = {
useColor = true,
useSound = true,
alert1 = 600, -- Alarm 1 set to 10 minutes before event
alert1Color = "|cffffff00", -- Yellow
alert2 = 300, -- Alarm 2 set to 5 minutes before event
alert2Color = "|cffff0000", -- Red
soundKit = 32585, -- Alarm sound
}
------------------------------------------------------------------------------------------------------
local function CalcTime(starttime, servertime, duration, interval)
local timeToEvent = (starttime - servertime) % interval
local inEvent, timeToRun
if timeToEvent > (interval - duration) then
inEvent = true
timeToRun = duration - (interval - timeToEvent)
else
inEvent = false
timeToRun = timeToEvent
end
return inEvent, timeToRun
end
local function printTime(self)
local serverTime = GetServerTime()
local remainingTime1 = (MyRegion.startTime - serverTime) % MyRegion.totalDuration
local remainingTime2 = 0
local longWait = ""
local inEvent1, inEvent2
if remainingTime1 > RegionTimes[1].B.duration then
inEvent1, remainingTime1 = CalcTime(MyRegion.startTime, serverTime, MyRegion.A.eventtime, MyRegion.A.interval)
else
longWait = "|cffffff00|r"
end
if MyRegion.A.interval > 0 then
local timer2Remaining = (MyRegion.startTime - serverTime) % MyRegion.A.interval
remainingTime2 = timer2Remaining
if timer2Remaining > (MyRegion.A.interval - MyRegion.A.eventtime) then
inEvent2 = true
remainingTime2 = MyRegion.A.eventtime - (MyRegion.A.interval - timer2Remaining)
else
inEvent2 = false
remainingTime2 = MyRegion.A.interval - timer2Remaining
end
end
local hideSeconds = remainingTime1 >= 120
local msg = L.Waiting
local msgColor = "|cffffffff"
if inEvent1 then
msg = L.Running
else
if defaults.useColor and remainingTime1 <= defaults.alert2 then
msgColor = defaults.alert2Color
elseif remainingTime1 <= defaults.alert1 then
if defaults.useSound and not self.Alerted then
self.Alerted = true
PlaySound(defaults.soundKit, "Master")
end
if defaults.useColor then
msgColor = defaults.alert1Color
end
end
end
-- Display timer 1
local timer1Msg = format("%s", SecondsToTime(remainingTime1, false))
-- Display timer 2 information
local timer2Msg = ""
if MyRegion.A.interval > 0 then
timer2Msg = format("\n\n%s\n%s", L.Timer2Interval, SecondsToTime(remainingTime2, false))
end
if MyRegion.A.eventtime > 0 and inEvent2 then
timer2Msg = format("%s\n\n%s\n%s", timer2Msg, L.Timer2EventTime, SecondsToTime(remainingTime2, false))
end
self.Text:SetText(format(msg, longWait, msgColor, timer1Msg) .. timer2Msg)
end
------------------------------------------------------------------------------------------------------
local Backdrop = {
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
}
local frame_x = 100
local frame_y = -250
local f = CreateFrame("Button", "ZAMTimer777", UIParent, "BackdropTemplate")
f:SetWidth(185)
f:SetHeight(30)
f:SetPoint("CENTER")
f:SetBackdrop(Backdrop)
f:SetClampedToScreen(true)
f:EnableMouse(true)
f:SetMovable(true)
f:SetUserPlaced(true)
f:RegisterForDrag("LeftButton")
f:RegisterForClicks("AnyUp")
f.Text = f:CreateFontString(nil, "OVERLAY", "GameTooltipText")
f.Text:SetPoint("CENTER")
f.Elapsed = 0 -- Set starting timeout (0 second)
f:SetScript("OnDragStart",function(self)
self:StartMoving()
end)
f:SetScript("OnDragStop",function(self)
self:StopMovingOrSizing()
end)
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function(self)
local locale = GetLocale()
L = Localizations[locale] or Localizations.enUS -- Default to enUS if locale doesn't exist in the table
MyRegion = RegionTimes[GetCurrentRegion()] or RegionTimes[1] -- Default to region 1 (US) if it doesn't exist in the table
self:SetScript("OnUpdate", function(self, elapsed)
self.Elapsed = self.Elapsed - elapsed
if self.Elapsed > 0 then -- Only check once per second
return
end
self.Elapsed = 1 -- reset the timeout (we've counted down 1 second)
printTime(self)
end)
end)
SLASH_ZAM1 = "/zam"
SlashCmdList["ZAM"] = function(msg)
if strupper(strtrim(msg)) == "HD" then -- toggle the shown state of the button if the type /hubb btn
ZAMTimer777:SetShown(not ZAMTimer777:IsShown()) -- show the button
return
end
updateData()
updateList()
ZAMTimer777:Show()
end