Files

1.8 KiB

IScriptFactory.vector4

← IScriptFactory · ← Master

Parça 6/11 · önceki · sonraki

var ui = mappet.createUI().background(); var label = ui.label("Hello, world!").background(0x88000000);

label.rxy(0.5, 0.5).wh(80, 20).anchor(0.5).labelAnchor(0.5);

c.getSubject().openUI(ui); }

createUI

default IMappetUIBuilder createUI(IScriptEvent event, java.lang.String function)

Create a UI with a script handler. You can send it to the player by using IScriptPlayer.openUI(IMappetUIBuilder) method.

function main(c) { var ui = mappet.createUI(c, "handler").background(); var label = ui.label("Hello, world!").background(0x88000000); var button = ui.button("Push me!").id("button");

label.rxy(0.5, 0.5).wh(80, 20).anchor(0.5).labelAnchor(0.5); label.rx(0.5).ry(0.5, 25).wh(80, 20).anchor(0.5);

c.getSubject().openUI(ui); }

function handler(c) { var uiContext = c.getSubject().getUIContext();

if (uiContext.getLast() === "button") { // Button was pressed } }

Parameters: event - Script event (whose script ID will be used for UI's user input handler). function - Given script's function that will be used as UI's user input handler.

createUI

IMappetUIBuilder createUI(java.lang.String script, java.lang.String function)

Create a UI with a script handler. You can send it to the player by using IScriptPlayer.openUI(IMappetUIBuilder) method.

Script and function arguments allow to point to the function in some script, which it will be responsible for handling the user input from scripted UI.

In the UI handler, you can access subject's UI context (IMappetUIContext) which has all the necessary methods to handle user's input.

// ui.js function main(c) { var ui = mappet.createUI("handler", "main").background();