Thread Tools Display Modes
08-30-23, 06:53 PM   #1
scottingram
A Murloc Raider
Join Date: Aug 2023
Posts: 7
SecureHandlerClickTemplate vs SecureActionButtonTemplate

My addon lets you create and put custom flyouts on your action bars.

The "main" button that sits on the action bar and opens/closes the flyout uses
̶S̶e̶c̶u̶r̶e̶A̶c̶t̶i̶o̶n̶B̶u̶t̶t̶o̶n̶T̶e̶m̶p̶l̶a̶t̶e̶ [EDIT] SecureHandlerClickTemplate with its SetFrameRef("flyoutRef", theFlyoutFrame) and flyoutRef:Show() / Hide()

The buttons on the flyout all use SecureActionButtonTemplate to cast the spells, summon pets, consume items, etc. via SetAttribute("type", "spell") etc etc.

My question: Can I get my "main" button to cast a spell, summon a pet, do any of the Restricted actions available to SecureActionButtonTemplate. (Goal: a right click on the "main" button will perform the action of the first of the flyout buttons).

I tried SetFrameRef("btn1", theFirstButton) but it's been pruned of its Click() method. I've tried mainBtn:SetAttribute("type", "spell") etc but I find that SecureHandlerClickTemplate lacks any of that magic. I've tried CastSpellById() inside the mainBtn:SetAttribute("_onclick", "bunch of lua code") but the Restricted Env does not provide that method.

Help please :-)

Last edited by scottingram : 08-30-23 at 10:40 PM.
  Reply With Quote
08-30-23, 10:42 PM   #2
scottingram
A Murloc Raider
Join Date: Aug 2023
Posts: 7
thanks for the reply! and OOPS! I made a copy/paste mistake in my original post. I said that the "main" button is a SecureActionButtonTemplate but I meant SecureHandlerClickTemplate. (I've gone fixed the original post with an edit)
  Reply With Quote
08-30-23, 10:42 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
SecureActionButtonTemplate supports using a custom type attribute to run a SecureHandler script.

Lua Code:
  1. button:SetAttribute("type1","customscript");-- Can be anything as long as it isn't one of the predefined actions
  2. button:SetAttribute("_customscript",[[-- Attribute name here must match the value of the "type" attribute above prefixed with "_"
  3.     -- Do something
  4. ]]);



(This post was meant to replace my previous one as a better option)
__________________
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
08-30-23, 10:44 PM   #4
scottingram
A Murloc Raider
Join Date: Aug 2023
Posts: 7
Thanks so much for the reply! But, I think I posted a reply to your reply as your were editing / deleting it and now it looks like I replied to myself. Anyway, for clarity I'll repeat it here... I made a copy/paste mistake in my original post. I said that the "main" button is a SecureActionButtonTemplate but I meant SecureHandlerClickTemplate. (I've gone fixed the original post with an edit)
  Reply With Quote
08-30-23, 10:48 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
SecureActionButtonTemplate can run SecureHandlerClickTemplate scripts, but SecureHandlerClickTemplate can't perform SecureActionButtonTemplate actions.
__________________
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
08-30-23, 11:31 PM   #6
scottingram
A Murloc Raider
Join Date: Aug 2023
Posts: 7
I tried to use SecureActionButtonTemplate

I changed my code from:
Code:
    local protoGerm = CreateFrame("CheckButton", myName, parent, "SmallActionButtonTemplate, SecureHandlerClickTemplate")
to
Code:
    local protoGerm = CreateFrame("CheckButton", myName, parent, "SmallActionButtonTemplate, SecureActionButtonTemplate")
but it breaks
self:SetFrameRef("flyoutMenu", self.flyoutMenu)
with
Message: Interface/AddOns/UFO/Germ.lua:167: attempt to call method 'SetFrameRef' (a nil value)
��

As a SecureHandlerClickTemplate it can flyoutMenu:Show() & Hide()

Can you suggest some alternative approach to accomplish Show()/Hide() with a SecureActionButtonTemplate ?

Last edited by scottingram : 08-30-23 at 11:37 PM.
  Reply With Quote
08-31-23, 02:04 PM   #7
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
It looks like :SetFrameRef() is inherited from SecureHandlerTemplate. This is the base template that the other handler templates inherit from and only uses an OnLoad script that assigns this function. You can add it to your inherit list yourself and it should work.

Code:
local protoGerm = CreateFrame("CheckButton", myName, parent, "SecureHandlerTemplate, SmallActionButtonTemplate, SecureActionButtonTemplate")
__________________
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-01-23, 01:17 AM   #8
scottingram
A Murloc Raider
Join Date: Aug 2023
Posts: 7
Thanks for your suggestions, insights, and time!

TLDR:

I'm using the _customscript facility of SecureActionButtonTemplate (thanks!) but have forsaken the evil Get/SetFrameRef of SecureHandlerClickTemplate. Instead, I am getting the flyout by rummaging through the children... which also presented a final(?) sadistic "fuck you" in that self:GetChildren()[1] isn't OK but you've gotta do table.new(self:GetChildren())[1] because reasons!


TL:

It didn't work even after mushing all the various FooBarSecureClickyWickyButtonHandyTemplates as you suggested. Yes, it did indeed make the GetFrameRef method available... but in a "hahaha, fooled you again!" way. GetFrameRef("flyout") == nil.

I've managed to get a proof of concept working with your help. Thank you! After I stop bleeding from running into brick wall after brick wall, I'll apply what I've learned to my addon and let you know how it goes.

thanks!
  Reply With Quote
09-01-23, 10:50 PM   #9
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
:GetChildren() doesn't return a table array of children. It returns multiple values, each one an independent pointer to each child object.

If you include a function in an expression, it always grabs the first return and discards everything else. When Lua gets to your index operation, it tries to run it on the child that happened to have been grabbed. There's likely to be nothing there, so this would result in nil.

An exception to this is if a function call is the last in a list of expressions or parameters to a function call. For example, table.new(self:GetChildren()) passes all children to table.new(), which then creates a table containing all the children. This is equivalent to wrapping it in a table constructor like {self:GetChildren()}

Note table.new() is from the RestrictedTables implementation and only exists within the RestrictedEnvironment.
__________________
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-01-23 at 11:30 PM.
  Reply With Quote
09-02-23, 04:46 PM   #10
scottingram
A Murloc Raider
Join Date: Aug 2023
Posts: 7
Oh, right! Thanks. I think I ran into that a few months ago as {foo:GetChildren()} , dealt with my surprise, and then forgot about it. Thanks for the reminder. Memory efficiency above all else is definitely a Lua thing.

I never ever thought I would say this, but I miss strongly typed languages now.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » SecureHandlerClickTemplate vs SecureActionButtonTemplate


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