A menu that uses the playdate's keyboard to navigate and select. Created as an aesthetic homage to traditional roguelikes!
Create menu items just like the playdate's menu system. Tie your callbacks and tweak your parameters to close the keyboard, menu/page or all menus when the item is selected.
If your menu has too many options and will overflow the space it has, it will automatically create a sub page at the bottom.
Whatever font you give it will automatically adjust its dimensions to fit it properly.
Added type and constructor definitions for LuaCATS used by Lua Language Server for the sumneko.lua VSCode extension. Highly recommend using with Playdate-LuaCATS by notpeter.
- You cannot change the font after the menu is created, you will need to recreate the menu if you wish to change the font.
Try it out on the Playdate (download pdx) and peruse some code at this git https://github.com/AavaGames/playdate-keyboard-based-menu-ui-example
- Download the repo
- Add the
keyboard-based-menu
folder to your project - import
SOURCEFOLDER\keyboard-based-menu\imports
- Now you can create a MenuManager singleton and open Menus!
Look through main.lua here to get a real example of its use.
- Create a MenuManager singleton
- Pass in your callback for what to do when a menu opens from gameplay and when all menus close. Example: Change GameManager state to menu so gameplay update stops running.
- Create a Menu: pass it the menu manager, a name and its items.
menu:open()
--[[
Initializes a menu item.
Parameters:
text (string): The text of the menu item.
assignedGlyph (string): The preferred assigned glyph for the menu item. Nil assigns the next in the keyboard sequence. First come, first serve. To skip use nil or empty string ""
closeKeyboardOnSelect (boolean): Whether to close the keyboard on selection.
closeMenuOnSelect (boolean): Whether to close the menu on selection.
allMenus (boolean): Whether to close all menus on selection. Requires closeMenuOnSelect.
selectionFunction (function): The function to execute when the menu item is selected.
]]