Try to do this:
1. Create a table:
Code: Select all
menus={{"line1","line2","line3","line4",},
{"line1","line2","line3","line4",},
{"line1","line2","line3","line4",},
{"line1","line2","line3","line4",},
...}
Every other sub-table should contain a list of the text of menu items. Every other menu and submenu you have, should go in here. You can make it more complicated, but that's up to you.
2. Create a variable
It will tell you which menu you're in.
3. Create a variable
It will tell you which menu *item* you've selected.
4. Now make your draw function look like this:
Code: Select all
for i=1, #menus[current_menu] do
love.graphics.print(menus[current_menu][i], X, Y+ 20*i)
end
This way you'll be drawing only current (sub)menu.
5. Apply controls.
Code: Select all
if love.keyreleased["up"] then
current_item = current_item - 1
if current_item<1 then
current_item = #menus[current_item]
end
end
if love.keyreleased["down"] then
current_item = current_item + 1
if current_item>#menus[current_item] then
current_item = 1
end
end
The actual way to determine current item (if needed) and/or setting it to some value may be changed. I haven't seen your code to tell for sure;)
6. The last, but the most complex (not really) would be to create a handler for those menus. Make an update function that does something like this:
Code: Select all
if current_menu==1 then
if current_item==1 then
-- handle item #1 from menu #1
elseif current_item==2 then
-- handle item #2 from menu #1
elseif current_item==3 then
...
elseif current_item==4 then
...
end
elseif current_menu==2 then
if current_item==1 then
-- handle item #1 from menu #2
elseif current_item==2 then
-- handle item #2 from menu #2
elseif current_item==3 then
...
elseif current_item==4 then
...
end
elseif current_menu==3 then
...
elseif current_menu==4 then
...
end
Note, that you can draw only inside of love.draw().
Note, that it's a good idea to move all your key-press detection inside love.update.
In order to make it more convenient, create your own functions menu.draw and menu.update, put everything needed into those, and call menu.draw in love.draw and menu.update in love.update.
Cheers!
P.S. You may want to see how I did something like this in MagicGems (see my signature). #NotSomeNastyAdvertisement