Thread Tools Display Modes
09-19-22, 12:41 AM   #1
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
SecureActionButtonTemplate with macrotext attribute not working

None of my secure buttons with macrotext attribute are working on PTR 10.x

In the main XML file (MyAddon.xml):
Code:
<Frame name="npcm_frameMain" frameStrata="BACKGROUND" virtual="false" hidden="true" resizable="true" parent="UIParent" inherits="SecureHandlerStateTemplate">

In the main lua file (MyAddon.lua):
Lua Code:
  1. local button = CreateFrame("Button", "secureBtnTest", npcm_frameMain, "SecureActionButtonTemplate")
  2. button:SetSize(32,32)
  3. button:SetPoint("LEFT", npcm_frameMain, "RIGHT", 300, 0)
  4. local texture = button:CreateTexture("$parent_tex", "BACKGROUND")
  5. texture:SetAllPoints(true)
  6. texture:SetTexture(GetSpellTexture("Forme de Voyage"))
  7. button.texture = texture
  8.    
  9. button:SetAttribute("type", "macro")
  10. button:SetAttribute("macrotext", "/sit")
  11. button:SetScript("PostClick", function(self, arg1)
  12.     print(self:GetName(), arg1, self:GetAttribute("macrotext"))--testing
  13. end)

Nothing happens when the button is clicked (and no error message nor warning about blocked action).
Thank you for your help.
__________________
Zax - Addons List, not all maintained.
  Reply With Quote
09-19-22, 01:41 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
You still need to call Button:RegisterForClicks() for the OnClick handler to work.

It's also good practice to make sure Frame:EnableMouse() or Frame:SetMouseClickEnabled() is set.
Frame:EnableMouse() is a legacy function that controls both clicks and mouseover while Frame:SetMouseClickEnabled() and Frame:SetMouseMotionEnabled() individually control each of their respective features.

On a side note, you don't need a SecureActionButton to send /sit. It's processed as an emote using the "SIT" and DoEmote() is not protected. You can run it as DoEmote("SIT").
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 09-19-22 at 02:00 PM.
  Reply With Quote
09-20-22, 06:06 AM   #3
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
I understand the value of following good practices, but as far as I know a frame defined as "button" handles mouseClick by default.

Anyhow, I tested with button:SetMouseClickEnabled() without success.
PostClick script works, so the button is active and correctly responds to clicks. The problem comes from:
Lua Code:
  1. button:SetAttribute("type", "macro")
  2. button:SetAttribute("macrotext", "/sit")

Concerning the macro itself (/sit), it's just a basic example used in my tests.
As the buttons in part of my addon NPCsMarker, the real macro is something like "/wm 1" or "/cwm 1" to place or clear ground markers.
__________________
Zax - Addons List, not all maintained.
  Reply With Quote
09-20-22, 08:50 AM   #4
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,359
Could it simply be a case of some script functionality not being enabled on the alpha/beta whatever 10 is atm?
  Reply With Quote
09-20-22, 06:18 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
You still didn't address Button:RegisterForClicks(), which tells the button what clicks to look for (Left, Right, Middle, etc.) If you don't register any, it won't know what to listen for and therefore won't work.

This is a separate function from just telling a frame it should react to mouse events.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
09-21-22, 12:36 AM   #6
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
To be sure, I just tested with Button:RegisterForClicks() without success.

Lua Code:
  1. button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
  2. button:SetMouseClickEnabled(true)
I think the PostClick script wouldn't be executed if the Click was ignored.
__________________
Zax - Addons List, not all maintained.

Last edited by Zax : 09-21-22 at 12:40 AM.
  Reply With Quote
09-21-22, 06:08 PM   #7
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Here's the OnClick handler on PTR.

Lua Code:
  1. function SecureActionButton_OnClick(self, inputButton, down, isKeyPress)
  2.     local pressAndHoldAction = SecureButton_GetAttribute(self, "pressAndHoldAction");
  3.     local useOnKeyDown = GetCVarBool("ActionButtonUseKeyDown") or pressAndHoldAction;
  4.     local clickAction = (down and useOnKeyDown) or (not down and not useOnKeyDown);
  5.     local releasePressAndHoldAction = (not down) and (pressAndHoldAction or GetCVarBool("ActionButtonUseKeyHeldSpell"));
  6.  
  7.     if clickAction then
  8.         OnActionButtonClick(self, inputButton, down, isKeyPress);
  9.         return true;
  10.     elseif releasePressAndHoldAction then
  11.         OnActionButtonPressAndHoldRelease(self, inputButton, isKeyPress);
  12.         return true;
  13.     end
  14.  
  15.     return false;
  16. end
-FrameXML\SecureTemplates.lua:730

Basically, the handler is looking for either an up or down click event specifically according to how the ActionButtonUseKeyDown CVar is set. If it never gets the matching click event, the code never runs. It's probably a good idea to register both up and down click events for every button you intend to respond to. If you don't care about registering individual buttons, you can use "AnyUp" and "AnyDown".



Originally Posted by Zax View Post
the real macro is something like "/wm 1" or "/cwm 1" to place or clear ground markers.
This code clip may be of interest to you.
Lua Code:
  1. SECURE_ACTIONS.worldmarker =
  2.     function(self, unit, button)
  3.         local marker = tonumber(SecureButton_GetModifiedAttribute(self, "marker", button));
  4.         local action = SecureButton_GetModifiedAttribute(self, "action", button) or "toggle";
  5.         if ( action == "set" ) then
  6.             PlaceRaidMarker(marker or 1);
  7.         elseif ( action == "clear" ) then
  8.             ClearRaidMarker(marker);
  9.         elseif ( action == "toggle" ) then
  10.             marker = marker or 1;
  11.             if ( IsRaidMarkerActive(marker) ) then
  12.                 ClearRaidMarker(marker);
  13.             else
  14.                 PlaceRaidMarker(marker);
  15.             end
  16.         end
  17.     end;
-FrameXML\SecureTemplates.lua:589

This defines type "worldmarker" with parameters "marker" and "action".
As with any other attribute fetched by SecureButton_GetModifiedAttribute(), you can append the attribute name (not the value) with a number representing the mouse button to bind to (1=Left, 2=Right, 3=Middle, etc.)
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 09-21-22 at 06:30 PM.
  Reply With Quote
09-22-22, 06:17 AM   #8
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
Interesting, SDPhantom. Thank you.

I have to say that I'm not sure how to adapt my code based on what you found.
As a reminder, I use the following basic code for a button with a macrotext attribute. It works fine on WoW 9.x:

Lua Code:
  1. local frame = CreateFrame("Frame", "Test", UIParent, "SecureHandlerStateTemplate")
  2.     frame:SetSize(40, 40)
  3.     frame:SetPoint("TOPLEFT", UIParent, 10, -150)
  4.  
  5.     local button = CreateFrame("Button", "TestBtn", frame, "SecureActionButtonTemplate")
  6.     button:ClearAllPoints()
  7.     button:SetSize(32, 32)
  8.     button:SetPoint("CENTER", frame)
  9.     local texture = button:CreateTexture("$parent_tex", "BACKGROUND")
  10.     texture:SetAllPoints(true)
  11.     texture:SetTexture(GetSpellTexture(783)) -- "Travel Form"
  12.     button.texture = texture
  13.  
  14.     button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
  15.     button:SetMouseClickEnabled(true)
  16.     button:SetAttribute("type", "macro")
  17.     button:SetAttribute("macrotext", "/abs")
  18.    
  19.     ------ testing purpose
  20.     button:SetScript("PostClick", function(self, arg1)
  21.         print("POSTCLICK: Clicked button=", self:GetName(), "  macroTxt=", self:GetAttribute("macrotext"))
  22.     end)
  23. end

Also, I believe the code you found concerns the raid markers (placed on units) and not the ground markers (placed on... the ground ).
__________________
Zax - Addons List, not all maintained.
  Reply With Quote
09-22-22, 07:23 AM   #9
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Based on the example on this page
https://wowpedia.fandom.com/wiki/Sec...ButtonTemplate

Have you tried changing type and macrotext to type1 and macrotext1 for left button click as these are attributes as SDPhantom mentioned. Although, I think ( not 100% sure ), that left button is default so maybe macrotext with no number is treated as macrotext1 :shrugs:

Just tested this version of your code using your original sit test on the PTR just now ( there was a big update ) and it worked

Lua Code:
  1. local frame = CreateFrame("Frame", "Test", UIParent, "SecureHandlerStateTemplate")
  2. frame:SetSize(40, 40)
  3. frame:SetPoint("TOPLEFT", UIParent, 10, -150)
  4.  
  5. local button = CreateFrame("Button", "TestBtn", frame, "SecureActionButtonTemplate")
  6. button:ClearAllPoints()
  7. button:SetSize(32, 32)
  8. button:SetPoint("CENTER", frame)
  9. local texture = button:CreateTexture("$parent_tex", "BACKGROUND")
  10. texture:SetAllPoints(true)
  11. texture:SetTexture(GetSpellTexture(783)) -- "Travel Form"
  12. button.texture = texture
  13.  
  14. button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
  15. button:SetMouseClickEnabled(true)
  16. button:SetAttribute("type1", "macro")
  17. button:SetAttribute("macrotext1", "/sit")
  18.  
  19. ------ testing purpose
  20. button:SetScript("PostClick", function(self, arg1)
  21.     print("POSTCLICK: Clicked button=", self:GetName(), "  macroTxt=", self:GetAttribute("macrotext1"))
  22. end)
__________________

Last edited by Xrystal : 09-22-22 at 07:43 AM.
  Reply With Quote
09-22-22, 08:07 AM   #10
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
Just copy/pasted your code Xrystal (after 2 PTR updates) but if it correctly print the PostClick, the macro (/sit or /abs) wasn't executed.
So, I'm a little bit confused... and still standing

Are you able to sit down with the code you posted? Or maybe we'll have another PTR server update in Europe.
__________________
Zax - Addons List, not all maintained.
  Reply With Quote
09-22-22, 11:48 AM   #11
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Zax View Post
I have to say that I'm not sure how to adapt my code based on what you found.
As for Button:RegisterForClicks(), change this
Code:
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
to either of these
Code:
button:RegisterForClicks("LeftButtonUp", "LeftButtonDown", "RightButtonUp", "RightButtonDown")
Code:
button:RegisterForClicks("AnyUp", "AnyDown")


Originally Posted by Zax View Post
Also, I believe the code you found concerns the raid markers (placed on units) and not the ground markers (placed on... the ground ).
RaidTarget is what's placed on units and WorldMarker is placed on the ground. RaidTargets aren't protected, so they don't need a SecureActionButton to set.

RaidTargets are set by SetRaidTarget() while WorldMarkers have PlaceRaidMarker() and ClearRaidMarker().
(WoWPedia doesn't have an API page on the WorldMarker functions)

Here's an example of your button configured for this.
Lua Code:
  1. button:SetMouseClickEnabled(true);--    Make sure OnClick is enabled
  2. button:RegisterForClicks("AnyUp","AnyDown");--  Listen for all mouse buttons (Both up and down are required for SecureActionButtonTemplate)
  3.  
  4. button:SetAttribute("type","worldmarker");--    Perform "WorldMarker" action
  5. button:SetAttribute("marker",1);--  Use marker index 1
  6. button:SetAttribute("action1","toggle");--  Set left button to toggle
  7. button:SetAttribute("action2","clear");--   Set right button to force clear



Originally Posted by Xrystal View Post
Although, I think ( not 100% sure ), that left button is default so maybe macrotext with no number is treated as macrotext1 :shrugs:
The default without the number suffix is to run on any button. Specifying one is useful if you want the same SecureActionButton to perform different actions depending on what mouse button you click it with and/or what modifier keys are held.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 09-22-22 at 12:07 PM.
  Reply With Quote
09-22-22, 03:56 PM   #12
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Originally Posted by Zax View Post
Just copy/pasted your code Xrystal (after 2 PTR updates) but if it correctly print the PostClick, the macro (/sit or /abs) wasn't executed.
So, I'm a little bit confused... and still standing

Are you able to sit down with the code you posted? Or maybe we'll have another PTR server update in Europe.

Yes, I was able to sit down on the 10.0 PTR with that code, and the print statement was displayed as well.
__________________
  Reply With Quote
09-22-22, 03:58 PM   #13
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Originally Posted by Zax View Post
Just copy/pasted your code Xrystal (after 2 PTR updates) but if it correctly print the PostClick, the macro (/sit or /abs) wasn't executed.
So, I'm a little bit confused... and still standing

Are you able to sit down with the code you posted? Or maybe we'll have another PTR server update in Europe.
That is actually a good thought.
I have a US account despite being in the UK and I had an update this morning ( UK time ) but my brother who has a UK account hasn't noticed any dragonflight changes on his PTR. I wonder if there is some sort of difference between the two regions onders:
__________________
  Reply With Quote
09-23-22, 03:01 AM   #14
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
OK, I'm now able to /sit
SDPhantom is right: both up and down listener are required for SecureActionButtonTemplate.

EDIT:
As PostClick debugging is now printed twice, I had to add a test before performing PostClick actions.

This is the actual /sit button. I'll test with ground markers this evening and keep you informed.

Lua Code:
  1. local frame = CreateFrame("Frame", "Test", UIParent, "SecureHandlerStateTemplate")
  2.     frame:SetSize(40, 40)
  3.     frame:SetPoint("TOPLEFT", UIParent, 10, -150)
  4.      
  5.     local button = CreateFrame("Button", "TestBtn", frame, "SecureActionButtonTemplate")
  6.     button:ClearAllPoints()
  7.     button:SetSize(32, 32)
  8.     button:SetPoint("CENTER", frame)
  9.     local texture = button:CreateTexture("$parent_tex", "BACKGROUND")
  10.     texture:SetAllPoints(true)
  11.     texture:SetTexture(GetSpellTexture(783)) -- "Travel Form"
  12.     button.texture = texture
  13.  
  14.     button:SetMouseClickEnabled(true) -- Make sure OnClick is enabled
  15.     --button:RegisterForClicks("LeftButtonUp", "LeftButtonDown", "RightButtonUp", "RightButtonDown")
  16.     -- button:RegisterForClicks("AnyUp", "AnyDown") -- up and down required for SecureActionButtonTemplate
  17.     button:RegisterForClicks("LeftButtonUp", "LeftButtonDown") -- up and down required for SecureActionButtonTemplate
  18.    
  19.     button:SetAttribute("type", "macro")
  20.     button:SetAttribute("macrotext1", "/sit")
  21.      
  22.     ------ testing purpose
  23.     button:SetScript("PostClick", function(self, btn, down)
  24.         if (down) then print("POSTCLICK: Clicked button=", self:GetName(), "  btn=", btn, "  down=", down, "  macroTxt=", self:GetAttribute("macrotext1")) end
  25.     end)
__________________
Zax - Addons List, not all maintained.

Last edited by Zax : 09-23-22 at 03:11 AM.
  Reply With Quote
09-24-22, 03:14 AM   #15
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
OK, placing Ground Markers works fine.
Thank you SDPhantom, you saved my addon

I have a specific icon to delete placed ground marker, so I don't use the right-click on marker's button.
But I used shift to trigger another macro (insert marker's icon in the opened chat box, but "/sit" to simplify in the following example:

Lua Code:
  1. button:SetAttribute("shift-macrotext1", "/sit")

This code is no longer working. Can you tell how to add a shift-clic macro to your code?
__________________
Zax - Addons List, not all maintained.
  Reply With Quote
09-24-22, 04:39 AM   #16
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
try the shift- on the type statement

As in btn:SetAttribute("shift-type1", "macro")
__________________
  Reply With Quote
09-24-22, 06:30 AM   #17
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
OK.

I still have an annoying problem: as the up and down mouse button are registered, it triggers the action twixe.
I can handle this on the PostClick script with the third argument, but I don't know how to handle the main action - the one defined as a shit-click macro.

For example, line #6 is executed twice

Lua Code:
  1. btnMarker:SetMouseClickEnabled(true) -- Make sure OnClick is enabled
  2.         btnMarker:RegisterForClicks("LeftButtonUp", "LeftButtonDown") -- up and down required for SecureActionButtonTemplate
  3.         btnMarker:SetAttribute("type", "macro")
  4.         local macroStr = format("/wm %d", markersOrder[i]) -- place ground marker #i
  5.         btnMarker:SetAttribute("macrotext1", macroStr)
  6.         btnMarker:SetAttribute("shift-macrotext1", "/say TESTING") -- executed twice !!!!!!!!
  7.         btnMarker:SetScript("PostClick", function(self, btn, isDown)
  8.             if (not isDown) then -- execute only when down
  9.                 if (not IsModifierKeyDown()) then
  10.                     -- do some stuff when mouseDown with modifier key
  11.                 end
  12.             end
  13.         end)

BTW, it's for NPCsMarker, a RP addon.
__________________
Zax - Addons List, not all maintained.
  Reply With Quote
09-24-22, 12:50 PM   #18
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
Originally Posted by Zax View Post
For example, line #6 is executed twice
My bad, it's executed twice on Retail, and only once on PTR.
So, all is OK. Thank you all
__________________
Zax - Addons List, not all maintained.
  Reply With Quote
09-25-22, 06:09 PM   #19
Arcinde
A Defias Bandit
Join Date: Jun 2017
Posts: 3
I had a similar confusing situation that was due to having a different setting of cvar `ActionButtonUseKeyDown` on retail vs beta. If `ActionButtonUseKeyDown` is off then `AnyDown` will not work at all.
  Reply With Quote

WoWInterface » PTR » PTR General Discussion » SecureActionButtonTemplate with macrotext attribute not working

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off