Skip to content

MenuBuilder

Sebastian Gabl edited this page Nov 28, 2020 · 16 revisions

When creating a menu with MenuBuilder:create_menu, you can specify the optional parameters values and order. These parameters should be tables with keys of same name as the keys in your main settings table.

For values the values for those keys determine wether the element turns into a slider or a multi-select. Specifying a table with three number values like setting_name = { -1, 1, 0.01 } makes a slider with min=-1, max=1 and step=0.01. Specifying a table containing string values makes a multi-select with those values as the available options. If no value is specified in the values table for a setting using a number value, it defaults to a slider with min=0, max=1 and step=0.1.
You can also specify values for a table value in settings, if you do so, those values will be passed down to any elements in that table and be used as default for them if no other values are specified.

For order simply specify a number value for a setting, like setting_name = 99. This number value is used as priority for the menu entry and by default entries are sorted alphabetically by their keys.

When creating the MenuBuilder, it looks for existing localization in the form of menu_ID_SETTING and menu_ID_SETTING_desc where ID is the id you specified when creating the MenuBuilder and SETTING is the name of the setting in the settings table. The main menu node is using menu_ID and menu_ID_desc. If these localization strings can't be found, the MenuBuilder automatically creates localization strings based on the settings names. Localization strings for menu items of multi-select elements always have to be created manually.

A minimal example usage of the MenuBuilder could look like this:

TestMod = {
  settings = {
    enabled = true,
    slider = 0
  }
}

Hooks:Add("MenuManagerBuildCustomMenus", "MenuManagerBuildCustomMenusTestMod", function(menu_manager, nodes)
  local builder = MenuBuilder:new("test_mod", TestMod.settings)
  builder:load_settings()
  builder:create_menu(nodes)
end)
Clone this wiki locally