WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   PTR General Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=172)
-   -   SecureActionButtonTemplate with macrotext attribute not working (https://www.wowinterface.com/forums/showthread.php?t=59225)

Zax 09-19-22 12:41 AM

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.

SDPhantom 09-19-22 01:41 PM

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").

Zax 09-20-22 06:06 AM

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.

Dridzt 09-20-22 08:50 AM

Could it simply be a case of some script functionality not being enabled on the alpha/beta whatever 10 is atm?

SDPhantom 09-20-22 06:18 PM

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.

Zax 09-21-22 12:36 AM

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.

SDPhantom 09-21-22 06:08 PM

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".



Quote:

Originally Posted by Zax (Post 341050)
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.)

Zax 09-22-22 06:17 AM

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 :D).

Xrystal 09-22-22 07:23 AM

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)

Zax 09-22-22 08:07 AM

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.

SDPhantom 09-22-22 11:48 AM

Quote:

Originally Posted by Zax (Post 341068)
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")


Quote:

Originally Posted by Zax (Post 341068)
Also, I believe the code you found concerns the raid markers (placed on units) and not the ground markers (placed on... the ground :D).

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



Quote:

Originally Posted by Xrystal (Post 341069)
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.

Xrystal 09-22-22 03:56 PM

Quote:

Originally Posted by Zax (Post 341070)
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.

Xrystal 09-22-22 03:58 PM

Quote:

Originally Posted by Zax (Post 341070)
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 :ponders:

Zax 09-23-22 03:01 AM

OK, I'm now able to /sit :banana:
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 09-24-22 03:14 AM

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?

Xrystal 09-24-22 04:39 AM

try the shift- on the type statement

As in btn:SetAttribute("shift-type1", "macro")

Zax 09-24-22 06:30 AM

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 09-24-22 12:50 PM

Quote:

Originally Posted by Zax (Post 341088)
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 :)

Arcinde 09-25-22 06:09 PM

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.


All times are GMT -6. The time now is 08:05 AM.

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