Thread Tools Display Modes
08-31-16, 07:15 AM   #1
dragonflyy
An Aku'mai Servant
 
dragonflyy's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 32
Copy a button

I have an addon that is a popup for battle pets. See PetBattleJunkie. I have a button on there that casts the Pet heal that has an 8 minute cooldown. Have most of it there, just doesn't have a tooltip. I know I can add the tooltip myself but I got to thinking, is it possible to copy the PetJournalHealPetButton that is in the standard WoW interface? If so, would make it easier to create the button (just copy and go).
  Reply With Quote
08-31-16, 08:06 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
There is no "copy a frame" function in the WoW API. If you want to create a button that's exactly like another button, you have to do it the long way. Create a frame of the same type (eg. "Button") that inherits from the same template (if any) and then set all the same properties, create all the same children and regions, give them the same properties, etc.

In this particular case, you actually can't use a 100% duplicate of the PetJournalPetHealButton because it calls "CastSpellByID" in an OnClick script, but an addon isn't allowed to do that. You'll need to inherit from "SecureActionButtonTemplate" instead of "SecureFrameTemplate" and then use attributes instead of an OnClick script:

myButton:SetAttribute("type", "spell")
myButton:SetAttribute("spell", GetSpellInfo(125439))


If you already have a button and just want to add a tooltip, you can just reuse the tooltip functions from the Blizzard button:

myButton.spellID = 125439
myButton:SetScript("OnEnter", PetJournalHealPetButton_OnEnter)
myButton:SetScript("OnLeave", GameTooltip_Hide)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 08-31-16 at 08:08 AM.
  Reply With Quote
08-31-16, 12:39 PM   #3
dragonflyy
An Aku'mai Servant
 
dragonflyy's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 32
Originally Posted by Phanx View Post
There is no "copy a frame" function in the WoW API. If you want to create a button that's exactly like another button, you have to do it the long way. Create a frame of the same type (eg. "Button") that inherits from the same template (if any) and then set all the same properties, create all the same children and regions, give them the same properties, etc.

In this particular case, you actually can't use a 100% duplicate of the PetJournalPetHealButton because it calls "CastSpellByID" in an OnClick script, but an addon isn't allowed to do that. You'll need to inherit from "SecureActionButtonTemplate" instead of "SecureFrameTemplate" and then use attributes instead of an OnClick script:

myButton:SetAttribute("type", "spell")
myButton:SetAttribute("spell", GetSpellInfo(125439))


If you already have a button and just want to add a tooltip, you can just reuse the tooltip functions from the Blizzard button:

myButton.spellID = 125439
myButton:SetScript("OnEnter", PetJournalHealPetButton_OnEnter)
myButton:SetScript("OnLeave", GameTooltip_Hide)
Thanks much
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Copy a button

Thread Tools
Display Modes

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