world creation and generators menus moved to xml

This commit is contained in:
MihailRis
2024-04-19 05:34:02 +03:00
parent ef4294ab47
commit 4f299be681
15 changed files with 187 additions and 136 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
<panel size='400' color='0' interval='1' context='menu'>
<button onclick='menu.page="new-world"' padding='10'>@New World</button>
<button onclick='menu.page="new_world"' padding='10'>@New World</button>
<panel id='worlds' size='390,1' padding='5' color='#FFFFFF11' max-length='400'>
</panel>
<button onclick='menu.page="settings"' padding='10'>@Settings</button>
+17
View File
@@ -0,0 +1,17 @@
<panel size='400' color='0' interval='1' context='world'>
<label>@Name</label>
<textbox id='name_box'
validator='world_name_validator'
placeholder='New World'
padding='4'>
</textbox>
<label>@Seed</label>
<textbox id='seed_box' placeholder='-' padding='4'></textbox>
<button onclick='menu.page="world_generators"' id='generator_btn' padding='10'>
@World generator
</button>
<button onclick='create_world()' padding='10' margin='1,20,1,1'>
@Create World
</button>
<button onclick='menu:back()' padding='10'>@Back</button>
</panel>
+35
View File
@@ -0,0 +1,35 @@
settings = session.get_entry('new_world')
function world_name_validator(name)
return name:match("^[%w-\\.\\ ]+$") ~= nil and not world.exists(name)
end
function settings.generator_name(id)
local prefix, name = parse_path(id)
if prefix == "core" then
return gui.str(name, "world.generators")
else
return id
end
end
function create_world()
if not document.name_box.valid then
return
end
local name = document.name_box.text
local seed = document.seed_box.text
core.new_world(name, seed, settings.generator)
end
function on_open()
if settings.generator == nil then
settings.generator = core.get_default_generator()
end
document.generator_btn.text = string.format(
"%s: %s",
gui.str("World generator", "world"),
settings.generator_name(settings.generator)
)
document.seed_box.placeholder = tostring(math.random()):sub(3)
end
+3
View File
@@ -0,0 +1,3 @@
<panel size='400' color='#00000080' padding='8'>
<!-- content is generated in script -->
</panel>
@@ -0,0 +1,16 @@
settings = session.get_entry('new_world')
function on_open()
local names = core.get_generators()
table.sort(names)
local panel = document.root
for _,k in ipairs(names) do
panel:add(gui.template("generator", {
callback=string.format("settings.generator=%q menu:back()", k),
id=k,
name=settings.generator_name(k)
}))
end
panel:add("<button padding='10' onclick='menu:back()'>@Back</button>")
end