Thread Tools Display Modes
05-07-12, 09:36 AM   #1
venoabyss
A Deviate Faerie Dragon
Join Date: Apr 2011
Posts: 13
Question XML Button Issue

I'm having issues getting this to show up, I'm trying to make a basic button with a transparent background, I will code the boarder if I think it would look better (have to see it).

All I want is to put the text in the bottom left corner of my addon window and if someone clicks on it it calls the function GRShowRoster();

I think my problem is the inherits="..." line but I can't seem to find a list of all the button templates to search through them, any help would be welcome.

Thanks,
V
Code:
<Button name="$parentButtonRoster" inherits="UIPanelButtonTemplate" text="Roster">
		<Anchors>
			<Anchor point="BOTTOMLEFT">
				<Offset>
					<AbsDimension x="12" y="16"/>
				</Offset>
			</Anchor>
		</Anchors>
		<Scripts>
			<OnClick>GRShowRoster(); </OnClick>
		</Scripts>
	</Button>
  Reply With Quote
05-07-12, 11:58 AM   #2
venoabyss
A Deviate Faerie Dragon
Join Date: Apr 2011
Posts: 13
Changed the button to LUA and it works great!

Code:
	local rosterButton = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
		rosterButton:SetPoint("BOTTOMLEFT", 10, 10)
		rosterButton:SetHeight(25)
		rosterButton:SetWidth(60)
		rosterButton:SetNormalFontObject("GameFontNormal")
		rosterButton:SetNormalTexture("Interface\DialogFrame\UI-DialogBox-Background-Dark")
		rosterButton:SetText("Roster")
		rosterButton:SetScript("OnClick", GRShowRoster)
		rosterButton:Enable()
	frame.rosterButton = rosterButton;
Thanks to an example regarding a close button last month. (as the xml hates me I think Lua programming the buttons will be better lol)

But if anyone sees a way to make this work better by all means let me know!

V
  Reply With Quote
05-07-12, 04:42 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Originally Posted by venoabyss View Post
Code:
<Button name="$parentButtonRoster" inherits="UIPanelButtonTemplate" text="Roster">
		<Anchors>
			<Anchor point="BOTTOMLEFT">
				<Offset>
					<AbsDimension x="12" y="16"/>
				</Offset>
			</Anchor>
		</Anchors>
		<Scripts>
			<OnClick>GRShowRoster(); </OnClick>
		</Scripts>
	</Button>
I'm not seeing <Size> tags to define the width and height.

It's up to the programmer to decide which route to take when setting up buttons. XML and Lua methods are both viable. From a design standpoint, XML was made for static buttons and templates that are created on load and Lua was to offer a way to create UI objects dynamically as needed. As the Lua method is completely capable of phasing out the XML method entirely, many programmers now solely use Lua for creating these objects.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 05-07-12 at 04:52 PM.
  Reply With Quote
05-08-12, 10:55 AM   #4
venoabyss
A Deviate Faerie Dragon
Join Date: Apr 2011
Posts: 13
Originally Posted by SDPhantom View Post
I'm not seeing <Size> tags to define the width and height.
Lol Well I feel like an idiot, It was displaying a button of 0x0 pixel size. and this is why I should stick to programming in the Lua, Markup Languages never made much sense to me except as templates.

the only thing I have yet to figure out is how to get a pure LUA addon to work. I see no way to call the initial functions to deal with making the primary frame ect.

Also I'm having an issue with this code:

Code:
tinsert(UISpecialFrames, GRFrame);
As I understand its spost to make my frame (named GRFrame) disappear when I press esc (like all of Blizzards other frames)

Its in my XML file at the bottom nested inside <Ui...><Frame>...<Scripts><OnLoad>code</OnLoad></Scripts></Frame></Ui> Is there a better place for it that would allow it to work all the time?

V

EDIT: figured out the tinsert issue, I was passing the frame not the name of the frame to the table! lol

Last edited by venoabyss : 05-13-12 at 03:57 PM. Reason: update
  Reply With Quote
05-09-12, 05:21 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by venoabyss View Post
the only thing I have yet to figure out is how to get a pure LUA addon to work. I see no way to call the initial functions to deal with making the primary frame ect.
You just make the frame. Any code in the main chunk (eg. not inside a function) will be executed immediately when the Lua file is loaded.

Instead of using an OnLoad script (which can be set, but won't be run for a frame created in Lua) you can either just call the code in the main chunk, or register for the ADDON_LOADED event (which fires with your addon's name as the first argument once your addon's files and saved variables have all been loaded) or the PLAYER_LOGIN event (which fires when all non-load-on-demand addons and saved variables have been loaded, and the loading screen has disappeared) and run your code in response to it.

If your code depends on data contained in saved variables, you should use the event method; otherwise, just put it in the main chunk.

Code:
local frame = CreateFrame("Frame", "MyFrame", UIParent)
frame:SetPoint("CENTER")
frame:SetSize(100, 160)
frame:SetBackdrop(GameTooltip:GetBackdrop()) -- copied because I'm too lazy to type it out

-- This might normally go in an OnLoad script, but you can just put it here:
frame:SetBackdropColor(0, 0, 0, 0.8)
frame:SetBackdropBorderColor(0.8, 0.8, 0.8, 1)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
frame:SetScript("OnHide", frame.StopMovingOrSizing) -- prevents frame sticking to cursor in some situations

-- Or you can register for a loading-related event:
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function(self, event, arg1)
	if event == "ADDON_LOADED" then -- realistically you don't need to check, since you're only registered for this one event
		if arg1 == "MyAddon" then -- this will be your TOC/folder name
			-- your addon's files and saved variables are all loaded
			self:SetBackdropColor(0, 0, 0, 0.8)
			self:SetBackdropBorderColor(0.8, 0.8, 0.8, 1)
			self:RegisterForDrag("LeftButton")
			self:SetScript("OnDragStart", frame.StartMoving)
			self:SetScript("OnDragStop", frame.StopMovingOrSizing)
			self:SetScript("OnHide", frame.StopMovingOrSizing) -- prevents frame sticking to cursor in some situations
		end
	end
end)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » XML Button Issue


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