summaryrefslogtreecommitdiff
path: root/builtin/mainmenu/dlg_create_world.lua
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2022-01-09 21:15:35 +0100
committerGitHub <noreply@github.com>2022-01-09 21:15:35 +0100
commit4c8c6497799c83cb5bac773ac4eac7ea572ec78f (patch)
treeffa67ce9002a94f6354eedbc94a1b768ed0cd336 /builtin/mainmenu/dlg_create_world.lua
parentb164e16d1be30220029729d63a1e621395ad00ad (diff)
downloadminetest-4c8c6497799c83cb5bac773ac4eac7ea572ec78f.tar.gz
minetest-4c8c6497799c83cb5bac773ac4eac7ea572ec78f.tar.bz2
minetest-4c8c6497799c83cb5bac773ac4eac7ea572ec78f.zip
Mainmenu game-related changes (#11887)
fixes: * Switching between games does not immediately hide creative mode / damage buttons if so specified * World creation menu has a game selection list even though the menu already provides a gamebar * Showing gameid in world list is unnecessary * Choice of mapgen parameters in menu persists between games (and was half-broken)
Diffstat (limited to 'builtin/mainmenu/dlg_create_world.lua')
-rw-r--r--builtin/mainmenu/dlg_create_world.lua266
1 files changed, 144 insertions, 122 deletions
diff --git a/builtin/mainmenu/dlg_create_world.lua b/builtin/mainmenu/dlg_create_world.lua
index 5456eb3eb..8d1509f33 100644
--- a/builtin/mainmenu/dlg_create_world.lua
+++ b/builtin/mainmenu/dlg_create_world.lua
@@ -15,7 +15,8 @@
--with this program; if not, write to the Free Software Foundation, Inc.,
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-local worldname = ""
+-- cf. tab_local, the gamebar already provides game selection so we hide the list from here
+local hide_gamelist = PLATFORM ~= "Android"
local function table_to_flags(ftable)
-- Convert e.g. { jungles = true, caves = false } to "jungles,nocaves"
@@ -31,9 +32,8 @@ local function strflag(flags, flag)
return (flags[flag] == true) and "true" or "false"
end
-local cb_caverns = { "caverns", fgettext("Caverns"), "caverns",
+local cb_caverns = { "caverns", fgettext("Caverns"),
fgettext("Very large caverns deep in the underground") }
-local tt_sea_rivers = fgettext("Sea level rivers")
local flag_checkboxes = {
v5 = {
@@ -41,39 +41,38 @@ local flag_checkboxes = {
},
v7 = {
cb_caverns,
- { "ridges", fgettext("Rivers"), "ridges", tt_sea_rivers },
- { "mountains", fgettext("Mountains"), "mountains" },
- { "floatlands", fgettext("Floatlands (experimental)"), "floatlands",
+ { "ridges", fgettext("Rivers"), fgettext("Sea level rivers") },
+ { "mountains", fgettext("Mountains") },
+ { "floatlands", fgettext("Floatlands (experimental)"),
fgettext("Floating landmasses in the sky") },
},
carpathian = {
cb_caverns,
- { "rivers", fgettext("Rivers"), "rivers", tt_sea_rivers },
+ { "rivers", fgettext("Rivers"), fgettext("Sea level rivers") },
},
valleys = {
- { "altitude-chill", fgettext("Altitude chill"), "altitude_chill",
+ { "altitude_chill", fgettext("Altitude chill"),
fgettext("Reduces heat with altitude") },
- { "altitude-dry", fgettext("Altitude dry"), "altitude_dry",
+ { "altitude_dry", fgettext("Altitude dry"),
fgettext("Reduces humidity with altitude") },
- { "humid-rivers", fgettext("Humid rivers"), "humid_rivers",
+ { "humid_rivers", fgettext("Humid rivers"),
fgettext("Increases humidity around rivers") },
- { "vary-river-depth", fgettext("Vary river depth"), "vary_river_depth",
+ { "vary_river_depth", fgettext("Vary river depth"),
fgettext("Low humidity and high heat causes shallow or dry rivers") },
},
flat = {
cb_caverns,
- { "hills", fgettext("Hills"), "hills" },
- { "lakes", fgettext("Lakes"), "lakes" },
+ { "hills", fgettext("Hills") },
+ { "lakes", fgettext("Lakes") },
},
fractal = {
- { "terrain", fgettext("Additional terrain"), "terrain",
+ { "terrain", fgettext("Additional terrain"),
fgettext("Generate non-fractal terrain: Oceans and underground") },
},
v6 = {
- { "trees", fgettext("Trees and jungle grass"), "trees" },
- { "flat", fgettext("Flat terrain"), "flat" },
- { "mudflow", fgettext("Mud flow"), "mudflow",
- fgettext("Terrain surface erosion") },
+ { "trees", fgettext("Trees and jungle grass") },
+ { "flat", fgettext("Flat terrain") },
+ { "mudflow", fgettext("Mud flow"), fgettext("Terrain surface erosion") },
-- Biome settings are in mgv6_biomes below
},
}
@@ -105,38 +104,26 @@ local function create_world_formspec(dialogdata)
"button[4.75,2.5;3,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
end
+ local current_mg = dialogdata.mg
local mapgens = core.get_mapgen_names()
- local current_seed = core.settings:get("fixed_map_seed") or ""
- local current_mg = core.settings:get("mg_name")
local gameid = core.settings:get("menu_last_game")
- local flags = {
- main = core.settings:get_flags("mg_flags"),
- v5 = core.settings:get_flags("mgv5_spflags"),
- v6 = core.settings:get_flags("mgv6_spflags"),
- v7 = core.settings:get_flags("mgv7_spflags"),
- fractal = core.settings:get_flags("mgfractal_spflags"),
- carpathian = core.settings:get_flags("mgcarpathian_spflags"),
- valleys = core.settings:get_flags("mgvalleys_spflags"),
- flat = core.settings:get_flags("mgflat_spflags"),
- }
-
- local gameidx = 0
- if gameid ~= nil then
- local _
- _, gameidx = pkgmgr.find_by_gameid(gameid)
+ local flags = dialogdata.flags
- if gameidx == nil then
- gameidx = 0
- end
+ local game, gameidx = pkgmgr.find_by_gameid(gameid)
+ if game == nil and hide_gamelist then
+ -- should never happen but just pick the first game
+ game = pkgmgr.get_game(1)
+ gameidx = 1
+ core.settings:set("menu_last_game", game.id)
+ elseif game == nil then
+ gameidx = 0
end
- local game_by_gameidx = core.get_game(gameidx)
local disallowed_mapgen_settings = {}
- if game_by_gameidx ~= nil then
- local gamepath = game_by_gameidx.path
- local gameconfig = Settings(gamepath.."/game.conf")
+ if game ~= nil then
+ local gameconfig = Settings(game.path.."/game.conf")
local allowed_mapgens = (gameconfig:get("allowed_mapgens") or ""):split()
for key, value in pairs(allowed_mapgens) do
@@ -156,7 +143,7 @@ local function create_world_formspec(dialogdata)
end
end
- if disallowed_mapgens then
+ if #disallowed_mapgens > 0 then
for i = #mapgens, 1, -1 do
if table.indexof(disallowed_mapgens, mapgens[i]) > 0 then
table.remove(mapgens, i)
@@ -172,23 +159,29 @@ local function create_world_formspec(dialogdata)
local mglist = ""
local selindex
- local i = 1
- local first_mg
- for k,v in pairs(mapgens) do
- if not first_mg then
- first_mg = v
+ do -- build the list of mapgens
+ local i = 1
+ local first_mg
+ for k, v in pairs(mapgens) do
+ if not first_mg then
+ first_mg = v
+ end
+ if current_mg == v then
+ selindex = i
+ end
+ i = i + 1
+ mglist = mglist .. core.formspec_escape(v) .. ","
end
- if current_mg == v then
- selindex = i
+ if not selindex then
+ selindex = 1
+ current_mg = first_mg
end
- i = i + 1
- mglist = mglist .. v .. ","
- end
- if not selindex then
- selindex = 1
- current_mg = first_mg
+ mglist = mglist:sub(1, -2)
end
- mglist = mglist:sub(1, -2)
+
+ -- The logic of the flag element IDs is as follows:
+ -- "flag_main_foo-bar-baz" controls dialogdata.flags["main"]["foo_bar_baz"]
+ -- see the buttonhandler for the implementation of this
local mg_main_flags = function(mapgen, y)
if mapgen == "singlenode" then
@@ -198,11 +191,11 @@ local function create_world_formspec(dialogdata)
return "", y
end
- local form = "checkbox[0," .. y .. ";flag_mg_caves;" ..
+ local form = "checkbox[0," .. y .. ";flag_main_caves;" ..
fgettext("Caves") .. ";"..strflag(flags.main, "caves").."]"
y = y + 0.5
- form = form .. "checkbox[0,"..y..";flag_mg_dungeons;" ..
+ form = form .. "checkbox[0,"..y..";flag_main_dungeons;" ..
fgettext("Dungeons") .. ";"..strflag(flags.main, "dungeons").."]"
y = y + 0.5
@@ -213,7 +206,7 @@ local function create_world_formspec(dialogdata)
else
d_tt = fgettext("Structures appearing on the terrain, typically trees and plants")
end
- form = form .. "checkbox[0,"..y..";flag_mg_decorations;" ..
+ form = form .. "checkbox[0,"..y..";flag_main_decorations;" ..
d_name .. ";" ..
strflag(flags.main, "decorations").."]" ..
"tooltip[flag_mg_decorations;" ..
@@ -221,7 +214,7 @@ local function create_world_formspec(dialogdata)
"]"
y = y + 0.5
- form = form .. "tooltip[flag_mg_caves;" ..
+ form = form .. "tooltip[flag_main_caves;" ..
fgettext("Network of tunnels and caves")
.. "]"
return form, y
@@ -235,13 +228,13 @@ local function create_world_formspec(dialogdata)
return "", y
end
local form = ""
- for _,tab in pairs(flag_checkboxes[mapgen]) do
- local id = "flag_mg"..mapgen.."_"..tab[1]
+ for _, tab in pairs(flag_checkboxes[mapgen]) do
+ local id = "flag_"..mapgen.."_"..tab[1]:gsub("_", "-")
form = form .. ("checkbox[0,%f;%s;%s;%s]"):
- format(y, id, tab[2], strflag(flags[mapgen], tab[3]))
+ format(y, id, tab[2], strflag(flags[mapgen], tab[1]))
- if tab[4] then
- form = form .. "tooltip["..id..";"..tab[4].."]"
+ if tab[3] then
+ form = form .. "tooltip["..id..";"..tab[3].."]"
end
y = y + 0.5
end
@@ -277,16 +270,14 @@ local function create_world_formspec(dialogdata)
-- biomeblend
y = y + 0.55
- form = form .. "checkbox[0,"..y..";flag_mgv6_biomeblend;" ..
+ form = form .. "checkbox[0,"..y..";flag_v6_biomeblend;" ..
fgettext("Biome blending") .. ";"..strflag(flags.v6, "biomeblend").."]" ..
- "tooltip[flag_mgv6_biomeblend;" ..
+ "tooltip[flag_v6_biomeblend;" ..
fgettext("Smooth transition between biomes") .. "]"
return form, y
end
- current_seed = core.formspec_escape(current_seed)
-
local y_start = 0.0
local y = y_start
local str_flags, str_spflags
@@ -323,21 +314,27 @@ local function create_world_formspec(dialogdata)
"container[0,0]"..
"field[0.3,0.6;6,0.5;te_world_name;" ..
fgettext("World name") ..
- ";" .. core.formspec_escape(worldname) .. "]" ..
+ ";" .. core.formspec_escape(dialogdata.worldname) .. "]" ..
+ "set_focus[te_world_name;false]" ..
"field[0.3,1.7;6,0.5;te_seed;" ..
fgettext("Seed") ..
- ";".. current_seed .. "]" ..
+ ";".. core.formspec_escape(dialogdata.seed) .. "]" ..
"label[0,2;" .. fgettext("Mapgen") .. "]"..
- "dropdown[0,2.5;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
+ "dropdown[0,2.5;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]"
+
+ if not hide_gamelist or devtest_only ~= "" then
+ retval = retval ..
+ "label[0,3.35;" .. fgettext("Game") .. "]"..
+ "textlist[0,3.85;5.8,"..gamelist_height..";games;" ..
+ pkgmgr.gamelist() .. ";" .. gameidx .. ";false]" ..
+ "container[0,4.5]" ..
+ devtest_only ..
+ "container_end[]"
+ end
- "label[0,3.35;" .. fgettext("Game") .. "]"..
- "textlist[0,3.85;5.8,"..gamelist_height..";games;" ..
- pkgmgr.gamelist() .. ";" .. gameidx .. ";false]" ..
- "container[0,4.5]" ..
- devtest_only ..
- "container_end[]" ..
+ retval = retval ..
"container_end[]" ..
-- Right side
@@ -360,9 +357,20 @@ local function create_world_buttonhandler(this, fields)
fields["key_enter"] then
local worldname = fields["te_world_name"]
- local gameindex = core.get_textlist_index("games")
+ local game, gameindex
+ if hide_gamelist then
+ game, gameindex = pkgmgr.find_by_gameid(core.settings:get("menu_last_game"))
+ else
+ gameindex = core.get_textlist_index("games")
+ game = pkgmgr.get_game(gameindex)
+ end
- if gameindex ~= nil then
+ local message
+ if game == nil then
+ message = fgettext("No game selected")
+ end
+
+ if message == nil then
-- For unnamed worlds use the generated name 'world<number>',
-- where the number increments: it is set to 1 larger than the largest
-- generated name number found.
@@ -377,36 +385,48 @@ local function create_world_buttonhandler(this, fields)
worldname = "world" .. worldnum_max + 1
end
- core.settings:set("fixed_map_seed", fields["te_seed"])
-
- local message
- if not menudata.worldlist:uid_exists_raw(worldname) then
- core.settings:set("mg_name",fields["dd_mapgen"])
- message = core.create_world(worldname,gameindex)
- else
+ if menudata.worldlist:uid_exists_raw(worldname) then
message = fgettext("A world named \"$1\" already exists", worldname)
end
+ end
- if message ~= nil then
- gamedata.errormessage = message
- else
- core.settings:set("menu_last_game",pkgmgr.games[gameindex].id)
- if this.data.update_worldlist_filter then
- menudata.worldlist:set_filtercriteria(pkgmgr.games[gameindex].id)
- mm_game_theme.update("singleplayer", pkgmgr.games[gameindex].id)
- end
- menudata.worldlist:refresh()
- core.settings:set("mainmenu_last_selected_world",
- menudata.worldlist:raw_index_by_uid(worldname))
+ if message == nil then
+ this.data.seed = fields["te_seed"]
+ this.data.mg = fields["dd_mapgen"]
+
+ -- actual names as used by engine
+ local settings = {
+ fixed_map_seed = this.data.seed,
+ mg_name = this.data.mg,
+ mg_flags = table_to_flags(this.data.flags.main),
+ mgv5_spflags = table_to_flags(this.data.flags.v5),
+ mgv6_spflags = table_to_flags(this.data.flags.v6),
+ mgv7_spflags = table_to_flags(this.data.flags.v7),
+ mgfractal_spflags = table_to_flags(this.data.flags.fractal),
+ mgcarpathian_spflags = table_to_flags(this.data.flags.carpathian),
+ mgvalleys_spflags = table_to_flags(this.data.flags.valleys),
+ mgflat_spflags = table_to_flags(this.data.flags.flat),
+ }
+ message = core.create_world(worldname, gameindex, settings)
+ end
+
+ if message == nil then
+ core.settings:set("menu_last_game", game.id)
+ if this.data.update_worldlist_filter then
+ menudata.worldlist:set_filtercriteria(game.id)
end
- else
- gamedata.errormessage = fgettext("No game selected")
+ menudata.worldlist:refresh()
+ core.settings:set("mainmenu_last_selected_world",
+ menudata.worldlist:raw_index_by_uid(worldname))
end
+
+ gamedata.errormessage = message
this:delete()
return true
end
- worldname = fields.te_world_name
+ this.data.worldname = fields["te_world_name"]
+ this.data.seed = fields["te_seed"]
if fields["games"] then
local gameindex = core.get_textlist_index("games")
@@ -417,22 +437,11 @@ local function create_world_buttonhandler(this, fields)
for k,v in pairs(fields) do
local split = string.split(k, "_", nil, 3)
if split and split[1] == "flag" then
- local setting
- if split[2] == "mg" then
- setting = "mg_flags"
- else
- setting = split[2].."_spflags"
- end
-- We replaced the underscore of flag names with a dash.
local flag = string.gsub(split[3], "-", "_")
- local ftable = core.settings:get_flags(setting)
- if v == "true" then
- ftable[flag] = true
- else
- ftable[flag] = false
- end
- local flags = table_to_flags(ftable)
- core.settings:set(setting, flags)
+ local ftable = this.data.flags[split[2]]
+ assert(ftable)
+ ftable[flag] = v == "true"
return true
end
end
@@ -446,18 +455,16 @@ local function create_world_buttonhandler(this, fields)
local entry = core.formspec_escape(fields["mgv6_biomes"])
for b=1, #mgv6_biomes do
if entry == mgv6_biomes[b][1] then
- local ftable = core.settings:get_flags("mgv6_spflags")
+ local ftable = this.data.flags.v6
ftable.jungles = mgv6_biomes[b][2].jungles
ftable.snowbiomes = mgv6_biomes[b][2].snowbiomes
- local flags = table_to_flags(ftable)
- core.settings:set("mgv6_spflags", flags)
return true
end
end
end
if fields["dd_mapgen"] then
- core.settings:set("mg_name", fields["dd_mapgen"])
+ this.data.mg = fields["dd_mapgen"]
return true
end
@@ -466,12 +473,27 @@ end
function create_create_world_dlg(update_worldlistfilter)
- worldname = ""
local retval = dialog_create("sp_create_world",
create_world_formspec,
create_world_buttonhandler,
nil)
- retval.update_worldlist_filter = update_worldlistfilter
+ retval.data = {
+ update_worldlist_filter = update_worldlistfilter,
+ worldname = "",
+ -- settings the world is created with:
+ seed = core.settings:get("fixed_map_seed") or "",
+ mg = core.settings:get("mg_name"),
+ flags = {
+ main = core.settings:get_flags("mg_flags"),
+ v5 = core.settings:get_flags("mgv5_spflags"),
+ v6 = core.settings:get_flags("mgv6_spflags"),
+ v7 = core.settings:get_flags("mgv7_spflags"),
+ fractal = core.settings:get_flags("mgfractal_spflags"),
+ carpathian = core.settings:get_flags("mgcarpathian_spflags"),
+ valleys = core.settings:get_flags("mgvalleys_spflags"),
+ flat = core.settings:get_flags("mgflat_spflags"),
+ }
+ }
return retval
end