Dialogs - ShaneBeee/SkNMS GitHub Wiki
For more general information, please see Dialog on McWiki.
Caution
This page is a work in progress.
Dialogs can be used in 2 ways:
- Static: Create and register in the
registry registration
structure, which you can then use theopen dialog
effect to open them to players.
This is similar to how Datapacks work.
Once registered, they cannot be changed/removed without a server restart. - Dynamic: Create and open dialogs on the fly.
This is useful if your action buttons/bodies/inputs need to change per player or any other reason.
There are 5 types of dialogs in Minecraft:
- server links (not covered in SkNMS)
- notice
- confirmation
- multi_action
- dialog_list
Each dialog has a bunch of different entries (referred to as "fields" in Minecraft) that allow you to setup/control the dialog.
These entires are common and can be used in all of the dialogs.
-
title
= Screen title. Should be always visible on screen, no matter the specific type (Can use a string or text component/mini message). -
external_title
= Name to be used for a button leading to this dialog (for example, on the pause menu), optional. If not present, title will be used instead. (Can use a string or text component/mini message) -
body
= Optional section of body elements or a single body element. See Body Format -
inputs
= Optional section of input controls. See INCLUDE LINK HERE!!! -
can_close_with_escape
= Can dialog be dismissed with Escape key. Defaults to true. -
after_action
= An additional operation performed on the dialog after click or submit actions (accepts a string). Choices are:- "close" = Closes the dialog and returns to the previous non-dialog screen (if any).
- "none" = Does nothing, i.e. keeps the current dialog screen open.
- "wait_for_response " = Replace the current dialog with a "Waiting for Response" screen.
A dialog screen with a single action button in footer, specified by an action button.
By default, the exit action (which returns the player back to gameplay) is the same as the action button.
Static = register [new] notice dialog with id %string/namespacedkey%:
Dynamic = open [new] notice dialog to %players%:
-
action
= Click action. Defaults to button withgui.ok
label and no action or tooltip.
This is a section where you'll use an aAction Format Section to add your action[s].
A dialog screen with two action buttons in footer, specified by a YES and NO set of action buttons.
By default, the exit action is the no button.
Static = register [new] confirmation dialog with id %string/namespacedkey%:
Dynamic = open [new] confirmation dialog to %players%:
-
actions
= Same as Notice above, but you must include 2 actions in this section.
The first is used for your "YES" action and the second used for your "NO" action.
Accepts Action Format Sections
A dialog screen with a scrollable list of action buttons arranged in columns.
If an exit_action is present, a button for it will appear in the footer, otherwise the footer is not present.
exit_action is also used for the Escape action.
Static = register [new] multi action dialog with id %string/namespacedkey%:
Dynamic = open [new] multi action dialog to %players%:
-
actions
= Similar to above, but you can include as many [action buttons[(https://github.com/ShaneBeee/SkNMS/wiki/Dialogs#action-format) in this section as you want. -
columns
= Positive integer describing number of columns. Defaults to 2. [Optional] -
exit_action
= Action for leaving the dialog. Same as action sections but will only accept one action. [Optional]
A dialog screen with scrollable list of buttons leading directly to other dialogs, arranged in columns.
Titles of those buttons will be taken from external_title
fields of targeted dialogs.
If exit_action
is present, a button for it will appear in the footer, otherwise the footer is not present.
exit_action
is also used for the Escape action.
Static = register [new] dialog list dialog with id %string/namespacedkey%:
Dynamic = open [new] dialog list dialog to %players%:
-
dialogs
= A list of strings of previously defined dialogs.
Will accept the ID of the other dialogs, whether registered by you or from datapacks. -
exit_action
= Action for leaving the dialog. Same as action sections but will only accept one action. [Optional] -
columns
= Positive integer describing number of columns. Defaults to 2. [Optional] -
button_width
= Integer value between 1 and 1024 — Width of the button. Defaults to 150.
All dialogs have a list of body elements describing contents between title and actions or inputs.
A body element that takes in a string or text component.
In SkNMS this is created by a section which will be used in the body
section of a dialog.
add (text|plain message) body:
-
contents
= A string or text component which supports multi lines. -
width
= Integer value between 1 and 1024 — Maximum width of message. Defaults to 200.
An item with optional description.
It appears like it is in the inventory slot when the mouse hovers over the item.
The size does not scale even if width and height are set to other values than the default (wtf is the point of this then??).
If the description is present, then it appears next to the right side of the item.
add item body:
-
item
= Takes in a single ItemStack/ItemType. -
description
= A section that accepts a plain message section to describe the item. -
show_decoration
= If true, count and damage bar will be rendered over the item. Defaults to true. [Optional] -
show_tooltip
= If true, item tooltip will show up when item is hovered. Defaults to true. [Optional] -
width
= Integer value between 1 and 256 — Horizontal size of element. Defaults to 16. [Optional] -
height
= Integer value between 1 and 256 — Vertical size of element. Defaults to 16. [Optional]
Input controls are used to receive certain information from the players.
These informations can be used with the associated key tag, for example, when an action button is clicked, the key can be used to reference information stored on that input control, either when running a command with macro substitution, or a custom NBT tag sent to the server.
These entries are common to all input types.
-
key
= String identifier of value used when submitting data, must be a valid template argument (letters, digits and _). -
label
= A string/text component to be displayed to the left of the input.
A basic, single line, text input.
-
width
= Integer value between 1 and 1024 — The width of the input. Defaults to 200. [Optional] -
label_visible
= Controls if the label is visible. Defaults to true. [Optional] -
initial
= The initial string value of the text input. [Optional] -
max_length
= Maximum length of input. Defaults to 32. [Optional] - The next two represent
multiline
and if used, must be used together.
If present, allows users to input multiple lines, optional object with entries:-
multiline_max_lines
= Positive integer. If present, limits maximum lines. -
multiline_height
= Integer value between 1 and 512 — Height of input.
-
A simple checkbox.
-
initial
= The initial boolean value of the checkbox. Defaults to false (unchecked). -
on_true
= The string value to send when true. Defaults to "true". -
on_false
= The string value to send when false. Defaults to "false".
A preset option selection.
It will be present as a button, each time you click the button the text in it will cycle through.
-
label_visible
= Controls if the label is visible. Defaults to true. -
width
= Integer value between 1 and 1024 — The width of the input. Defaults to 200. -
options
= A section for adding options.
add options entry:
-
display
= A string/text component for what is displayed as the option. -
initial
= Only one option can have this set to true. If true, the option chosen will be the initial one. Defaults to the first option being true, and all others false.
A number slider.
-
label_format
= A translation key to be used for building label (first argument is contents of label field, second argument is current value). Defaults to "options.generic_value". -
width
= Integer value between 1 and 1024 — The width of the input. Defaults to 200. [Optional] -
start
= The minimum number of the slider. -
end
= The maximum number of the slider. -
step
= Step size (If present, only values of initial+*step will be allowed. If absent, any value from the range is allowed). [Optional] -
initial
= The initial increment value of the slider. Defaults to the middle of the range. [Optional]
Static actions are actions that don't depend on the value of an input field.
The static actions use Click Events from SkBee.
See Static Action Types on McWiki for further details.
add static action button:
-
label
= String/text component labelled on the button. -
tooltip
= String/text component to display when button is highlighted or hovered over. [Optional] -
width
= Integer value between 1 and 1024 — Width of the button. Defaults to 150. [Optional] -
action
= An action to perform when button is clicked. Accepts a Click Events from SkBee.
Can be used in conjunction with input controls. See Dynamic Action Types on McWiki for further details.
Currently not implemented in SkNMS.
The class for this has private access... no bueno!
Warning
This may change based on how Paper/Adventure handles this in the future.
This method will build a minecraft:custom
event using all input values.
All input contents will be sent together inside an NBT Compound Tag, with tag value of each input put under id from key field of that input.
As of right now a custom event is called which allows you collect the player, key and NBT data when the action takes place.
add dynamic action button:
-
label
= String/text component labelled on the button. -
tooltip
= String/text component to display when button is highlighted or hovered over. [Optional] -
width
= Integer value between 1 and 1024 — Width of the button. Defaults to 150. [Optional] -
id
= The ID that will be referenced in the event. Accepts a string or NamespacedKey from SkBee. -
additions
= Additional NBT data that will be sent to the event, this accepts an NBT Compound.