Thread Tools Display Modes
03-12-13, 05:47 PM   #1
shamby
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Apr 2010
Posts: 17
How to incorporate cooldowns on clickable button frames generated in xml file.

I am trying to redo an outdated Hunter Trap mod. This is my first attempt at addons. I want to add cooldowns to existing frames and cannot find a method that works. The button frames are in the xml file. Is there a website (other than "Hello World") that can point me in the right direction? Thank you.
  Reply With Quote
03-12-13, 06:23 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
First of all, I'd highly recommend rewriting your frames in Lua, and avoid using XML.

Secondly, to add a cooldown, you create a new frame with the "Cooldown" object type (instead of "Frame" or "Button"), parent and anchor to your frame, give it the same size as your frame (or use SetAllPoints, or SetPoint if you need offsets). Then :Show() your cooldown and use :SetCooldown(...) to start the sweeping animation.

See also:
* http://www.wowpedia.org/Widget_API#Cooldown
* http://www.wowpedia.org/API_Cooldown_SetCooldown (there's a code example here)
__________________
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
03-12-13, 06:30 PM   #3
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
SetCooldown

He's adding a cooldown on top of the playerframe for the example.
You would do the same for your frames.

If you want to do that in .xml you'd add a Cooldown as a child of your frame something like this:
Code:
<Frame name="YourFrameNameHere">
 <Frames>
  <Cooldown name="$parentCD" inherits="CooldownFrameTemplate" parentKey="cooldown" />
 </Frames>
</Frame>
The inherits and parentKey attributes are optional, parentKey makes it so you have a reference to your cooldown frame on its parent ie _G["YourFrameNameHere"].cooldown let's you run methods on the cooldown.
  Reply With Quote
03-13-13, 11:45 AM   #4
shamby
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Apr 2010
Posts: 17
Still unable to get the cooldowns on buttons.

Thank you guys for your informative and rapid responses. I agree that .lua would be a better choice, especially for what I eventually want to do in the Addon. But I do have a better understanding of what needs to be done here. I have researched the material you've provided and through trial and error am still unable to get a CD on the button(s). There's 4 Trap buttons and the Launcher on this set up and I have included part of the beginning .xml. I have been working on the 1st trap-Explosive- and if you would again point me in the proper direction I will be able to get back to the 'Daily' marathon that is MoP. Thank you.
Sorry--have never included attachments before and not sure so I am placing an original part of the .xml here devoid of any changes that I tried.
<Script file="EZTrap.lua" />
<Frame name="Frame1" parent="UIParent" toplevel="true" movable="true" enableMouse="true">
<Size>
<AbsDimension x="110" y="110" />
</Size>
<Anchors>
<Anchor point="CENTER">
<Offset x="-1" y="-144" />
</Anchor>
</Anchors>
<Backdrop bgFile="Interface\FrameGeneral\UI-Background-Rock" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
<BackgroundInsets>
<AbsInset left="11" right="12" top="12" bottom="11" />
</BackgroundInsets>
<TileSize>
<AbsValue val="32" />
</TileSize>
<EdgeSize>
<AbsValue val="32" />
</EdgeSize>
</Backdrop>
<Frames>
<Button name="Explosive" inherits="SecureActionButtonTemplate">
<Size>
<AbsDimension x="28" y="28" />
</Size>
<Anchors>
<Anchor point="CENTER">
<Offset x="32" y="30" />
</Anchor>
</Anchors>
<Scripts>
<OnLoad>
self:RegisterForClicks("LeftButtonUp");
self:SetAttribute("type1", "spell");
self:SetAttribute("spell1", "Explosive Trap");
</OnLoad>
</Scripts>
<NormalTexture file="Interface\Icons\Spell_fire_selfdestruct" />
</Button>
  Reply With Quote
03-13-13, 11:52 AM   #5
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Haven't looked at your actual code yet but you can use a [code]your code here[/code] ( button at the post editor) to make your code easier to read and make it create a fixed size scrollable region in your post.
  Reply With Quote
03-13-13, 01:31 PM   #6
shamby
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Apr 2010
Posts: 17
Thanks. Here it is again.

Thank ya, D. Let's try that.
Code:
	<Frame name="Frame1" parent="UIParent" toplevel="true" movable="true" enableMouse="true">
		<Size>
			<AbsDimension x="110" y="110" />
		</Size>
		<Anchors>
			<Anchor point="CENTER">
				<Offset x="-1" y="-144" />
			</Anchor>
		</Anchors>
		<Backdrop bgFile="Interface\FrameGeneral\UI-Background-Rock" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
			<BackgroundInsets>
				<AbsInset left="11" right="12" top="12" bottom="11" />
			</BackgroundInsets>
			<TileSize>
				<AbsValue val="32" />
			</TileSize>
			<EdgeSize>
				<AbsValue val="32" />
			</EdgeSize>
		</Backdrop>
		<Frames>
			<Button name="Explosive" inherits="SecureActionButtonTemplate">
				<Size>
					<AbsDimension x="28" y="28" />
				</Size>
				<Anchors>
					<Anchor point="CENTER">
						<Offset x="32" y="30" />
					</Anchor>
				</Anchors>
				<Scripts>
					<OnLoad>
						self:RegisterForClicks("LeftButtonUp");
						self:SetAttribute("type1", "spell");
						self:SetAttribute("spell1", "Explosive Trap");
					</OnLoad>
				</Scripts>
				<NormalTexture file="Interface\Icons\Spell_fire_selfdestruct" />
			</Button>
  Reply With Quote
03-13-13, 03:55 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Please don't use names like "Frame1" for your frames. Those names are global, which means they sit in the same namespace as Lua functions, WoW API functions, WoW UI objects and functions, other addons' global objects, etc.

Instead, use names that are both (a) descriptive, so users can easily match them to their parent addon, and (b) unique, so they won't collide with other badly named global variables. A simple and effective tactic is to prepend your addon's name, so "MyAddon_Frame1" would be fine, though "MyAddon_TrapButton1" or "MyAddon_Cooldown1" would be even better.

When you're referring to your frames in Lua, you can create a local reference with a shorter name that's easier to work with, eg:

Code:
local f = MyAddon_TrapButton1
f:Show()
__________________
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

WoWInterface » Developer Discussions » General Authoring Discussion » How to incorporate cooldowns on clickable button frames generated in xml file.


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