Thread Tools Display Modes
10-20-05, 02:56 PM   #1
sweede
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Oct 2005
Posts: 18
Getting the text of a button when clicked

I'm modifying an existing addon that sorts people who send a tell by order of their DKP values.

so you would have a list like

Joe dkp 302
hank dkp 156
frank dkp -1

I would like to be able to click on one of the above names and have a box pop up saying "Award loot to playername", and then i hit yes / no and it announces to raid.

The problem i have is getting from the buttom in the XML to the function in the lua file.

the XML....
Code:
<Button name="DKPBidAuctionButtonTemplate" virtual="true">
		<Size>
			<AbsDimension x="160" y="16" />
		</Size>
		<Layers>
			<Layer level="BORDER">
				<FontString name="$parentText" inherits="GameFontNormalSmall" justifyH="LEFT">
					<Size>
						<AbsDimension x="160" y="14" />
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT">
							<Offset>
								<AbsDimension x="2" y="-1" />
							</Offset>
						</Anchor>
					</Anchors>
				
				</FontString>
			</Layer>
		</Layers>
		
		<HighlightTexture file="Interface\QuestFrame\UI-QuestTitleHighlight" alphaMode="ADD">
			<Size>
				<AbsDimension x="160" y="16" />
			</Size>
			<Anchors>
				<Anchor point="TOP">
					<Offset>
						<AbsDimension x="0" y="0" />
					</Offset>
				</Anchor>
			</Anchors>
		</HighlightTexture>
		<Scripts>
			<OnClick>
				DKP_Bid_Bidder_OnClick();
			</OnClick>
		</Scripts>
	</Button>				
.. some more stuff ....
<Button name="DKPBidAuctionButton1" inherits="DKPBidAuctionButtonTemplate" id="1">
				<Anchors>
					<Anchor point="TOPLEFT" relativeTo="DKP_Bid_GUI_AuctionInfo">
						<Offset>
							<AbsDimension x="10" y="-30" />
						</Offset>
					</Anchor>
				</Anchors>
			</Button>
x 10

The lua code right now is simply
Code:
function DKP_Bid_Bidder_OnClick()
 		DEFAULT_CHAT_FRAME:AddMessage("wtf do i put here to get the name or text of what i click on!!!!");
end


Thanks very much !!!!
  Reply With Quote
10-20-05, 04:15 PM   #2
Gello
A Molten Giant
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 521
function DKP_Bid_Bidder_OnClick()
DEFAULT_CHAT_FRAME:AddMessage("wtf do i put here to get the name or text of what i click on!!!!");
end
When this is called, the global variable "this" is the frame that called it.

this:GetName() will be the name of the button that called it. Another good method is to number your controls like you did there. You have id="1" in the button, so you can do button=this:GetID()

<Button name="DKPBidAuctionButton1" inherits="DKPBidAuctionButtonTemplate" id="1"/>
<Button name="DKPBidAuctionButton2" inherits="DKPBidAuctionButtonTemplate" id="2"/>
<Button name="DKPBidAuctionButton3" inherits="DKPBidAuctionButtonTemplate" id="3"/>
<Button name="DKPBidAuctionButton4" inherits="DKPBidAuctionButtonTemplate" id="4"/>
etc

When they click the third button:
button = this -- button == the frame DKPBidAuctionButton3 itself
buttonName = this:GetName() -- button == "DKPBidAuctionButton3"
buttonID = this:GetID() -- button == 3
  Reply With Quote
10-20-05, 05:36 PM   #3
noraj
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 102
lol yeah and to get the text

local buttontext = this:GetText() or simillar should work

check out the XML widget API on wowwiki
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Getting the text of a button when clicked


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