Improve UX when no game exists and drop default_game (#13550)

This commit is contained in:
ROllerozxa 2023-09-17 19:45:28 +02:00 committed by GitHub
parent 5bfc5d44c0
commit a88e61c2cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 78 additions and 80 deletions

@ -91,16 +91,6 @@ local mgv6_biomes = {
local function create_world_formspec(dialogdata) local function create_world_formspec(dialogdata)
-- Point the player to ContentDB when no games are found
if #pkgmgr.games == 0 then
return "size[8,2.5,true]" ..
"style[label_button;border=false]" ..
"button[0.5,0.5;7,0.5;label_button;" ..
fgettext("You have no games installed.") .. "]" ..
"button[0.5,1.5;2.5,0.5;world_create_open_cdb;" .. fgettext("Install a game") .. "]" ..
"button[5.0,1.5;2.5,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
end
local current_mg = dialogdata.mg local current_mg = dialogdata.mg
local mapgens = core.get_mapgen_names() local mapgens = core.get_mapgen_names()
@ -310,8 +300,8 @@ local function create_world_formspec(dialogdata)
"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 .. "]"
-- Warning if only devtest is installed -- Warning when making a devtest world
if #pkgmgr.games == 1 and pkgmgr.games[1].id == "devtest" then if game.id == "devtest" then
retval = retval .. retval = retval ..
"container[0,3.5]" .. "container[0,3.5]" ..
"box[0,0;5.8,1.7;#ff8800]" .. "box[0,0;5.8,1.7;#ff8800]" ..

@ -87,15 +87,8 @@ local function init_globals()
menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic) menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
menudata.worldlist:set_sortmode("alphabetic") menudata.worldlist:set_sortmode("alphabetic")
local gameid = core.settings:get("menu_last_game")
local game = gameid and pkgmgr.find_by_gameid(gameid)
if not game then
gameid = core.settings:get("default_game") or "minetest"
game = pkgmgr.find_by_gameid(gameid)
core.settings:set("menu_last_game", gameid)
end
mm_game_theme.init() mm_game_theme.init()
mm_game_theme.reset()
-- Create main tabview -- Create main tabview
local tv_main = tabview_create("maintab", {x = 15.5, y = 7.1}, {x = 0, y = 0}) local tv_main = tabview_create("maintab", {x = 15.5, y = 7.1}, {x = 0, y = 0})
@ -127,12 +120,6 @@ local function init_globals()
end, end,
}) })
-- In case the folder of the last selected game has been deleted,
-- display "Minetest" as a header
if tv_main.current_tab == "local" and not game then
mm_game_theme.reset()
end
ui.set_default("maintab") ui.set_default("maintab")
check_new_version() check_new_version()
tv_main:show() tv_main:show()

@ -18,7 +18,11 @@
local packages_raw, packages local packages_raw, packages
local function get_formspec(tabview, name, tabdata) local function on_change(type)
if type ~= "ENTER" then
return
end
if not pkgmgr.global_mods then if not pkgmgr.global_mods then
pkgmgr.refresh_globals() pkgmgr.refresh_globals()
end end
@ -26,25 +30,25 @@ local function get_formspec(tabview, name, tabdata)
pkgmgr.update_gamelist() pkgmgr.update_gamelist()
end end
if not packages then packages_raw = {}
packages_raw = {} table.insert_all(packages_raw, pkgmgr.games)
table.insert_all(packages_raw, pkgmgr.games) table.insert_all(packages_raw, pkgmgr.get_texture_packs())
table.insert_all(packages_raw, pkgmgr.get_texture_packs()) table.insert_all(packages_raw, pkgmgr.global_mods:get_list())
table.insert_all(packages_raw, pkgmgr.global_mods:get_list())
local function get_data() local function get_data()
return packages_raw return packages_raw
end
local function is_equal(element, uid) --uid match
return (element.type == "game" and element.id == uid) or
element.name == uid
end
packages = filterlist.create(get_data, pkgmgr.compare_package,
is_equal, nil, {})
end end
local function is_equal(element, uid) --uid match
return (element.type == "game" and element.id == uid) or
element.name == uid
end
packages = filterlist.create(get_data, pkgmgr.compare_package,
is_equal, nil, {})
end
local function get_formspec(tabview, name, tabdata)
if not tabdata.selected_pkg then if not tabdata.selected_pkg then
tabdata.selected_pkg = 1 tabdata.selected_pkg = 1
end end
@ -227,5 +231,5 @@ return {
caption = fgettext("Content"), caption = fgettext("Content"),
cbf_formspec = get_formspec, cbf_formspec = get_formspec,
cbf_button_handler = handle_buttons, cbf_button_handler = handle_buttons,
on_change = pkgmgr.update_gamelist on_change = on_change
} }

@ -29,8 +29,24 @@ local current_port = core.settings:get("port")
-- Currently chosen game in gamebar for theming and filtering -- Currently chosen game in gamebar for theming and filtering
function current_game() function current_game()
local last_game_id = core.settings:get("menu_last_game") local gameid = core.settings:get("menu_last_game")
local game = pkgmgr.find_by_gameid(last_game_id) local game = gameid and pkgmgr.find_by_gameid(gameid)
-- Fall back to first game installed if one exists.
if not game and #pkgmgr.games > 0 then
-- If devtest is the first game in the list and there is another
-- game available, pick the other game instead.
local picked_game
if pkgmgr.games[1].id == "devtest" and #pkgmgr.games > 1 then
picked_game = 2
else
picked_game = 1
end
game = pkgmgr.games[picked_game]
gameid = game.id
core.settings:set("menu_last_game", gameid)
end
return game return game
end end
@ -63,16 +79,12 @@ function singleplayer_refresh_gamebar()
old_bar:delete() old_bar:delete()
end end
local function game_buttonbar_button_handler(fields) -- Hide gamebar if no games are installed
if fields.game_open_cdb then if #pkgmgr.games == 0 then
local maintab = ui.find_by_name("maintab") return false
local dlg = create_store_dlg("game") end
dlg:set_parent(maintab)
maintab:hide()
dlg:show()
return true
end
local function game_buttonbar_button_handler(fields)
for _, game in ipairs(pkgmgr.games) do for _, game in ipairs(pkgmgr.games) do
if fields["game_btnbar_" .. game.id] then if fields["game_btnbar_" .. game.id] then
apply_game(game) apply_game(game)
@ -108,6 +120,7 @@ function singleplayer_refresh_gamebar()
local plus_image = core.formspec_escape(defaulttexturedir .. "plus.png") local plus_image = core.formspec_escape(defaulttexturedir .. "plus.png")
btnbar:add_button("game_open_cdb", "", plus_image, fgettext("Install games from ContentDB")) btnbar:add_button("game_open_cdb", "", plus_image, fgettext("Install games from ContentDB"))
return true
end end
local function get_disabled_settings(game) local function get_disabled_settings(game)
@ -137,6 +150,15 @@ local function get_disabled_settings(game)
end end
local function get_formspec(tabview, name, tabdata) local function get_formspec(tabview, name, tabdata)
-- Point the player to ContentDB when no games are found
if #pkgmgr.games == 0 then
return table.concat({
"style[label_button;border=false]",
"button[2.75,1.5;10,1;label_button;", fgettext("You have no games installed."), "]",
"button[5.25,3.5;5,1.2;game_open_cdb;", fgettext("Install a game"), "]"})
end
local retval = "" local retval = ""
local index = filterlist.get_current_index(menudata.worldlist, local index = filterlist.get_current_index(menudata.worldlist,
@ -237,6 +259,15 @@ local function main_button_handler(this, fields, name, tabdata)
assert(name == "local") assert(name == "local")
if fields.game_open_cdb then
local maintab = ui.find_by_name("maintab")
local dlg = create_store_dlg("game")
dlg:set_parent(maintab)
maintab:hide()
dlg:show()
return true
end
if this.dlg_create_world_closed_at == nil then if this.dlg_create_world_closed_at == nil then
this.dlg_create_world_closed_at = 0 this.dlg_create_world_closed_at = 0
end end
@ -411,8 +442,9 @@ local function on_change(type, old_tab, new_tab)
apply_game(game) apply_game(game)
end end
singleplayer_refresh_gamebar() if singleplayer_refresh_gamebar() then
ui.find_by_name("game_button_bar"):show() ui.find_by_name("game_button_bar"):show()
end
else else
menudata.worldlist:set_filtercriteria(nil) menudata.worldlist:set_filtercriteria(nil)
local gamebar = ui.find_by_name("game_button_bar") local gamebar = ui.find_by_name("game_button_bar")

@ -2194,10 +2194,6 @@ address (Server address) string
# Note that the port field in the main menu overrides this setting. # Note that the port field in the main menu overrides this setting.
remote_port (Remote port) int 30000 1 65535 remote_port (Remote port) int 30000 1 65535
# Default game when creating a new world.
# This will be overridden when creating a world from the main menu.
default_game (Default game) string minetest
# Enable players getting damage and dying. # Enable players getting damage and dying.
enable_damage (Damage) bool false enable_damage (Damage) bool false

@ -3179,11 +3179,6 @@
# type: int min: 1 max: 65535 # type: int min: 1 max: 65535
# remote_port = 30000 # remote_port = 30000
# Default game when creating a new world.
# This will be overridden when creating a world from the main menu.
# type: string
# default_game = minetest
# Enable players getting damage and dying. # Enable players getting damage and dying.
# type: bool # type: bool
# enable_damage = false # enable_damage = false

@ -397,11 +397,6 @@ bool ClientLauncher::launch_game(std::string &error_message,
spec.path = start_data.world_path; spec.path = start_data.world_path;
spec.gameid = getWorldGameId(spec.path, true); spec.gameid = getWorldGameId(spec.path, true);
spec.name = _("[--world parameter]"); spec.name = _("[--world parameter]");
if (spec.gameid.empty()) { // Create new
spec.gameid = g_settings->get("default_game");
spec.name += " [new]";
}
} }
/* Show the GUI menu /* Show the GUI menu

@ -367,7 +367,6 @@ void set_default_settings()
settings->setDefault("max_simultaneous_block_sends_per_client", "40"); settings->setDefault("max_simultaneous_block_sends_per_client", "40");
settings->setDefault("time_send_interval", "5"); settings->setDefault("time_send_interval", "5");
settings->setDefault("default_game", "minetest");
settings->setDefault("motd", ""); settings->setDefault("motd", "");
settings->setDefault("max_users", "15"); settings->setDefault("max_users", "15");
settings->setDefault("creative_mode", "false"); settings->setDefault("creative_mode", "false");

@ -994,15 +994,15 @@ static bool determine_subgame(GameParams *game_params)
if (game_params->game_spec.isValid()) { if (game_params->game_spec.isValid()) {
gamespec = game_params->game_spec; gamespec = game_params->game_spec;
infostream << "Using commanded gameid [" << gamespec.id << "]" << std::endl; infostream << "Using commanded gameid [" << gamespec.id << "]" << std::endl;
} else { // Otherwise we will be using "minetest" } else {
gamespec = findSubgame(g_settings->get("default_game")); if (game_params->is_dedicated_server) {
infostream << "Using default gameid [" << gamespec.id << "]" << std::endl; // If this is a dedicated server and no gamespec has been specified,
if (!gamespec.isValid()) { // print a friendly error pointing to ContentDB.
errorstream << "Game specified in default_game [" errorstream << "To run a " PROJECT_NAME_C " server, you need to select a game using the '--gameid' argument." << std::endl
<< g_settings->get("default_game") << "Check out https://content.minetest.net for a selection of games to pick from and download." << std::endl;
<< "] is invalid." << std::endl;
return false;
} }
return false;
} }
} else { // World exists } else { // World exists
std::string world_gameid = getWorldGameId(game_params->world_path, false); std::string world_gameid = getWorldGameId(game_params->world_path, false);