|
|
Line 1: |
Line 1: |
| __FORCETOC__
| |
| This mod template creates a custom UI overlay.
| |
|
| |
|
| == Code ==
| |
| === def.json ===
| |
| Content<syntaxhighlight lang="json">
| |
| {
| |
| "id": "ModTemplateUIAddon",
| |
| "name": "Mod Template UI Addon",
| |
| "version_name": "1.0",
| |
| "version_code": 1,
| |
| "author": "The Desynced Team",
| |
| "homepage": "https://www.desyncedgame.com/",
| |
| "description": "Mod Template UI Addon",
| |
| "packages": {
| |
| "UI": {
| |
| "name": "UI",
| |
| "entry": "ui.lua",
| |
| "dependencies": [ "Main/UI" ],
| |
| "type": "Addon"
| |
| }
| |
| }
| |
| }
| |
| </syntaxhighlight>
| |
| === ui.lua ===
| |
| Content<syntaxhighlight lang="lua">
| |
| local package = ...
| |
|
| |
| -- define the layout of the widget
| |
| local ModSampleUI_layout<const> =
| |
| [[
| |
| <Box dock=bottom padding=3>
| |
| <Button text="Hello World" on_click={on_click_hello}/>
| |
| </Box>
| |
| ]]
| |
|
| |
| -- register the widget layout
| |
| local ModSampleUI<const> = {}
| |
| UI.Register("ModSampleUI", ModSampleUI_layout, ModSampleUI)
| |
|
| |
| -- called when the registered widget is created
| |
| function ModSampleUI:construct()
| |
| end
| |
|
| |
| -- called when the button is clicked
| |
| function ModSampleUI:on_click_hello(btn)
| |
| MessageBox("Hello World from the UI Sample")
| |
| end
| |
|
| |
| -- called when the UI is being set up
| |
| function UIMsg.OnSetup()
| |
| UI.AddLayout("ModSampleUI", 9)
| |
| end
| |
|
| |
| -- called when mod is initializing
| |
| function package:init_ui()
| |
| end
| |
| </syntaxhighlight>
| |
|
| |
| -----
| |
|
| |
| {{ModdingNav}}
| |