# Configuration

`Menu System` uses a simple configuration file located in:

* `data/config.lua`

This file controls localization for the resource.

### Localization

```lua
return {
    Locale = 'en',
}
```

#### `Locale`

Defines which language should be used.

Supported values:

* `en`
* `pl`

Example:

```lua
return {
    Locale = 'pl',
}
```

To add a new language, copy `locales/en.json` and create your own language file.

***

### Command

The resource includes the following command:

```lua
/menu_edit
```

This opens the layout editor for menu and input dialog positioning.

***

### Client Exports

### Menu Exports

#### `registerMenu(data, cb)`

Registers a menu definition.

```lua
exports['msk_menu']:registerMenu({
    id = 'example_menu',
    title = 'My Menu',
    position = 'bottom-right',
    canClose = true,
    options = {
        {
            label = 'Simple option',
            icon = 'fa-solid fa-house',
            args = { action = 'home' },
        },
        {
            label = 'With description',
            icon = 'fa-solid fa-circle-info',
            description = 'Shown at the bottom when selected',
            args = { action = 'info' },
        },
        {
            label = 'With progress',
            icon = 'fa-solid fa-star',
            progress = 65,
            colorScheme = 'green',
        },
        {
            label = 'Scrollable values',
            icon = 'fa-solid fa-sliders',
            values = { 'Low', 'Medium', 'High' },
            defaultIndex = 1,
        },
        {
            label = 'Checkbox',
            icon = 'fa-solid fa-toggle-on',
            checked = false,
        },
        {
            label = 'Colored icon',
            icon = 'fa-solid fa-palette',
            iconColor = '#FF4757',
        },
        {
            label = 'Stay open on select',
            close = false,
        },
    },
    onSelected = function(index, scrollIndex, args) end,
    onSideScroll = function(index, scrollIndex, args) end,
    onCheck = function(index, checked, args) end,
    onClose = function(key) end,
}, function(index, scrollIndex, args, checked)
end)
```

#### Supported menu fields

**`id`**

Unique menu identifier.

**`title`**

Menu title shown in the header.

**`position`**

Optional menu position hint.

**`canClose`**

Defines whether the menu can be closed normally.

**`options`**

Array of menu entries.

**`onSelected`**

Runs when the selected item changes.

**`onSideScroll`**

Runs when left or right scroll is used on value items.

**`onCheck`**

Runs when a checkbox item is toggled.

**`onClose`**

Runs when the menu is closed.

**`cb`**

Main callback fired when an item is confirmed.

***

#### `showMenu(id, startIndex?)`

Opens a previously registered menu.

```lua
exports['msk_menu']:showMenu('example_menu')
```

You can also optionally open the menu on a specific item index.

***

#### `hideMenu(onExit?)`

Closes the current menu.

```lua
exports['msk_menu']:hideMenu()
```

If `onExit` is enabled, the menu `onClose` callback is triggered.

***

#### `setMenuOptions(id, options, index?)`

Updates menu options.

```lua
exports['msk_menu']:setMenuOptions('example_menu', {
    { label = 'Updated option' }
})
```

You can replace the entire options list or update a specific entry.

***

#### `getOpenMenu()`

Returns the currently opened menu ID.

```lua
local menuId = exports['msk_menu']:getOpenMenu()
```

Returns `nil` if no menu is open.

***

### Input Dialog Exports

#### `inputDialog(heading, rows, options?)`

Opens an input dialog and returns user input.

```lua
local result = exports['msk_menu']:inputDialog('Dialog Title', {
    'Simple text field',
    { type = 'input', label = 'Username', placeholder = 'Enter name...', icon = 'fa-solid fa-user', required = true },
    { type = 'input', label = 'Password', password = true },
    { type = 'number', label = 'Amount', min = 0, max = 100, step = 1, default = 10 },
    { type = 'checkbox', label = 'I agree', checked = false },
    { type = 'select', label = 'Choose', clearable = true, options = {
        { value = 'a', label = 'Option A' },
        { value = 'b', label = 'Option B' },
    }},
    { type = 'multi-select', label = 'Tags', options = {
        { value = 'vip', label = 'VIP' },
        { value = 'admin', label = 'Admin' },
    }},
    { type = 'slider', label = 'Volume', min = 0, max = 100, step = 5, default = 50 },
    { type = 'date', label = 'Birthday' },
    { type = 'date-range', label = 'Period' },
    { type = 'time', label = 'Alarm' },
    { type = 'textarea', label = 'Notes', placeholder = 'Write...', autosize = true },
}, {
    allowCancel = true,
})
```

Returns:

* table of entered values
* `nil` if cancelled

***

#### `closeInputDialog()`

Closes the currently opened dialog.

```lua
exports['msk_menu']:closeInputDialog()
```

***

#### `getOpenInput()`

Returns whether an input dialog is currently open.

```lua
local isOpen = exports['msk_menu']:getOpenInput()
```

Returns:

* `true`
* `false`

***

### Input Row Types

Supported row types:

* `input`
* `number`
* `checkbox`
* `select`
* `multi-select`
* `slider`
* `date`
* `date-range`
* `time`
* `textarea`

#### Common row properties

* `type` — row type
* `label` — field label
* `icon` — Font Awesome icon
* `placeholder` — placeholder text
* `description` — additional text below the label
* `required` — whether the field must be filled
* `disabled` — disables the field
* `default` — default value

#### Type-specific properties

**`input`**

* `password`

**`number`**

* `min`
* `max`
* `step`

**`checkbox`**

* `checked`

**`select` and `multi-select`**

* `options`
* `clearable` for `select`

**`slider`**

* `min`
* `max`
* `step`

**`textarea`**

* `autosize`

***

### Menu Option Features

Menu entries can include:

* label
* icon
* description
* args
* checkbox state
* progress value
* value lists
* icon color
* progress color scheme
* close behavior

#### Example option types

Simple option:

```lua
{ label = 'Simple option' }
```

Option with description:

```lua
{ label = 'Info', description = 'Extra details here' }
```

Option with values:

```lua
{ label = 'Mode', values = { 'Low', 'Medium', 'High' }, defaultIndex = 1 }
```

Checkbox option:

```lua
{ label = 'Enabled', checked = true }
```

Progress option:

```lua
{ label = 'Health', progress = 65, colorScheme = 'green' }
```

***

### Controls

#### Menu Controls

* `Up / Down Arrow` — navigate items
* `Left / Right Arrow` — scroll values
* `Enter` — confirm item
* `Backspace` — go back or close
* `1` to `9` — quick-select menu items
* `Shift + 1` to `9` — quick-select items 10 to 18
* mouse wheel — navigate items
* mouse hover — highlight item
* mouse click — confirm item

#### Layout Editor

* `F9` — open editor while menu is open
* mouse drag — move menu or dialog
* right click — open scaling menu
* `Enter` — save changes
* `Escape` — discard changes

#### Input Dialog

* `Escape` — cancel dialog or close dropdown

***

### Layout Editor

The layout editor allows players to reposition and scale both:

* menu list
* input dialog

Settings are saved locally and restored automatically.

Stored values include:

* position
* scale

This data is saved in browser storage under:

```
msk_menu_settings
```

***

### Behavior Notes

* Menus support a history stack
* Opening a new menu while another is open pushes the previous one into history
* Pressing `Backspace` returns to the previous menu when available
* Items with `close = false` keep the menu open after selection
* String rows in input dialogs are automatically converted into text inputs
* While a menu is open, gameplay controls related to selection and combat are disabled to prevent conflicts
* The resource is fully client-side in practice, with only a lightweight server version check


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mskscripts.gitbook.io/mskscripts/scripts/menu-system/configuration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
