View Single Post
04-27-24, 09:11 AM   #2
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 122
Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local Backdrop = {
  4.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  5. }
  6.  
  7. local frame_x = 0
  8. local frame_y = -200
  9.  
  10. local f = CreateFrame("Button", "ZAMROTimer", UIParent, "BackdropTemplate")
  11. f:SetWidth(185)
  12. f:SetHeight(30)
  13. f:SetBackdrop(Backdrop)
  14. f.text = f:CreateFontString(nil, "OVERLAY", "GameTooltipText")
  15. f.text:SetPoint("CENTER")
  16. f:SetClampedToScreen(true)
  17. f:SetPoint("CENTER", UIParent, "CENTER", frame_x, frame_y)
  18. f:EnableMouse(true)
  19. f:SetMovable(true)
  20. f:RegisterForDrag("LeftButton")
  21. f:RegisterForClicks("AnyUp")
  22. f:Show()
  23. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  24. f:SetScript("OnDragStart", function(this)
  25.     this:StartMoving()
  26. end)
  27. f:SetScript("OnDragStop", function(this)
  28.     this:StopMovingOrSizing()
  29.     frame_x, frame_y = this:GetCenter()
  30.     frame_x = frame_x - GetScreenWidth() / 2
  31.     frame_y = frame_y - GetScreenHeight() / 2
  32.     this:ClearAllPoints()
  33.     this:SetPoint("CENTER", UIParent, "CENTER", frame_x, frame_y)
  34. end)
  35.  
  36. local Localizations = {
  37.     enUS = {
  38.         Waiting = "|c1C7BCEFFCommunity Feast:\nbefore the start: %s%s|r",
  39.         Running = "|cFF35BE21Community Feast:\n%s%s until completion|r",
  40.     },
  41.     deDE = {
  42.         Waiting = "|c1C7BCEFFGemeinschaftliches Festmahl:\nvor dem Anfang: %s%s|r",
  43.         Running = "|cFF35BE21Gemeinschaftliches Festmahl:\n%s%s bis zur Fertigstellung|r",
  44.     },
  45. }
  46.  
  47. local locale = GetLocale()
  48. local L = Localizations[locale] or Localizations.enUS
  49.  
  50. local useColor = true
  51. local useSound = true
  52. local alert1 = 600
  53. local alert1Color = "|cffffff00"
  54. local alert2 = 300
  55. local alert2Color = "|cffff0000"
  56. local soundKit = 32585
  57.  
  58. local function printTime(timetotrun, inevent)
  59.     local hideSeconds = timetotrun >= 120
  60.     local msg = L.Waiting
  61.     local msgColor = "|cffffffff"
  62.     if inevent then
  63.         msg = L.Running
  64.     else
  65.         if useColor and timetotrun <= alert2 then
  66.             msgColor = alert2Color
  67.         elseif timetotrun <= alert1 then
  68.             if useSound and not ZAMROTimer.Alerted then
  69.                 ZAMROTimer.Alerted = true
  70.                 PlaySound(soundKit, "Master")
  71.             end
  72.             if useColor then
  73.                 msgColor = alert1Color
  74.             end
  75.         end
  76.     end
  77.     f.text:SetText(format(msg, msgColor, SecondsToTime(timetotrun, hideSeconds)))
  78. end
  79.  
  80. local regionEventStartTime = {
  81.     [1] = { -- eu
  82.         starttime = 1670331660,
  83.         eventDuration = 900,
  84.         eventIntervalInSeconds = 5400,
  85.         enable = true,
  86.         datablock = {}
  87.     },
  88.     [2] = { -- na
  89.         starttime = 1670338860,
  90.         eventDuration = 900,
  91.         eventIntervalInSeconds = 5400,
  92.         enable = true,
  93.         datablock = {}
  94.     }
  95. }
  96.  
  97. local startTime, eventTime, waitTime
  98.  
  99. if GetCVar("portal") == "EU" then
  100.     startTime = regionEventStartTime[1].starttime
  101.     eventTime = regionEventStartTime[1].eventDuration
  102.     waitTime = regionEventStartTime[1].eventIntervalInSeconds
  103. else
  104.     startTime = regionEventStartTime[2].starttime
  105.     eventTime = regionEventStartTime[2].eventDuration
  106.     waitTime = regionEventStartTime[2].eventIntervalInSeconds
  107. end
  108.  
  109. local serverTime = GetServerTime()
  110. local timeToEvent = (startTime - serverTime) % waitTime
  111.  
  112. local inEvent, timeToRun
  113.  
  114. if timeToEvent > (waitTime - eventTime) then
  115.     inEvent = true
  116.     timeToRun = eventTime - (waitTime - timeToEvent)
  117. else
  118.     inEvent = false
  119.     timeToRun = timeToEvent
  120. end
  121.  
  122. local ticker = C_Timer.NewTicker(1, function()
  123.     if timeToRun > 0 then
  124.         timeToRun = timeToRun - 1
  125.         printTime(timeToRun, inEvent)
  126.         return
  127.     end
  128.     ZAMROTimer.Alerted = false
  129.     if inEvent then
  130.         inEvent = false
  131.         timeToRun = waitTime - eventTime
  132.     else
  133.         inEvent = true
  134.         timeToRun = eventTime
  135.     end
  136.     printTime(timeToRun, inEvent)
  137. end)
  138.  
  139. printTime(timeToRun, inEvent)

I solved this problem myself like this. There might have been another solution, but that was the only option I could come up with.
  Reply With Quote