Skip to content

Commit

Permalink
classicons: refactored class enable/disable code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adirelle committed Oct 24, 2013
1 parent 9af8f3f commit 53d38b0
Showing 1 changed file with 22 additions and 41 deletions.
63 changes: 22 additions & 41 deletions elements/classicons.lua
Expand Up @@ -149,41 +149,33 @@ local ForceUpdate = function(element)
end

do
local _ClassPowerEnable = function(self)
self:RegisterEvent('UNIT_DISPLAYPOWER', Update)
self:RegisterEvent('UNIT_POWER_FREQUENT', Update)
end

local _ClassPowerDisable = function(self)
self:UnregisterEvent('UNIT_DISPLAYPOWER', Update)
self:UnregisterEvent('UNIT_POWER_FREQUENT', Update)
end

if(PlayerClass == 'MONK') then
ClassPowerType = SPELL_POWER_CHI
ClassPowerTypes = {
['CHI'] = true,
['DARK_FORCE'] = true,
}

ClassPowerEnable = function(self)
local element = self.ClassIcons

self:RegisterEvent('UNIT_DISPLAYPOWER', Update)
self:RegisterEvent('UNIT_POWER_FREQUENT', Update)
end

ClassPowerDisable = function(self)
self:UnregisterEvent('UNIT_DISPLAYPOWER', Update)
self:UnregisterEvent('UNIT_POWER_FREQUENT', Update)
end
ClassPowerEnable = _ClassPowerEnable
ClassPowerEnable = _ClassPowerDisable
elseif(PlayerClass == 'PALADIN') then
ClassPowerType = SPELL_POWER_HOLY_POWER
ClassPowerTypes = {
HOLY_POWER = true,
}

ClassPowerEnable = function(self)
local element = self.ClassIcons

self:RegisterEvent('UNIT_DISPLAYPOWER', Update)
self:RegisterEvent('UNIT_POWER', Update)
end

ClassPowerDisable = function(self)
self:UnregisterEvent('UNIT_DISPLAYPOWER', Update)
self:UnregisterEvent('UNIT_POWER', Update)
end
ClassPowerEnable = _ClassPowerEnable
ClassPowerEnable = _ClassPowerDisable
elseif(PlayerClass == 'PRIEST') then
ClassPowerType = SPELL_POWER_SHADOW_ORBS
ClassPowerTypes = {
Expand All @@ -192,15 +184,13 @@ do
RequireSpec = SPEC_PRIEST_SHADOW

ClassPowerEnable = function(self)
local element = self.ClassIcons

self:RegisterEvent('UNIT_DISPLAYPOWER', Update)
self:RegisterEvent('UNIT_POWER_FREQUENT', Update)
self:RegisterEvent('PLAYER_TALENT_UPDATE', Visibility, true)
return _ClassPowerEnable(self)
end

ClassPowerDisable = function(self)
self:UnregisterEvent('UNIT_DISPLAYPOWER', Update)
self:UnregisterEvent('UNIT_POWER_FREQUENT', Update)
self:UnregisterEvent('PLAYER_TALENT_UPDATE', Visibility)

This comment has been minimized.

Copy link
@p3lim

p3lim Jul 26, 2014

Member

This will prevent the whole element from working if you swap specs back and forth

return _ClassPowerDisable(self)
end
elseif(PlayerClass == 'WARLOCK') then
ClassPowerType = SPELL_POWER_SOUL_SHARDS
Expand All @@ -210,15 +200,13 @@ do
RequireSpell = WARLOCK_SOULBURN

ClassPowerEnable = function(self)
local element = self.ClassIcons

self:RegisterEvent('UNIT_DISPLAYPOWER', Update)
self:RegisterEvent('UNIT_POWER_FREQUENT', Update)
self:RegisterEvent('SPELLS_CHANGED', Visibility, true)
return _ClassPowerEnable(self)
end

ClassPowerDisable = function(self)
self:UnregisterEvent('UNIT_DISPLAYPOWER', Update)
self:UnregisterEvent('UNIT_POWER_FREQUENT', Update)
self:UnregisterEvent('SPELLS_CHANGED', Visibility)

This comment has been minimized.

Copy link
@p3lim

p3lim Jul 26, 2014

Member

This will prevent the whole element from working if you swap specs back and forth

return _ClassPowerDisable(self)
end
end
end
Expand All @@ -232,11 +220,6 @@ local Enable = function(self, unit)
element.ForceUpdate = ForceUpdate

if(ClassPowerEnable) then
if(PlayerClass == 'PRIEST') then
self:RegisterEvent('PLAYER_TALENT_UPDATE', Visibility, true)
elseif(PlayerClass == 'WARLOCK') then
self:RegisterEvent('SPELLS_CHANGED', Visibility, true)
end
ClassPowerEnable(self)

for i=1, 5 do
Expand All @@ -257,8 +240,6 @@ local Disable = function(self)
local element = self.ClassIcons
if(not element) then return end

self:UnregisterEvent('SPELLS_CHANGED', Visibility)
self:UnregisterEvent('PLAYER_TALENT_UPDATE', Visibility)
ClassPowerDisable(self)
end

Expand Down

0 comments on commit 53d38b0

Please sign in to comment.