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)
-- 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 mapgens = core.get_mapgen_names()
@ -310,8 +300,8 @@ local function create_world_formspec(dialogdata)
"label[0,2;" .. fgettext("Mapgen") .. "]"..
"dropdown[0,2.5;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]"
-- Warning if only devtest is installed
if #pkgmgr.games == 1 and pkgmgr.games[1].id == "devtest" then
-- Warning when making a devtest world
if game.id == "devtest" then
retval = retval ..
"container[0,3.5]" ..
"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: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.reset()
-- Create main tabview
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,
})
-- 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")
check_new_version()
tv_main:show()

@ -18,7 +18,11 @@
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
pkgmgr.refresh_globals()
end
@ -26,25 +30,25 @@ local function get_formspec(tabview, name, tabdata)
pkgmgr.update_gamelist()
end
if not packages then
packages_raw = {}
table.insert_all(packages_raw, pkgmgr.games)
table.insert_all(packages_raw, pkgmgr.get_texture_packs())
table.insert_all(packages_raw, pkgmgr.global_mods:get_list())
packages_raw = {}
table.insert_all(packages_raw, pkgmgr.games)
table.insert_all(packages_raw, pkgmgr.get_texture_packs())
table.insert_all(packages_raw, pkgmgr.global_mods:get_list())
local function get_data()
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, {})
local function get_data()
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
local function get_formspec(tabview, name, tabdata)
if not tabdata.selected_pkg then
tabdata.selected_pkg = 1
end
@ -227,5 +231,5 @@ return {
caption = fgettext("Content"),
cbf_formspec = get_formspec,
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
function current_game()
local last_game_id = core.settings:get("menu_last_game")
local game = pkgmgr.find_by_gameid(last_game_id)
local gameid = core.settings:get("menu_last_game")
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
end
@ -63,16 +79,12 @@ function singleplayer_refresh_gamebar()
old_bar:delete()
end
local function game_buttonbar_button_handler(fields)
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
-- Hide gamebar if no games are installed
if #pkgmgr.games == 0 then
return false
end
local function game_buttonbar_button_handler(fields)
for _, game in ipairs(pkgmgr.games) do
if fields["game_btnbar_" .. game.id] then
apply_game(game)
@ -108,6 +120,7 @@ function singleplayer_refresh_gamebar()
local plus_image = core.formspec_escape(defaulttexturedir .. "plus.png")
btnbar:add_button("game_open_cdb", "", plus_image, fgettext("Install games from ContentDB"))
return true
end
local function get_disabled_settings(game)
@ -137,6 +150,15 @@ local function get_disabled_settings(game)
end
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 index = filterlist.get_current_index(menudata.worldlist,
@ -237,6 +259,15 @@ local function main_button_handler(this, fields, name, tabdata)
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
this.dlg_create_world_closed_at = 0
end
@ -411,8 +442,9 @@ local function on_change(type, old_tab, new_tab)
apply_game(game)
end
singleplayer_refresh_gamebar()
ui.find_by_name("game_button_bar"):show()
if singleplayer_refresh_gamebar() then
ui.find_by_name("game_button_bar"):show()
end
else
menudata.worldlist:set_filtercriteria(nil)
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.
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_damage (Damage) bool false

@ -3179,11 +3179,6 @@
# type: int min: 1 max: 65535
# 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.
# type: bool
# enable_damage = false

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

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

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