mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 01:53:45 +01:00
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)
This commit is contained in:
parent
b164e16d1b
commit
4c8c649779
@ -125,17 +125,21 @@ os.tmpname = function()
|
|||||||
end
|
end
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
function menu_render_worldlist()
|
function menu_render_worldlist(show_gameid)
|
||||||
local retval = ""
|
local retval = {}
|
||||||
local current_worldlist = menudata.worldlist:get_list()
|
local current_worldlist = menudata.worldlist:get_list()
|
||||||
|
|
||||||
|
local row
|
||||||
for i, v in ipairs(current_worldlist) do
|
for i, v in ipairs(current_worldlist) do
|
||||||
if retval ~= "" then retval = retval .. "," end
|
row = v.name
|
||||||
retval = retval .. core.formspec_escape(v.name) ..
|
if show_gameid == nil or show_gameid == true then
|
||||||
" \\[" .. core.formspec_escape(v.gameid) .. "\\]"
|
row = row .. " [" .. v.gameid .. "]"
|
||||||
|
end
|
||||||
|
retval[#retval+1] = core.formspec_escape(row)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return retval
|
return table.concat(retval, ",")
|
||||||
end
|
end
|
||||||
|
|
||||||
function menu_handle_key_up_down(fields, textlist, settingname)
|
function menu_handle_key_up_down(fields, textlist, settingname)
|
||||||
|
@ -15,7 +15,8 @@
|
|||||||
--with this program; if not, write to the Free Software Foundation, Inc.,
|
--with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
--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)
|
local function table_to_flags(ftable)
|
||||||
-- Convert e.g. { jungles = true, caves = false } to "jungles,nocaves"
|
-- 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"
|
return (flags[flag] == true) and "true" or "false"
|
||||||
end
|
end
|
||||||
|
|
||||||
local cb_caverns = { "caverns", fgettext("Caverns"), "caverns",
|
local cb_caverns = { "caverns", fgettext("Caverns"),
|
||||||
fgettext("Very large caverns deep in the underground") }
|
fgettext("Very large caverns deep in the underground") }
|
||||||
local tt_sea_rivers = fgettext("Sea level rivers")
|
|
||||||
|
|
||||||
local flag_checkboxes = {
|
local flag_checkboxes = {
|
||||||
v5 = {
|
v5 = {
|
||||||
@ -41,39 +41,38 @@ local flag_checkboxes = {
|
|||||||
},
|
},
|
||||||
v7 = {
|
v7 = {
|
||||||
cb_caverns,
|
cb_caverns,
|
||||||
{ "ridges", fgettext("Rivers"), "ridges", tt_sea_rivers },
|
{ "ridges", fgettext("Rivers"), fgettext("Sea level rivers") },
|
||||||
{ "mountains", fgettext("Mountains"), "mountains" },
|
{ "mountains", fgettext("Mountains") },
|
||||||
{ "floatlands", fgettext("Floatlands (experimental)"), "floatlands",
|
{ "floatlands", fgettext("Floatlands (experimental)"),
|
||||||
fgettext("Floating landmasses in the sky") },
|
fgettext("Floating landmasses in the sky") },
|
||||||
},
|
},
|
||||||
carpathian = {
|
carpathian = {
|
||||||
cb_caverns,
|
cb_caverns,
|
||||||
{ "rivers", fgettext("Rivers"), "rivers", tt_sea_rivers },
|
{ "rivers", fgettext("Rivers"), fgettext("Sea level rivers") },
|
||||||
},
|
},
|
||||||
valleys = {
|
valleys = {
|
||||||
{ "altitude-chill", fgettext("Altitude chill"), "altitude_chill",
|
{ "altitude_chill", fgettext("Altitude chill"),
|
||||||
fgettext("Reduces heat with altitude") },
|
fgettext("Reduces heat with altitude") },
|
||||||
{ "altitude-dry", fgettext("Altitude dry"), "altitude_dry",
|
{ "altitude_dry", fgettext("Altitude dry"),
|
||||||
fgettext("Reduces humidity with altitude") },
|
fgettext("Reduces humidity with altitude") },
|
||||||
{ "humid-rivers", fgettext("Humid rivers"), "humid_rivers",
|
{ "humid_rivers", fgettext("Humid rivers"),
|
||||||
fgettext("Increases humidity around 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") },
|
fgettext("Low humidity and high heat causes shallow or dry rivers") },
|
||||||
},
|
},
|
||||||
flat = {
|
flat = {
|
||||||
cb_caverns,
|
cb_caverns,
|
||||||
{ "hills", fgettext("Hills"), "hills" },
|
{ "hills", fgettext("Hills") },
|
||||||
{ "lakes", fgettext("Lakes"), "lakes" },
|
{ "lakes", fgettext("Lakes") },
|
||||||
},
|
},
|
||||||
fractal = {
|
fractal = {
|
||||||
{ "terrain", fgettext("Additional terrain"), "terrain",
|
{ "terrain", fgettext("Additional terrain"),
|
||||||
fgettext("Generate non-fractal terrain: Oceans and underground") },
|
fgettext("Generate non-fractal terrain: Oceans and underground") },
|
||||||
},
|
},
|
||||||
v6 = {
|
v6 = {
|
||||||
{ "trees", fgettext("Trees and jungle grass"), "trees" },
|
{ "trees", fgettext("Trees and jungle grass") },
|
||||||
{ "flat", fgettext("Flat terrain"), "flat" },
|
{ "flat", fgettext("Flat terrain") },
|
||||||
{ "mudflow", fgettext("Mud flow"), "mudflow",
|
{ "mudflow", fgettext("Mud flow"), fgettext("Terrain surface erosion") },
|
||||||
fgettext("Terrain surface erosion") },
|
|
||||||
-- Biome settings are in mgv6_biomes below
|
-- 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") .. "]"
|
"button[4.75,2.5;3,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local current_mg = dialogdata.mg
|
||||||
local mapgens = core.get_mapgen_names()
|
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 gameid = core.settings:get("menu_last_game")
|
||||||
|
|
||||||
local flags = {
|
local flags = dialogdata.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
|
local game, gameidx = pkgmgr.find_by_gameid(gameid)
|
||||||
if gameid ~= nil then
|
if game == nil and hide_gamelist then
|
||||||
local _
|
-- should never happen but just pick the first game
|
||||||
_, gameidx = pkgmgr.find_by_gameid(gameid)
|
game = pkgmgr.get_game(1)
|
||||||
|
gameidx = 1
|
||||||
if gameidx == nil then
|
core.settings:set("menu_last_game", game.id)
|
||||||
gameidx = 0
|
elseif game == nil then
|
||||||
end
|
gameidx = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local game_by_gameidx = core.get_game(gameidx)
|
|
||||||
local disallowed_mapgen_settings = {}
|
local disallowed_mapgen_settings = {}
|
||||||
if game_by_gameidx ~= nil then
|
if game ~= nil then
|
||||||
local gamepath = game_by_gameidx.path
|
local gameconfig = Settings(game.path.."/game.conf")
|
||||||
local gameconfig = Settings(gamepath.."/game.conf")
|
|
||||||
|
|
||||||
local allowed_mapgens = (gameconfig:get("allowed_mapgens") or ""):split()
|
local allowed_mapgens = (gameconfig:get("allowed_mapgens") or ""):split()
|
||||||
for key, value in pairs(allowed_mapgens) do
|
for key, value in pairs(allowed_mapgens) do
|
||||||
@ -156,7 +143,7 @@ local function create_world_formspec(dialogdata)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if disallowed_mapgens then
|
if #disallowed_mapgens > 0 then
|
||||||
for i = #mapgens, 1, -1 do
|
for i = #mapgens, 1, -1 do
|
||||||
if table.indexof(disallowed_mapgens, mapgens[i]) > 0 then
|
if table.indexof(disallowed_mapgens, mapgens[i]) > 0 then
|
||||||
table.remove(mapgens, i)
|
table.remove(mapgens, i)
|
||||||
@ -172,23 +159,29 @@ local function create_world_formspec(dialogdata)
|
|||||||
|
|
||||||
local mglist = ""
|
local mglist = ""
|
||||||
local selindex
|
local selindex
|
||||||
local i = 1
|
do -- build the list of mapgens
|
||||||
local first_mg
|
local i = 1
|
||||||
for k,v in pairs(mapgens) do
|
local first_mg
|
||||||
if not first_mg then
|
for k, v in pairs(mapgens) do
|
||||||
first_mg = v
|
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
|
end
|
||||||
if current_mg == v then
|
if not selindex then
|
||||||
selindex = i
|
selindex = 1
|
||||||
|
current_mg = first_mg
|
||||||
end
|
end
|
||||||
i = i + 1
|
mglist = mglist:sub(1, -2)
|
||||||
mglist = mglist .. v .. ","
|
|
||||||
end
|
end
|
||||||
if not selindex then
|
|
||||||
selindex = 1
|
-- The logic of the flag element IDs is as follows:
|
||||||
current_mg = first_mg
|
-- "flag_main_foo-bar-baz" controls dialogdata.flags["main"]["foo_bar_baz"]
|
||||||
end
|
-- see the buttonhandler for the implementation of this
|
||||||
mglist = mglist:sub(1, -2)
|
|
||||||
|
|
||||||
local mg_main_flags = function(mapgen, y)
|
local mg_main_flags = function(mapgen, y)
|
||||||
if mapgen == "singlenode" then
|
if mapgen == "singlenode" then
|
||||||
@ -198,11 +191,11 @@ local function create_world_formspec(dialogdata)
|
|||||||
return "", y
|
return "", y
|
||||||
end
|
end
|
||||||
|
|
||||||
local form = "checkbox[0," .. y .. ";flag_mg_caves;" ..
|
local form = "checkbox[0," .. y .. ";flag_main_caves;" ..
|
||||||
fgettext("Caves") .. ";"..strflag(flags.main, "caves").."]"
|
fgettext("Caves") .. ";"..strflag(flags.main, "caves").."]"
|
||||||
y = y + 0.5
|
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").."]"
|
fgettext("Dungeons") .. ";"..strflag(flags.main, "dungeons").."]"
|
||||||
y = y + 0.5
|
y = y + 0.5
|
||||||
|
|
||||||
@ -213,7 +206,7 @@ local function create_world_formspec(dialogdata)
|
|||||||
else
|
else
|
||||||
d_tt = fgettext("Structures appearing on the terrain, typically trees and plants")
|
d_tt = fgettext("Structures appearing on the terrain, typically trees and plants")
|
||||||
end
|
end
|
||||||
form = form .. "checkbox[0,"..y..";flag_mg_decorations;" ..
|
form = form .. "checkbox[0,"..y..";flag_main_decorations;" ..
|
||||||
d_name .. ";" ..
|
d_name .. ";" ..
|
||||||
strflag(flags.main, "decorations").."]" ..
|
strflag(flags.main, "decorations").."]" ..
|
||||||
"tooltip[flag_mg_decorations;" ..
|
"tooltip[flag_mg_decorations;" ..
|
||||||
@ -221,7 +214,7 @@ local function create_world_formspec(dialogdata)
|
|||||||
"]"
|
"]"
|
||||||
y = y + 0.5
|
y = y + 0.5
|
||||||
|
|
||||||
form = form .. "tooltip[flag_mg_caves;" ..
|
form = form .. "tooltip[flag_main_caves;" ..
|
||||||
fgettext("Network of tunnels and caves")
|
fgettext("Network of tunnels and caves")
|
||||||
.. "]"
|
.. "]"
|
||||||
return form, y
|
return form, y
|
||||||
@ -235,13 +228,13 @@ local function create_world_formspec(dialogdata)
|
|||||||
return "", y
|
return "", y
|
||||||
end
|
end
|
||||||
local form = ""
|
local form = ""
|
||||||
for _,tab in pairs(flag_checkboxes[mapgen]) do
|
for _, tab in pairs(flag_checkboxes[mapgen]) do
|
||||||
local id = "flag_mg"..mapgen.."_"..tab[1]
|
local id = "flag_"..mapgen.."_"..tab[1]:gsub("_", "-")
|
||||||
form = form .. ("checkbox[0,%f;%s;%s;%s]"):
|
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
|
if tab[3] then
|
||||||
form = form .. "tooltip["..id..";"..tab[4].."]"
|
form = form .. "tooltip["..id..";"..tab[3].."]"
|
||||||
end
|
end
|
||||||
y = y + 0.5
|
y = y + 0.5
|
||||||
end
|
end
|
||||||
@ -277,16 +270,14 @@ local function create_world_formspec(dialogdata)
|
|||||||
|
|
||||||
-- biomeblend
|
-- biomeblend
|
||||||
y = y + 0.55
|
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").."]" ..
|
fgettext("Biome blending") .. ";"..strflag(flags.v6, "biomeblend").."]" ..
|
||||||
"tooltip[flag_mgv6_biomeblend;" ..
|
"tooltip[flag_v6_biomeblend;" ..
|
||||||
fgettext("Smooth transition between biomes") .. "]"
|
fgettext("Smooth transition between biomes") .. "]"
|
||||||
|
|
||||||
return form, y
|
return form, y
|
||||||
end
|
end
|
||||||
|
|
||||||
current_seed = core.formspec_escape(current_seed)
|
|
||||||
|
|
||||||
local y_start = 0.0
|
local y_start = 0.0
|
||||||
local y = y_start
|
local y = y_start
|
||||||
local str_flags, str_spflags
|
local str_flags, str_spflags
|
||||||
@ -323,21 +314,27 @@ local function create_world_formspec(dialogdata)
|
|||||||
"container[0,0]"..
|
"container[0,0]"..
|
||||||
"field[0.3,0.6;6,0.5;te_world_name;" ..
|
"field[0.3,0.6;6,0.5;te_world_name;" ..
|
||||||
fgettext("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;" ..
|
"field[0.3,1.7;6,0.5;te_seed;" ..
|
||||||
fgettext("Seed") ..
|
fgettext("Seed") ..
|
||||||
";".. current_seed .. "]" ..
|
";".. core.formspec_escape(dialogdata.seed) .. "]" ..
|
||||||
|
|
||||||
"label[0,2;" .. fgettext("Mapgen") .. "]"..
|
"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 .. "]"
|
||||||
|
|
||||||
"label[0,3.35;" .. fgettext("Game") .. "]"..
|
if not hide_gamelist or devtest_only ~= "" then
|
||||||
"textlist[0,3.85;5.8,"..gamelist_height..";games;" ..
|
retval = retval ..
|
||||||
pkgmgr.gamelist() .. ";" .. gameidx .. ";false]" ..
|
"label[0,3.35;" .. fgettext("Game") .. "]"..
|
||||||
"container[0,4.5]" ..
|
"textlist[0,3.85;5.8,"..gamelist_height..";games;" ..
|
||||||
devtest_only ..
|
pkgmgr.gamelist() .. ";" .. gameidx .. ";false]" ..
|
||||||
"container_end[]" ..
|
"container[0,4.5]" ..
|
||||||
|
devtest_only ..
|
||||||
|
"container_end[]"
|
||||||
|
end
|
||||||
|
|
||||||
|
retval = retval ..
|
||||||
"container_end[]" ..
|
"container_end[]" ..
|
||||||
|
|
||||||
-- Right side
|
-- Right side
|
||||||
@ -360,9 +357,20 @@ local function create_world_buttonhandler(this, fields)
|
|||||||
fields["key_enter"] then
|
fields["key_enter"] then
|
||||||
|
|
||||||
local worldname = fields["te_world_name"]
|
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>',
|
-- For unnamed worlds use the generated name 'world<number>',
|
||||||
-- where the number increments: it is set to 1 larger than the largest
|
-- where the number increments: it is set to 1 larger than the largest
|
||||||
-- generated name number found.
|
-- generated name number found.
|
||||||
@ -377,36 +385,48 @@ local function create_world_buttonhandler(this, fields)
|
|||||||
worldname = "world" .. worldnum_max + 1
|
worldname = "world" .. worldnum_max + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
core.settings:set("fixed_map_seed", fields["te_seed"])
|
if menudata.worldlist:uid_exists_raw(worldname) then
|
||||||
|
|
||||||
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
|
|
||||||
message = fgettext("A world named \"$1\" already exists", worldname)
|
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))
|
|
||||||
end
|
|
||||||
else
|
|
||||||
gamedata.errormessage = fgettext("No game selected")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
menudata.worldlist:refresh()
|
||||||
|
core.settings:set("mainmenu_last_selected_world",
|
||||||
|
menudata.worldlist:raw_index_by_uid(worldname))
|
||||||
|
end
|
||||||
|
|
||||||
|
gamedata.errormessage = message
|
||||||
this:delete()
|
this:delete()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
worldname = fields.te_world_name
|
this.data.worldname = fields["te_world_name"]
|
||||||
|
this.data.seed = fields["te_seed"]
|
||||||
|
|
||||||
if fields["games"] then
|
if fields["games"] then
|
||||||
local gameindex = core.get_textlist_index("games")
|
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
|
for k,v in pairs(fields) do
|
||||||
local split = string.split(k, "_", nil, 3)
|
local split = string.split(k, "_", nil, 3)
|
||||||
if split and split[1] == "flag" then
|
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.
|
-- We replaced the underscore of flag names with a dash.
|
||||||
local flag = string.gsub(split[3], "-", "_")
|
local flag = string.gsub(split[3], "-", "_")
|
||||||
local ftable = core.settings:get_flags(setting)
|
local ftable = this.data.flags[split[2]]
|
||||||
if v == "true" then
|
assert(ftable)
|
||||||
ftable[flag] = true
|
ftable[flag] = v == "true"
|
||||||
else
|
|
||||||
ftable[flag] = false
|
|
||||||
end
|
|
||||||
local flags = table_to_flags(ftable)
|
|
||||||
core.settings:set(setting, flags)
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -446,18 +455,16 @@ local function create_world_buttonhandler(this, fields)
|
|||||||
local entry = core.formspec_escape(fields["mgv6_biomes"])
|
local entry = core.formspec_escape(fields["mgv6_biomes"])
|
||||||
for b=1, #mgv6_biomes do
|
for b=1, #mgv6_biomes do
|
||||||
if entry == mgv6_biomes[b][1] then
|
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.jungles = mgv6_biomes[b][2].jungles
|
||||||
ftable.snowbiomes = mgv6_biomes[b][2].snowbiomes
|
ftable.snowbiomes = mgv6_biomes[b][2].snowbiomes
|
||||||
local flags = table_to_flags(ftable)
|
|
||||||
core.settings:set("mgv6_spflags", flags)
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields["dd_mapgen"] then
|
if fields["dd_mapgen"] then
|
||||||
core.settings:set("mg_name", fields["dd_mapgen"])
|
this.data.mg = fields["dd_mapgen"]
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -466,12 +473,27 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function create_create_world_dlg(update_worldlistfilter)
|
function create_create_world_dlg(update_worldlistfilter)
|
||||||
worldname = ""
|
|
||||||
local retval = dialog_create("sp_create_world",
|
local retval = dialog_create("sp_create_world",
|
||||||
create_world_formspec,
|
create_world_formspec,
|
||||||
create_world_buttonhandler,
|
create_world_buttonhandler,
|
||||||
nil)
|
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
|
return retval
|
||||||
end
|
end
|
||||||
|
@ -33,10 +33,30 @@ if enable_gamebar then
|
|||||||
return game
|
return game
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Apply menu changes from given game
|
||||||
|
function apply_game(game)
|
||||||
|
core.set_topleft_text(game.name)
|
||||||
|
core.settings:set("menu_last_game", game.id)
|
||||||
|
menudata.worldlist:set_filtercriteria(game.id)
|
||||||
|
|
||||||
|
mm_game_theme.update("singleplayer", game) -- this refreshes the formspec
|
||||||
|
|
||||||
|
local index = filterlist.get_current_index(menudata.worldlist,
|
||||||
|
tonumber(core.settings:get("mainmenu_last_selected_world")))
|
||||||
|
if not index or index < 1 then
|
||||||
|
local selected = core.get_textlist_index("sp_worlds")
|
||||||
|
if selected ~= nil and selected < #menudata.worldlist:get_list() then
|
||||||
|
index = selected
|
||||||
|
else
|
||||||
|
index = #menudata.worldlist:get_list()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
menu_worldmt_legacy(index)
|
||||||
|
end
|
||||||
|
|
||||||
function singleplayer_refresh_gamebar()
|
function singleplayer_refresh_gamebar()
|
||||||
|
|
||||||
local old_bar = ui.find_by_name("game_button_bar")
|
local old_bar = ui.find_by_name("game_button_bar")
|
||||||
|
|
||||||
if old_bar ~= nil then
|
if old_bar ~= nil then
|
||||||
old_bar:delete()
|
old_bar:delete()
|
||||||
end
|
end
|
||||||
@ -51,26 +71,10 @@ if enable_gamebar then
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
for key,value in pairs(fields) do
|
for _, game in ipairs(pkgmgr.games) do
|
||||||
for j=1,#pkgmgr.games,1 do
|
if fields["game_btnbar_" .. game.id] then
|
||||||
if ("game_btnbar_" .. pkgmgr.games[j].id == key) then
|
apply_game(game)
|
||||||
mm_game_theme.update("singleplayer", pkgmgr.games[j])
|
return true
|
||||||
core.set_topleft_text(pkgmgr.games[j].name)
|
|
||||||
core.settings:set("menu_last_game",pkgmgr.games[j].id)
|
|
||||||
menudata.worldlist:set_filtercriteria(pkgmgr.games[j].id)
|
|
||||||
local index = filterlist.get_current_index(menudata.worldlist,
|
|
||||||
tonumber(core.settings:get("mainmenu_last_selected_world")))
|
|
||||||
if not index or index < 1 then
|
|
||||||
local selected = core.get_textlist_index("sp_worlds")
|
|
||||||
if selected ~= nil and selected < #menudata.worldlist:get_list() then
|
|
||||||
index = selected
|
|
||||||
else
|
|
||||||
index = #menudata.worldlist:get_list()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
menu_worldmt_legacy(index)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -79,25 +83,22 @@ if enable_gamebar then
|
|||||||
game_buttonbar_button_handler,
|
game_buttonbar_button_handler,
|
||||||
{x=-0.3,y=5.9}, "horizontal", {x=12.4,y=1.15})
|
{x=-0.3,y=5.9}, "horizontal", {x=12.4,y=1.15})
|
||||||
|
|
||||||
for i=1,#pkgmgr.games,1 do
|
for _, game in ipairs(pkgmgr.games) do
|
||||||
local btn_name = "game_btnbar_" .. pkgmgr.games[i].id
|
local btn_name = "game_btnbar_" .. game.id
|
||||||
|
|
||||||
local image = nil
|
local image = nil
|
||||||
local text = nil
|
local text = nil
|
||||||
local tooltip = core.formspec_escape(pkgmgr.games[i].name)
|
local tooltip = core.formspec_escape(game.name)
|
||||||
|
|
||||||
if pkgmgr.games[i].menuicon_path ~= nil and
|
if (game.menuicon_path or "") ~= "" then
|
||||||
pkgmgr.games[i].menuicon_path ~= "" then
|
image = core.formspec_escape(game.menuicon_path)
|
||||||
image = core.formspec_escape(pkgmgr.games[i].menuicon_path)
|
|
||||||
else
|
else
|
||||||
|
local part1 = game.id:sub(1,5)
|
||||||
local part1 = pkgmgr.games[i].id:sub(1,5)
|
local part2 = game.id:sub(6,10)
|
||||||
local part2 = pkgmgr.games[i].id:sub(6,10)
|
local part3 = game.id:sub(11)
|
||||||
local part3 = pkgmgr.games[i].id:sub(11)
|
|
||||||
|
|
||||||
text = part1 .. "\n" .. part2
|
text = part1 .. "\n" .. part2
|
||||||
if part3 ~= nil and
|
if part3 ~= "" then
|
||||||
part3 ~= "" then
|
|
||||||
text = text .. "\n" .. part3
|
text = text .. "\n" .. part3
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -147,8 +148,12 @@ local function get_formspec(tabview, name, tabdata)
|
|||||||
tonumber(core.settings:get("mainmenu_last_selected_world")))
|
tonumber(core.settings:get("mainmenu_last_selected_world")))
|
||||||
local list = menudata.worldlist:get_list()
|
local list = menudata.worldlist:get_list()
|
||||||
local world = list and index and list[index]
|
local world = list and index and list[index]
|
||||||
local gameid = world and world.gameid
|
local game
|
||||||
local game = gameid and pkgmgr.find_by_gameid(gameid)
|
if world then
|
||||||
|
game = pkgmgr.find_by_gameid(world.gameid)
|
||||||
|
else
|
||||||
|
game = current_game()
|
||||||
|
end
|
||||||
local disabled_settings = get_disabled_settings(game)
|
local disabled_settings = get_disabled_settings(game)
|
||||||
|
|
||||||
local creative, damage, host = "", "", ""
|
local creative, damage, host = "", "", ""
|
||||||
@ -182,7 +187,7 @@ local function get_formspec(tabview, name, tabdata)
|
|||||||
damage ..
|
damage ..
|
||||||
host ..
|
host ..
|
||||||
"textlist[3.9,0.4;7.9,3.45;sp_worlds;" ..
|
"textlist[3.9,0.4;7.9,3.45;sp_worlds;" ..
|
||||||
menu_render_worldlist() ..
|
menu_render_worldlist(not enable_gamebar) ..
|
||||||
";" .. index .. "]"
|
";" .. index .. "]"
|
||||||
|
|
||||||
if core.settings:get_bool("enable_server") and disabled_settings["enable_server"] == nil then
|
if core.settings:get_bool("enable_server") and disabled_settings["enable_server"] == nil then
|
||||||
@ -319,7 +324,7 @@ local function main_button_handler(this, fields, name, tabdata)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if fields["world_create"] ~= nil then
|
if fields["world_create"] ~= nil then
|
||||||
local create_world_dlg = create_create_world_dlg(true)
|
local create_world_dlg = create_create_world_dlg(enable_gamebar)
|
||||||
create_world_dlg:set_parent(this)
|
create_world_dlg:set_parent(this)
|
||||||
this:hide()
|
this:hide()
|
||||||
create_world_dlg:show()
|
create_world_dlg:show()
|
||||||
@ -371,11 +376,8 @@ if enable_gamebar then
|
|||||||
function on_change(type, old_tab, new_tab)
|
function on_change(type, old_tab, new_tab)
|
||||||
if (type == "ENTER") then
|
if (type == "ENTER") then
|
||||||
local game = current_game()
|
local game = current_game()
|
||||||
|
|
||||||
if game then
|
if game then
|
||||||
menudata.worldlist:set_filtercriteria(game.id)
|
apply_game(game)
|
||||||
core.set_topleft_text(game.name)
|
|
||||||
mm_game_theme.update("singleplayer",game)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
singleplayer_refresh_gamebar()
|
singleplayer_refresh_gamebar()
|
||||||
|
@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "util/strfnd.h"
|
#include "util/strfnd.h"
|
||||||
#include "defaultsettings.h" // for set_default_settings
|
#include "defaultsettings.h" // for set_default_settings
|
||||||
#include "mapgen/mapgen.h" // for MapgenParams
|
#include "map_settings_manager.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
|
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
@ -370,19 +370,12 @@ void loadGameConfAndInitWorld(const std::string &path, const std::string &name,
|
|||||||
// Create map_meta.txt if does not already exist
|
// Create map_meta.txt if does not already exist
|
||||||
std::string map_meta_path = final_path + DIR_DELIM + "map_meta.txt";
|
std::string map_meta_path = final_path + DIR_DELIM + "map_meta.txt";
|
||||||
if (!fs::PathExists(map_meta_path)) {
|
if (!fs::PathExists(map_meta_path)) {
|
||||||
verbosestream << "Creating map_meta.txt (" << map_meta_path << ")"
|
MapSettingsManager mgr(map_meta_path);
|
||||||
<< std::endl;
|
|
||||||
std::ostringstream oss(std::ios_base::binary);
|
|
||||||
|
|
||||||
Settings conf;
|
mgr.setMapSetting("seed", g_settings->get("fixed_map_seed"));
|
||||||
MapgenParams params;
|
|
||||||
|
|
||||||
params.readParams(g_settings);
|
mgr.makeMapgenParams();
|
||||||
params.writeParams(&conf);
|
mgr.saveMapMeta();
|
||||||
conf.writeLines(oss);
|
|
||||||
oss << "[end_of_params]\n";
|
|
||||||
|
|
||||||
fs::safeWriteToFile(map_meta_path, oss.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Settings object is no longer needed for created worlds
|
// The Settings object is no longer needed for created worlds
|
||||||
|
@ -52,14 +52,7 @@ MapSettingsManager::~MapSettingsManager()
|
|||||||
bool MapSettingsManager::getMapSetting(
|
bool MapSettingsManager::getMapSetting(
|
||||||
const std::string &name, std::string *value_out)
|
const std::string &name, std::string *value_out)
|
||||||
{
|
{
|
||||||
// Try getting it normally first
|
return m_map_settings->getNoEx(name, *value_out);
|
||||||
if (m_map_settings->getNoEx(name, *value_out))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// If not we may have to resolve some compatibility kludges
|
|
||||||
if (name == "seed")
|
|
||||||
return Settings::getLayer(SL_GLOBAL)->getNoEx("fixed_map_seed", *value_out);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1018,10 +1018,11 @@ MapgenParams::~MapgenParams()
|
|||||||
|
|
||||||
void MapgenParams::readParams(const Settings *settings)
|
void MapgenParams::readParams(const Settings *settings)
|
||||||
{
|
{
|
||||||
std::string seed_str;
|
// should always be used via MapSettingsManager
|
||||||
const char *seed_name = (settings == g_settings) ? "fixed_map_seed" : "seed";
|
assert(settings != g_settings);
|
||||||
|
|
||||||
if (settings->getNoEx(seed_name, seed_str)) {
|
std::string seed_str;
|
||||||
|
if (settings->getNoEx("seed", seed_str)) {
|
||||||
if (!seed_str.empty())
|
if (!seed_str.empty())
|
||||||
seed = read_seed(seed_str.c_str());
|
seed = read_seed(seed_str.c_str());
|
||||||
else
|
else
|
||||||
|
@ -414,25 +414,53 @@ int ModApiMainMenu::l_create_world(lua_State *L)
|
|||||||
const char *name = luaL_checkstring(L, 1);
|
const char *name = luaL_checkstring(L, 1);
|
||||||
int gameidx = luaL_checkinteger(L,2) -1;
|
int gameidx = luaL_checkinteger(L,2) -1;
|
||||||
|
|
||||||
|
StringMap use_settings;
|
||||||
|
luaL_checktype(L, 3, LUA_TTABLE);
|
||||||
|
lua_pushnil(L);
|
||||||
|
while (lua_next(L, 3) != 0) {
|
||||||
|
// key at index -2 and value at index -1
|
||||||
|
use_settings[luaL_checkstring(L, -2)] = luaL_checkstring(L, -1);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
std::string path = porting::path_user + DIR_DELIM
|
std::string path = porting::path_user + DIR_DELIM
|
||||||
"worlds" + DIR_DELIM
|
"worlds" + DIR_DELIM
|
||||||
+ sanitizeDirName(name, "world_");
|
+ sanitizeDirName(name, "world_");
|
||||||
|
|
||||||
std::vector<SubgameSpec> games = getAvailableGames();
|
std::vector<SubgameSpec> games = getAvailableGames();
|
||||||
|
if (gameidx < 0 || gameidx >= (int) games.size()) {
|
||||||
if ((gameidx >= 0) &&
|
|
||||||
(gameidx < (int) games.size())) {
|
|
||||||
|
|
||||||
// Create world if it doesn't exist
|
|
||||||
try {
|
|
||||||
loadGameConfAndInitWorld(path, name, games[gameidx], true);
|
|
||||||
lua_pushnil(L);
|
|
||||||
} catch (const BaseException &e) {
|
|
||||||
lua_pushstring(L, (std::string("Failed to initialize world: ") + e.what()).c_str());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
lua_pushstring(L, "Invalid game index");
|
lua_pushstring(L, "Invalid game index");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the settings for world creation
|
||||||
|
// this is a bad hack but the best we have right now..
|
||||||
|
StringMap backup;
|
||||||
|
for (auto it : use_settings) {
|
||||||
|
if (g_settings->existsLocal(it.first))
|
||||||
|
backup[it.first] = g_settings->get(it.first);
|
||||||
|
g_settings->set(it.first, it.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create world if it doesn't exist
|
||||||
|
try {
|
||||||
|
loadGameConfAndInitWorld(path, name, games[gameidx], true);
|
||||||
|
lua_pushnil(L);
|
||||||
|
} catch (const BaseException &e) {
|
||||||
|
auto err = std::string("Failed to initialize world: ") + e.what();
|
||||||
|
lua_pushstring(L, err.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore previous settings
|
||||||
|
for (auto it : use_settings) {
|
||||||
|
auto it2 = backup.find(it.first);
|
||||||
|
if (it2 == backup.end())
|
||||||
|
g_settings->remove(it.first); // wasn't set before
|
||||||
|
else
|
||||||
|
g_settings->set(it.first, it2->second); // was set before
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,9 +659,7 @@ bool Settings::getNoiseParamsFromGroup(const std::string &name,
|
|||||||
|
|
||||||
bool Settings::exists(const std::string &name) const
|
bool Settings::exists(const std::string &name) const
|
||||||
{
|
{
|
||||||
MutexAutoLock lock(m_mutex);
|
if (existsLocal(name))
|
||||||
|
|
||||||
if (m_settings.find(name) != m_settings.end())
|
|
||||||
return true;
|
return true;
|
||||||
if (auto parent = getParent())
|
if (auto parent = getParent())
|
||||||
return parent->exists(name);
|
return parent->exists(name);
|
||||||
@ -669,6 +667,14 @@ bool Settings::exists(const std::string &name) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Settings::existsLocal(const std::string &name) const
|
||||||
|
{
|
||||||
|
MutexAutoLock lock(m_mutex);
|
||||||
|
|
||||||
|
return m_settings.find(name) != m_settings.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::string> Settings::getNames() const
|
std::vector<std::string> Settings::getNames() const
|
||||||
{
|
{
|
||||||
MutexAutoLock lock(m_mutex);
|
MutexAutoLock lock(m_mutex);
|
||||||
|
@ -172,9 +172,12 @@ public:
|
|||||||
bool getNoiseParamsFromValue(const std::string &name, NoiseParams &np) const;
|
bool getNoiseParamsFromValue(const std::string &name, NoiseParams &np) const;
|
||||||
bool getNoiseParamsFromGroup(const std::string &name, NoiseParams &np) const;
|
bool getNoiseParamsFromGroup(const std::string &name, NoiseParams &np) const;
|
||||||
|
|
||||||
// return all keys used
|
// return all keys used in this object
|
||||||
std::vector<std::string> getNames() const;
|
std::vector<std::string> getNames() const;
|
||||||
|
// check if setting exists anywhere in the hierarchy
|
||||||
bool exists(const std::string &name) const;
|
bool exists(const std::string &name) const;
|
||||||
|
// check if setting exists in this object ("locally")
|
||||||
|
bool existsLocal(const std::string &name) const;
|
||||||
|
|
||||||
|
|
||||||
/***************************************
|
/***************************************
|
||||||
|
Loading…
Reference in New Issue
Block a user