Skip to content

GUIs and triggers

GUI callbacks are lambdas:

auto gui = Gui::fromLayout("$CONTENT_DATA/Gui/Layouts/Panel.layout", {.destroyOnClose = true});
gui.setText("Title", "Settings");
gui.onButton("Ok", [this] { apply(); });
gui.horizontalSlider("Volume", 10, volume_, [this](int v) { volume_ = v; });
gui.open();

In Lua, a GUI callback is the name of a method on the script that created the GUI. The SDK stores each lambda in a numbered slot, and the loader's sm.allthelanguages.bindCallback(slot) adds a matching method to that script's class. This also works from ATL_MOD code, whose GUIs belong to the loader's runtime tool.

A part's GUIs are destroyed with the part. A destroyOnClose GUI frees its callbacks when it closes.

The game's built-in GUIs have typed forms too, such as gui::createContainerGui(), along with fades, text measuring and the garage import GUI. See atl/gui.hpp.

zone_ = areaTrigger::attachedBox(shape(), {4, 4, 4});
zone_.onEnter([](atl::Vector<Target> in) {
for (auto &t : in)
if (t.is<Character>()) { }
});

Triggers are cleaned up with the script that created them, like GUIs. See atl/trigger.hpp.