Quantcast
DropDown Menus - WoWInterface
Thread Tools Display Modes
06-08-14, 05:52 PM   #1
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
DropDown Menus

I have been trying to create a wrapper function to make a dropdown list by using a table as the master container. I can get the main level to populate but not the following lists.

I am trying to make it run off the following table layout:

menuList = {text, hasArrow, function, menuList}

it will parse through and use the text and function if hasArrow is false. Otherwise it runs through the text and hasArrow and menuList.

The examples I found otherwise I havent been able to adapt to work. Mainly because I dont fully understand the level building for sublevels.
 
06-08-14, 06:00 PM   #2
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Have you consulted this guide?
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
 
06-08-14, 06:07 PM   #3
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Originally Posted by Torhal View Post
Have you consulted this guide?
Yes cant seem to adapt it to my needs... I dont populate it off a random or set generation like that and I dont pass a list. It needs to allow a table in place of "Games" and run through the table to set all the elements.

I tried to replace the elseif menuList == "Games" and make it instead:
Code:
else
    for a,b in pairs(menuList[2]) do
        info.func = menuList[1]
        info.text = menuList[2][a]
        UIDropDownMenu_AddButton(info, level)
    end
end
The above is a rough cut estimation of what I remember but is basically what I did. All it did was add to the end of the 1st level.
 
06-08-14, 06:18 PM   #4
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
If someone can help out with a more direct function running off a table I would appreciate it. I just had one more idea I am going to try and if it works I will post it back here.

Otherwise I will still be looking.
 
06-08-14, 06:40 PM   #5
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Originally Posted by TULOA View Post
If someone can help out with a more direct function running off a table I would appreciate it. I just had one more idea I am going to try and if it works I will post it back here.

Otherwise I will still be looking.
Ok I wiggled something up that I can improve off of:

Following Requires: menuList, SubList with texts in menuList as keys.
Code:
	local info = UIDropDownMenu_CreateInfo()
		
		if level == 1 then
			for a,b in pairs(menuList) do
				info.text = b[1]
				info.hasArrow = b[2]
				
				UIDropDownMenu_AddButton(info, level)
			end
		elseif level == 2 then
			
			for a,b in pairs(menuList[UIDROPDOWNMENU_MENU_VALUE][3]) do
				info.text = b
				info.func = OnClick
				
				UIDropDownMenu_AddButton(info, level)
			end
		end
Edit: Fixed to run off one table.

Last edited by TULOA : 06-08-14 at 06:50 PM.
 
06-08-14, 06:57 PM   #6
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
So my new question becomes...:

How can I make that function infinitely nesting?

Heres the sample table I used in the function above:
Code:
testMenuList = {Greetings = {"Greetings", true, {"hi", "hello", "good day"}}, Farewells = {"Farewells", true, {"bye", "goodbye", "later"}}}
 
06-09-14, 08:01 PM   #7
kurapica.igas
A Flamescale Wyrmkin
Join Date: Aug 2011
Posts: 142
You can't create infinite menus by using system features. Try some drop down menu libs or just create one yourself.

Like http://forums.wowace.com/showthread.php?t=18946
 
06-10-14, 06:06 AM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Rather than inventing your own special table format, just use the existing EasyMenu format as described in the thread Torhal linked (scroll down to post #4). It allows you to pass your table directly to the menu system.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.
 
06-10-14, 05:44 PM   #9
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Originally Posted by Phanx View Post
Rather than inventing your own special table format, just use the existing EasyMenu format as described in the thread Torhal linked (scroll down to post #4). It allows you to pass your table directly to the menu system.
Tried every time I try EasyMenu it fails saying it cant find the menuList or its nil. Ill just do it promatically the standard way then.
 
06-10-14, 06:40 PM   #10
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Nevermind I just got it off a random idea that happened to work.

For all of you to see and test here is the code:
Code:
function IOLib_CreateDropDown(parent, name, title, width, anchor, posX, posY, menuList, OnClick)
	local dropDown = CreateFrame("Button", name, parent, "UIDropDownMenuTemplate")
	--_G[name].list = menuList
	dropDown.list = menuList
	-- dropDown.Func = OnClick
	dropDown:ClearAllPoints()
	dropDown:SetPoint(anchor, posY, posX)
	
	local function initialize(self, level)
		local info = UIDropDownMenu_CreateInfo()
		
		if level ~= nil then
			info = UIDropDownMenu_CreateInfo()
			info.text = title
			info.isTitle = true
			UIDropDownMenu_AddButton(info, level)
			
			if level == 1 then
				
				for a,b in pairs(menuList) do
					info = UIDropDownMenu_CreateInfo()
					info.text = b[1]
					info.hasArrow = b[2]
					info.func = OnClick
					if info.hasArrow then _menuLists[b[1]] = b[3] end
					UIDropDownMenu_AddButton(info, level)
				end
				
			elseif level > 1 then
				--print(#_menuLists[UIDROPDOWNMENU_MENU_VALUE][2])
				--for x=1, #_menuLists[UIDROPDOWNMENU_MENU_VALUE] do
				for a,b in pairs(_menuLists[UIDROPDOWNMENU_MENU_VALUE]) do
					info = UIDropDownMenu_CreateInfo()
					info.text = b[1]
					info.hasArrow = b[2]
					if info.hasArrow then _menuLists[b[1]] = b[3] end
					info.func = OnClick
					UIDropDownMenu_AddButton(info, level)
				end
			end
			
			
		end
	end
	
	UIDropDownMenu_Initialize(dropDown, initialize)
	UIDropDownMenu_SetWidth(dropDown, width) -- Use in place of dropDown:SetWidth
	UIDropDownMenu_SetButtonWidth(dropDown, width + 24)
	UIDropDownMenu_SetSelectedID(dropDown, 1)
	UIDropDownMenu_JustifyText(dropDown, "LEFT")
	
	return dropDown
end
I used this table passed to it:
Code:
testMenuList = {{"Greetings", true, {{"Hi", true, {{"H", true, {{"Amazing", false, nil}}},{"i", false, nil}}},
										 {"Hello", false, nil}}},
					{"Farewells", true, {{"Bye", false, nil},
										 {"Goodbye", false, nil}}},
					{"Test", false, nil}}
Note: The ending level has to be enclosed in a {} as seen by the "Amazing" level. It stores all the level 3 entries of each table into a table. That had the chance for infinity and does have repeated information in the table but it works and I say thats fine by me. Anyone else can see about removing the useless cloned info if needed but for now it should be left as is.
 
06-11-14, 04:28 AM   #11
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Originally Posted by TULOA View Post
Tried every time I try EasyMenu it fails saying it cant find the menuList or its nil. Ill just do it promatically the standard way then.
Well do you know how to use EasyMenu then? It's fairly straightforward and it'll deal with indefinite levels.
__________________
Grab your sword and fight the Horde!
 
06-11-14, 09:32 AM   #12
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Originally Posted by Lombra View Post
Well do you know how to use EasyMenu then? It's fairly straightforward and it'll deal with indefinite levels.
From what I was shown yes but it never works for me. Its solved and done from my post above anyways.
 
06-11-14, 01:55 PM   #13
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by TULOA View Post
Tried every time I try EasyMenu it fails saying it cant find the menuList or its nil. Ill just do it promatically the standard way then.
Without seeing your code and the actual error message, it's impossible to say for sure, but I'd put money on the problem being bad scoping in your code, eg:

Code:
print(SomeVar) -- error because SomeVar is not defined yet
local SomeVar = "cats"
or:

Code:
do
    local SomeVar = "cats"
end
print(SomeVar) -- error because SomeVar only exists in the do-end block above, not here
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.
 
06-11-14, 07:41 PM   #14
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Originally Posted by Phanx View Post
Without seeing your code and the actual error message, it's impossible to say for sure, but I'd put money on the problem being bad scoping in your code, eg:

Code:
print(SomeVar) -- error because SomeVar is not defined yet
local SomeVar = "cats"
or:

Code:
do
    local SomeVar = "cats"
end
print(SomeVar) -- error because SomeVar only exists in the do-end block above, not here
No Phanx I didnt go through 4 years of college to fall to bad scope issues. And menuList wasnt defined by me through it. Its something you pass to the EasyMenu function as a table that should be named menuList in teh internal functions and yet manages to lose it after its run. If it was a code error it would error on login.
 
06-12-14, 12:13 AM   #15
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by TULOA View Post
And menuList wasnt defined by me through it. Its something you pass to the EasyMenu function as a table that should be named menuList in teh internal functions and yet manages to lose it after its run. If it was a code error it would error on login.
#1 - The default error display cannot show you errors that occur during the initial loading process. If you're not using BugSack or Swatter, then "no errors" is quite possibly wrong.

#2 - A scoping problem does not necessarily mean you have a syntax error. You are allowed to refer to a variable that isn't defined -- the end result is the same as if you'd explicitly defined the variable with a value of nil -- and you are allowed to pass nil to functions.

#3 - The error points to whichever line in Blizzard's code tries to do something with the value you passed into the function. If the value is nil at that point, it was also nil (or some other non-table value) when you passed it. This, again, points to a scoping issue within your code, or a misnamed variable.

#4 - Four years of college and you're still using the term "code error" and don't understand how a stack trace works? Really? I tried to give you a second chance here, despite the fact that your previous posts have made it quite clear that you don't really want help. You're always right, you never make mistakes, you know everything, and every line of code you write is perfect just the way it is. Carry on.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.
 
06-12-14, 12:44 AM   #16
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Originally Posted by Phanx View Post
#1 - The default error display cannot show you errors that occur during the initial loading process. If you're not using BugSack or Swatter, then "no errors" is quite possibly wrong.

#2 - A scoping problem does not necessarily mean you have a syntax error. You are allowed to refer to a variable that isn't defined -- the end result is the same as if you'd explicitly defined the variable with a value of nil -- and you are allowed to pass nil to functions.

#3 - The error points to whichever line in Blizzard's code tries to do something with the value you passed into the function. If the value is nil at that point, it was also nil (or some other non-table value) when you passed it. This, again, points to a scoping issue within your code, or a misnamed variable.

#4 - Four years of college and you're still using the term "code error" and don't understand how a stack trace works? Really? I tried to give you a second chance here, despite the fact that your previous posts have made it quite clear that you don't really want help. You're always right, you never make mistakes, you know everything, and every line of code you write is perfect just the way it is. Carry on.
No I am not always right and I dumb down terms to fit the needs of general public.

At this point I am sick of you. You only seem to mock those that dont worship you as a god. You arent.

Sure I dont know about stack traces as it wasnt taught. I know I coded it right as some were copies from source that failed as a test.

DO not reply back. I know I wont reply back to you. There is absolutely no reason for you to be this smug and arrogant when I already stated I had solved my issue when no one else could and I never said I needed help with EasyMenu. I simply wont use it.
 

WoWInterface » Developer Discussions » Lua/XML Help » DropDown Menus

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off