WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   DropDown Menus (https://www.wowinterface.com/forums/showthread.php?t=49372)

TULOA 06-08-14 05:52 PM

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.

Torhal 06-08-14 06:00 PM

Have you consulted this guide?

TULOA 06-08-14 06:07 PM

Quote:

Originally Posted by Torhal (Post 293254)
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.

TULOA 06-08-14 06:18 PM

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.

TULOA 06-08-14 06:40 PM

Quote:

Originally Posted by TULOA (Post 293256)
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.

TULOA 06-08-14 06:57 PM

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"}}}

kurapica.igas 06-09-14 08:01 PM

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

Phanx 06-10-14 06:06 AM

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.

TULOA 06-10-14 05:44 PM

Quote:

Originally Posted by Phanx (Post 293281)
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.

TULOA 06-10-14 06:40 PM

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.

Lombra 06-11-14 04:28 AM

Quote:

Originally Posted by TULOA (Post 293298)
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.

TULOA 06-11-14 09:32 AM

Quote:

Originally Posted by Lombra (Post 293304)
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.

Phanx 06-11-14 01:55 PM

Quote:

Originally Posted by TULOA (Post 293298)
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


TULOA 06-11-14 07:41 PM

Quote:

Originally Posted by Phanx (Post 293317)
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.

Phanx 06-12-14 12:13 AM

Quote:

Originally Posted by TULOA (Post 293323)
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. :rolleyes:

TULOA 06-12-14 12:44 AM

Quote:

Originally Posted by Phanx (Post 293326)
#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. :rolleyes:

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.


All times are GMT -6. The time now is 01:49 AM.

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