WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   SecureHandlerClickTemplate vs SecureActionButtonTemplate (https://www.wowinterface.com/forums/showthread.php?t=59658)

scottingram 08-30-23 06:53 PM

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

scottingram 08-30-23 10:42 PM

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)

SDPhantom 08-30-23 10:42 PM

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)

scottingram 08-30-23 10:44 PM

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)

SDPhantom 08-30-23 10:48 PM

SecureActionButtonTemplate can run SecureHandlerClickTemplate scripts, but SecureHandlerClickTemplate can't perform SecureActionButtonTemplate actions.

scottingram 08-30-23 11:31 PM

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
Quote:

self:SetFrameRef("flyoutMenu", self.flyoutMenu)
with
Quote:

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 ?

SDPhantom 08-31-23 02:04 PM

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

scottingram 09-01-23 01:17 AM

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!

SDPhantom 09-01-23 10:50 PM

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

scottingram 09-02-23 04:46 PM

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.


All times are GMT -6. The time now is 07:14 AM.

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