WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   How to change pet bar hotkey color? (https://www.wowinterface.com/forums/showthread.php?t=59802)

atshn 02-20-24 04:01 PM

How to change pet bar hotkey color?
 
I'm using this code to change the color of hotkeys for all my bars. Works fine for everything except the pet bar. Is "PetActionButton" not the correct name or am I completely off and the code doesn't work for the pet bar at all?

Code:

for i = 1, NUM_ACTIONBAR_BUTTONS do
  local hotkey = _G["PetActionButton"..i.."HotKey"]
  hotkey:SetFont("Fonts\\FRIZQT__.ttf", 12, "THICKOUTLINE")
end

local function CustomizeHotkey(self)
  local hotkey = _G[self:GetName().."HotKey"]
  hotkey:SetTextColor(1, 1, 1, 1)
end

hooksecurefunc("ActionButton_Update", CustomizeHotkey)
hooksecurefunc("ActionButton_OnUpdate", CustomizeHotkey)


Xrystal 02-20-24 07:22 PM

PetActionBar has it's own set of Update routines. You probably need to hook into those to apply the changes to that bar.

https://github.com/Gethe/wow-ui-sour...ionBar.lua#L93

atshn 02-20-24 10:03 PM

Quote:

Originally Posted by Xrystal (Post 343383)
PetActionBar has it's own set of Update routines. You probably need to hook into those to apply the changes to that bar.

https://github.com/Gethe/wow-ui-sour...ionBar.lua#L93

I fear this one is over my head, but thank you for pointing me in the right direction.

Xrystal 02-21-24 12:09 AM

I haven't tested these but, looking at the Blizzard Dragonflight code ( 10.2.5 ) these lines should work for the main action bar and pet action bar for retail wow.

Lua Code:
  1. for i=1, NUM_PET_ACTION_SLOTS, 1 do
  2.         local button = PetActionBar.actionButtons[i]);
  3.                 hooksecurefunc(button, "SetHotKeys",function()
  4.                     local hotkey = self.HotKey;
  5.                      -- do your hotkey additions here
  6.                 end)
  7.     end

Lua Code:
  1. for i, actionButton in pairs(ActionBar.actionButtons) do
  2.        hooksecurefunc(actionButton,"UpdateHotKeys",function()
  3.           local hotkey = self.HotKey;
  4.           -- do your hotkey additions here
  5.        end
  6.     end


If you are working on Classic versions of wow (1.14.4 and 3.4.3) then it looks like the following could be done instead. Again, untested.

Lua Code:
  1. for i=1, NUM_ACTIONBAR_SLOTS, 1 do
  2.         local button = _G["ActionButton" .. i]);
  3.                 hooksecurefunc("ActionButton_UpdateHotkeys",function(self)
  4.                     local hotkey = self.HotKey;
  5.                      -- do your hotkey additions here
  6.                 end)
  7.     end

Lua Code:
  1. for i=1, NUM_PET_ACTION_SLOTS, 1 do
  2.         local button = _G["PetActionButton" .. i]);
  3.                 hooksecurefunc("PetActionButton_SetHotKeys",function(self)
  4.                     local hotkey = _G[self:GetName().."HotKey"];
  5.                      -- do your hotkey additions here
  6.                 end)
  7.     end

Give those a go and let us know if they work as expected for you.

atshn 02-21-24 12:38 AM

Not working on Classic. Anything wrong with my hotkey additions?

Code:

for i=1, NUM_ACTIONBAR_SLOTS, 1 do
        local button = _G["ActionButton" .. i]);
                hooksecurefunc("ActionButton_UpdateHotkeys",function(self)
                    local hotkey = self.HotKey;
                    hotkey:SetFont("Fonts\\FRIZQT__.ttf", 12, "THICKOUTLINE")
                    hotkey:SetTextColor(1, 1, 1, 1)
                end)
    end

for i=1, NUM_PET_ACTION_SLOTS, 1 do
        local button = _G["PetActionButton" .. i]);
                hooksecurefunc("PetActionButton_SetHotKeys",function(self)
                    local hotkey = _G[self:GetName().."HotKey"];
                    hotkey:SetFont("Fonts\\FRIZQT__.ttf", 12, "THICKOUTLINE")
                    hotkey:SetTextColor(1, 1, 1, 1)
                end)
    end


Xrystal 02-21-24 04:22 AM

Not that I can see. I'll play with it later and see if there's something else you have to do for it to work in Classic

Xrystal 02-21-24 06:04 AM

Okay, took a while, but managed to get it working on Wrath Classic 3.4.3 using the following code


Lua Code:
  1. local function UpdateHotKeys(self,buttonType)
  2.     local hotkey = self.HotKey;
  3.     hotkey:SetFont("Fonts\\FRIZQT__.ttf", 12, "THICKOUTLINE")
  4.     local binding = GetBindingText(GetBindingKey("ACTIONBUTTON"..self:GetID()), true);
  5.     hotkey:SetText("|cFF00FF00" .. binding or RANGE_INDICATOR .. "|r")
  6.     -- Green text on main action bars ( |cAARRGGBB text |r)
  7. end
  8.  
  9. for i=1, NUM_ACTIONBAR_BUTTONS, 1 do
  10.     local button = _G["ActionButton" .. i]
  11.     hooksecurefunc("ActionButton_UpdateHotkeys",UpdateHotKeys)
  12.     ActionButton_UpdateHotkeys(button)
  13. end
  14.  
  15.  
  16. local function SetHotKeys(self)
  17.     local hotkey = _G[self:GetName().."HotKey"];
  18.     hotkey:SetFont("Fonts\\FRIZQT__.ttf", 12, "THICKOUTLINE")
  19.     local binding = GetBindingText(GetBindingKey("BONUSACTIONBUTTON"..self:GetID()), true);
  20.     hotkey:SetText("|cFFFF0000" .. binding or RANGE_INDICATOR .. "|r")
  21.     -- Red text on pet action bars
  22. end
  23.  
  24. for i=1, NUM_PET_ACTION_SLOTS, 1 do
  25.     local button = _G["PetActionButton" .. i]
  26.     hooksecurefunc("PetActionButton_SetHotkeys",SetHotKeys)
  27.     PetActionButton_SetHotkeys(button)
  28. end

The call after the hook line triggers it straight away, otherwise it won't trigger until you change the hot key via the options. Not sure whether there will be in combat/secure issues but hopefully being done immediately on addon load rather than via event watching means it won't be a problem.

SetTextColor doesn't seem to make a difference at all regardless of where you put it in the code. But, inserting the |c and |r start and end color formatting code sequences seems to work as expected.

atshn 02-21-24 07:40 AM

Appreciate you taking the time to do that. Me and my old eyes thank you. Didn't have much time to test it in combat but did notice that the hotkey text acting as a range indicator on both pet and action bars no longer works.

Xrystal 02-21-24 08:28 AM

Quote:

Originally Posted by atshn (Post 343392)
Appreciate you taking the time to do that. Me and my old eyes thank you. Didn't have much time to test it in combat but did notice that the hotkey text acting as a range indicator on both pet and action bars no longer works.

oh, thought I had that covered with the RANGE_INDICATOR addition if there isn't a hot key set up

You could try using this in the hotkey functions and see if that works better

Lua Code:
  1. if ( binding == "" ) then
  2.    hotkey:SetText(RANGE_INDICATOR);
  3.    hotkey:Hide();
  4. else
  5.    hotkey:SetText("|cFF00FF00" .. binding .. "|r")
  6. end

or simplify it further to

Lua Code:
  1. if ( binding ~= "" ) then
  2.     hotkey:SetText("|cFF00FF00" .. binding .. "|r")
  3. end

atshn 02-21-24 02:43 PM

Perfect. Thanks again, Xrystal!


All times are GMT -6. The time now is 07:46 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI