WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Getting the text of a button when clicked (https://www.wowinterface.com/forums/showthread.php?t=2136)

sweede 10-20-05 02:56 PM

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 !!!!

Gello 10-20-05 04:15 PM

Quote:

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

noraj 10-20-05 05:36 PM

lol yeah and to get the text

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

check out the XML widget API on wowwiki


All times are GMT -6. The time now is 12:57 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI