added ultimate tracking and better ability updating.

Sammy James [03-22-14 - 15:18]
added ultimate tracking and better ability updating.
Filename
PSBT.txt
core/PSBT.lua
core/PSBT_Constants.lua
modules/PSBT_Auras.lua
modules/PSBT_Combat.lua
modules/PSBT_Cooldowns.lua
modules/PSBT_Experience.lua
modules/PSBT_LowSomething.lua
modules/PSBT_Ultimate.lua
diff --git a/PSBT.txt b/PSBT.txt
index 5e87c42..858d7d6 100644
--- a/PSBT.txt
+++ b/PSBT.txt
@@ -26,6 +26,7 @@ modules/PSBT_Combat.lua
 modules/PSBT_Cooldowns.lua
 modules/PSBT_Experience.lua
 modules/PSBT_LowSomething.lua
+modules/PSBT_Ultimate.lua

 ## core
 core/PSBT_Fifo.lua
diff --git a/core/PSBT.lua b/core/PSBT.lua
index 28daf91..fd945fa 100644
--- a/core/PSBT.lua
+++ b/core/PSBT.lua
@@ -33,6 +33,7 @@ if ( not LMP ) then return end
 local PSBT = ZO_ObjectPool:Subclass()
 PSBT._modules  = {}
 PSBT._areas    = {}
+PSBT._events   = {}

 local CBM               = CALLBACK_MANAGER
 local PSBT_ScrollArea   = PSBT_ScrollArea
@@ -41,6 +42,11 @@ local PSBT_EVENTS       = PSBT_EVENTS
 local PSBT_MODULES      = PSBT_MODULES
 local PSBT_SETTINGS     = PSBT_SETTINGS

+local tinsert = table.insert
+local tremove = table.remove
+
+local _
+
 function PSBT:New( ... )
     local result = ZO_ObjectPool.New( self, PSBT.CreateLabel, function( ... ) self:ResetLabel( ... ) end )
     result:Initialize( ... )
@@ -143,11 +149,44 @@ function PSBT:SetSetting( name, value )
 end

 function PSBT:RegisterForEvent( event, callback )
-    self.control:RegisterForEvent( event, callback )
+    if ( not self._events[ event ] ) then
+        self._events[ event ] = {}
+    end
+
+    tinsert( self._events[ event ], callback )
+
+    self.control:RegisterForEvent( event, function( ... ) self:OnEvent( ... ) end )
+end
+
+function PSBT:OnEvent( event, ... )
+    if ( not self._events[ event ] ) then
+        return
+    end
+
+    local callbacks = self._events[ event ]
+    for _,v in pairs( callbacks ) do
+        v( ... )
+    end
 end

 function PSBT:UnregisterForEvent( event, callback )
-    self.control:UnregisterForEvent( event, callback )
+    if ( not self._events[ event ] ) then
+        return
+    end
+
+    local callbacks = self._events[ event ]
+    local i = 1
+    while( i <= #callbacks ) do
+        if ( callbacks[ i ] == callback ) then
+            tremove( callbacks, i )
+        else
+            i = i + 1
+        end
+    end
+
+    if ( #callbacks == 0 ) then
+        self.control:UnregisterForEvent( event, function( ... ) self:OnEvent( ... ) end )
+    end
 end

 function PSBT:NewEvent( scrollArea, sticky, icon, text )
diff --git a/core/PSBT_Constants.lua b/core/PSBT_Constants.lua
index e63b95f..bc46244 100644
--- a/core/PSBT_Constants.lua
+++ b/core/PSBT_Constants.lua
@@ -7,6 +7,7 @@ PSBT_MODULES =
     AURAS               = 'auras',
     XP                  = 'experience',
     LOW                 = 'lowsomething',
+    ULTIMATE            = 'ultimate',
 }

 PSBT_AREAS =
diff --git a/modules/PSBT_Auras.lua b/modules/PSBT_Auras.lua
index 10daac0..3590541 100644
--- a/modules/PSBT_Auras.lua
+++ b/modules/PSBT_Auras.lua
@@ -12,7 +12,7 @@ local PSBT_MODULES          = PSBT_MODULES
 function PSBT_Auras:Initialize( ... )
     PSBT_Module.Initialize( self, ... )

-    self:RegisterForEvent( EVENT_EFFECT_CHANGED, function( eventCode, ... ) self:OnEffectChanged( ... ) end )
+    self:RegisterForEvent( EVENT_EFFECT_CHANGED, function( ... ) self:OnEffectChanged( ... ) end )
 end

 function PSBT_Auras:OnEffectChanged( changeType, effectSlot, effectName, unitTag, beginTime, endTime, stackCount, iconName, buffType, effectType, abilityType, statusEffectType )
@@ -20,7 +20,9 @@ function PSBT_Auras:OnEffectChanged( changeType, effectSlot, effectName, unitTag
         return
     end

-    print( 'OnEffectChanged' )
+    if ( iconName == '/esoui/art/icons/ability_warrior_008.dds') then
+        return
+    end

     if ( changeType == EFFECT_RESULT_FADED ) then
         self:Remove( effectName, iconName )
diff --git a/modules/PSBT_Combat.lua b/modules/PSBT_Combat.lua
index 484f8b2..f35fed2 100644
--- a/modules/PSBT_Combat.lua
+++ b/modules/PSBT_Combat.lua
@@ -297,12 +297,18 @@ function PSBT_Combat:Initialize( ... )
     self._index     = 1
     self._free      = nil

+    self:RegisterForEvent( EVENT_COMBAT_EVENT,          function( ... ) self:OnCombatEvent( ... )    end )
+    self:RegisterForEvent( EVENT_SKILLS_FULL_UPDATE,    function() self:RefreshAbilityIcons()        end )
+    self:RegisterForEvent( EVENT_SKILL_POINTS_CHANGED,  function() self:RefreshAbilityIcons()        end )
+
+    self:RefreshAbilityIcons()
+end
+
+function PSBT_Combat:RefreshAbilityIcons()
     for i=1,GetNumAbilities() do
         local name, icon = GetAbilityInfoByIndex( i )
         self._iconRegistry[ name ] = icon
     end
-
-    self:RegisterForEvent( EVENT_COMBAT_EVENT, function( event, ... ) self:OnCombatEvent( ... ) end )
 end

 function PSBT_Combat:OnCombatEvent( ... )
diff --git a/modules/PSBT_Cooldowns.lua b/modules/PSBT_Cooldowns.lua
index 363e858..6645b4b 100644
--- a/modules/PSBT_Cooldowns.lua
+++ b/modules/PSBT_Cooldowns.lua
@@ -9,10 +9,13 @@ function PSBT_Cooldowns:Initialize( ... )
     PSBT_Module.Initialize( self, ... )

     self:RegisterForEvent( EVENT_ABILITY_COOLDOWN_UPDATED, function( abilityId ) self:OnAbilityCooldownUpdated( abilityId ) end )
+    self:RegisterForEvent( EVENT_ACTION_UPDATE_COOLDOWNS, function() self:OnActionCooldownUpdate() end )
 end

 function PSBT_Cooldowns:OnAbilityCooldownUpdated( abilityId )
+end

+function PSBT_Cooldowns:OnActionCooldownUpdate()
 end

 CBM:RegisterCallback( PSBT_EVENTS.LOADED,
diff --git a/modules/PSBT_Experience.lua b/modules/PSBT_Experience.lua
index 91c5315..649066a 100644
--- a/modules/PSBT_Experience.lua
+++ b/modules/PSBT_Experience.lua
@@ -14,7 +14,7 @@ function PSBT_Experience:Initialize( ... )

     self._currentExperience = GetUnitXP( 'player' )

-    self:RegisterForEvent( EVENT_EXPERIENCE_UPDATE, function( event, ... ) self:OnXPUpdated( ... ) end )
+    self:RegisterForEvent( EVENT_EXPERIENCE_UPDATE, function( ... ) self:OnXPUpdated( ... ) end )
 end

 function PSBT_Experience:OnXPUpdated( tag, exp, maxExp, reason  )
diff --git a/modules/PSBT_LowSomething.lua b/modules/PSBT_LowSomething.lua
index da92fbb..ea1b190 100644
--- a/modules/PSBT_LowSomething.lua
+++ b/modules/PSBT_LowSomething.lua
@@ -17,12 +17,12 @@ local POWERTYPE_MOUNT_STAMINA = POWERTYPE_MOUNT_STAMINA
 function PSBT_LowSomething:Initialize( ... )
     PSBT_Module.Initialize( self, ... )

-    self._pools[POWERTYPE_HEALTH]        = 0
-    self._pools[POWERTYPE_MAGICKA]       = 0
-    self._pools[POWERTYPE_STAMINA]       = 0
-    self._pools[POWERTYPE_MOUNT_STAMINA] = 0
+    self._pools[ POWERTYPE_HEALTH ]        = 0
+    self._pools[ POWERTYPE_MAGICKA ]       = 0
+    self._pools[ POWERTYPE_STAMINA ]       = 0
+    self._pools[ POWERTYPE_MOUNT_STAMINA ] = 0

-    self:RegisterForEvent( EVENT_POWER_UPDATE, function( event, ... ) self:OnPowerUpdate( ... ) end )
+    self:RegisterForEvent( EVENT_POWER_UPDATE, function( ... ) self:OnPowerUpdate( ... ) end )
 end

 function PSBT_LowSomething:OnPowerUpdate( unit, powerPoolIndex, powerType, powerPool, powerPoolMax )
diff --git a/modules/PSBT_Ultimate.lua b/modules/PSBT_Ultimate.lua
new file mode 100644
index 0000000..3100f2a
--- /dev/null
+++ b/modules/PSBT_Ultimate.lua
@@ -0,0 +1,60 @@
+local PSBT_Module = PSBT_Module
+local PSBT_Ultimate = PSBT_Module:Subclass()
+local CBM = CALLBACK_MANAGER
+
+local PSBT_MODULES = PSBT_MODULES
+local PSBT_AREAS   = PSBT_AREAS
+local PSBT_EVENTS  = PSBT_EVENTS
+
+
+local POWERTYPE_ULTIMATE                = POWERTYPE_ULTIMATE
+local ACTION_BAR_ULTIMATE_SLOT_INDEX    = ACTION_BAR_ULTIMATE_SLOT_INDEX
+
+function PSBT_Ultimate:Initialize( ... )
+    PSBT_Module.Initialize( self, ... )
+
+    self:RegisterForEvent( EVENT_POWER_UPDATE,                  function( ... ) self:OnPowerUpdate( ... ) end )
+    self:RegisterForEvent( EVENT_ACTION_SLOTS_FULL_UPDATE,      function( ... ) self:UpdateUltimateMin() end )
+    self:RegisterForEvent( EVENT_ACTION_SLOT_ABILITY_SLOTTED,   function( ... ) self:UpdateUltimateMin() end )
+
+    self._ready   = false
+    self._current = 0
+    self._needed  = 0
+    self._texture = nil
+
+    self:UpdateUltimateMin()
+end
+
+function PSBT_Ultimate:OnPowerUpdate( unit, powerPoolIndex, powerType, powerPool, powerPoolMax )
+    if ( unit ~= 'player' ) then
+        return
+    end
+
+    if ( powerType ~= POWERTYPE_ULTIMATE ) then
+        return
+    end
+
+    if ( powerPool > self._current ) then
+        if ( powerPool >= self._needed and not self._ready ) then
+            self._ready = true
+            PlaySound( 'Quest_Complete' )
+            self:NewEvent( PSBT_AREAS.NOTIFICATION, true, self._texture, 'Ultimate Ready!' )
+        elseif ( powerPool - self._current >= 5 ) then
+            self:NewEvent( PSBT_AREAS.INCOMING, false, self._texture, 'Ultimate: ' .. powerPool )
+        end
+    else
+        self._ready = powerPool >= self._needed
+    end
+
+    self._current = powerPool
+end
+
+function PSBT_Ultimate:UpdateUltimateMin()
+    self._needed = GetSlotAbilityCost( ACTION_BAR_ULTIMATE_SLOT_INDEX + 1 )
+    self._texture = GetSlotTexture( ACTION_BAR_ULTIMATE_SLOT_INDEX + 1 )
+end
+
+CBM:RegisterCallback( PSBT_EVENTS.LOADED,
+    function( psbt )
+        psbt:RegisterModule( PSBT_MODULES.ULTIMATE, PSBT_Ultimate:New( psbt ) )
+    end )
\ No newline at end of file