Skip to content

Latest commit

 

History

History
177 lines (103 loc) · 4.88 KB

File metadata and controls

177 lines (103 loc) · 4.88 KB

Menu

A menu of various items that can be rendered on screen.


Constructor

new Menu(scene, config);

Arguments

  • sceneScene The scene this Menu is a part of.
  • configObject The Menu's config object.
    • xnumber This Menu object's x-coordinate.
    • ynumber This Menu object's y-coordinate.
    • itemsArray<Menu.Item> An array of Menu.Item instances. You can extend the Menu.Item class to make your own items.
    • titlestring Optional menu title.
    • alignCenterboolean Whether or not to align the content to the center of the menu. Default true.
    • borderboolean Whether or not to create a border around the menu. Default true.
    • layerstring The label of the layer to start the Menu on.
    • autoFocusboolean Whether to automatically focus on the Menu after it has been instantiated. Default true.
    • maintainFocusboolean Forces the menu to stay focused. Default true.
    • deleteOnBlurboolean Whether to delete the menu when it becomes unfocused. Default false.
    • gamepadnumber An optional number indicating the gamepad (0-based index) this menu should accept input from. Set to -1 to accept input from all gamepads.

Properties

gamepad

The current gamepad index.

items

An array of Menu.Item instances that are part of the menu.

title

The title of the menu.

index

The index of the current item that is selected in the menu.


Methods

handleInput(event)

Handle input events to navigate and select options in the menu.

Arguments

  • eventObject The input event to handle.

get width()

Get the width of the menu.

Returns

  • number The width of the menu based on the longest option and title.

get height()

Get the height of the menu.

Returns

  • number The height of the menu based on the number of options.

determineLongestOption()

Determine the length of the longest option label.

Returns

  • number The length of the longest option label.

get renderable()

Generate the renderable representation of the menu.

Returns

  • PixelMesh The PixelMesh representation of the menu including options and title.

blur()

Unfocus the menu. If maintainFocus is true, the menu will not be unfocused.


itemAtCoordinate(y)

Get an item at a y-coordinate relative to the menu.

Arguments

  • ynumber The y-coordinate to check.

Returns

  • Menu.Item|undefined The item at that coordinate, or undefined if there is no item at the coordinate.

Sub-Classes

Menu.Item

Base class for menu items, which can be extended to create custom items.

Menu.Button

A string of text that triggers an event when clicked.

Constructor

new Menu.Button(config);

Arguments
  • configObject The Button's config object.
    • labelstring The Button's display label.
    • callbackfunction The function to call when this item is clicked/activated.
    • wrapboolean Whether or not to wrap the text if it overflows the container. Will break words. Default false.

Menu.Slider

A slider that allows value selection.

Constructor

new Menu.Slider(config);

Arguments
  • configObject The Slider's config object.
    • labelstring An optional Slider display label.
    • valuenumber The starting value of the Slider.
    • minnumber The minimum value for the Slider.
    • maxnumber The maximum value for the Slider.
    • stepnumber The amount the value will change by each input.
    • onChangefunction The function to call when the value of this Slider changes.
    • callbackfunction The function to call when "enter" is pressed on the Slider. This callback is passed the current Menu.Slider value as an argument.
    • showValueboolean Whether to show the value of the Slider after it. Default: false.
    • showPercentageboolean Whether to show the value (in percentage format) of the Slider after it. Default: true.

Menu.Toggle

A checkbox that can be toggled on or off.

Constructor

new Menu.Toggle(config);

Arguments
  • configObject The Toggle's config object.
    • labelstring The Toggle's display label.
    • checkedboolean The initial status of the Toggle. Default: false.
    • prependboolean Whether to put the checkbox icon at the start or end of the label. Default: true.
    • callbackfunction The function to call when this item is toggled.