From 0eb18780e4149e5e1a8ffefc88bfeda4f4ae335c Mon Sep 17 00:00:00 2001 From: luk3yx Date: Mon, 6 Nov 2023 02:42:27 +1300 Subject: [PATCH] Add "hide_game = true" option to game.conf (#152) --- builtin/mainmenu/init.lua | 19 ++++++++++++------- builtin/mainmenu/pkgmgr.lua | 1 + builtin/mainmenu/tab_content.lua | 2 +- src/content/subgames.cpp | 6 +++++- src/content/subgames.h | 5 +++-- src/script/lua_api/l_mainmenu.cpp | 4 ++++ 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index 9c5189910..ba859f425 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -104,14 +104,19 @@ function menudata.init_tabs() tab_name_selected = "content", is_open_cdb = true, on_click = function(this) - if #pkgmgr.games > 1 or (pkgmgr.games[1] and pkgmgr.games[1].id ~= "default") then - this:set_tab("content") - else - local dialog = create_store_dlg() - dialog:set_parent(this) - this:hide() - dialog:show() + -- Show the content tab if no hidden games are installed + for _, game in ipairs(pkgmgr.games) do + if not game.hidden then + this:set_tab("content") + return + end end + + -- Otherwise open the store dialog + local dialog = create_store_dlg("game") + dialog:set_parent(this) + this:hide() + dialog:show() end, }) diff --git a/builtin/mainmenu/pkgmgr.lua b/builtin/mainmenu/pkgmgr.lua index 912375255..36ea597b3 100644 --- a/builtin/mainmenu/pkgmgr.lua +++ b/builtin/mainmenu/pkgmgr.lua @@ -908,6 +908,7 @@ function pkgmgr.update_gamelist() -- Update default_game_idx for i, game in ipairs(pkgmgr.games) do if game.id == "default" then + -- Used by tab_local pkgmgr.default_game_idx = i break end diff --git a/builtin/mainmenu/tab_content.lua b/builtin/mainmenu/tab_content.lua index 5380dba7b..8c2d2104e 100644 --- a/builtin/mainmenu/tab_content.lua +++ b/builtin/mainmenu/tab_content.lua @@ -32,7 +32,7 @@ local function get_formspec(tabview, name, tabdata) packages_raw = {} local i = 0 for _, game in ipairs(pkgmgr.games) do - if game.id ~= "default" then + if not game.hidden then i = i + 1 packages_raw[i] = game end diff --git a/src/content/subgames.cpp b/src/content/subgames.cpp index 97a3964e0..e45dfc26f 100644 --- a/src/content/subgames.cpp +++ b/src/content/subgames.cpp @@ -144,13 +144,17 @@ SubgameSpec findSubgame(const std::string &id) if (conf.exists("moddable")) moddable = conf.getBool("moddable"); + bool hide_game = false; + if (conf.exists("hide_game")) + hide_game = conf.getBool("hide_game"); + std::string menuicon_path; #ifndef SERVER menuicon_path = getImagePath( game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png"); #endif return SubgameSpec(id, game_path, gamemod_path, mods_paths, game_name, - menuicon_path, game_author, game_release, moddable); + menuicon_path, game_author, game_release, moddable, hide_game); } SubgameSpec findWorldSubgame(const std::string &world_path) diff --git a/src/content/subgames.h b/src/content/subgames.h index 2ee93eb55..5eeff0c5c 100644 --- a/src/content/subgames.h +++ b/src/content/subgames.h @@ -36,6 +36,7 @@ struct SubgameSpec std::set addon_mods_paths; std::string menuicon_path; bool moddable; + bool hidden; SubgameSpec(const std::string &id = "", const std::string &path = "", const std::string &gamemods_path = "", @@ -44,11 +45,11 @@ struct SubgameSpec const std::string &name = "", const std::string &menuicon_path = "", const std::string &author = "", int release = 0, - const bool moddable = true) : + const bool moddable = true, const bool hidden = false) : id(id), name(name), author(author), release(release), path(path), gamemods_path(gamemods_path), addon_mods_paths(addon_mods_paths), - menuicon_path(menuicon_path), moddable(moddable) + menuicon_path(menuicon_path), moddable(moddable), hidden(hidden) { } diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 2c2fbc6d2..6af66df75 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -330,6 +330,10 @@ int ModApiMainMenu::l_get_games(lua_State *L) lua_pushboolean(L, game.moddable); lua_settable(L, top_lvl2); + lua_pushstring(L, "hidden"); + lua_pushboolean(L, game.hidden); + lua_settable(L, top_lvl2); + lua_pushstring(L, "addon_mods_paths"); lua_newtable(L); int table2 = lua_gettop(L);