Keybind Matrix Map¶
Our UI can create matrix maps of the interactable elements on the screen through a universal Screens function. This map then allows the player to utilize the arrow keys of their keyboard to move through the screen's elements fluidly, with the enter key allowing them to interact with a selected element.
Screens need to be set up with this matrix map in order for the keybinding to work.
- Any interactable elements need to be added to the matrix map. Within the
screen_switchesfunc, you should compile all interactable elements into a list calledinteractive_elements. - This list can then be passed into the
self.add_to_mapfunction. The function will generate a newself.matrix_mapfor the screen. - An element should be designated as the "starting" focus by setting the
self.current_focusof the screen to the desired element.
If elements aren't being added or removed during screen-use, then you're finished. Nothing else needs to be done, the screen will now work with matrix keybinds.
However, if elements are being added or removed, then you'll need to be updating the map periodically as you do so.
- When elements are added, pass a list of them through
self.add_to_mapand the map will be updated. - When elements are removed, pass a list of them through
self.remove_from_mapbefore they are killed. - The map will have been updated and no further action from you is required.
Tip
You don't have to worry about adding and removing elements if they're being temporarily disabled or hidden. The map automatically skips over "invalid" elements when searching for a new element to focus on.