Docs » API reference » Menu

Menu

A panel a plugin shows: tabs down its left side, and in each tab text, buttons, item tiles, toggles, sliders and Voxelmon.

A menu floats in front of the player in the game's own panel style, and they point and press as on any other panel. The plugin only describes the menu. The player's game draws it, so no plugin code runs on the headset. Each press comes back as a MenuPressed event with the pressed element's id, sent only to the plugin that made the menu, and the plugin decides what happens. A toggle or slider keeps and shows its new value without the plugin doing anything.

A menu can be changed at any time. Players who have it open see the change at the end of the tick, or at once with update. A player has one plugin menu open at a time, so opening another closes the first (MenuClosed). Walking about 3 blocks away from a floating menu, or fainting, also closes it.

A menu with an anchor stands at that place in the world and opens for any player who comes within 3.5 blocks of it (measured across the ground) with no menu open. If they close it, it stays shut for them until they have been 6 blocks away.

The limits keep every menu light on a headset: 8 tabs, with 64 elements and 24 item tiles a tab. A title has 32 letters at most, a tab's name 16 and an element's text 48. Ids are 64 bytes at most, each used once in its tab. Letters outside plain ASCII show as ?.

A handle to something in the game. Once that thing is gone, its calls fail with Gone. You get one from Menu.create(title); shown with player.open_menu(menu).

Methods

MethodDescription

Tab

One tab of a menu: rows of elements, top to bottom, side by side in a row. Each call adds an element and returns the tab, so calls chain.

A handle to something in the game. Once that thing is gone, its calls fail with Gone.

MethodDescription
fn text(&self, id: &str, text: &str) -> Result<Tab>Tab text(String id, String text)A line of text.
fn heading(&self, id: &str, text: &str) -> Result<Tab>Tab heading(String id, String text)A heading.
fn button(&self, id: &str, text: &str) -> Result<Tab>Tab button(String id, String text)A button.
fn item(&self, id: &str, stack: ItemStack, tooltip: &str) -> Result<Tab>Tab item(String id, ItemStack stack, String tooltip)An item tile: its model, count, and a card when pointed at.
fn toggle(&self, id: &str, text: &str, on: bool) -> Result<Tab>Tab toggle(String id, String text, boolean on)An on/off switch.
fn slider(&self, id: &str, text: &str, min: f64, max: f64, value: f64) -> Result<Tab>Tab slider(String id, String text, double min, double max, double value)A slider.
fn creature(&self, id: &str, species: Species, caption: &str) -> Result<Tab>Tab creature(String id, Species species, String caption)A Voxelmon's portrait with a caption.
fn row(&self) -> Result<Tab>Tab row()Starts a new row.
fn grid(&self, columns: i64) -> Result<Tab>Tab grid(long columns)Lays the next elements out in a grid (a shop's items), until the next row.
fn set_text(&self, id: &str, text: &str) -> Result<()>void setText(String id, String text)Changes an element's text.
fn set_on(&self, id: &str, on: bool) -> Result<()>void setOn(String id, boolean on)Changes a toggle.
fn set_value(&self, id: &str, value: f64) -> Result<()>void setValue(String id, double value)Changes a slider.
fn set_enabled(&self, id: &str, enabled: bool) -> Result<()>void setEnabled(String id, boolean enabled)Greys an element out, or not.
fn clear(&self) -> Result<()>void clear()Empties the tab.

Events

Related events: MenuPressed, MenuClosed.