WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   How to build custom pet action buttons? (https://www.wowinterface.com/forums/showthread.php?t=50010)

Duugu 10-06-14 06:01 PM

How to build custom pet action buttons?
 
I would like to create some pet action buttons.

I'm using secure buttons with type/pet and action/1-10, which is working as expected.
But ... of course my custom buttons do not provide the right click functionality of the Blizzard pet buttons (enable/disable autocast if spell).

I can't figure out how I could add this. The Bilzzard stuff is:
Lua Code:
  1. function PetActionButton_OnClick (self, button)
  2.     if ( button == "LeftButton" ) then
  3.         CastPetAction(self:GetID());
  4.     else
  5.         TogglePetAutocast(self:GetID());
  6.     end
  7. end
TogglePetAutocast is protected. :/
The only thing I could use is the macro
Code:

/petautocasttoggle <spellname>
But obv. I can't query the spell name from the pet bar action button within my secure buttons code.

Is there really no option to use pet action buttons except re-using the Blizzard buttons??

Lombra 10-06-14 06:56 PM

You have a few options. For one, I believe you can actually inherit the pet button template and then set the IDs on all buttons. I think Bartender does that for shapeshift buttons. The more waterproof solution would be to either bind the right click to macrotext attribute /petautocasttoggle... or, not sure how that'll work if it only takes names. Anyway, you can also just a click attribute on the whole button to click the default button.

Duugu 10-06-14 07:04 PM

Hey, thanks Lombra. That sounds good. :)

Quote:

Originally Posted by Lombra (Post 297477)
The more waterproof solution would be to either bind the right click to macrotext attribute /petautocasttoggle... or, not sure how that'll work if it only takes names.

It only accepts names ... no IDs. But I can't access either names nor IDs of the pet action spells in my secure code. And this would be mandatory as pets could be called/dismissed in combat. :(

Quote:

Originally Posted by Lombra (Post 297477)
Anyway, you can also just a click attribute on the whole button to click the default button.

Wow. That's it. :D So simple. Thanks again. I'll do it that way.

[e]
Hm. On a second thought ... it has to be a right click to trigger the autocast on/off thing. :/

I've not tested it right now, but I'm almost sure that inheriting from the pet template will introduce a lot of new problems.

[e2]
Wouldn't a button that inherits vom PetActionButtonTemplate be blocked too if TogglePetAutocast(self:GetID()) is called on click?

[e3]
I'm just realizing that /click passes the mouse buttons to the target button. :)
I'll try it tomorrow. Thanks again.

Lombra 10-07-14 03:39 AM

Quote:

Originally Posted by Duugu (Post 297478)
[e2]
Wouldn't a button that inherits vom PetActionButtonTemplate be blocked too if TogglePetAutocast(self:GetID()) is called on click?

Apparently not, unless that all has changed. Because the OnClick was set securely, and the function is secure, or something. But yeah it's possible that it may introduce other problems. /click should be the best solution if it works and if the target buttons' OnClick scripts doesn't do unwanted stuff.

Duugu 10-07-14 11:00 AM

Ok, I got this working now. It's even more complicated and stupid than I thought.

"type/click" expects a object in "clickbutton". It doesn't work with a frame name. :/
In my secure code PetActionButtonx obv. isn't a valid reference.
So I tried to pre-set a frame reference via unsecure code. Like
Lua Code:
  1. BABHeader:SetFrameRef("PetActionButton1", _G["PetActionButton1"])
Then I tried to use this in my secure code:
Lua Code:
  1. local tbutton = self:GetFrameRef("BABHeader"):GetFrameRef("PetActionButton1")
  2. print(tbutton:GetName())
  3. self:SetAttribute("type2", "click")
  4. self:SetAttribute("clickbutton2", tbutton)
Which printed the string "PetActionButton1" and as a total surprise triggered the error
Quote:

6x FrameXML\SecureTemplates.lua:542: attempt to call method "IsForbidden" (a nil value)
on a right click. :D

Must be another bug within the secure button stuff (see http://www.wowinterface.com/forums/s...493#post297493)
Seems as I have to set the clickbutton2/frameref thing via unsecure code. :/

Lombra 10-07-14 11:49 AM

Quote:

Originally Posted by Duugu (Post 297492)
In my secure code PetActionButtonx obv. isn't a valid reference.

Why do you need to do it securely?

Duugu 10-07-14 12:00 PM

I would like to build a bar that supports dragging pet buttons in combat and states that change the button actions.

Like
state 1 = type/spell
state 2 = type/pet

To do this I have to set the buttons type attribute at OnStateChanged.
And to fully support type/pet on a state change I'll have to securely set type2/clickbutton2 to the actual pet bar button ... which is not possible due to the broken GetFrameRef() function. :/

Whatever ... I'll skip that and use a "fixed" pet bar. It's not worth the trouble.


All times are GMT -6. The time now is 05:41 PM.

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