Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
WoW
Talk
English
Views
Read
Edit
History
More
Search
Navigation
Home
Random page
Help using wiki
Editions
for WoW
for WildStar
for Solar2D
Documentation
for WoW
for WildStar
Reference
WoW
⦁ FrameXML
⦁ AddOns
⦁ API
⦁ WoW Lua
WildStar
⦁ AddOns
⦁ API
⦁ WildStar Lua
Engine
Tools
What links here
Related changes
Special pages
Page information
Site
Recent Changes
Editing
WoW:USEROBJECT MenuClass
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Code == <pre>-- Set to false to use file-scoped variables or true to use the new addon-scoped variables local useAddonScope = true local addonName, MenuClass if useAddonScope then addonName, MenuClass = ... else addonName, MenuClass = "--your addon's name--", {} end function MenuClass:New() local ret = {} -- set the defaults ret.menuList = {} ret.anchor = 'cursor'; -- default at the cursor ret.x = nil; ret.y = nil; ret.displayMode = 'MENU'; -- default ret.autoHideDelay = nil; ret.menuFrame = nil; -- If not defined, :Show() will create a generic menu frame ret.uniqueID = 1 -- import the functions for k,v in pairs(self) do ret[k] = v end -- return a copy of the class return ret end --[[ Return the index where "text" lives. ; text : The text to search for. --]] function MenuClass:GetItemByText(text) for k,v in pairs(self.menuList) do if v.text == text then return k end end end --[[ Add menu items ; text : The display text. ; func : The function to execute OnClick. ; isTitle : 1 if this is a header (usually the first one) returns the last index of the menu item that was just added. --]] function MenuClass:AddItem(text, func, isTitle) local info = {} info["text"] = text info["isTitle"] = isTitle info["func"] = func table.insert(self.menuList, info) return #self.menuList end --[[ Set an attribute for the menu item. Valid attributes are found in the FrameXML\UIDropDownMenu.lua file with their valid values. Arbitrary non-official attributes are allowed, but are only useful if you plan to access them with :GetAttribute(). ; text : The text of the menu item or index of the menu item. ; attribute : Set this attribute to "value". ; value : The value to set the attribute to. --]] function MenuClass:SetAttribute(text, attribute, value) self.menuList[self:GetItemByText(text) or (self.menuList[text] and text) or 1][attribute or "uniqueID"] = value end --[[ Get an attribute for the menu item. Valid attributes are found in the FrameXML\UIDropDownMenu.lua file with their valid values or any arbitrary attribute set with :SetAttribute(). ; text : The text of the menu item or index of the menu item. ; attribute : Get this attribute. --]] function MenuClass:GetAttribute(text, attribute) return self.menuList[self:GetItemByText(text) or (self.menuList[text] and text) or 1][attribute or "uniqueID"] end --[[ Remove the first item matching "text" ; text : The text to search for. --]] function MenuClass:RemoveItem(text) table.remove(self.menuList, self:GetItemByText(text)) end --[[ ; anchor : Set the anchor point. --]] function MenuClass:SetAnchor(anchor) if anchor ~= 'cursor' then self.x = 0 self.y = 0 end self.anchor = anchor end --[[ ; displayMode : "MENU" --]] function MenuClass:SetDisplayMode(displayMode) self.displayMode = displayMode end --[[ ; autoHideDelay : How long, without a click, before the menu goes away. --]] function MenuClass:SetAutoHideDelay(autoHideDelay) self.autoHideDelay = tonumber(autoHideDelay) end --[[ ; menuFrame : Should inherit a Drop Down Menu template. --]] function MenuClass:SetMenuFrame(menuFrame) self.menuFrame = menuFrame end function MenuClass:GetMenuList() return self.menuList end --[[ ; x : X position ; save : When not nil, will add to the current value rather than replace it --]] function MenuClass:SetX(x, save) if save then self.x = self.x + x else self.x = x end end --[[ ; y : Y position ; save : When not nil, will add to the current value rather than replace it --]] function MenuClass:SetY(y, save) if save then self.y = self.y + y else self.y = y end end function MenuClass:Activate() if not self.menuFrame then while _G['GenericMenuClassFrame'..self.uniqueID] do -- ensure that there's no namespace collisions self.uniqueID = self.uniqueID + 1 end -- the frame must be named for some reason self.menuFrame = CreateFrame('Frame', 'GenericMenuClassFrame'..self.uniqueID, UIParent, "UIDropDownMenuTemplate") end self.menuFrame.menuList = self.menuList end --[[ Show the menu. --]] function MenuClass:Show() self:Activate() EasyMenu(self.menuList, self.menuFrame, self.anchor, self.x, self.y, self.displayMode, self.autoHideDelay) end -- If you're not using the addon-scoped variables, you must have a global variable in order to use this menu. if not useAddonScope then _G[addonName.."Menu"] = MenuClass end </pre>
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)