1. #1
    Deleted

    Adding a button to a template UI

    Hi!

    So I want to add a button to a template, the template I'm talking about is this one:

    This red area is this one :
    Code:
    	<Button name="LFGListApplicantMemberTemplate" virtual="true">
    		<Size x="190" y="20"/>
    		<Layers>
    			<Layer level="ARTWORK">
    				<FontString parentKey="Name" inherits="GameFontNormalSmall" justifyH="LEFT" text="NAME">
    					<Size x="100" y="10"/>
    					<Anchors>
    						<Anchor point="LEFT" x="7" y="-1"/>
    					</Anchors>
    				</FontString>
    				<FontString parentKey="ItemLevel" inherits="GameFontNormalSmall" justifyH="CENTER" text="529">
    					<Anchors>
    						<Anchor point="CENTER" relativeKey="$parent" relativePoint="LEFT" x="177" y="-1"/>
    					</Anchors>
    				</FontString>
    			</Layer>
    		</Layers>
    		<Frames>
    			<Frame parentKey="FriendIcon">
    				<Size x="20" y="19"/>
    				<Anchors>
    					<Anchor point="LEFT" relativeKey="$parent.Name" relativePoint="RIGHT" x="0" y="0"/>
    				</Anchors>
    				<Layers>
    					<Layer level="ARTWORK">
    						<Texture parentKey="Icon" atlas="groupfinder-icon-friend" setAllPoints="true"/>
    					</Layer>
    				</Layers>
    				<Scripts>
    					<OnEnter>
    						if ( self.relationship == "friend" ) then
    							GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
    							GameTooltip:SetText(LFG_LIST_FRIEND, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, 1, true);
    							GameTooltip:Show();
    						elseif ( self.relationship == "guild" ) then
    							GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
    							GameTooltip:SetText(LFG_LIST_GUILD_MEMBER, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, 1, true);
    							GameTooltip:Show();
    						else
    							GameTooltip:Hide();
    						end
    					</OnEnter>
    					<OnLeave function="GameTooltip_Hide"/>
    				</Scripts>
    			</Frame>
    			<Button parentKey="RoleIcon1">
    				<Size x="18" y="18"/>
    				<Anchors>
    					<Anchor point="LEFT" x="104" y="0"/>
    				</Anchors>
    				<NormalTexture/>
    				<HighlightTexture alphaMode="ADD"/>
    				<Scripts>
    					<OnClick>
    						PlaySound("igMainMenuOptionCheckBoxOn");
    						C_LFGList.SetApplicantMemberRole(self:GetParent():GetParent().applicantID, self:GetParent().memberIdx, self.role);
    					</OnClick>
    				</Scripts>
    			</Button>
    			<Button parentKey="RoleIcon2">
    				<Size x="18" y="18"/>
    				<Anchors>
    					<Anchor point="LEFT" relativeKey="$parent.RoleIcon1" relativePoint="RIGHT" x="1" y="0"/>
    				</Anchors>
    				<NormalTexture/>
    				<HighlightTexture alphaMode="ADD"/>
    				<Scripts>
    					<OnClick>
    						PlaySound("igMainMenuOptionCheckBoxOn");
    						C_LFGList.SetApplicantMemberRole(self:GetParent():GetParent().applicantID, self:GetParent().memberIdx, self.role);
    					</OnClick>
    				</Scripts>
    			</Button>
    			<Button parentKey="RoleIcon3">
    				<Size x="18" y="18"/>
    				<Anchors>
    					<Anchor point="LEFT" relativeKey="$parent.RoleIcon2" relativePoint="RIGHT" x="1" y="0"/>
    				</Anchors>
    				<NormalTexture/>
    				<HighlightTexture alphaMode="ADD"/>
    				<Scripts>
    					<OnClick>
    						PlaySound("igMainMenuOptionCheckBoxOn");
    						C_LFGList.SetApplicantMemberRole(self:GetParent():GetParent().applicantID, self:GetParent().memberIdx, self.role);
    					</OnClick>
    				</Scripts>
    			</Button>
    		</Frames>
    		<Scripts>
    			<OnLoad>
    				self:RegisterForClicks("RightButtonUp");
    			</OnLoad>
    			<OnClick>
    				PlaySound("igMainMenuOptionCheckBoxOn");
    				EasyMenu(LFGListUtil_GetApplicantMemberMenu(self:GetParent().applicantID, self.memberIdx), LFGListFrameDropDown, self, 60, -5, "MENU");
    			</OnClick>
    			<OnEnter function="LFGListApplicantMember_OnEnter"/>
    			<OnLeave function="GameTooltip_Hide"/>
    		</Scripts>
    	</Button>
    So my code looks like this:
    Code:
    <Ui>
        <Frame name="MyAddon" parent="LFGListApplicantMemberTemplate">
            <Size x="18" y="18"/>
            <Anchors>
                <Anchor point="TOPLEFT" relativePoint="TOPLEFT" x="4" y="-2"/>
            </Anchors>
            <Frames>
                <Button parentKey="MyAddonButton" inherits="UIMenuButtonStretchTemplate">
                    <Size x="18" y="18"/>
                    <Anchors>
                        <Anchor point="LEFT" relativeKey="$parent.Name" relativePoint="RIGHT" x="0" y="0"/>
                    </Anchors>
                    <HighlightTexture file="Interface\Buttons\UI-Common-MouseHilight" alphaMode="ADD"/>
                </Button>
            </Frames>
            <Scripts>
                <OnLoad>
                        self.MyAddonButton:SetText("Addon")
                </OnLoad>
            </Scripts>
        </Frame>
    </Ui>
    But nothing shows up. Any help please?

  2. #2

  3. #3
    Deleted
    You can't set a template as a parent for a frame.

    When a template is used, like in:
    Code:
    CreateFrame("Frame", "ExampleFrame", UIParent, "ExampleFrameTemplate")
    It loads all the attributes and elements from that frame template to the created frame. It doesn't look anywhere else, if the frame template is ever referred to by anything else.

    An actual frame called "LFGListApplicantMemberTemplate" never exists, so your code just creates the frame "MyAddon" without a parent. Also, since you're not creating a template (by virtual="true"), the frame is created when the XML file loads. Since you want to create this button dynamically for each line, you need to create a template for the button and create frames using that template with CreateFrame.

    Since the buttons are created dynamically instead of before AddOns are loaded, you can just hook the function, where the frames are created (LFGListApplicationViewer_UpdateApplicant).

    So in your Lua file you would do something like:

    Code:
    hooksecurefunc(LFGListApplicationViewer_UpdateApplicant, function(button, id)
    	button.numHandled = button.numHandled or 0
    	local members = button.Members
    	for i = button.numHandled + 1, #members do
    		CreateFrame("Button", nil, members[i], "MyAddonTemplate")
    	end
    	button.numHandled = #members
    end)
    Then your XML template would look something like this:

    Code:
    <Button name="MyAddonTemplate" inherits="UIMenuButtonStretchTemplate" virtual="true">
    	<Size x="18" y="18"/>
    	<Anchors>
    		<Anchor point="RIGHT" relativeKey="$parent.Name" relativePoint="RIGHT" x="0" y="0"/>
    	</Anchors>
    	<HighlightTexture file="Interface\Buttons\UI-Common-MouseHilight" alphaMode="ADD"/>
    	<Scripts>
    		<OnLoad>
    			self:SetText("Addon")
    		</OnLoad>
    	</Scripts>
    </Button>
    I don't understand why you would want to have the button nested inside of another frame, unless you're planning to have something more there, so I just changed it so that it's just the button.

    You should pay attention to relationships between the frames. The relativeKey="$parent.Name" part in your code tried to access MyAddon.Name.

    I can't be arsed to test anything right now, so I can't guarantee that what I posted will work, but it should be very close to what you need to do.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •