public class UIClickComponent extends UIComponent
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:
0
= X coordinate relative to click area's frame.1
= Y coordinate relative to click area's frame.2
= X factor (0..1) how far into the click area's width (0
being left edge, 1
being the right edge).3
= Y factor (0..1) how far into the click area's height (0
being top edge, 1
being the bottom edge).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);
var button = Math.floor(list.getFloat(4));
// Draw random rectangle on the back drop
if (button === 0)
{
var backdrop = uiContext.get("backdrop");
backdrop.rect(x - 10, y - 10, 20, 20, 0xff000000 + Math.floor(Math.random() * 0xffffff));
}
}
}
changedProperties, context, DELAY, enabled, h, id, keybinds, marginBottom, marginLeft, marginRight, marginTop, tooltip, tooltipDirection, updateDelay, visible, w, x, y
Constructor and Description |
---|
UIClickComponent() |
Modifier and Type | Method and Description |
---|---|
GuiElement |
create(Minecraft mc,
UIContext context) |
void |
populateData(NBTTagCompound tag) |
anchor, anchor, anchorX, anchorY, apply, applyKeybinds, applyProperty, change, clearChanges, context, context, createContext, deserializeNBT, enabled, getChanges, getChildComponents, getDefaultUpdateDelay, h, handleChanges, id, isDataReserved, keybind, keybind, keybind, keybind, margin, marginBottom, marginLeft, marginRight, marginTop, resetContext, rh, rh, rw, rw, rwh, rx, rx, rxy, ry, ry, serializeNBT, serializeNBT, tooltip, tooltip, updateDelay, visible, w, wh, x, xy, y
public GuiElement create(Minecraft mc, UIContext context)
create
in class UIComponent
public void populateData(NBTTagCompound tag)
populateData
in class UIComponent