View Single Post
07-19-23, 10:51 AM   #4
Tair
A Deviate Faerie Dragon
Join Date: Aug 2020
Posts: 10
Thank you both for the replies!

Originally Posted by SDPhantom View Post
Hooking directly into the function that sets the icons worked for me.
This does indeed work. And more importantly, the code you provided made me confident that I was looking through incorrect code last night. I exported the interface code on my computer this morning and was able to find the function you referenced as well as similar one for the action bars. Thank you for steering me in the right direction.

Code:
hooksecurefunc("ActionButton_UpdateState",function(button)
    local spellType, spellId, subType = GetActionInfo(button.action);
    if spellType ~= "spell" then return end; -- only check spells for now
    -- local aura = GetPlayerAuraBySpellID(spellId) -- not available in classic?
    local spellName = GetSpellInfo(spellId);
    -- assume that a player aura w/ no duration and name equal to the spell's name is a toggle...
    local auraName, buff, count, buffType, duration, expirationTime, isMine, isStealable, _, auraId = AuraUtil.FindAuraByName(spellName, "player");
    if auraName == spellName and duration == 0 then
        print('Matching aura found: ' .. auraName); -- works
        print('Spell icon texture: ' .. GetSpellTexture(spellId)); -- debug; returns the correct icon
        print('Aura icon texture: ' .. GetSpellTexture(auraId)); -- debug; returns the correct icon
        button.icon:SetTexture(GetSpellTexture(spellId)); -- does not change the icon
        button.icon:SetDesaturated(true) -- works;
    end;
end);
The only issue with this is that the icon texture doesn't update. Which made me wonder if the icon switching is being handled by a different function that's maybe running after my code?

Edit 1: The default code is calling GetActionTexture() instead of GetSpellTexture(). GetActionTexture returns the wisp icon.

Solved it, sort of. I needed to hook ActionButton_Update, as opposed to ActionButton_UpdateState. The mostly-working code for the action bars is:

Code:
hooksecurefunc("ActionButton_Update",function(self)
    local action = self.action;
    local icon = self.icon;
    local type, id = GetActionInfo(action);
    -- only check spells for now
    if type ~= "spell" then return end;
    local spellName = GetSpellInfo(id);
    -- assume player aura w/ no duration and name equal to spell name is a toggle
    local auraName, buff, count, buffType, duration, expirationTime, isMine, isStealable, _, auraId = AuraUtil.FindAuraByName(spellName, "player");
    if auraName == spellName and duration == 0 then
        icon:SetTexture(GetSpellTexture(id));
        icon:SetDesaturated(true);
    end;
end);
The only outstanding issue I've found so far is that the icon will eventually revert to the wisp icon.

After some further testing, it seems as though both ActionButton_Update and ActionButton_OnEvent need to be hooked in order to cover all of the apparent cases where the default code is changing the icon.

Last edited by Tair : 07-19-23 at 12:51 PM.
  Reply With Quote