Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve UX when no game exists and drop default_game #13550

Merged
merged 9 commits into from Sep 17, 2023
Merged
1 change: 1 addition & 0 deletions builtin/mainmenu/dlg_config_world.lua
Expand Up @@ -338,6 +338,7 @@ local function handle_buttons(this, fields)
dlg:set_parent(this)
this:hide()
dlg:show()
tab_content_clear_packages()
return true
end

Expand Down
15 changes: 3 additions & 12 deletions builtin/mainmenu/dlg_create_world.lua
Expand Up @@ -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()

Expand Down Expand Up @@ -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 pkgmgr.games[1].id == "devtest" then
rubenwardy marked this conversation as resolved.
Show resolved Hide resolved
retval = retval ..
"container[0,3.5]" ..
"box[0,0;5.8,1.7;#ff8800]" ..
Expand Down Expand Up @@ -346,6 +336,7 @@ local function create_world_buttonhandler(this, fields)
this:delete()
this.parent:hide()
dlg:show()
tab_content_clear_packages()
return true
end

Expand Down
15 changes: 1 addition & 14 deletions builtin/mainmenu/init.lua
Expand Up @@ -104,15 +104,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 = 12, y = 5.4}, {x = 0, y = 0})
Expand All @@ -133,12 +126,6 @@ local function init_globals()
tv_main:set_tab(last_tab)
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()
Expand Down
6 changes: 6 additions & 0 deletions builtin/mainmenu/tab_content.lua
Expand Up @@ -19,6 +19,12 @@
local packages_raw
local packages

-- HACK: Update package list when installing content from a button to CDB
-- elsewhere (e.g. tab_local or config_world).
function tab_content_clear_packages()
rollerozxa marked this conversation as resolved.
Show resolved Hide resolved
packages = nil
end

--------------------------------------------------------------------------------
local function get_formspec(tabview, name, tabdata)
if pkgmgr.global_mods == nil then
Expand Down
62 changes: 49 additions & 13 deletions builtin/mainmenu/tab_local.lua
Expand Up @@ -25,8 +25,26 @@ local valid_disabled_settings = {

-- 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)
if not game then
grorp marked this conversation as resolved.
Show resolved Hide resolved
-- 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
end

return game
end
Expand Down Expand Up @@ -59,16 +77,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)
Expand Down Expand Up @@ -105,6 +119,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)
Expand Down Expand Up @@ -134,6 +149,16 @@ 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"), "]"},
"size[15.5,7.1,false]real_coordinates[true]"
rollerozxa marked this conversation as resolved.
Show resolved Hide resolved
end

local retval = ""

local index = filterlist.get_current_index(menudata.worldlist,
Expand Down Expand Up @@ -215,6 +240,16 @@ 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()
tab_content_clear_packages()
return true
end

if this.dlg_create_world_closed_at == nil then
this.dlg_create_world_closed_at = 0
end
Expand Down Expand Up @@ -381,8 +416,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")
Expand Down
4 changes: 0 additions & 4 deletions builtin/settingtypes.txt
Expand Up @@ -2090,10 +2090,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

Expand Down
5 changes: 0 additions & 5 deletions minetest.conf.example
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/client/clientlauncher.cpp
Expand Up @@ -398,11 +398,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
Expand Down
1 change: 0 additions & 1 deletion src/defaultsettings.cpp
Expand Up @@ -368,7 +368,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");
Expand Down
16 changes: 8 additions & 8 deletions src/main.cpp
Expand Up @@ -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 will need some kind of game." << std::endl
grorp marked this conversation as resolved.
Show resolved Hide resolved
<< "Check out content.minetest.net for a selection of games to pick from and download." << std::endl;
grorp marked this conversation as resolved.
Show resolved Hide resolved
}

return false;
}
} else { // World exists
std::string world_gameid = getWorldGameId(game_params->world_path, false);
Expand Down