tweak OnUpdate code, now uses ~30-40% less CPU then Bartender3

This commit is contained in:
Hendrik Leppkes
2008-03-07 13:53:36 +00:00
parent 160e9ffe4f
commit 83e787fa06
+48 -29
View File
@@ -104,19 +104,17 @@ function onLeave()
end end
function onUpdate(self, elapsed) function onUpdate(self, elapsed)
if not self.iconTex then self:UpdateIcon() end if self.flashing == 1 then
self.flashtime = self.flashtime - elapsed
if ( self.flashing == 1 ) then if self.flashtime <= 0 then
self.flashtime = self.flashtime - elapsed; local overtime = -self.flashtime
if ( self.flashtime <= 0 ) then if overtime >= ATTACK_BUTTON_FLASH_TIME then
local overtime = -self.flashtime; overtime = 0
if ( overtime >= ATTACK_BUTTON_FLASH_TIME ) then
overtime = 0;
end end
self.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime self.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime
local flashTexture = self.flash local flashTexture = self.flash
if ( flashTexture:IsVisible() ) then if flashTexture:IsVisible() then
flashTexture:Hide() flashTexture:Hide()
else else
flashTexture:Show() flashTexture:Show()
@@ -124,9 +122,9 @@ function onUpdate(self, elapsed)
end end
end end
if ( self.rangeTimer ) then if self.rangeTimer then
self.rangeTimer = self.rangeTimer - elapsed self.rangeTimer = self.rangeTimer - elapsed
if ( self.rangeTimer <= 0 ) then if self.rangeTimer <= 0 then
local valid = IsActionInRange(self.action) local valid = IsActionInRange(self.action)
local hotkey = self.hotkey local hotkey = self.hotkey
local hkshown = (hotkey:GetText() == RANGE_INDICATOR and self.settings.profile.outofrange == "hotkey") local hkshown = (hotkey:GetText() == RANGE_INDICATOR and self.settings.profile.outofrange == "hotkey")
@@ -171,7 +169,7 @@ function Button:Update()
self:RegisterActionEvents() self:RegisterActionEvents()
self:UpdateState() self:UpdateState()
self:UpdateUsable() self:UpdateUsable(true)
self:UpdateCooldown() self:UpdateCooldown()
self:UpdateFlash() self:UpdateFlash()
@@ -253,27 +251,48 @@ function Button:UpdateState()
end end
end end
function Button:UpdateUsable() local oor, oorcolor, oomcolor
local oor = self.settings.profile.outofrange
function Button:UpdateUsable(force)
local isUsable, notEnoughMana = IsUsableAction(self.action) local isUsable, notEnoughMana = IsUsableAction(self.action)
local oorcolor, oomcolor = self.settings.profile.colors.range, self.settings.profile.colors.mana local icon, hotkey = self.icon, self.hotkey
if ( oor ~= "button" or not self.outOfRange) then if force or not oor then
if ( oor == "none" or not self.outOfRange) then icon.state, hotkey.state = 1, 1
self.hotkey:SetVertexColor(1.0, 1.0, 1.0) oor = self.settings.profile.outofrange
elseif ( oor == "hotkey" ) then oorcolor, oomcolor = self.settings.profile.colors.range, self.settings.profile.colors.mana
self.hotkey:SetVertexColor(oorcolor.r, oorcolor.g, oorcolor.b) end
if oor == "button" and self.outOfRange then
if icon.state ~= "range" then
icon:SetVertexColor(oorcolor.r, oorcolor.g, oorcolor.b)
hotkey:SetVertexColor(1.0, 1.0, 1.0)
icon.state = "range"
end
else
if oor == "hotkey" and self.outOfRange then
if hotkey.state ~= "range" then
hotkey:SetVertexColor(oorcolor.r, oorcolor.g, oorcolor.b)
hotkey.state = "range"
end
elseif hotkey.state ~= nil then
hotkey:SetVertexColor(1.0, 1.0, 1.0)
hotkey.state = nil
end end
if ( isUsable ) then if isUsable then
self.icon:SetVertexColor(1.0, 1.0, 1.0); if icon.state then
elseif ( notEnoughMana ) then icon:SetVertexColor(1.0, 1.0, 1.0);
self.icon:SetVertexColor(oomcolor.r, oomcolor.g, oomcolor.b) icon.state = nil
else end
self.icon:SetVertexColor(0.4, 0.4, 0.4); elseif notEnoughMana then
if icon.state ~= "mana" then
icon:SetVertexColor(oomcolor.r, oomcolor.g, oomcolor.b)
icon.state = "mana"
end
elseif icon.state ~= "n/a" then
icon:SetVertexColor(0.4, 0.4, 0.4)
icon.state = "n/a"
end end
elseif ( oor == "button" ) then
self.icon:SetVertexColor(oorcolor.r, oorcolor.g, oorcolor.b)
self.hotkey:SetVertexColor(1.0, 1.0, 1.0)
end end
end end