Interface
Interfaces are built in the editor interface tab. In code, an interface and its elements are referred to by name.
local loja = Ui.get("Loja")loja["Moedas"]:setText("Moedas: 12")loja["Fechar"]:onClick(self, function() Ui.hide("Loja") end)loja:show()Ui::Element loja = Ui::get("Loja");loja["Moedas"].setText("Moedas: 12");loja["Fechar"].onClick(this, [] { Ui::hide("Loja"); });loja.show();Interfaces
Section titled “Interfaces”| Function | What it does |
|---|---|
Ui.get(ui) |
The interface with that name. |
Ui.show(ui) |
Shows the interface, on top of the ones already on screen. |
Ui.hide(ui) |
Hides the interface. What the code changed in it remains. |
Ui.visible(ui) |
true if the interface is on screen. |
Ui.reset(ui) |
Returns the interface to its editor state and removes the onClick handlers. |
Ui.mouseOver() |
true if the mouse is over a button or panel. |
Elements
Section titled “Elements”element["Name"] returns an inner element. The set... methods return the element itself and can be chained.
| Function | What it does |
|---|---|
exists() |
true if the interface or element exists. |
setText(text), text() |
The text of a Text or a Button. |
setValue(value), value() |
How full a Bar is, from 0 to 1. |
show(), hide(), setVisible(visible), visible() |
Shows or hides the interface or the element, with its contents. |
setEnabled(on), enabled() |
A disabled button is dimmed and does not respond. |
setSprite(sprite, frame), setFrame(frame) |
The sprite of an Image, or the background of a Panel or Button. |
setColor(color) |
The main color: background of the Panel and Button, filled part of the Bar, letters of the Text. |
setTextColor(color), setBorderColor(color) |
The color of the letters and of the border. |
setFont(font, size), setTextSize(size) |
The project font (empty = the built-in one) and the size in pixels. |
setPosition(x, y), setSize(width, height) |
Position (from the anchor) and size, in game pixels. |
setScroll(pixels), scroll() |
The scroll of a Panel with Scroll, in pixels. |
clone(name) |
Copies the element into the same panel, at the end of the list, and returns the copy. |
remove() |
Removes the element from the interface. |
onClick(owner, fn) |
Runs fn when the Button is pressed. With the instance as owner, the handler ends when it is destroyed. |
onMouseEnter(owner, fn), onMouseLeave(owner, fn) |
Runs fn when the mouse enters the element and when it leaves. |
local hud = Ui.get("Hud")hud["Vida"]:setValue(self.vida / 10):setColor(colors.red)
local item = Ui.get("Loja")["Itens"]["Modelo"]:clone("Item1")item["Nome"]:setText("Espada")item["Comprar"]:onClick(self, function() self:comprar("espada") end)Ui::Element hud = Ui::get("Hud");hud["Vida"].setValue(vida / 10.0f).setColor(colors::red);
Ui::Element item = Ui::get("Loja")["Itens"]["Modelo"].clone("Item1");item["Nome"].setText("Espada");item["Comprar"].onClick(this, [this] { comprar("espada"); });- Each interface exists only once. Hiding and showing does not undo the changes;
Ui.resetdoes. - Interfaces checked under Interfaces, in the room Inspector, open with it and close on leaving. The ones shown by code stay until the code hides them.
- With the mouse over a button or a panel with background,
mousePressed,mouseHeldandmouseReleasedreturnfalseto the game. - Keyboard and gamepad navigate the buttons of the front interface, with the actions
cima,baixo,esquerda,direitaandconfirmar. - Pausing the game:
setPaused, in Rooms and window. In C++ the functions are underUi::.
