mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Improve UX when no game exists and drop default_game
(#13550)
This commit is contained in:
parent
5bfc5d44c0
commit
a88e61c2cf
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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue