Skip to content

ModMenu 2: mod-storm, the re-menuing (& Knuckles) #85

Description

@Emmehehe

Various changes to reduce the coding effort for people using the tool:

  • New json style api format + utility functions.
  • Data validation and error reporting (makes troubleshooting menus easier).
  • Standardised 'data ref' format makes hooking variables into the menu easier.
    • var field is now where the variable name lives
    • Mandatory default field, a default value which modmenu uses if save data is missing or var is not initialised.
    • May optionally provide the handle field, this lets you change the handle from global to any other type of handle, such as an object instance.
    • May optionally provide the ini_key field, this lets you override the key for the property in save data (normally just uses var field).
  • Data can save/load automatically using quick settings
    • Choose between: no save data, Single save file, PerSlot save files (1 per slot, max of 3), PerFile save files (1 per game save data, same behaviour as vanilla saves).
    • Menu items have a no_save option to disable save/load for specific properties.
    • additional_save_data_refs to save/load any variables that aren't shown in the menu, uses 'data ref' format
  • apply declare call-back function for applying your settings
    • Will run OnChange (of any menu item) or OnClose (of the menu)
    • Will also run on loading save data (if you have that configured)
  • type used to declare the type of a menu item, enables data validation from second point
  • Various function callbacks added: open_func (menu opened), close_func (menu closed), trigger_func (menu item clicked), change_func (menu item value changed), cancel_func (menu item selection cancelled), accept_func (menu item selection confirmed)
  • New standardised localisation format. If you're only adding one language you can simply set the value without any _en type postfix. e.g. title: "Hello"
    • To add localisation, replace single value with array of this format title: [{lang: "en", val: "Hello"}, {lang: "fr", val: "Bonjour"}] The first entry in the array will be the default if the lang can't be found.
  • Callbacks are no longer defined by supplying a string matching the name of the global callback, now you simply supply a reference to the callback.
  • Many bool type fields can instead accept a callable function for dynamic behaviour if you wish.
  • revert_on_cancel added to Slider menu items - if the user cancels out of the selection [X]/(B), the value changes will be reverted.
  • ref - use to set a reference to the menu item, if you need to access it elsewhere in code.

Hope is for a new api for creating menus following this format:

if (variable_instance_exists(id, "modmenu"))
    modmenu.create({
        title: localised string,
        left_margin: localised int, // optional
        left_value_pos: localised int, // optional
        apply: {type: "OnChange" | "OnClose", func: callable}, // optional
        save: {type:"Single" | "PerSlot" | "PerFile", name: string}, // optional
        open_func: callable, // optional
        close_func: callable, // optional
        form: [
            {
                type: "Toggle",
                title: localised string,
                data_ref: {handle: handle /* optional(=global) */, var: string, default: any, ini_key: string  /* optional */},
                value_range: localised string,
                no_save: bool, // optional
                trigger_func: callable, // optional
                change_func: callable, // optional
                disabled: bool | callable, // optional
                hidden: bool | callable, // optional
                ref: {handle: handle /* optional(=global)*/, var: string} //optional
            },{
                type: "Slider",
                title: localised string,
                data_ref: {handle: handle /* optional(=global)*/, var: string, default: any, ini_key: string  /* optional */},
                value_range: localised string,
                no_save: bool, // optional
                revert_on_cancel: bool | callable, // optional
                trigger_func: callable, // optional
                change_func: callable, // optional
                cancel_func: callable, // optional
                accept_func: callable // optional
                disabled: bool | callable, // optional
                hidden: bool | callable, // optional
                ref: {handle: handle /* optional(=global)*/, var: string} //optional
            },{
                type: "Button",
                title: localised string,
                trigger_func: callable,
                disabled: bool | callable, // optional
                hidden: bool | callable, // optional
                ref: {handle: handle /* optional(=global)*/, var: string} //optional
            },{
                type: "Header",
                title: localised string, // optional
                disabled: bool | callable, // optional
                hidden: bool | callable, // optional
                ref: {handle: handle /* optional(=global)*/, var: string} //optional
            }
        ],
        additional_save_data_refs: [ // optional
            {handle: handle /* optional(=global)*/, var: string, default: any, ini_key: string  /* optional */}
        ]
    });

modmenu.create - in addition to adding the menu to ModMenu's registry, this function will also validate the data and report any issues it finds so you can know why your menu data didn't work.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions