enigma-bbs/docs/_docs/modding/menu-modules.md

57 lines
2.0 KiB
Markdown
Raw Normal View History

2019-02-06 01:42:10 +00:00
---
layout: page
2022-02-04 14:51:03 +00:00
title: Menu Modules
2019-02-06 01:42:10 +00:00
---
## Menu Modules
2022-08-07 19:06:47 +00:00
All menu entries found within `menu.hjson` are backed by *menu modules*. Menus are any screen or sectionin within the system. A main menu, a door launcher, and MRC chat are all examples of menus. For basic menus, a standard handler is implemented requiring no code. However, if you would like to create a menu that has custom handling, simply inherit from `MenuModule`. More on this below.
> :information_source: Remember that ENiGMA does not impose any stucture to your system! The "flow" of all `menu.hjson` entries is up to you!
2019-02-06 01:42:10 +00:00
## Creating a New Module
2022-08-07 19:06:47 +00:00
At the highest level, to create a new custom menu or mod, inherit from `MenuModule` and expose it via the `getModule` exported method:
```javascript
// my_fancy_module.js
exports.getModule = class MyFancyModule extends MenuModule {
constructor(options) {
super(options);
}
};
```
## Lifecycle
Below is a very high level diagram showing the basic lifecycle of a menu.
2019-02-06 01:42:10 +00:00
2022-08-07 04:51:59 +00:00
![Basic Menu Lifecycle](../../assets/images/basic_menu_lifecycle.png)
2019-02-06 01:42:10 +00:00
2022-08-07 19:06:47 +00:00
Methods indicated above with `()` in their name such as `enter()` are overridable when inheriting form `MenuModule`.
## MenuModule Helper Methods
Many helper methods exist and are available to code inheriting from `MenuModule`. Below are some examples. Poke around at [menu_module.js](../../../core/menu_module.js) to discover more!
2022-08-09 02:15:23 +00:00
### Views & View Controller
2022-08-07 19:06:47 +00:00
* `displayAsset()`
* `prepViewController()`
* `prepViewControllerWithArt()`
* `displayArtAndPrepViewController()`
* `setViewText()`
* `getView()`
* `updateCustomViewTextsWithFilter()`
* `refreshPredefinedMciViewsByCode()`
2022-08-09 02:15:23 +00:00
### Validation
2022-08-07 19:06:47 +00:00
* `validateMCIByViewIds()`
* `validateConfigFields()`
2022-08-09 02:15:23 +00:00
### Date/Time Helpers
The following methods take a single input to specify style, defaulting to `short`:
2022-08-07 19:06:47 +00:00
* `getDateFormat()`
* `getTimeFormat()`
* `getDateTimeFormat()`
2019-02-06 01:42:10 +00:00
2022-08-09 02:15:23 +00:00
### Misc
* `promptForInput()`
2022-08-07 19:06:47 +00:00
> :information_source: Search the code for the above methods to see how they are used in the base system!