WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Having issues with secureactionbuttontemplate. (https://www.wowinterface.com/forums/showthread.php?t=57931)

timpoole247 04-12-20 07:41 PM

Having issues with secureactionbuttontemplate.
 
Hi there,

I am currently using the lockdown to finally get round to making my own addon, after 15 years of thinking wouldn't it be nice if I had this addon! Anyway, my experience with Lua is pretty poor, I am reasonably good with basic php so I'm not a complete coding novice.

I am currently making an addon to keep track of my professions on my characters, known patterns, show trainer locations etc etc. So far it has been going well, until I started getting involved with the Enchanting profession! Before I rant on and bore you to death with the details of my struggle, the issue I would like some help with is this; I have a button in my frame which when clicked will open my bags, and cast disenchant. I then discovered its a protected 'spell'. So after doing some googling on the secure template I tried to get it working, but now my button has vanished from the frame. I know the path to my texture works, as it was there before I added the secure template. It could just be weary eyes, but I can't figure out whats wrong with my code.

I would be very grateful is someone could help me with this issue. Here is my code:

Code:

--        Make top frame                               
                                local topfram = CreateFrame("Frame", "topfram", profra);
                                topfram:SetPoint("TOPLEFT", "profra", "TOPLEFT", 5, 0);
                                topfram:SetSize(330, 90);
                               
--        Make button

                                local topframbtn = CreateFrame("Button", "topframbtn", topfram, "SecureActionButtonTemplate");
                                topframbtn:SetSize(22, 22);
                                topframbtn:SetPoint("TOPLEFT", topfram, "TOPLEFT", 5, -10);
                                topframbtn:SetNormalTexture("Interface\\AddOns\\TPPT\\images\\disenchant.blp");
                                --topframbtn.bg = topframbtn:CreateTexture(nil, "BACKGROUND")
                                --topframbtn.bg:SetAllPoints(true)
                                --topframbtn.bg:SetTexture(1, 1, 0, 1);
                               
--        Make text

                                local toptext = topfram:CreateFontString("toptext", "OVERLAY", "GameFontNormal");
                                toptext:SetPoint("TOPLEFT", "topfram", "TOPLEFT", 37, -14);
                                toptext:SetText("Disenchant");

--        On click do this
                               
                                topframbtn:SetAttribute("type", "spell");
                                topframbtn:SetAttribute("spell", "disenchant");
                                -- topframbtn:SetScript("OnClick", function()
                                -- CastSpellByName("disenchant")
                                -- OpenAllBags()
                                -- end)


Fizzlemizz 04-12-20 09:47 PM

Set the button NormalTexture rather than creating a separate icon texture.

This sets it to the standard bag icon.

Code:

btn:SetNormalTexture("Interface/Buttons/Button-Backpack-Up");

-- local icon = btn:CreateTexture(nil, "BACKGROUND");
-- icon:SetAllPoints(true);
-- icon:SetTexture("Interface\\AddOns\\TPPT\\images\\disenchant.blp");
-- icon:SetTexture("Interface/Buttons/Button-Backpack-Up");
-- btn.Texture = icon;

If you can't see the button I would look at the frame supplied as the parent to topfram, "profra" and see where that one has been anchored (and any others that might be further up the chain to the topmost frame which is presumably UIParent)

timpoole247 04-13-20 05:49 AM

It made no difference, apart from making my code shorter and cleaner, which I am grateful for showing me a better way of doing it.

I believe the issue is definitely related to the secure template. If I remove the reference to the template, the button displays correctly. When using framestack the button and all parents are anchored correctly. As soon as I set the secure template, the button vanishes, the parent frame to the button remains visible.

I tried removing the texture and using a solid colour background instead, again no button with the same results from framestack.

kurapica.igas 04-13-20 06:25 AM

Using secure template doesn't mean you can use features like CastSpellByName, the template handle the OnClick for you, so you can only set attributes on the button.

For simple, we can bind the macro to the button:

Lua Code:
  1. btn:SetAttribute("type", "macro")
  2. btn:SetAttribute("macrotext", "/cast disenchant\n/run OpenAllBags()")

timpoole247 04-13-20 07:09 AM

Well according to https://wowwiki.fandom.com/wiki/Secu...ButtonTemplate it is possible. I realise I hadn't commented out my old onclick function, (which is how I discovered disenchant was protected) but the execution of the button isn't my issue. I just can't see the button when using the secure template.

Xrystal 04-13-20 08:11 AM

Hmm, I'm not 100% sure, but I thought I found that the new SecureActionButtonTemplate isn't a visual template just handles the secure elements.

You would have to add in the visual elements or combine it with a visual template.

Granted the following is an XML version but the same thing should apply when creating by code.

Lua Code:
  1. <!-- Buttons that have textures  -->
  2.     <Button name = "XMP_IconTemplate" parentArray = "Buttons" virtual = "true">
  3.         <Size x="30" y="30"/>
  4.         <Layers>
  5.             <Layer level="BACKGROUND">
  6.                 <Texture parentKey="Icon" setAllPoints = "true"/>
  7.             </Layer>
  8.         </Layers>
  9.         <NormalTexture parentKey="NormalTexture" file="Interface\Buttons\UI-EmptySlot" setAllPoints = "true"/>
  10.         <PushedTexture parentKey ="PushedTexture" file="Interface\Buttons\CheckButtonHilight" alphaMode = "ADD" setAllPoints = "true"/>
  11.         <HighlightTexture parentKey = "HighlightTexture" file="Interface\Buttons\CheckButtonHilight"  alphaMode = "ADD" setAllPoints = "true"/>  
  12.     </Button>
  13.  
  14.     <!-- Buttons used to cast spells -->
  15.     <Button name = "XMP_SpellButtonTemplate" inherits = "XMP_IconTemplate,SecureActionButtonTemplate" virtual = "true">
  16.         <Attributes>
  17.             <Attribute name="type" value="spell" />
  18.             <Attribute name="spell" value="0" type="number" />
  19.         </Attributes>
  20.         <Frames>
  21.             <Cooldown inherits="CooldownFrameTemplate" parentKey="Cooldown" />
  22.         </Frames>
  23.     </Button>

As you can see by this my spell button is actually a combination of an icon button template and the secureactionbuttontemplate

As you can see from this link the secureactionbuttontemplate only handles the onclick event
https://www.townlong-yak.com/framexm...eTemplates.xml

So, moving from your old button template to the new button template you have inadvertently removed the visual functionality of the button.

This is a collection of Blizzards ActionButtonTemplates.
https://www.townlong-yak.com/framexm...onTemplate.xml

As you can see these don't have any onclick functionality as Blizzard has separated them.

Xrystal 04-13-20 08:13 AM

Quote:

Originally Posted by timpoole247 (Post 335633)
Well according to https://wowwiki.fandom.com/wiki/Secu...ButtonTemplate it is possible. I realise I hadn't commented out my old onclick function, (which is how I discovered disenchant was protected) but the execution of the button isn't my issue. I just can't see the button when using the secure template.

And for future reference. this is the new info page for wow api information. The other is no longer updated and will likely contain out of date functionality.

https://wow.gamepedia.com/Wowpedia

timpoole247 04-13-20 08:34 AM

Quote:

Originally Posted by Xrystal (Post 335635)
And for future reference. this is the new info page for wow api information. The other is no longer updated and will likely contain out of date functionality.

https://wow.gamepedia.com/Wowpedia

Awesome, thankyou very much.

I have also just solved my issue too; InsecureActionButtonTemplate rather than SecureActionButtonTemplate.

6 hours of trying different things for the sake of 2 letters.


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

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI