View Single Post
02-18-24, 08:17 AM   #27
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,894
I've modified the message texts to allow for colouring of the time portion.
(my editor seems to have swallowed the chinese characters)

Lua Code:
  1. local addonName, addon = ...
  2. local Backdrop = {
  3.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  4. }
  5.  
  6. local frame_x = 0    
  7. local frame_y = -200    
  8. f = CreateFrame("Button", "ZAMROTimer", UIParent, "BackdropTemplate")
  9. f:SetWidth(255)                                          
  10. f:SetHeight(20)
  11. f:SetBackdrop(Backdrop)
  12. f.text = f:CreateFontString(nil,"OVERLAY","GameTooltipText")
  13. f.text:SetTextHeight(15)
  14. f.text:SetPoint("CENTER")
  15. f:SetClampedToScreen(true)
  16. f:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  17. f:EnableMouse(true)
  18. f:SetMovable(true)
  19. f:RegisterForDrag("LeftButton")
  20. f:RegisterForClicks("AnyUp")
  21. f:Show()
  22. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  23. f:SetScript("OnDragStart",function(this)
  24.     this:StartMoving()
  25. end)
  26. f:SetScript("OnDragStop",function(this)  
  27.     this:StopMovingOrSizing()
  28.     frame_x,frame_y = this:GetCenter()
  29.     frame_x = frame_x - GetScreenWidth() / 2
  30.     frame_y = frame_y - GetScreenHeight() / 2
  31.     this:ClearAllPoints()
  32.     this:SetPoint("CENTER",UIParent,"CENTER",frame_x,frame_y)
  33. end)
  34. -- first %s is replaced by the color. The second is replaced by the time. |r resets the color back to default
  35. local Localizations = {
  36.     enUS = {
  37.         Waiting = "Next event is in: %s%s|r",
  38.         Running = "%s%s|r until event ends",
  39.     },
  40.     zhCN = {
  41.         Waiting = "??????: %s%s|r",
  42.         Running = "%s%s|r ??????",
  43.     },
  44.     deDE = {
  45.         Waiting = "Nächste Veranstaltung ist in: %s%s|r",
  46.         Running = "bis zum Ende der Veranstaltung: %s%s|r",
  47.     },
  48. }
  49.  
  50. local locale = GetLocale()
  51. local L = Localizations[locale] or Localizations.enUS -- Default to enUS if locale doesn't exist in the table
  52.  
  53. ------------------------------------------------------------------------------------------------------
  54. -- These might be converted to Saved Variables so each character can determine
  55. -- wether or not to play a sound, the alert times and colors and sound to play.
  56. -- If so then most of the code below will have to move into an event handler for
  57. -- the PLAYER_LOGIN or PLAYER_ENTERING_WORLD event.
  58. local useColor = true
  59. local useSound = true
  60. local alert1 = 600 -- Alarm 1 set to 5 minutes before event
  61. local alert1Color = "|cffffff00" -- Yellow
  62. local alert2 = 30 -- Alarm 2 set to 30 seconds before event
  63. local alert2Color = "|cffff0000" -- Red
  64. local soundKit = 32585 -- Alarm sound
  65. ------------------------------------------------------------------------------------------------------
  66.  
  67. local function printTime(timetotrun, inevent)
  68.     local hideSeconds = timetotrun >= 120
  69.     local msg = L.Waiting
  70.     local msgColor = "|cffffffff"
  71.     if inevent then
  72.         msg = L.Running
  73.     else
  74.         if useColor and timetotrun <= alert2 then
  75.             msgColor = alert2Color
  76.         elseif timetotrun <= alert1 then
  77.             if useSound and not ZAMROTimer.Alerted then
  78.                 ZAMROTimer.Alerted = true
  79.                 PlaySound(soundKit, "Master")
  80.             end
  81.             if useColor then
  82.                 msgColor = alert1Color
  83.             end
  84.         end
  85.     end
  86.     f.text:SetText(format(msg, msgColor, SecondsToTime(timetotrun, hideSeconds)))
  87. end
  88.  
  89. regionEventStartTime = {
  90.     [1] = { -- eu
  91.         starttime = 1670331660,
  92.         eventDuration = 900,
  93.         eventIntervalInSeconds = 5400,
  94.         enable = true,
  95.         datablock = {}
  96.     },
  97. }
  98.  
  99. local inEvent, timeToRun
  100. local eventTime = regionEventStartTime[1].eventDuration -- Time the event runs in seconds(15 mins)
  101. local waitTime = regionEventStartTime[1].eventIntervalInSeconds -- Time between events in seconds (90 mins)
  102. local startTime = regionEventStartTime[1].starttime -- Start time from the table
  103. local serverTime = GetServerTime()
  104. local timeToEvent = (startTime - serverTime) % waitTime -- Remaining time before next event starts
  105.  
  106. if timeToEvent > (waitTime - eventTime) then -- Is there between 1:15 and 1:30 to go? If so, we're in the event
  107.     inEvent = true
  108.     timeToRun = eventTime - (waitTime - timeToEvent)
  109. else                    -- Otherwise, set the ticker timer to time to next event
  110.     inEvent = false
  111.     timeToRun = timeToEvent
  112. end
  113. local ticker = C_Timer.NewTicker(1, function()
  114.     if timeToRun > 0 then
  115.         timeToRun = timeToRun - 1
  116.         printTime(timeToRun, inEvent)
  117.         return
  118.     end
  119.     ZAMROTimer.Alerted = false
  120.     if inEvent then -- The event just finished
  121.         inEvent = false
  122.         timeToRun = waitTime - eventTime -- Reset ticker timer to 90 minutes wait time minus 15 mins event time
  123.     else  -- Waiting for the next event just expired
  124.         inEvent = true
  125.         timeToRun = eventTime -- And the event is running
  126.     end
  127.     printTime(timeToRun, inEvent)
  128. end)
  129. printTime(timeToRun, inEvent)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-18-24 at 08:21 AM.
  Reply With Quote