Files

77 lines
1.7 KiB
Markdown

# UIIconButtonComponent — giriş
[← UIIconButtonComponent](index.md) · [← Master](../../wiki.md)
mchorse.mappet.api.ui.components
Class UIIconButtonComponent
java.lang.Object
mchorse.mappet.api.ui.components.UIComponent
mchorse.mappet.api.ui.components.UIIconButtonComponent
public class UIIconButtonComponent
extends UIComponent
Clickable icon button component.
This component displays an icon, which allows users to trigger the handler script. The value that gets written to UI
context's data (if ID is present) is how many times the icon button was pressed.
This component can be created using IMappetUIBuilder.icon(String) method.
function main(c)
{
var ui = mappet.createUI(c, "handler").background();
var button = ui.icon("more").id("icon");
button.rxy(0.5, 0.5).wh(20, 20).anchor(0.5);
c.getSubject().openUI(ui);
}
function handler(c)
{
var uiContext = c.getSubject().getUIContext();
if (uiContext.getLast() === "icon")
{
// Get a set of all icons
var icons = Java.type("mchorse.mclib.client.gui.utils.IconRegistry").icons.keySet();
// Set a random icon
var index = Math.floor(Math.random() * icons.size());
var i = 0;
for each (var icon in icons)
{
if (i == index)
{
uiContext.get("icon").icon(icon);
break;
}
i += 1;
}
}
}
Field Summary
Fields
Modifier and Type Field and Description
java.lang.String icon
Fields inherited from class mchorse.mappet.api.ui.components.UIComponent
changedProperties, context, DELAY, enabled, h, id, keybinds, marginBottom, marginLeft, marginRight, marginTop,
tooltip, tooltipDirection, updateDelay, visible, w, x, y
Constructor Summary
Constructors
Constructor and Description