WoWInterface

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

suicidalkatt 12-05-10 07:48 PM

Simplest Button Example?
 
Can anyone point me to a relatively simple button preferably in Lua vs XML.

I'm attempting to change the GuildRosterFrame's drop-down menu to buttons.

I'm not too familiar with using XML and using button templates.

Ailae 12-05-10 07:59 PM

Code:

local b = CreateFrame("Button", "MyButton", UIParent, "UIPanelButtonTemplate")
b:SetSize(80 ,22) -- width, height
b:SetText("Button!")
b:SetPoint("CENTER")
b:SetScript("OnClick", function()
    print("I'm in your buttonz")
end)

This gives you the most basic interface-button, like "Okay" and "Cancel" that you see in the interface options.

p3lim 12-05-10 08:03 PM

lua Code:
  1. local button = CreateFrame('Button', 'MyButtonName', UIParent)
  2. button:SetPoint('CENTER')
  3. button:SetSize(16, 16)
  4. button:SetScript('OnClick', function()
  5.    -- do something
  6. end)

xml Code:
  1. <Ui>
  2.    <Button name='MyButtonName' parent='UIParent'>
  3.       <Size x='16' y='16' />
  4.       <Anchors>
  5.          <Anchor point='CENTER' />
  6.       </Anchors>
  7.       <Scripts>
  8.          <OnClick>
  9.             -- do something
  10.          </OnClick>
  11.       </Scripts>
  12.    </Button>
  13. </Ui>

Seerah 12-05-10 08:18 PM

Note (when trying the above examples) that p3lim's code snippets DO work, they're just invisible. :)

suicidalkatt 12-05-10 08:54 PM

Quote:

Originally Posted by Seerah (Post 221720)
Note (when trying the above examples) that p3lim's code snippets DO work, they're just invisible. :)

Lol they'd have no textures.

Anyway result:

Code:

local f = CreateFrame("frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function(self,event,...)
        if event == "PLAYER_LOGIN" then
                LoadAddOn("Blizzard_GuildUI")
                GuildRosterViewDropdown:Hide()
        end
        local function Update()
                GuildRoster();
                GuildRoster_Update();
                SetCVar("guildRosterView", currentGuildView);
        end
        local b1 = CreateFrame("Button", "playerStatus", GuildRosterFrame, "UIPanelButtonTemplate")
        b1:SetSize(120 ,18)
        b1:SetText("Player Status")
        b1:SetPoint("TOPRIGHT",-25,-26)
        b1:SetScript("OnClick", function()
                GuildRoster_SetView("playerStatus");
                Update()
        end)
        local b2 = CreateFrame("Button", "guildStatus", b1, "UIPanelButtonTemplate")
        b2:SetSize(120 ,18)
        b2:SetText("Guild Status")
        b2:SetPoint("TOPRIGHT", b1, "TOPLEFT")
        b2:SetScript("OnClick", function()
                GuildRoster_SetView("guildStatus");
                Update()
        end)
        local b3 = CreateFrame("Button", "achievement", b1, "UIPanelButtonTemplate")
        b3:SetSize(120 ,18)
        b3:SetText("Achievements")
        b3:SetPoint("TOPRIGHT", b1, "BOTTOMRIGHT")
        b3:SetScript("OnClick", function()
                GuildRoster_SetView("achievement");
                Update()
        end)
        local b4 = CreateFrame("Button", "tradeskill", b3, "UIPanelButtonTemplate")
        b4:SetSize(120 ,18)
        b4:SetText("Professions")
        b4:SetPoint("TOPRIGHT", b3, "TOPLEFT")
        b4:SetScript("OnClick", function()
                GuildRoster_SetView("tradeskill");
                Update()
        end)
end)



All times are GMT -6. The time now is 11:38 PM.

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