Thread Tools Display Modes
05-06-17, 08:08 PM   #1
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
CooldownCount trying to edit the FormatTimes

Hi, i'm trying to edit/add formated times to my cooldown count, although im not getting anywhere anyone that could help out?

Lua Code:
  1. local A, C, M, L = select(2, ...):unpack()
  2.  
  3. A.FormatTime = function(Seconds)
  4.     local Day, Hour, Minutes
  5.     Day, Hour, Minutes = 0, 0, 0
  6.    
  7.     if Seconds >= 86400 then
  8.         Day = Seconds / 86400
  9.         Seconds = Seconds % 86400
  10.     end
  11.  
  12.     if Seconds >= 3600 then
  13.         Hour = Seconds / 3600
  14.         Seconds = Seconds % 3600
  15.     end
  16.    
  17.     if Seconds >= 60 then
  18.         Minutes = Seconds / 60
  19.         Seconds = Seconds % 60
  20.     end
  21.    
  22.     if Day > 0 then
  23.         return format("%.2d:%.2d", Day, Hour)
  24.     elseif Hour > 0 then
  25.         return format("%.2d:%.2d", Hour, Minutes)
  26.     elseif Minutes > 0 then
  27.         return format("%.2d:%.2d", Minutes, Seconds)
  28.     else
  29.         if Seconds < 10 then
  30.             return format("%.1f", Seconds)
  31.         else
  32.             return format("%d", Seconds)
  33.         end
  34.     end
  35. end
  36.  
  37. local function CooldownCountUpdate(self)
  38.     local Now, Start, Duration = GetTime(), self:GetCooldownTimes()
  39.     Start, Duration = Start/1000, Duration/1000
  40.  
  41.     local Elapsed = Now - Start
  42.     local TimeLeft = math.max(0, Duration - Elapsed)
  43.  
  44.     local NumRegions = self:GetNumRegions()
  45.     for i = 1, NumRegions do
  46.         local Region = select(i, self:GetRegions())
  47.         if (Region.GetText) then   
  48.             if (TimeLeft <= 10) then
  49.                 Region:SetTextColor(1, 0, 0)
  50.             elseif (TimeLeft <= 30) then
  51.                 Region:SetTextColor(1, 0.42, 0)
  52.             elseif (TimeLeft <= 60) then
  53.                 Region:SetTextColor(1, 0.82, 0)
  54.             else
  55.                 Region:SetTextColor(unpack(C.Cooldowns.TextColor))
  56.             end
  57.            
  58.             --local TimeText = A.FormatTime() -- Not quite sure how to make it work
  59.             --Region:SetText(TimeText)
  60.         end
  61.     end
  62. end
  63.  
  64. hooksecurefunc("CooldownFrame_Set", function(self, start, duration, enable, forceShowDrawEdge, modRate)
  65.     local CooldownCount = GetCVar("countdownForCooldowns")
  66.    
  67.     if (CooldownCount and not self.IsCooldownEdited) then
  68.         local NumRegions = self:GetNumRegions()
  69.         self:SetFrameStrata("HIGH")
  70.         self:HookScript("OnUpdate", CooldownCountUpdate)
  71.    
  72.         for i = 1, NumRegions do
  73.             local Region = select(i, self:GetRegions())
  74.             if (Region.GetText) then
  75.                 Region:SetPoint("CENTER", 1, 0)
  76.                 Region:SetFontTemplate(C.Media.Font2, C.Cooldowns.FontSize)
  77.             end
  78.         end
  79.  
  80.         self.IsCooldownEdited = true
  81.     end
  82. end)

Cheers!
  Reply With Quote
05-06-17, 09:56 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
From my experience, the countdown text on cooldown frames is managed by C code and seems to run after OnUpdate, so it isn't actually possible to change the format of it since it's immediately overwritten prior to the rendering pass. Your best bet is to hide the original and create your own as a substitute.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 05-06-17 at 10:00 PM.
  Reply With Quote
05-07-17, 01:43 AM   #3
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Thanks for letting me know
  Reply With Quote
05-08-17, 10:32 AM   #4
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
If anyone wanna use

Lua Code:
  1. local A, C, M, L = select(2, ...):unpack()
  2.  
  3. A.FormatTime = function(Seconds)
  4.     local Day, Hour, Minutes = 0, 0, 0
  5.    
  6.     if Seconds >= 86400 then
  7.         Day = Seconds / 86400
  8.         Seconds = Seconds % 86400
  9.     end
  10.  
  11.     if Seconds >= 3600 then
  12.         Hour = Seconds / 3600
  13.         Seconds = Seconds % 3600
  14.     end
  15.    
  16.     if Seconds >= 60 then
  17.         Minutes = Seconds / 60
  18.         Seconds = Seconds % 60
  19.     end
  20.    
  21.     if Day > 0 then
  22.         return format("%.2d:%.2d", Day, Hour)
  23.     elseif Hour > 0 then
  24.         return format("%.2d:%.2d", Hour, Minutes)
  25.     elseif Minutes > 0 then
  26.         return format("%.1d:%.2d", Minutes, Seconds)
  27.     else
  28.         if Seconds < 10 then
  29.             return format("%.1f", Seconds)
  30.         else
  31.             return format("%d", Seconds)
  32.         end
  33.     end
  34. end
  35.  
  36. local ICON_SIZE = 36
  37. local MIN_SCALE = 0.5
  38. local MIN_DURATION = 1.5
  39.  
  40. local floor = math.floor
  41. local GetTime = GetTime
  42.  
  43. local function TimerStop(self)
  44.     self.Enabled = nil
  45.     self:Hide()
  46. end
  47.  
  48. local function TimerForceUpdate(self)
  49.     self.NextUpdate = 0
  50.     self:Show()
  51. end
  52.  
  53. local function TimerOnSizeChanged(self, Width)
  54.     local FontScale = floor(Width +.5) / ICON_SIZE
  55.     if FontScale == self.FontScale then
  56.         return
  57.     end
  58.    
  59.     self.FontScale = FontScale
  60.  
  61.     if FontScale < MIN_SCALE then
  62.         self:Hide()
  63.     else
  64.         self.Text:SetFontTemplate(C.Media.Font2, FontScale * C.Cooldowns.FontSize)
  65.  
  66.         if self.Enabled then
  67.             TimerForceUpdate(self)
  68.         end
  69.     end
  70. end
  71.  
  72. local function TimerOnUpdate(self, Elapsed)
  73.     if (self.NextUpdate > 0) then
  74.         self.NextUpdate = self.NextUpdate - Elapsed
  75.         return
  76.     end
  77.    
  78.     local TimeLeft = self.Duration - (GetTime() - self.Start)
  79.  
  80.     if (TimeLeft > 0.05) then
  81.         if (self.FontScale * self:GetEffectiveScale() / UIParent:GetScale()) < MIN_SCALE then
  82.             self.Text:SetText("")
  83.             self.NextUpdate = 500
  84.         else
  85.             local TimeText = A.FormatTime(TimeLeft)
  86.             self.Text:SetText(TimeText)
  87.         end
  88.    
  89.         if (TimeLeft <= 10) then
  90.             self.Text:SetTextColor(unpack(C.Cooldowns.ExpireColor))
  91.         elseif (TimeLeft <= 30) then
  92.             self.Text:SetTextColor(unpack(C.Cooldowns.SecondsColor))
  93.         elseif (TimeLeft <= 60) then
  94.             self.Text:SetTextColor(unpack(C.Cooldowns.SecondsColor2))
  95.         else
  96.             self.Text:SetTextColor(unpack(C.Cooldowns.NormalColor))
  97.         end
  98.     else
  99.         TimerStop(self)
  100.     end
  101. end
  102.  
  103. local function Timer_Create(self)
  104.     local Scaler = CreateFrame("Frame", nil, self)
  105.     Scaler:SetAllPoints(self)
  106.  
  107.     local Timer = CreateFrame("Frame", nil, Scaler)
  108.     Timer:Hide()
  109.     Timer:SetAllPoints(Scaler)
  110.     Timer:SetFrameStrata("HIGH")
  111.     Timer:SetScript("OnUpdate", TimerOnUpdate)
  112.  
  113.     local Text = Timer:CreateFontString(nil, "OVERLAY")
  114.     Text:Point("CENTER", Timer, 1, 0)
  115.     Timer.Text = Text
  116.  
  117.     TimerOnSizeChanged(Timer, Scaler:GetSize())
  118.     Scaler:SetScript("OnSizeChanged", function(self, ...)
  119.         TimerOnSizeChanged(Timer, ...)
  120.     end)
  121.  
  122.     self.Timer = Timer
  123.     return Timer
  124. end
  125.  
  126. local function TimerStart(self, Start, Duration)
  127.     if (self.noOCC) then
  128.         return
  129.     end
  130.    
  131.     if (Start > 0 and Duration > MIN_DURATION) then
  132.         local Timer = self.Timer or Timer_Create(self)
  133.         Timer.Start = Start
  134.         Timer.Duration = Duration
  135.         Timer.Enabled = true
  136.         Timer.NextUpdate = 0
  137.        
  138.         if Timer.FontScale >= MIN_SCALE then
  139.             Timer:Show()
  140.         end
  141.     else
  142.         local Timer = self.Timer
  143.         if (Timer) then
  144.             TimerStop(Timer)
  145.         end
  146.     end
  147. end
  148. hooksecurefunc(getmetatable(ActionButton1Cooldown).__index, "SetCooldown", TimerStart)
  149.  
  150. local Active = {}
  151.  
  152. local function CooldownOnShow(self)
  153.     Active[self] = true
  154. end
  155.  
  156. local function CooldownOnHide(self)
  157.     Active[self] = nil
  158. end
  159.  
  160. local function CooldownShouldUpdateTimer(self, Start, Duration)
  161.     local Timer = self.Timer
  162.     if not (Timer) then return true end
  163.     return Timer.Start ~= Start
  164. end
  165.  
  166. local function CooldownUpdate(self)
  167.     local Button = self:GetParent()
  168.     local Start, Duration, Enable = GetActionCooldown(Button.action)
  169.  
  170.     if CooldownShouldUpdateTimer(self, Start, Duration) then
  171.         TimerStart(self, Start, Duration)
  172.     end
  173. end
  174.  
  175. local EventWatcher = CreateFrame("Frame")
  176. EventWatcher:RegisterEvent("ACTIONBAR_UPDATE_COOLDOWN")
  177. EventWatcher:SetScript("OnEvent", function(self, event)
  178.     for Cooldown in pairs(Active) do
  179.         CooldownUpdate(Cooldown)
  180.     end
  181. end)
  182.  
  183. local function ActionButtonRegister(frame)
  184.     local Cooldown = frame.cooldown
  185.  
  186.     if not (Cooldown.IsHooked) then
  187.         Cooldown:HookScript("OnShow", CooldownOnShow)
  188.         Cooldown:HookScript("OnHide", CooldownOnHide)
  189.         Cooldown.IsHooked = true
  190.     end
  191. end
  192.  
  193. if _G["ActionBarButtonEventsFrame"].frames then
  194.     for i, frame in pairs(_G["ActionBarButtonEventsFrame"].frames) do
  195.         ActionButtonRegister(frame)
  196.     end
  197. end
  198. hooksecurefunc("ActionBarButtonEventsFrame_RegisterFrame", ActionButtonRegister)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » CooldownCount trying to edit the FormatTimes

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off