11-- License: LICENSE.txt
22
33local MAJOR_VERSION = " LibActionButton-1.0-ElvUI"
4- local MINOR_VERSION = 81 -- the real minor version is 147
4+ local MINOR_VERSION = 82 -- the real minor version is 151
55
66local LibStub = LibStub
77if not LibStub then error (MAJOR_VERSION .. " requires LibStub." ) end
@@ -77,6 +77,7 @@ lib.buttonRegistry = lib.buttonRegistry or {}
7777lib .activeButtons = lib .activeButtons or {}
7878lib .actionButtons = lib .actionButtons or {}
7979lib .nonActionButtons = lib .nonActionButtons or {}
80+ lib .actionButtonsNonUI = lib .actionButtonsNonUI or {}
8081lib .activeAlerts = lib .activeAlerts or {}
8182lib .activeAssist = lib .activeAssist or {}
8283
@@ -134,9 +135,9 @@ local type_meta_map = {
134135
135136local GetFlyoutHandler
136137local InitializeEventHandler , OnEvent , ForAllButtonsWithSpell , ForAllButtons
137- local ButtonRegistry , ActiveButtons , ActionButtons , NonActionButtons = lib .buttonRegistry , lib .activeButtons , lib .actionButtons , lib .nonActionButtons
138+ local ButtonRegistry , ActiveButtons , ActionButtons , NonActionButtons , ActionButtonsNonUI = lib .buttonRegistry , lib .activeButtons , lib .actionButtons , lib .nonActionButtons , lib . actionButtonsNonUI
138139
139- local Update , UpdateButtonState , UpdateUsable , UpdateCount , UpdateCooldown , UpdateTooltip , UpdateNewAction , UpdateSpellHighlight , ClearNewActionHighlight
140+ local Update , UpdateButtonState , UpdateUsable , UpdateCount , UpdateCooldown , UpdateCooldownNumberHidden , UpdateTooltip , UpdateNewAction , UpdateSpellHighlight , ClearNewActionHighlight
140141local StartFlash , StopFlash , UpdateFlash , UpdateHotkeys , UpdateRangeTimer , UpdateOverlayGlow
141142local UpdateFlyout , ShowGrid , HideGrid , UpdateGrid , SetupSecureSnippets , WrapOnClick
142143local ShowOverlayGlow , HideOverlayGlow
@@ -207,6 +208,7 @@ local DefaultConfig = {
207208 cooldownCount = nil , -- nil: use cvar, true/false: enable/disable
208209 lossOfControlCooldown = true ,
209210 flyoutDirection = " UP" ,
211+ actionButtonUI = false , -- register the button with SetActionUIButton, this has some side-effects if the button changes from action type to another type, but is required for certain UI integrations. Recommended to only set on pure type=action buttons
210212 useDrawBling = true ,
211213 handleOverlay = true ,
212214 text = {
@@ -318,6 +320,10 @@ function lib:CreateButton(id, name, header, config)
318320 button :SetScript (" PreClick" , Generic .PreClick )
319321 button :SetScript (" PostClick" , Generic .PostClick )
320322 button :SetScript (" OnEvent" , Generic .OnButtonEvent )
323+ button :SetScript (" OnAttributeChanged" , nil ) -- inherited templates bring in a handler here which we don't want, so get rid of it
324+
325+ -- unwanted mixin functions, which we override through the metatable
326+ button .HasAction = nil
321327
322328 button .id = id
323329 button .header = header
@@ -1444,6 +1450,7 @@ function Generic:UpdateConfig(config)
14441450 self .Name :Show ()
14451451 end
14461452
1453+ UpdateCooldownNumberHidden (self )
14471454 UpdateTextElements (self )
14481455 UpdateHotkeys (self )
14491456 UpdateGrid (self )
@@ -1577,6 +1584,8 @@ function OnEvent(_, event, arg1, arg2, arg3, arg4)
15771584 elseif event == " CVAR_UPDATE" then
15781585 if arg1 == " assistedCombatHighlight" then
15791586 wipe (lib .activeAssist )
1587+ elseif arg1 == " countdownForCooldowns" then
1588+ ForAllButtons (UpdateCooldownNumberHidden )
15801589 end
15811590 elseif event == " SPELLS_CHANGED" or event == " SPELL_FLYOUT_UPDATE" then
15821591 if UseCustomFlyout then
@@ -1635,7 +1644,11 @@ function OnEvent(_, event, arg1, arg2, arg3, arg4)
16351644 if TARGETAURA_ENABLED then
16361645 UpdateTargetAuras (event , arg1 , arg2 )
16371646 end
1638- elseif (event == " ACTIONBAR_UPDATE_STATE" or event == " UNIT_ENTERED_VEHICLE" or event == " UNIT_EXITED_VEHICLE" )
1647+ elseif event == " ACTIONBAR_UPDATE_STATE" then
1648+ for button in next , ActionButtonsNonUI do
1649+ UpdateButtonState (button )
1650+ end
1651+ elseif (event == " UNIT_ENTERED_VEHICLE" or event == " UNIT_EXITED_VEHICLE" )
16391652 or (event == " TRADE_SKILL_SHOW" or event == " TRADE_SKILL_CLOSE" or event == " ARCHAEOLOGY_CLOSED" or event == " TRADE_CLOSED" ) then
16401653 ForAllButtons (UpdateButtonState , true , event )
16411654 elseif event == " ACTION_RANGE_CHECK_UPDATE" then
@@ -2101,7 +2114,10 @@ function Generic:UpdateAction(force)
21012114 self ._state_action = action
21022115
21032116 -- set action attribute for action buttons
2104- self .action = self ._state_type == " action" and action or nil
2117+ self .action = self ._state_type == " action" and action or 0
2118+ if self .config .actionButtonUI then
2119+ SetActionUIButton (self , self .action , self .cooldown )
2120+ end
21052121
21062122 Update (self , ' UpdateAction' )
21072123 end
@@ -2113,9 +2129,13 @@ function Update(self, which)
21132129 if self ._state_type == " action" then
21142130 ActionButtons [self ] = true
21152131 NonActionButtons [self ] = nil
2132+ if not self .config .actionButtonUI then
2133+ ActionButtonsNonUI [self ] = true
2134+ end
21162135 else
21172136 ActionButtons [self ] = nil
21182137 NonActionButtons [self ] = true
2138+ ActionButtonsNonUI [self ] = nil
21192139 end
21202140
21212141 self :SetAlpha (1.0 )
@@ -2128,6 +2148,7 @@ function Update(self, which)
21282148 ActiveButtons [self ] = nil
21292149 ActionButtons [self ] = nil
21302150 NonActionButtons [self ] = nil
2151+ ActionButtonsNonUI [self ] = nil
21312152
21322153 if gridCounter == 0 and not self .config .showGrid then
21332154 self :SetAlpha (0.0 )
@@ -2363,6 +2384,16 @@ function UpdateCount(self)
23632384 self .Count :SetText (self :GetDisplayCount ())
23642385end
23652386
2387+ function UpdateCooldownNumberHidden (self )
2388+ local shouldBeHidden
2389+ if self .config .cooldownCount == nil then
2390+ shouldBeHidden = GetCVar (" countdownForCooldowns" ) ~= " 1"
2391+ else
2392+ shouldBeHidden = not self .config .cooldownCount
2393+ end
2394+ self .cooldown :SetHideCountdownNumbers (shouldBeHidden )
2395+ end
2396+
23662397function ClearChargeCooldown (self )
23672398 if self .chargeCooldown then
23682399 CooldownFrame_Clear (self .chargeCooldown )
@@ -2469,6 +2500,7 @@ else
24692500 if hasLocCooldown and ((not hasCooldown ) or ((locStart + locDuration ) > (start + duration ))) then
24702501 if self .cooldown .currentCooldownType ~= _G .COOLDOWN_TYPE_LOSS_OF_CONTROL then
24712502 self .cooldown .currentCooldownType = _G .COOLDOWN_TYPE_LOSS_OF_CONTROL
2503+ UpdateCooldownNumberHidden (self )
24722504 end
24732505
24742506 CooldownFrame_Set (self .cooldown , locStart , locDuration , true , true , modRate )
@@ -2477,6 +2509,7 @@ else
24772509 else
24782510 if self .cooldown .currentCooldownType ~= _G .COOLDOWN_TYPE_NORMAL then
24792511 self .cooldown .currentCooldownType = _G .COOLDOWN_TYPE_NORMAL
2512+ UpdateCooldownNumberHidden (self )
24802513 end
24812514
24822515 self .cooldown :SetScript (" OnCooldownDone" , OnCooldownDone , hasLocCooldown )
@@ -3023,7 +3056,7 @@ end
30233056
30243057-- fallback for pre-12.0
30253058
3026- local GetActionCount = C_ActionBar . GetActionUseCount or GetActionCount
3059+ local GetActionCount = GetActionCount
30273060
30283061-- the remaining uses of GetActionCount can't deal with secrets, so disable on Midnight
30293062if WoWRetail then
@@ -3146,9 +3179,7 @@ if WoWClassic then
31463179 return LibClassicSpellActionCount :GetActionCount (self ._state_action )
31473180 end
31483181 else -- if we don't have the library, only show count for items, like the default UI
3149- Action .IsConsumableOrStackable = function (self )
3150- return IsConsumableAction (self ._state_action ) or IsStackableAction (self ._state_action ) or (not IsItemAction (self ._state_action ) and GetActionCount (self ._state_action ) > 0 )
3151- end
3182+ Action .IsConsumableOrStackable = function (self ) return IsItemAction (self ._state_action ) and (IsConsumableAction (self ._state_action ) or IsStackableAction (self ._state_action )) end
31523183 end
31533184end
31543185
@@ -3173,22 +3204,31 @@ else
31733204end
31743205local GetSpellLossOfControlCooldownInfo = C_Spell and C_Spell .GetSpellLossOfControlCooldownInfo or GetSpellLoCCooldownInfoFallback
31753206
3207+ local GetSpellTexture = C_Spell and C_Spell .GetSpellTexture or GetSpellTexture
3208+ local GetSpellCastCount = C_Spell and C_Spell .GetSpellCastCount or GetSpellCount
3209+ local IsAttackSpell = C_SpellBook and C_SpellBook .IsAutoAttackSpellBookItem or IsAttackSpell
3210+ local IsCurrentSpell = C_Spell and C_Spell .IsCurrentSpell or IsCurrentSpell
3211+ local IsAutoRepeatSpell = C_Spell and C_Spell .IsAutoRepeatSpell or IsAutoRepeatSpell
3212+ local IsSpellUsable = C_Spell and C_Spell .IsSpellUsable or IsUsableSpell
3213+ local IsSpellInRange = C_Spell and C_Spell .IsSpellInRange or IsSpellInRange
3214+
3215+ local BOOKTYPE_SPELL = Enum .SpellBookSpellBank and Enum .SpellBookSpellBank .Player or " spell"
31763216---- -------------------------------------------------------
31773217--- Spell Button
31783218Spell .HasAction = function (self ) return true end
31793219Spell .GetActionText = function (self ) return " " end
3180- Spell .GetTexture = function (self ) return C_Spell . GetSpellTexture (self ._state_action ) end
3181- Spell .GetCount = function (self ) return C_Spell . GetSpellCastCount (self ._state_action ) end
3220+ Spell .GetTexture = function (self ) return GetSpellTexture (self ._state_action ) end
3221+ Spell .GetCount = function (self ) return GetSpellCastCount (self ._state_action ) end
31823222Spell .GetChargeInfo = function (self ) return C_Spell .GetSpellCharges (self ._state_action ) end
31833223Spell .GetCooldownInfo = function (self ) return C_Spell .GetSpellCooldown (self ._state_action ) end
31843224Spell .GetLoCCooldownInfo = function (self ) return GetSpellLossOfControlCooldownInfo (self ._state_action ) end
3185- Spell .IsAttack = function (self ) return C_Spell . IsAutoAttackSpell (self ._state_action ) or nil end
3225+ Spell .IsAttack = function (self ) local slot = FindSpellBookSlotBySpellID (self ._state_action ) return slot and IsAttackSpell ( slot , BOOKTYPE_SPELL ) or nil end
31863226Spell .IsEquipped = function (self ) return nil end
3187- Spell .IsCurrentlyActive = function (self ) return C_Spell . IsCurrentSpell (self ._state_action ) end
3188- Spell .IsAutoRepeat = function (self ) return C_Spell . IsAutoRepeatSpell (self ._state_action ) or nil end
3189- Spell .IsUsable = function (self ) return C_Spell . IsSpellUsable (self ._state_action ) end
3227+ Spell .IsCurrentlyActive = function (self ) return IsCurrentSpell (self ._state_action ) end
3228+ Spell .IsAutoRepeat = function (self ) local slot = FindSpellBookSlotBySpellID (self ._state_action ) return slot and IsAutoRepeatSpell ( slot , BOOKTYPE_SPELL ) or nil end
3229+ Spell .IsUsable = function (self ) return IsSpellUsable (self ._state_action ) end
31903230Spell .IsConsumableOrStackable = function (self ) return IsConsumableSpell (self ._state_action ) end
3191- Spell .IsUnitInRange = function (self , unit ) return C_Spell . IsSpellInRange (self ._state_action , unit ) or nil end
3231+ Spell .IsUnitInRange = function (self , unit ) local slot = FindSpellBookSlotBySpellID (self ._state_action ) return slot and IsSpellInRange ( slot , BOOKTYPE_SPELL , unit ) or nil end
31923232Spell .SetTooltip = function (self ) return GameTooltip :SetSpellByID (self ._state_action ) end
31933233Spell .GetSpellId = function (self ) return self ._state_action end
31943234
0 commit comments