WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Can't SetText for HotKey (https://www.wowinterface.com/forums/showthread.php?t=59816)

wmcarlos 03-10-24 01:59 AM

Can't SetText for HotKey
 
I duplicated the slots (ActionButton) from the MainMenuBar by:
Code:

for i = 1, 12 do
    local originalActionButton _G["ActionButton" .. i],
    local duplicateActionButton = CreateFrame("CheckButton", "DuplicateActionButton" .. i, ActionButtons, "ActionBarButtonTemplate")
    duplicateActionButton:SetSize(45, 45)
    if i == 1 then
        duplicateActionButton:SetPoint("LEFT", ActionButtons)
    else
        duplicateActionButton:SetPoint("LEFT", _G["DuplicateActionButton" .. (i - 1)], "RIGHT", 0, 0)
    end
    duplicateActionButton:SetAttribute("action", i); duplicateActionButton:SetAttribute("type", "action")
end



But when trying to assign text to the HotKey..:
Code:

local hotkey = _G["DuplicateActionButton" .. i .. "HotKey"];
hotkey:setFont("Interface\\AddOns\\Testing\\SPRODM__.OTF", 12, "OUTLINE");
hotkey:SetText(GetBindingText(GetBindingKey("ACTIONBUTTON" .. i), "KEY_", 1))



..nothing happens, but the RANGE_INDICATOR disappears for some slots.

I can only assign text in this way:
Code:

local hotkey2 = duplicateActionButton:CreateFontString(nil, "OVERLAY", "GameFontNormal")
hotkey2:SetPoint("TOPRIGHT", -4, -4); hotkey2:SetText(GetBindingText(GetBindingKey("ACTIONBUTTON" .. i), "KEY_", 1))
hotkey2:SetFont("Interface\\AddOns\\Testing\\SPRODM__.OTF", 12, "OUTLINE");



But in this case, it will be a simple text with a fixed color without indicating the range.

I'm in a bit of a stupor because in the game using the command /run DuplicateActionButton9.HotKey:SetText() - the text is changing, but only for those slots where there is a RANGE_INDICATOR.

I've just started learning LUA and WoW API and I don't really have a lot of free time to get into it. If anyone could help me out, that would be great.

P.S.: I've tried to be as concise as possible, but if there's anything else I need to provide, let me know.

Xrystal 03-10-24 03:48 AM

This is code I got from the official action button file and incorporated into my own button.

Lua Code:
  1. -- Get the binding key ( if any ) for this button and display it
  2.     local key = GetBindingKey("CLICK "..DFMB:GetName()..":LeftButton")
  3.     local text = GetBindingText(key, 1)
  4.     if ( text == "" ) then
  5.         DFMB.HotKey:Hide()
  6.     else
  7.         DFMB.HotKey:SetText(text)
  8.         DFMB.HotKey:Show()
  9.     end

This is the part of the official code I based it on.
https://github.com/Gethe/wow-ui-sour...utton.lua#L453

Hopefully it will help see where you might be going wrong. Because my button isn't based on a Blizzard template ( it doesn't have to be a secure frame ) I had to set up the related Binding information such as a localized global string and a Bindings.xml file set up with the binding key chosen by the player.

wmcarlos 03-10-24 05:28 AM

Quote:

Originally Posted by Xrystal (Post 343515)
This is code I got from the official action button file and incorporated into my own button.

Lua Code:
  1. -- Get the binding key ( if any ) for this button and display it
  2.     local key = GetBindingKey("CLICK "..DFMB:GetName()..":LeftButton")
  3.     local text = GetBindingText(key, 1)
  4.     if ( text == "" ) then
  5.         DFMB.HotKey:Hide()
  6.     else
  7.         DFMB.HotKey:SetText(text)
  8.         DFMB.HotKey:Show()
  9.     end

This is the part of the official code I based it on.
https://github.com/Gethe/wow-ui-sour...utton.lua#L453

Hopefully it will help see where you might be going wrong. Because my button isn't based on a Blizzard template ( it doesn't have to be a secure frame ) I had to set up the related Binding information such as a localized global string and a Bindings.xml file set up with the binding key chosen by the player.

Oh yeah, thanks a lot!


All times are GMT -6. The time now is 12:32 AM.

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