WoW:Changing a button's action slot ID (source)
Revision as of 18:25, 26 February 2007
, 26 February 2007Updated to be 2.0 compatible
(Updated to be 2.0 compatible) |
|||
| Line 1: | Line 1: | ||
Sometimes you would like to control the action a button will start when it is clicked. Maybe you want to add extra buttons, maybe you just want to control the behavior of existing ones. I will tell you in a moment how to do that, but first you should know something about how the default UI handles it's buttons. | Sometimes you would like to control the action a button will start when it is clicked. Maybe you want to add extra buttons, maybe you just want to control the behavior of existing ones. I will tell you in a moment how to do that, but first you should know something about how the default UI handles it's buttons. | ||
[b]IMPORTANT: Recommendations involving changing ActionButton_GetPagedID do not work after WoW 2.0[/b] | |||
==Button Handling in the Default UI== | ==Button Handling in the Default UI== | ||
| Line 8: | Line 10: | ||
In the ActionButton.lua file, every time a function (i.e. [[API_UseAction]]) needs to know the action ID of a specific button, it calls | In the ActionButton.lua file, every time a function (i.e. [[API_UseAction]]) needs to know the action ID of a specific button, it calls | ||
id = ActionButton_GetPagedID(button) | id = ActionButton_GetPagedID(button) | ||
I wouldn't recommend looking at the code of this method, because your brain may explode (unless you are good at reading uncommented and foreign code in Lua), but I will summarize the method for you. Every button has an ID, specified in the corresponding XML File: | I wouldn't recommend looking at the code of this method, because your brain may explode (unless you are good at reading uncommented and foreign code in Lua), but I will summarize the method for you. Every Blizzard UI button has an ID, specified in the corresponding XML File: | ||
<Button name="SomeName" ...someOtherValues... id="2"> | <Button name="SomeName" ...someOtherValues... id="2"> | ||
...some Code | ...some Code | ||
</Button> | </Button> | ||
This ID can be obtained by calling button:GetID(). Unfortunately, this ID ranges from only 1-12 | This ID can be obtained by calling button:GetID(). Unfortunately, this ID ranges from only 1-12, and is then offset based on the type of button or action page page, so it's not very convenient if you want to create your own button. | ||
Luckily, the blizzard code recognizes that AddOns need to create their own buttons so it provides special behaviour if you set the id of your Button to 0, using the "action" attribute of the button. | |||
==Controlling a Button's Action Slot ID== | ==Controlling a Button's Action Slot ID== | ||
To make your own action button with a specific slot you simply have to set your button's ID to 0 (which is the default if you dont specify, but I recommend you set it anyway), and set the button's "action" attribute. You can do this in the XML, or in lua code afterwards. | |||
XML: | |||
<CheckButton name="customButton" inherits="ActionBarButtonTemplate"> | <CheckButton name="customButton" inherits="ActionBarButtonTemplate" id="0"> | ||
<Attributes> | |||
<Attribute name="action" value="101"/> | |||
</Attributes> | |||
</CheckButton> | </CheckButton> | ||
LUA: | |||
customButton:SetAttribute("action", 101); | |||
[[Category: HOWTOs|Changing a Buttons Action Slot ID]] | [[Category: HOWTOs|Changing a Buttons Action Slot ID]] | ||