Skip to content

Instantly share code, notes, and snippets.

@kyzentun
Created January 24, 2017 05:01
Show Gist options
  • Save kyzentun/456f0041d94239f41556a48a11b55791 to your computer and use it in GitHub Desktop.
Save kyzentun/456f0041d94239f41556a48a11b55791 to your computer and use it in GitHub Desktop.
Menu data example:
{ -- Each table inside this table is one item in the menu.
-- A menu can have any number of items.
{name= "foo", arg= {}, func= function(arg) end},
-- arg is for any information that func needs. The menu system will not
-- touch arg in any way except to pass it to func.
-- func must return the action to perform when the item is chosen.
-- If func returns nil, the menu stays as-is.
-- If func returns "'refresh', {}", the table replaces the current menu.
-- If func returns "'submenu', {}", the table is another menu to open.
-- If func returns "'close', 1", the current submenu is closed.
-- The number returned with "close" is the number of submenu layers to
-- close. -1 will close the entire menu.
-- If func returns "'close', 1, {}", the table replaces the items in the
-- menu after closing that number of levels. This is equivalent to
-- "'close', 1" followed by "'refresh', {}".
{name= "foo", value= "bar", arg= {}, func= function(arg) end,
adjust_up= function(arg) end, adjust_down= function(arg) end},
-- func has the same behavior as the first example.
-- The player has two buttons for adjusting the value of a menu item.
-- adjust_up and adjust_down are used for these buttons.
-- adjust_* must return the new value to display.
on_return= function() end, -- Optional.
-- When a submenu is closed and the menu returns to this level,
-- on_return is called. Its return values are handled the same way as
-- the func function of a menu item.
-- A submenu that passes by this menu level when closing (by returning
-- "'close', 2" or similar) also calls the on_return functions of each
-- menu level that is closed.
...
}
Input options:
* 3 key mode (L, R, Start)
L and R go up and down the menu items. Start toggles adjust mode for an item. When adjust mode is on, L and R adjust the item instead. Pressing Start on an item with an action function instead of adjust functions activates that item instead of toggling adjust mode.
* 4 key mode (L, R, Select, Start)
Select and Start go up and down items. L and R adjust values. If an item has an action function instead of adjust functions, L does nothing, and R activates the item.
* 5+ key mode (L, R, U, D, Start)
U and D go up and down. L and R adjust values. Start activates items. Select jumps to the top item in the menu.
* Touch screen
Pop up a numpad for changing numeric values, use submenus for setting choice values.
Screenshot:
http://i.imgur.com/DSxU8sh.png
This is the most primitive menu structure. Menus for changing preferences or whatever are built on top of it by writing a function that fills in the common parts (i.e. accessing preferences structure) and allows the rest to be set by parameters.
Options that set a number or pick one choice from a set use the adjust_up and adjust_down functions.
Submenus and toggle options use the func function.
Also, each player has their own separate menu. Which allows one player to set speed mod while the other sets turn or insert mods (which Simply Love puts on different screens).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment