WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   XML Button Issue (https://www.wowinterface.com/forums/showthread.php?t=43412)

venoabyss 05-07-12 09:36 AM

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>


venoabyss 05-07-12 11:58 AM

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

SDPhantom 05-07-12 04:42 PM

Quote:

Originally Posted by venoabyss (Post 256180)
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.

venoabyss 05-08-12 10:55 AM

Quote:

Originally Posted by SDPhantom (Post 256198)
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

Phanx 05-09-12 05:21 AM

Quote:

Originally Posted by venoabyss (Post 256233)
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)



All times are GMT -6. The time now is 01:06 PM.

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