View Single Post
02-14-15, 08:27 PM   #17
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Malsomnus View Post
I don't understand all of the code (specifically the attributes *macrotext31and macrotext1, what do those mean?) ...
Some basics:
Code:
button:SetAttribute("type", "spell")
button:SetAttribute("spell", "Frostbolt")
^ This button will cast Frostbolt no matter which mouse button you click on it.

Code:
button:SetAttribute("type", "spell")
button:SetAttribute("type1", "Frostbolt")
button:SetAttribute("type2", "Fireball")
^ This button will cast Frostbolt when left-clicked (button1) or Fireball when right-clicked (button2).

Code:
button:SetAttribute("type", "macro")
button:SetAttribute("macrotext", "/cast Frostbolt")
^ Same as example #1, but using a macro command instead of a spell.

Code:
button:SetAttribute("type", "macro")
button:SetAttribute("macrotext1", "Frostbolt")
button:SetAttribute("macrotext2", "Fireball")
^ Same as example #2, but using macro commands instead of spells.

In Semlar's code:

Code:
macro:RegisterForClicks('AnyUp', 'AnyDown')
^ This tells the button to respond to both mousedown and mouseup events.

Code:
macro:SetAttribute('downbutton', 'Button31')
^ This tells the button to treat all mousedown events as if they were triggered by pressing button31. WoW supports up to 32 mouse buttons, but I don't think any of the "gaming" mice it supports actually have 32 buttons (???) so the only real use for these high-numbered buttons is in secure attribute trickery like this.

Code:
macro:WrapScript(macro, 'OnClick', [[ <snip> ]])
^ This provides secure snippets to be run before and/or after the button's original OnClick handler. In this case, only a "before" snippet is given. Basically this is setting a PreClick script, but using the secure handler API instead. (See here for the internal implementation.)

Code:
self:SetAttribute('*macrotext31', '/click ' .. parent .. ' ' .. button .. '\n/click StaticPopup1Button1')
^ This tells the button what to do when it receives a click from button31. Since we're in (effectively) a PreClick script, the current mousedown event hasn't been handled yet.

Code:
self:SetAttribute('macrotext1', '/click PlayerTalentFrameTalentsLearnButton\n/use [nomounted] !Trap Launcher')
^ This tells the button what to do when it recieves a click from button1. (I have no idea why Trap Launcher is mentioned here though!)

This is what occurs when this button is left-clicked:

1. The "before" wrapper snippet is run.

2. The "what to do when clicked with button31" attribute is set to a macro that clicks on the currently hovered talent or glyph button (if you look elsewhere in the code you'll see that the "macro" button is parented to those OnEnter) and then accepts the current static popup.

3. The "what to do when clicked with button1" attribute is set to a macro that clicks the "Learn Talents" button. (Just going to ignore Trap Launcher.)

4. The mousedown event is received.

5. The button arg is remapped to button31.

6. The "what to do when clicked with button31" attribute is invoked, causing its macro to run. The talent is clicked and the popup is accepted.

7. The mouseup event is received.

8. The "what to do when clicked with button1" attribute is invoked, causing its macro to run. The "Learn Talents" button is clicked.

You are correct that it doesn't do exactly what you wanted, but you may be able to use similar principles to accomplish what you want.
__________________
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.
  Reply With Quote