Commit 73115967 authored by Simpy's avatar Simpy 🐹
Browse files

update LibActionButton

parent 380e436f
--[[
Copyright (c) 2010-2019, Hendrik "nevcairiel" Leppkes <h.leppkes@gmail.com>
Copyright (c) 2010-2020, Hendrik "nevcairiel" Leppkes <h.leppkes@gmail.com>
All rights reserved.
......@@ -26,31 +26,21 @@ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
]]
]]
local MAJOR_VERSION = "LibActionButton-1.0-ElvUI"
local MINOR_VERSION = 20 -- the real minor version is 74
local MINOR_VERSION = 21 -- the real minor version is 79
if not LibStub then error(MAJOR_VERSION .. " requires LibStub.") end
local lib, oldversion = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
if not lib then return end
-- Lua functions
local type, error, tostring, tonumber, assert, select = type, error, tostring, tonumber, assert, select
local setmetatable, wipe, unpack, pairs, next = setmetatable, wipe, unpack, pairs, next
local str_match, format, tinsert, tremove = string.match, format, tinsert, tremove
-- GLOBALS: ATTACK_BUTTON_FLASH_TIME, C_ToyBox, ClearCursor, COOLDOWN_TYPE_LOSS_OF_CONTROL, COOLDOWN_TYPE_NORMAL
-- GLOBALS: CooldownFrame_Set, CreateFrame, FindSpellBookSlotBySpellID, FlyoutHasSpell, GameTooltip, GameTooltip_SetDefaultAnchor
-- GLOBALS: GetActionCharges, GetActionCooldown, GetActionCount, GetActionInfo, GetActionLossOfControlCooldown, GetActionText
-- GLOBALS: GetActionTexture, GetBindingKey, GetBindingText, GetCursorInfo, GetCVar, GetCVarBool, GetItemCooldown, GetItemCount
-- GLOBALS: GetItemIcon, GetLastZoneAbilitySpellTexture, GetMacroInfo, GetMacroSpell, GetModifiedClick, GetMouseFocus, GetSpellCharges
-- GLOBALS: GetSpellCooldown, GetSpellCount, GetSpellInfo, GetSpellTexture, HasAction, HasZoneAbility, InCombatLockdown, IsActionInRange
-- GLOBALS: IsAltKeyDown, IsAttackAction, IsAttackSpell, IsAutoRepeatAction, IsAutoRepeatSpell, IsConsumableAction, IsConsumableItem
-- GLOBALS: IsConsumableSpell, IsControlKeyDown, IsCurrentAction, IsCurrentItem, IsCurrentSpell, IsEquippedAction, IsEquippedItem
-- GLOBALS: IsItemAction, IsItemInRange, IsShiftKeyDown, IsSpellInRange, IsSpellOverlayed, IsStackableAction, IsUsableAction, IsUsableItem
-- GLOBALS: IsUsableSpell, LibStub, PickupAction, PickupCompanion, PickupEquipmentSet, PickupItem, PickupMacro, PickupPetAction, PickupSpell
-- GLOBALS: RANGE_INDICATOR, SetBinding, SetBindingClick, SetClampedTextureRotation, SpellFlyout, TOOLTIP_UPDATE_TIME, UIParent, ZoneAbilityFrame
-- GLOBALS: GetOnBarHighlightMark
local WoWClassic = select(4, GetBuildInfo()) < 20000
local KeyBound = LibStub("LibKeyBound-1.0", true)
local CBH = LibStub("CallbackHandler-1.0")
......@@ -109,7 +99,7 @@ local type_meta_map = {
local ButtonRegistry, ActiveButtons, ActionButtons, NonActionButtons = lib.buttonRegistry, lib.activeButtons, lib.actionButtons, lib.nonActionButtons
local Update, UpdateButtonState, UpdateUsable, UpdateCount, UpdateCooldown, UpdateTooltip, UpdateNewAction, ClearNewActionHighlight
local Update, UpdateButtonState, UpdateUsable, UpdateCount, UpdateCooldown, UpdateTooltip, UpdateNewAction, UpdateSpellHighlight, ClearNewActionHighlight
local StartFlash, StopFlash, UpdateFlash, UpdateHotkeys, UpdateRangeTimer, UpdateOverlayGlow
local UpdateFlyout, ShowGrid, HideGrid, UpdateGrid, SetupSecureSnippets, WrapOnClick
local ShowOverlayGlow, HideOverlayGlow
......@@ -195,6 +185,7 @@ function lib:CreateButton(id, name, header, config)
-- adjust hotkey style for better readability
button.HotKey:SetFont(button.HotKey:GetFont(), 13, "OUTLINE")
button.HotKey:SetVertexColor(0.75, 0.75, 0.75)
button.HotKey:SetPoint("TOPLEFT", button, "TOPLEFT", -2, -4)
-- adjust count/stack size
button.Count:SetFont(button.Count:GetFont(), 16, "OUTLINE")
......@@ -702,8 +693,10 @@ function InitializeEventHandler()
lib.eventFrame:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
lib.eventFrame:RegisterEvent("UPDATE_BINDINGS")
lib.eventFrame:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
lib.eventFrame:RegisterEvent("UPDATE_VEHICLE_ACTIONBAR")
lib.eventFrame:RegisterEvent("PLAYER_MOUNT_DISPLAY_CHANGED")
if not WoWClassic then
lib.eventFrame:RegisterEvent("UPDATE_VEHICLE_ACTIONBAR")
end
lib.eventFrame:RegisterEvent("ACTIONBAR_UPDATE_STATE")
lib.eventFrame:RegisterEvent("ACTIONBAR_UPDATE_USABLE")
......@@ -711,23 +704,26 @@ function InitializeEventHandler()
lib.eventFrame:RegisterEvent("PLAYER_TARGET_CHANGED")
lib.eventFrame:RegisterEvent("TRADE_SKILL_SHOW")
lib.eventFrame:RegisterEvent("TRADE_SKILL_CLOSE")
lib.eventFrame:RegisterEvent("ARCHAEOLOGY_CLOSED")
lib.eventFrame:RegisterEvent("PLAYER_ENTER_COMBAT")
lib.eventFrame:RegisterEvent("PLAYER_LEAVE_COMBAT")
lib.eventFrame:RegisterEvent("START_AUTOREPEAT_SPELL")
lib.eventFrame:RegisterEvent("STOP_AUTOREPEAT_SPELL")
lib.eventFrame:RegisterEvent("UNIT_ENTERED_VEHICLE")
lib.eventFrame:RegisterEvent("UNIT_EXITED_VEHICLE")
lib.eventFrame:RegisterEvent("COMPANION_UPDATE")
lib.eventFrame:RegisterEvent("UNIT_INVENTORY_CHANGED")
lib.eventFrame:RegisterEvent("LEARNED_SPELL_IN_TAB")
lib.eventFrame:RegisterEvent("PET_STABLE_UPDATE")
lib.eventFrame:RegisterEvent("PET_STABLE_SHOW")
lib.eventFrame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW")
lib.eventFrame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_HIDE")
lib.eventFrame:RegisterEvent("SPELL_UPDATE_CHARGES")
lib.eventFrame:RegisterEvent("UPDATE_SUMMONPETS_ACTION")
lib.eventFrame:RegisterEvent("SPELL_UPDATE_ICON")
if not WoWClassic then
lib.eventFrame:RegisterEvent("ARCHAEOLOGY_CLOSED")
lib.eventFrame:RegisterEvent("UNIT_ENTERED_VEHICLE")
lib.eventFrame:RegisterEvent("UNIT_EXITED_VEHICLE")
lib.eventFrame:RegisterEvent("COMPANION_UPDATE")
lib.eventFrame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW")
lib.eventFrame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_HIDE")
lib.eventFrame:RegisterEvent("UPDATE_SUMMONPETS_ACTION")
end
-- With those two, do we still need the ACTIONBAR equivalents of them?
lib.eventFrame:RegisterEvent("SPELL_UPDATE_COOLDOWN")
......@@ -1063,13 +1059,13 @@ end
--- button management
function Generic:UpdateAction(force)
local type, action = self:GetAction()
if force or (type ~= self._state_type) or (action ~= self._state_action) then
local action_type, action = self:GetAction()
if force or (action_type ~= self._state_type) or (action ~= self._state_action) then
-- type changed, update the metatable
if force or (self._state_type ~= type) then
local meta = type_meta_map[type] or type_meta_map.empty
if force or (self._state_type ~= action_type) then
local meta = type_meta_map[action_type] or type_meta_map.empty
setmetatable(self, meta)
self._state_type = type
self._state_type = action_type
end
self._state_action = action
Update(self)
......@@ -1103,6 +1099,10 @@ function Update(self, fromUpdateConfig)
if self.chargeCooldown then
EndChargeCooldown(self.chargeCooldown)
end
if self.LevelLinkLockIcon then
self.LevelLinkLockIcon:SetShown(false)
end
end
-- Add a green border if button is an equipped item
......@@ -1148,7 +1148,6 @@ function Update(self, fromUpdateConfig)
self.icon:Show()
self.rangeTimer = - 1
self:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2")
if not self.LBFSkinned and not self.MasqueSkinned then
self.NormalTexture:SetTexCoord(0, 0, 0, 0)
end
......@@ -1177,6 +1176,8 @@ function Update(self, fromUpdateConfig)
UpdateButtonState(self)
UpdateSpellHighlight(self)
if GameTooltip_GetOwnerForbidden() == self then
UpdateTooltip(self)
end
......@@ -1228,6 +1229,18 @@ function UpdateUsable(self)
else
self.icon:SetVertexColor(unpack(self.config.colors.usable))
end
if not WoWClassic and self._state_type == "action" then
local isLevelLinkLocked = C_LevelLink.IsActionLocked(self._state_action)
if not self.icon:IsDesaturated() then
self.icon:SetDesaturated(isLevelLinkLocked)
end
if self.LevelLinkLockIcon then
self.LevelLinkLockIcon:SetShown(isLevelLinkLocked)
end
end
lib.callbacks:Fire("OnButtonUsable", self)
end
......@@ -1331,7 +1344,7 @@ function UpdateCooldown(self)
self.cooldown.currentCooldownType = COOLDOWN_TYPE_NORMAL
end
if charges and maxCharges and charges > 0 and charges < maxCharges then
if charges and maxCharges and maxCharges > 1 and charges < maxCharges then
StartChargeCooldown(self, chargeStart, chargeDuration, chargeModRate)
self.chargeCooldown:SetDrawSwipe(duration <= 0 and self.config.useDrawSwipeOnCharges)
......@@ -1383,11 +1396,9 @@ function UpdateHotkeys(self)
local key = self:GetHotkey()
if not key or key == "" or self.config.hideElements.hotkey then
self.HotKey:SetText(RANGE_INDICATOR)
self.HotKey:SetPoint("TOPLEFT", self, "TOPLEFT", 1, - 2)
self.HotKey:Hide()
else
self.HotKey:SetText(key)
self.HotKey:SetPoint("TOPLEFT", self, "TOPLEFT", - 2, - 2)
self.HotKey:Show()
end
......@@ -1486,6 +1497,54 @@ function UpdateNewAction(self)
end
end
hooksecurefunc("UpdateOnBarHighlightMarksBySpell", function(spellID)
lib.ON_BAR_HIGHLIGHT_MARK_TYPE = "spell"
lib.ON_BAR_HIGHLIGHT_MARK_ID = tonumber(spellID)
for button in next, ButtonRegistry do
UpdateSpellHighlight(button)
end
end)
hooksecurefunc("UpdateOnBarHighlightMarksByFlyout", function(flyoutID)
lib.ON_BAR_HIGHLIGHT_MARK_TYPE = "flyout"
lib.ON_BAR_HIGHLIGHT_MARK_ID = tonumber(flyoutID)
for button in next, ButtonRegistry do
UpdateSpellHighlight(button)
end
end)
hooksecurefunc("ClearOnBarHighlightMarks", function()
lib.ON_BAR_HIGHLIGHT_MARK_TYPE = nil
for button in next, ButtonRegistry do
UpdateSpellHighlight(button)
end
end)
function UpdateSpellHighlight(self)
local shown = false
local highlightType, id = lib.ON_BAR_HIGHLIGHT_MARK_TYPE, lib.ON_BAR_HIGHLIGHT_MARK_ID
if highlightType == "spell" and self:GetSpellId() == id then
shown = true
elseif highlightType == "flyout" and self._state_type == "action" then
local actionType, actionId = GetActionInfo(self._state_action)
if actionType == "flyout" and actionId == id then
shown = true
end
end
if shown then
self.SpellHighlightTexture:Show()
self.SpellHighlightAnim:Play()
else
self.SpellHighlightTexture:Hide()
self.SpellHighlightAnim:Stop()
end
end
-- Hook UpdateFlyout so we can use the blizzy templates
hooksecurefunc("ActionButton_UpdateFlyout", function(self, ...)
if ButtonRegistry[self] then
......@@ -1598,6 +1657,21 @@ Action.GetSpellId = function(self)
end
Action.GetLossOfControlCooldown = function(self) return GetActionLossOfControlCooldown(self._state_action) end
-- Classic overrides for item count breakage
if WoWClassic then
-- if the library is present, simply use it to override action counts
local LibClassicSpellActionCount = LibStub("LibClassicSpellActionCount-1.0", true)
if LibClassicSpellActionCount then
Action.GetCount = function(self) return LibClassicSpellActionCount:GetActionCount(self._state_action) end
else
-- if we don't have the library, only show count for items, like the default UI
Action.IsConsumableOrStackable = function(self) return IsItemAction(self._state_action) and (IsConsumableAction(self._state_action) or IsStackableAction(self._state_action)) end
end
-- disable loss of control cooldown on classic
Action.GetLossOfControlCooldown = function(self) return 0,0 end
end
-----------------------------------------------------------
--- Spell Button
Spell.HasAction = function(self) return true end
......@@ -1615,6 +1689,7 @@ Spell.IsConsumableOrStackable = function(self) return IsConsumableSpell(self._st
Spell.IsUnitInRange = function(self, unit) return IsSpellInRange(FindSpellBookSlotBySpellID(self._state_action), "spell", unit) end -- needs spell book id as of 4.0.1.13066
Spell.SetTooltip = function(self) return GameTooltip:SetSpellByID(self._state_action) end
Spell.GetSpellId = function(self) return self._state_action end
Spell.GetLossOfControlCooldown = function(self) return GetSpellLossOfControlCooldown(self._state_action) end
-----------------------------------------------------------
--- Item Button
......@@ -1694,6 +1769,11 @@ Custom.SetTooltip = function(self) return GameTooltip:SetText(self.
Custom.GetSpellId = function(self) return nil end
Custom.RunCustom = function(self, unit, button) return self._state_action.func(self, unit, button) end
--- WoW Classic overrides
if WoWClassic then
UpdateOverlayGlow = function() end
end
-----------------------------------------------------------
--- Update old Buttons
if oldversion and next(lib.buttonRegistry) then
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment