Avoid no-toggle action tooltip scans

This commit is contained in:
Dusk-92
2026-08-26 09:27:51 +02:00
parent a0781c2b86
commit ef3ed8ca2b
+59 -9
View File
@@ -1,5 +1,6 @@
local _G = ShaguTweaks.GetGlobalEnv() local _G = ShaguTweaks.GetGlobalEnv()
local T = ShaguTweaks.T local T = ShaguTweaks.T
local API = ShaguTweaks.API
local module = ShaguTweaks:register({ local module = ShaguTweaks:register({
title = T["No Toggle Auto-Attack"], title = T["No Toggle Auto-Attack"],
@@ -13,6 +14,25 @@ local module = ShaguTweaks:register({
module.enable = function(self) module.enable = function(self)
local attacking, shooting local attacking, shooting
local attackNames = {
["attack"] = "melee",
["auto attack"] = "melee",
["auto shot"] = "ranged",
["shoot"] = "ranged",
}
local function AddAttackName(spellID, attackType)
if not API or not API.GetSpellInfo then return end
local name = API.GetSpellInfo(spellID)
if name then attackNames[strlower(name)] = attackType end
end
-- Add the current client's localized spell names while retaining the
-- original English aliases for the legacy fallback.
AddAttackName(6603, "melee")
AddAttackName(75, "ranged")
AddAttackName(5019, "ranged")
local combatFrame = CreateFrame("Frame") local combatFrame = CreateFrame("Frame")
combatFrame:RegisterEvent("PLAYER_ENTER_COMBAT") combatFrame:RegisterEvent("PLAYER_ENTER_COMBAT")
combatFrame:RegisterEvent("PLAYER_LEAVE_COMBAT") combatFrame:RegisterEvent("PLAYER_LEAVE_COMBAT")
@@ -27,35 +47,65 @@ module.enable = function(self)
shooting = event == "START_AUTOREPEAT_SPELL" shooting = event == "START_AUTOREPEAT_SPELL"
end) end)
local function active(name) local function activeName(name)
if not name then return false end if not name then return false end
name = strlower(name) local attackType = attackNames[strlower(name)]
return (name == "attack" and attacking) or return (attackType == "melee" and attacking) or
((name == "auto shot" or name == "shoot") and shooting) (attackType == "ranged" and shooting)
end
local function activeSpell(spellID)
if not API or not API.autoattack or not spellID then return false end
return (API.IsAutoAttackSpell(spellID) and attacking) or
(API.IsRangedAutoAttackSpell(spellID) and shooting)
end
local function activeSpellBook(index, booktype)
if API and API.autoattackbook then
return (API.IsAutoAttackSpellBookItem(index, booktype) and attacking) or
(API.IsRangedAutoAttackSpellBookItem(index, booktype) and shooting)
end
return activeName(GetSpellName(index, booktype))
end end
local origCastSpell = CastSpell local origCastSpell = CastSpell
function _G.CastSpell(index, booktype) function _G.CastSpell(index, booktype)
if active(GetSpellName(index, booktype)) then return end if activeSpellBook(index, booktype) then return end
return origCastSpell(index, booktype) return origCastSpell(index, booktype)
end end
local origCastSpellByName = CastSpellByName local origCastSpellByName = CastSpellByName
function _G.CastSpellByName(text, onself) function _G.CastSpellByName(text, onself)
if active(text) then return end local spellID = tonumber(text)
if activeSpell(spellID) or activeName(text) then return end
return origCastSpellByName(text, onself) return origCastSpellByName(text, onself)
end end
local tt = CreateFrame("GameTooltip", "ShaguTweaksNoToggleTT", nil, "GameTooltipTemplate") local tt
tt:SetOwner(UIParent, "ANCHOR_NONE") local function GetLegacyTooltip()
if tt then return tt end
tt = CreateFrame("GameTooltip", "ShaguTweaksNoToggleTT", nil, "GameTooltipTemplate")
tt:SetOwner(UIParent, "ANCHOR_NONE")
return tt
end
local origUseAction = UseAction local origUseAction = UseAction
function _G.UseAction(slot, clicked, onself) function _G.UseAction(slot, clicked, onself)
if API and API.actioninfo and API.autoattack then
local actionType, spellID = API.GetActionInfo(slot)
if actionType == "spell" and activeSpell(spellID) then return end
if actionType then return origUseAction(slot, clicked, onself) end
end
-- Legacy clients have no action descriptor API. Keep the tooltip scan as
-- a fallback only, instead of paying for it on every spell/item action.
if HasAction(slot) and not GetActionText(slot) then if HasAction(slot) and not GetActionText(slot) then
local tt = GetLegacyTooltip()
tt:SetOwner(UIParent, "ANCHOR_NONE") tt:SetOwner(UIParent, "ANCHOR_NONE")
tt:SetAction(slot) tt:SetAction(slot)
local label = _G["ShaguTweaksNoToggleTTTextLeft1"] local label = _G["ShaguTweaksNoToggleTTTextLeft1"]
if label and active(label:GetText()) then return end if label and activeName(label:GetText()) then return end
end end
return origUseAction(slot, clicked, onself) return origUseAction(slot, clicked, onself)
end end