world creation and generators menus moved to xml
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,4 @@
|
||||
<container onclick='%{callback}' size='80,30' hover-color='#FFFFFF10'>
|
||||
<label pos='80,4' size='300,25' color='#FFFFFF80' align='right'>[%{id}]</label>
|
||||
<label pos='0,8'>%{name}</label>
|
||||
</container>
|
||||
@@ -215,6 +215,23 @@ function gui.template(name, params)
|
||||
return text
|
||||
end
|
||||
|
||||
session = {
|
||||
entries={}
|
||||
}
|
||||
|
||||
function session.get_entry(name)
|
||||
local entry = session.entries[name]
|
||||
if entry == nil then
|
||||
entry = {}
|
||||
session.entries[name] = entry
|
||||
end
|
||||
return entry
|
||||
end
|
||||
|
||||
function session.reset_entry(name)
|
||||
session.entries[name] = nil
|
||||
end
|
||||
|
||||
-- Deprecated functions
|
||||
block_index = block.index
|
||||
block_name = block.name
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ world.Name=Название
|
||||
world.World generator=Генератор мира
|
||||
world.generators.default=Обычный
|
||||
world.generators.flat=Плоский
|
||||
menu.Create World=Создать Мир
|
||||
world.Create World=Создать Мир
|
||||
|
||||
world.convert-request=Есть изменения в индексах! Конвертировать мир?
|
||||
world.delete-confirm=Удалить мир безвозвратно?
|
||||
|
||||
Reference in New Issue
Block a user