Example mod · theonaris.examples.menu-tweaks 1.0.0
Menu Tweaks
Changes the game's own menus: edits text and styles, adds a news panel and a pause-menu button, and removes the About button. Everything is put back when the mod is turned off.
Changes the game's own interface: the three operations every UI mod is made of.
| Operation | Example here | API |
|---|---|---|
| Edit | Main menu subtitle text, Play button border and tooltip | ui.find, UiElement:setText, :style, :set("tooltip", …) |
| Add | A news panel built from .uxml + JSON; a Tip button on the pause menu | ui.screen, ui.load, ui.element, UiElement:add |
| Remove | The About button | UiElement:remove |
Everything is undone when the mod stops. Switch it off in Mods, press Apply changes, and the menus are exactly as they were.
Try it
- Install, start the game and allow Change the game's interface (
ui.game). - The main menu subtitle reads Now with mods, the Play button has an orange edge, a news panel sits in the corner, and the About button is gone.
- In a game, press Escape. The pause menu has a 💡 Tip button.
- Switch the mod off in Mods and press Apply changes. Everything goes back.
How it works
Finding the game's elements
Game screens have ids (main-menu, pause-menu, building, vehicle-hud, interaction-prompt, planet-hud, hangar). ui.screens() lists them and whether each is open. Inside a screen, use the selectors you would use in a .uss file:
ui.find("main-menu", "#btn-about") -- by name
ui.find("main-menu", ".brand-subtitle") -- by class
ui.findAll("main-menu", "Button") -- by typeTo explore a screen's element names, list them while it is open. In the script editor's Console, on this mod's client copy:
for _, e in ipairs(ui.findAll("main-menu", "Button")) do log.info(e.name, e:text()) endScreens come and go
A screen's elements are created when it opens and discarded when it closes, so a mod applies its changes on ui.screen.opened, and once at start for screens that are already open. Check before adding (screen:find("#mt-news")) so reopening does not add a second copy.
Undo is built in
With ui.game, every change to a game element (text, style, class, tooltip, enabled state, removal, children added) is recorded against your mod. When the mod stops for any reason, the game replays the record backwards. Elements you create are destroyed at the same time.
Styling your own elements
ui.load("ui/news.uxml") applies <Style src="news.uss" /> to the elements in that file only. Game elements keep their own styles, so prefix your class names (mt-… here) to keep them distinct. To restyle a game element, use :style{ … }.
Files
mod.json
scripts/client.lua
ui/news.uxml, ui/news.uss, ui/banner.png
data/news.json the panel's text
data/tips.json the pause-menu tipsAll files
| File | Size |
|---|---|
data/news.json | 444 B |
data/tips.json | 442 B |
mod.json | 1023 B |
README.md | 3 KB |
scripts/client.lua | 4 KB |
ui/banner.png | 17 KB |
ui/news.uss | 1 KB |
ui/news.uxml | 525 B |