I just rigged up a dropdown menu myself. Granted very simple so far but it is spread across 3 files.
1. The interface generic function file where the basics are definited
2. The addons interface specific file where the menu is created for the addon
3. The main addon file that creates the button that calls the menu
I haven't added a submenu yet so this code may not work for that scenario but here's what I managed to do for a single menu list.
This is the generic code fragments in file 1.
Code:
addonData["Interface"].OnShowMenu = function(self,dropDownLevel,dropDownValue,dropDownFrame,dropDownAnchor,xOffset,yOffset)
ToggleDropDownMenu(dropDownLevel, dropDownValue, dropDownFrame, dropDownAnchor, xOffset, yOffset);
end
addonData["Interface"].OnInitMenu = function(self)
UIDropDownMenu_Initialize(self, self.InitFunction, self.MenuType);
end
addonData["Interface"].OnClick = function(self,button,down)
-- Is this a drop down menu object ?
if ( self.Menu ) then
addonData["Interface"].OnShowMenu(self,1,nil,self.Menu,self,0,0);
end
end
addonData["Interface"].AddDropDownMenu = function(name,parent,initFunction,menuType)
local f = CreateFrame("Button",name,parent,"UIDropDownMenuTemplate");
if ( initFunction and menuType ) then
f.InitFunction = initFunction;
f.MenuType = menuType;
addonData["Interface"].OnInitMenu(f);
end
return f;
end
addonData["Interface"].AddDropDownTooltip = function(info,tooltipTitle,tooltipText)
local info = info;
if ( tooltipTitle and tooltipText ) then
info.tooltipTitle = tooltipTitle;
info.tooltipText = tooltipText;
end
return info;
end
addonData["Interface"].AddDropDownClickableItem = function(name,parent,text,isDisabled,isCheckable,isChecked,funcCall,funcArg1,funcArg2, tooltipTitle,tooltipText)
local info = UIDropDownMenu_CreateInfo();
info.text = text;
if ( isDisabled ~= nil ) then
info.disabled = isDisabled;
end
if ( isCheckable and isChecked ) then
info.notCheckable = not isCheckable;
info.checked = isChecked;
end
-- Deal with Function Calls ( funcCall(self,arg1,arg2,checked) )
if ( funcCall ) then
info.func = funcCall;
-- Deal with Arguments
if ( funcArg1 ) then
info.arg1 = funcArg1;
if ( funcArg2 ) then
info.arg2 = funcArg2;
end
end
end
if ( tooltipTitle and tooltipText ) then
info = addonData["Interface"].AddDropDownTooltip(info,tooltipTitle,tooltipText);
end
UIDropDownMenu_AddButton(info, UIDROPDOWN_MENU_LEVEL);
addonData["Interface"].AddDropDownItem = function(name,parent,text,isHeader,hasSubMenu,hasValue,value, tooltipTitle,tooltipText)
local info = UIDropDownMenu_CreateInfo();
info.text = text;
-- Deal with Header Item
if ( isHeader ) then
info.isTitle = 1;
info.notCheckable = 1;
end
-- Deal With SubMenu Items ( Not sure how to deal with this in this layout yet )
if ( hasSubMenu ) then
info.hasArrow = true;
end
if ( hasValue and value ) then
info.value = value;
end
if ( tooltipTitle and tooltipText ) then
info = addonData["Interface"].AddDropDownTooltip(info,tooltipTitle,tooltipText);
end
UIDropDownMenu_AddButton(info, UIDROPDOWN_MENU_LEVEL);
end
This is file 2 that define's the addon's specific menu options and their functionality on clicking them
Code:
addonData["SlashCmds"].OnMenuClick = function(self,arg1,arg2,checked)
if ( arg1 == 1 ) then
addonData["WatchFrame"].AutoHide = not addonData["WatchFrame"].AutoHide;
end
if ( arg1 == 2 ) then
addonData["ScrollFrame"].Movable = not addonData["ScrollFrame"].Movable;
end
if ( arg1 == 3 ) then
addonData["SlashCmds"].OnDock();
end
if ( arg1 == 4 ) then
addonData["SlashCmds"].OnReset();
end
if ( arg1 < 3 ) then
addonData["SlashCmds"].Update();
-- If the Options frame is visible then refresh it
if ( addonData["Frames"].SWF_Options:IsShown() ) then addonData["SlashCmds"].OnShow(addonData["Frames"].SWF_Options); end
end
end
addonData["SlashCmds"].CreateMenu = function(self)
addonData["Interface"].AddDropDownItem("OptionHeader1",self,"Scrolling Watch Frame",true);
local isDisabled = false;
local isChecked = false;
-- Add AutoHide to the menu
isChecked = addonData["WatchFrame"].AutoHide;
isDisabled = false;
if ( addonData["nUI"].InfoPanel ) then
isDisabled = true;
isChecked = false;
end
addonData["Interface"].AddDropDownClickableItem("OptionItem1",self,"Auto Hide",isDisabled,true,isChecked, addonData["SlashCmds"].OnMenuClick,1);
-- Add Locked Toggle to the menu
isChecked = not addonData["ScrollFrame"].Movable;
isDisabled = false;
if ( addonData["nUI"].InfoPanel ) then
isDisabled = true;
isChecked = false;
end
addonData["Interface"].AddDropDownClickableItem("OptionItem2",self,"Lock",isDisabled,true,isChecked, addonData["SlashCmds"].OnMenuClick,2);
-- Add Docking Option to the menu
local DockText = "Dock";
if ( addonData["nUI"].InfoPanel ) then DockText = "UnDock"; end
isChecked = addonData["nUI"].InfoPanel;
isDisabled = false;
if ( not addonData["nUI"].Loaded ) then
isDisabled = true;
isChecked = false;
end
addonData["Interface"].AddDropDownClickableItem("OptionItem3",self,DockText,isDisabled,true,isChecked, addonData["SlashCmds"].OnMenuClick,3);
-- Add Reset Option to the menu
isChecked = false;
isDisabled = false;
addonData["Interface"].AddDropDownClickableItem("OptionItem4",self,"Reset to Default Settings",isDisabled,false,isChecked, addonData["SlashCmds"].OnMenuClick,4);
And this is file 3 that creates the button ( inherited from OptionsButtonTemplate ) and links it to the generic click menu after assigning the menu frame to display.
Code:
local o = addonData["Interface"].AddPushButton("WatchFrameOptionsButton","O",f)
o:SetWidth(10);
o:SetParent(f);
o:RegisterForClicks("AnyDown");
o:ClearAllPoints();
o:SetPoint("TOPLEFT",f,"TOPLEFT",10,-10);
o.Menu = addonData["Frames"].SWF_DropDownMenu;
o:SetScript("OnClick",function(self,button,down)
if ( button == "RightButton" ) then
addonData["Interface"].OnClick(self,button,down);
elseif ( button == "LeftButton" ) then
if ( addonData["Frames"].SWF_Options:IsShown() ) then
addonData["Frames"].SWF_Options:Hide();
else
addonData["Frames"].SWF_Options:Show();
end
end
end);
And this code is what starts it all off in Variables_Loaded event catcher for the addon.
Code:
-- Set Up the Menu System
addonData["Frames"].SWF_DropDownMenu = addonData["Interface"].AddDropDownMenu("SWF_OptionsMenu",UIParent,addonData["SlashCmds"].CreateMenu,"MENU");
Here's a screenshot of what the result is. As a first attempt without using ace stuff I was surprised it worked so well so quickly rofl.