Files

74 lines
1.9 KiB
Markdown

# IMappetUIContext.sendToPlayer
[← IMappetUIContext](index.md) · [← Master](../../wiki.md)
Parça 1/3 · [sonraki](sendToPlayer-2.md)
sendToPlayer()
void Sends UI changes to the player.
Method Detail
getData
INBTCompound getData()
Get the NBT compound of the UI data.
This data is formed by the UI components that have ID. The data will be populated only when the UI
elements will actually change their values. Until then this data will be empty.
function main(c)
{
var ui = mappet.createUI(c, "handler").background();
var name = ui.textbox().id("name");
var lastname = ui.textbox().id("lastname");
// Place two text fields in the middle of the screen
name.rxy(0.5, 0.5).wh(140, 20).anchor(0.5);
lastname.rx(0.5).ry(0.5, 25).wh(140, 20).anchor(0.5);
c.getSubject().openUI(ui);
}
function handler(c)
{
var uiContext = c.getSubject().getUIContext();
// If the user will input first in the name text box, the data
// will be just {name:"John"}. If the user will input first
// the lastname, then the data will be {lastname:"Appleseed"}.
// Once both fields will be edited, you'll get:
// {name:"John",lastname:"Appleseed"}
c.send(uiContext.getData().stringify());
}
isClosed
boolean isClosed()
Returns whether the UI was just closed.
The return value is true only when the user closed the screen, and the UI context is about to get cleared
from the player.
function main(c)
{
var ui = mappet.createUI(c, "handler").background();
var button = ui.button("Push me").id("button");
// Place a button in the middle of the screen
button.rxy(0.5, 0.5).wh(80, 20).anchor(0.5);
c.getSubject().openUI(ui);
}
function handler(c)
{
var uiContext = c.getSubject().getUIContext();
// Check if the user closed the screen
if (uiContext.isClosed())
{
// Do something with the data