Permalink
Browse files

Implemented ActionUIButton support. Yay!

  • Loading branch information...
1 parent 4cac2ae commit e83fa301f76795fabfc1e15ac8b54e9487a5225e @Jaliborc Jaliborc committed Nov 15, 2011
Showing with 75 additions and 34 deletions.
  1. +1 −1 LICENSE
  2. +74 −33 timer.lua
View
2 LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2010 Jason Greer
+Copyright (c) 2010 Jason Greer and João Cardoso
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
View
107 timer.lua
@@ -15,15 +15,15 @@ local Classy = LibStub('Classy-1.0')
local OmniCC = OmniCC
--constants!
+local ADDON = ...
local ICON_SIZE = 36 --the normal size for an icon (don't change this)
local DAY, HOUR, MINUTE = 86400, 3600, 60 --used for formatting text
local DAYISH, HOURISH, MINUTEISH, SOONISH = 3600 * 23.5, 60 * 59.5, 59.5, 5.5 --used for formatting text at transition points
local HALFDAYISH, HALFHOURISH, HALFMINUTEISH = DAY/2 + 0.5, HOUR/2 + 0.5, MINUTE/2 + 0.5 --used for calculating next update times
local PADDING = 0 --amount of spacing between the timer text and the rest of the cooldown
--local bindings!
-local floor = math.floor
-local min = math.min
+local floor, min, type = floor, min, type
local round = function(x) return floor(x + 0.5) end
local GetTime = GetTime
@@ -70,22 +70,17 @@ end
--starts the timer for the given cooldown
function Timer:Start(start, duration)
self.start = start
- self.duration = duration
- self.enabled = true
self.visible = self.cooldown:IsVisible()
+ self.duration = duration
self.textStyle = nil
+ self.enabled = true
self:UpdateShown()
end
--stops the timer
function Timer:Stop()
- self.start = nil
- self.duration = nil
- self.enabled = nil
- self.visible = nil
- self.textStyle = nil
-
+ self.start, self.duration, self.enabled, self.visible, self.textStyle = nil
self:CancelUpdate()
self:Hide()
end
@@ -268,7 +263,7 @@ function Timer:GetTimeText(remain)
elseif remain < MINUTEISH then
--prevent 0 seconds from displaying
local seconds = round(remain)
- return (seconds == 0 and '') or seconds
+ return seconds ~= 0 and seconds or ''
--format text as MM:SS when below the MM:SS threshold
elseif remain < sets.mmSSDuration then
local seconds = round(remain)
@@ -302,10 +297,17 @@ function Timer:ShouldShow()
return sets.enabled
end
+
+--[[ Settings Methods ]]--
+
function Timer:GetSettings()
return OmniCC:GetGroupSettings(OmniCC:CDToGroup(self.cooldown))
end
+--[[function Timer:GetSettings()
+
+end]]--
+
--[[ Meta Functions ]]--
@@ -332,7 +334,7 @@ function Timer:ForAllShown(f, ...)
end
---[[ cooldown display ]]--
+--[[ Cooldown Display ]]--
--show the timer if the cooldown is shown
local function cooldown_OnShow(self)
@@ -384,10 +386,11 @@ local function cooldown_Init(self)
self:HookScript('OnShow', cooldown_OnShow)
self:HookScript('OnHide', cooldown_OnHide)
self:HookScript('OnSizeChanged', cooldown_OnSizeChanged)
+ self.omnicc = true
end
-local function cooldown_OnSetCooldown(self, start, duration)
+local function cooldown_Show(self, start, duration)
--don't do anything if there's no timer to display, or the timer has been blacklisted
if self.noCooldownCount or not(start and duration) then
cooldown_StopTimer(self)
@@ -404,7 +407,6 @@ local function cooldown_OnSetCooldown(self, start, duration)
--apply methods to the cooldown frame if they do not exist yet
if not self.omnicc then
cooldown_Init(self)
- self.omnicc = true
end
--hide cooldown model if necessary and start the timer
@@ -416,24 +418,63 @@ local function cooldown_OnSetCooldown(self, start, duration)
end
end
---bugfix: force update timers when entering an arena
-do
- local addonName = ...
-
- local f = CreateFrame('Frame'); f:Hide()
- f:SetScript('OnEvent', function(self, event, ...)
- --update visible timers on player_entering_world (arena update hack)
- if event == 'PLAYER_ENTERING_WORLD' then
- Timer:ForAllShown('UpdateText')
- --hook cooldown stuff only after the addon is actually loaded
- elseif event == 'ADDON_LOADED' then
- local name = ...
- if name == addonName then
- hooksecurefunc(getmetatable(ActionButton1Cooldown).__index, 'SetCooldown', cooldown_OnSetCooldown)
- self:UnregisterEvent('ADDON_LOADED')
+
+--[[ ActionUI Button ]]--
+
+local actions = {}
+local function action_OnShow(self)
+ actions[self] = true
+end
+
+local function action_OnHide(self)
+ actions[self] = nil
+end
+
+local function action_Add(button, action, cooldown)
+ --if type(cooldown) ~= 'table' then return end
+
+ if not cooldown.omniccAction then
+ cooldown:HookScript('OnShow', action_OnShow)
+ cooldown:HookScript('OnHide', action_OnHide)
+ end
+ cooldown.omniccAction = action
+end
+
+local function actions_Update()
+ for cooldown in pairs(actions) do
+ local start, duration = GetActionCooldown(cooldown.omniccAction)
+ cooldown_Show(cooldown, start, duration)
+ end
+end
+
+
+--[[ Events ]]--
+
+local f = CreateFrame('Frame'); f:Hide()
+f:SetScript('OnEvent', function(self, event, ...)
+ -- update action cooldowns
+ if event == 'ACTIONBAR_UPDATE_COOLDOWN' then
+ actions_Update()
+
+ -- update visible timers on player_entering_world (arena update hack)
+ elseif event == 'PLAYER_ENTERING_WORLD' then
+ Timer:ForAllShown('UpdateText')
+
+ -- hook cooldown stuff only after the addon is actually loaded
+ else
+ if ... == ADDON then
+ hooksecurefunc(getmetatable(ActionButton1Cooldown).__index, 'SetCooldown', cooldown_Show)
+ hooksecurefunc('SetActionUIButton', action_Add)
+
+ for i, button in pairs(ActionBarButtonEventsFrame.frames) do
+ action_Add(button, button.action, button.cooldown)
end
+
+ self:UnregisterEvent('ADDON_LOADED')
end
- end)
- f:RegisterEvent('PLAYER_ENTERING_WORLD')
- f:RegisterEvent('ADDON_LOADED')
-end
+ end
+end)
+
+f:RegisterEvent('ACTIONBAR_UPDATE_COOLDOWN')
+f:RegisterEvent('PLAYER_ENTERING_WORLD')
+f:RegisterEvent('ADDON_LOADED')

0 comments on commit e83fa30

Please sign in to comment.