Get an Epic Experience with Premium

LibAddonButton

Miscellaneous Login to Add Favorites
  • 0 Likes
  • Warhammer Online
  • 33 Monthly Downloads
  • Supports: 1.4.0
  • 5,951 Total Downloads
  • Updated 11/19/2010
  • Created 09/13/2010
  • 6 Favorites
  • Project Site
  • Comments
  • Release Type: Release
  • License: GNU General Public License version 3 (GPLv3)
  • Newest File: 1.0.6
or

About LibAddonButton

Description

Intended for addons with a GUI but only accessible by slash commands, LibAddonButton can be used to create buttons that house menus to display various addons. The button can me moved by dragging it, locked/unlocked by right-clicking it and the menu can be accessed by left-clicking it. New buttons will be automatically unlocked on their first use.

By default, all first level menu items are sorted alphabetically and all sub menu items are displayed in the order they were added.

Registering a button

LibAddonButton.Register("uniqeName", buttonWidth, buttonHeight, "DefaultTexture", "HighlightTexture", "PressedTexture")

By default, if the "PressedTexture" or "HighlightTexture" is left blank, then "DefaultTexture" will be used. If they are all left blank, the default animated gear button will be used.

A texture can be a simple string that is the name of a texture, or an animation. The format of an animation is:

local animation =
{
	FPS = 10,	-- display 1 frame every 0.1 seconds
	Frames =	-- this must be an index-based array from 1 to n
	{
		"FrameTexture1", "FrameTexture2", "FrameTexture3"
	}
}

Adding a menu item

LibAddonButton.AddMenuItem("uniqeName", L"label text", callbackFunction)

The callbackFunction will be called when a menu item is clicked.

Adding a cascading menu item

local menu = LibAddonButton.AddCascadingMenuItem("uniqeName", L"label text")

This function returns the created menu that is used to add sub menu items. Examples to add submenu items:

LibAddonButton.AddMenuSubitem(menu, L"A", callbackFunction)
menu = LibAddonButton.AddCascadingMenuSubitem(menu, L"B", callbackFunction)
LibAddonButton.AddMenuSubitem(menu, L"C", callbackFunction)
menu = LibAddonButton.AddCascadingMenuSubitem(menu, L"D", callbackFunction)
LibAddonButton.AddMenuSubitem(menu, L"E", callbackFunction)

The above will result in:

A
B	>	C
		D	>	E

Overriding the default behavior of the LUp/RUp events

First you must find the button using either method:

local button = LibAddonButton.Register("uniqueName", ... )
local button = LibAddonButton.GetButton("uniqueName")

Then to override the LUp/RUp events:

button:SetLUpOverride(callbackFunction)
button:SetRUpOverride(callbackFunction)
  • User defined menu items can now be added to menus using the following functions

    LibAddonButton.AddUserDefinedMenuItem(uniqueName, text, window)
    LibAddonButton.AddUserDefinedMenuSubitem(menu, text, window)
  • LUp/RUp button overrides will now pass the parameters flags, mouseX and mouseY
  • Menu creation can now be overriden using the following function

    button:SetFinalizeMenuOverride(callbackFunction)
    • The menuId will be passed as a parameter
    • If the callback function returns true, the menu is aborted and finalize will not be called

Comments

First Previous Page 1 of 3 Next Last
  • #41
    how can i add a tooltip at the button?
  • #42
    Though it's not supported, here is an example of how to display a tooltip on a button:

    local button = LibAddonButton.Register("mybutton")
    function ShowTooltip()
    local windowName = SystemData.ActiveWindow.name
    Tooltips.CreateTextOnlyTooltip(windowName, nil)
    Tooltips.SetTooltipText(1, 1, L"Example")
    Tooltips.Finalize()
    local anchor = { Point = "top", RelativeTo = windowName, RelativePoint = "center", XOffset = 0, YOffset = -32 }
    Tooltips.AnchorTooltip(anchor)
    end
    local old = LibAddonButton.Button.OnMouseOver
    LibAddonButton.Button.OnMouseOver = function(...)
    old(...)
    local self = ...
    if (self == button) then
    ShowTooltip()
    end
    end
  • #37
    Btw. I´ve hacked CheckBox support for the menus into it for one of my addons in the making. It´s not entirely waterproof since it doesn´t loop through all levels, however I went for a "least chances possible" approach since I didn´t want to hook all that functions. Integrated, this flaw should easily be solvable.

    For your consideration:
    http://war.pastey.net/142794
  • #38
    Addendum: Creating a personal template instead of ChatContextMenuItemCheckBox would even eliminate the need to manually set the button check state in the handler, like switching it in onlbuttondown, so the lbuttonup handler can just ask if it´s checked.
    But I was too lazy for that for now ;)
  • #39
    .
  • #40
    That´d be fine :)
    Feel free to borrow my Yak-Mantra: "Sorry, that´s technically not possible" ;) It´s underused since he´s gone and could use some appliances.
  • #36
    The following change would be helpful for me:
    function LibAddonButton.Button:OnLButtonUp(flags, mouseX, mouseY)
    function LibAddonButton.Button:OnRButtonUp(flags, mouseX, mouseY)

    passing on the arguments:
    local success, errmsg = pcall(self.Override.LUp, flags, mouseX, mouseY)
    local success, errmsg = pcall(self.Override.RUp, flags, mouseX, mouseY)

  • #30
    Some new things:-)

    one bug: Divider not work in 1st menu. I can create it but not move and not show.

    New ideas:
    - add some own textures for buttons. Like some folder where I copy icon in specific format and after that chose it in GUI.
    - add description to every menu item (like on mouse over tooltip)
    - add item moving between buttons (like between submenus in one button)

    and one question:-)

    For example when U post some position by State of Realm it send into the chat little icon before text. Is possible add that icons into my chat macro? Is here some list of that icons?
  • #32
    You can add "code" to chat. For example

    makes a break and makes an icon.

    The reason I made it so you can only copy a pre-existing button is because of the way textures are handled in WAR. You can't simply drop textures in a folder, you also have to add them to the xml file. Since this would required basic coding anyways, that's why I left choosing the texture to buttons created by addons only.

  • #33
    Nice is here more tags?
  • #34
    Besides , probably. There's isn't exactly a list or anything.
  • #35

    works too
  • #31
    My by for that bug, I dont uncheck autosorting:-)
  • #23
    Ome new thing:

    - in Manager, can U add my own items sorting? (by own id perhaps) not just alphabetical?
  • #25
    What else is there to sort by? An item only has its name to represent it.
  • To post a comment, please login or register a new account.
Login to Curse

Don't have an account? Create One.

Get an epic experience with Curse Premium
  • Faster addon downloads
  • Premium-Only Beta Giveaways
  • Ad-Free Curse experience
  • Premium Curse Client
  • and many More Features
  • Learn More »

Infinite Crisis NA

Get Your Preferred Access Code!