Files

59 lines
1.8 KiB
Markdown

# UIClickComponent — giriş
[← UIClickComponent](index.md) · [← Master](../../wiki.md)
Parça 1/2 · [sonraki](_giris-2.md)
mchorse.mappet.api.ui.components
Class UIClickComponent
java.lang.Object
mchorse.mappet.api.ui.components.UIComponent
mchorse.mappet.api.ui.components.UIClickComponent
public class UIClickComponent
extends UIComponent
Click area component.
This component doesn't display anything but rather acts as a special user input field. When an ID is assigned and
users clicks on the component's bounds, this component will be sending a NBT list containing 5 floats:
Index 0 = X coordinate relative to click area's frame.
Index 1 = Y coordinate relative to click area's frame.
Index 2 = X factor (0..1) how far into the click area's width (0 being left edge, 1 being the right edge).
Index 3 = Y factor (0..1) how far into the click area's height (0 being top edge, 1 being the bottom edge).
Index 4 = Mouse button (0 is left button, 1 is right button, 2 is middle button, etc.).
This component can be created using IMappetUIBuilder.click() method.
function main(c)
{
var ui = mappet.createUI(c, "handler").background();
var click = ui.click().id("click");
var backdrop = ui.graphics().id("backdrop");
backdrop.rxy(0.5, 0.5).wh(300, 150).anchor(0.5);
backdrop.rect(0, 0, 300, 150, 0x88000000);
click.rxy(0.5, 0.5).wh(300, 150).anchor(0.5);
c.getSubject().openUI(ui);
}
function handler(c)
{
var uiContext = c.getSubject().getUIContext();
var data = uiContext.getData();
if (uiContext.getLast() === "click")
{
// Math.floor just in case there are precision issues
var list = data.getList("click");
var x = Math.floor(list.getFloat(0));
var y = Math.floor(list.getFloat(1));
var fx = list.getFloat(2);
var fy = list.getFloat(3);