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
14 changes: 2 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 game.id == "devtest" then
retval = retval ..
"container[0,3.5]" ..
"box[0,0;5.8,1.7;#ff8800]" ..
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
38 changes: 21 additions & 17 deletions builtin/mainmenu/tab_content.lua
Expand Up @@ -18,33 +18,37 @@

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
if not pkgmgr.games then
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())

local function get_data()
return packages_raw
end
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 is_equal(element, uid) --uid match
return (element.type == "game" and element.id == uid) or
element.name == uid
end
local function get_data()
return packages_raw
end

packages = filterlist.create(get_data, pkgmgr.compare_package,
is_equal, nil, {})
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
Expand Down Expand Up @@ -228,5 +232,5 @@ return {
caption = fgettext("Content"),
cbf_formspec = get_formspec,
cbf_button_handler = handle_buttons,
on_change = pkgmgr.update_gamelist
on_change = on_change
}
58 changes: 45 additions & 13 deletions builtin/mainmenu/tab_local.lua
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -109,6 +121,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 @@ -138,6 +151,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"), "]"}
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 @@ -219,6 +241,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
Expand Down Expand Up @@ -393,8 +424,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 @@ -2195,10 +2195,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 @@ -388,11 +388,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 need a game." << std::endl
<< "Check out https://content.minetest.net for a selection of games to pick from and download." << std::endl;
rollerozxa 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