From 4f8784c78948f27f8675da83376fb5d5bda23495 Mon Sep 17 00:00:00 2001 From: grorp Date: Wed, 1 Jan 2025 17:49:38 +0100 Subject: [PATCH] Implement keychange/touchscreenlayout, don't implement filepicker --- builtin/common/settings/components.lua | 4 +++- src/script/lua_api/CMakeLists.txt | 1 + src/script/lua_api/l_pause_menu.cpp | 28 ++++++++++++++++++++++++++ src/script/lua_api/l_pause_menu.h | 17 ++++++++++++++++ src/script/lua_api/l_settings.cpp | 1 + src/script/scripting_pause_menu.cpp | 2 ++ 6 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/script/lua_api/l_pause_menu.cpp create mode 100644 src/script/lua_api/l_pause_menu.h diff --git a/builtin/common/settings/components.lua b/builtin/common/settings/components.lua index 64cd27c3c..0a4bf13c7 100644 --- a/builtin/common/settings/components.lua +++ b/builtin/common/settings/components.lua @@ -249,8 +249,10 @@ local function make_path(setting) } end -if PLATFORM == "Android" then +if PLATFORM == "Android" or INIT == "pause_menu" then -- The Irrlicht file picker doesn't work on Android. + -- Access to the Irrlicht file picker isn't implemented in the pause menu + -- since we want to delete it anyway, so any time spent on it would be wasted. make.path = make.string make.filepath = make.string else diff --git a/src/script/lua_api/CMakeLists.txt b/src/script/lua_api/CMakeLists.txt index 3909eb3fe..ef1be9525 100644 --- a/src/script/lua_api/CMakeLists.txt +++ b/src/script/lua_api/CMakeLists.txt @@ -37,5 +37,6 @@ set(client_SCRIPT_LUA_API_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/l_menu_common.cpp ${CMAKE_CURRENT_SOURCE_DIR}/l_minimap.cpp ${CMAKE_CURRENT_SOURCE_DIR}/l_particles_local.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/l_pause_menu.cpp ${CMAKE_CURRENT_SOURCE_DIR}/l_storage.cpp PARENT_SCOPE) diff --git a/src/script/lua_api/l_pause_menu.cpp b/src/script/lua_api/l_pause_menu.cpp new file mode 100644 index 000000000..6af62d3e3 --- /dev/null +++ b/src/script/lua_api/l_pause_menu.cpp @@ -0,0 +1,28 @@ +// Luanti +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2025 grorp + +#include "l_pause_menu.h" +#include "gui/mainmenumanager.h" +#include "lua_api/l_internal.h" + +/******************************************************************************/ +int ModApiPauseMenu::l_show_keys_menu(lua_State *L) +{ + g_gamecallback->keyConfig(); + return 0; +} + +/******************************************************************************/ +int ModApiPauseMenu::l_show_touchscreen_layout(lua_State *L) +{ + g_gamecallback->touchscreenLayout(); + return 0; +} + +/******************************************************************************/ +void ModApiPauseMenu::Initialize(lua_State *L, int top) +{ + API_FCT(show_keys_menu); + API_FCT(show_touchscreen_layout); +} diff --git a/src/script/lua_api/l_pause_menu.h b/src/script/lua_api/l_pause_menu.h new file mode 100644 index 000000000..507c1c4b7 --- /dev/null +++ b/src/script/lua_api/l_pause_menu.h @@ -0,0 +1,17 @@ +// Luanti +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2025 grorp + +#pragma once + +#include "l_base.h" + +class ModApiPauseMenu: public ModApiBase +{ +private: + static int l_show_keys_menu(lua_State *L); + static int l_show_touchscreen_layout(lua_State *L); + +public: + static void Initialize(lua_State *L, int top); +}; diff --git a/src/script/lua_api/l_settings.cpp b/src/script/lua_api/l_settings.cpp index 241eb2542..d5f833fbd 100644 --- a/src/script/lua_api/l_settings.cpp +++ b/src/script/lua_api/l_settings.cpp @@ -31,6 +31,7 @@ static inline int checkSettingSecurity(lua_State* L, const std::string &name) { #if CHECK_CLIENT_BUILD() // Main menu is allowed everything + // TODO: also permit pause menu if (ModApiBase::getGuiEngine(L) != nullptr) return 0; #endif diff --git a/src/script/scripting_pause_menu.cpp b/src/script/scripting_pause_menu.cpp index 2bbde0628..ebcc55d2b 100644 --- a/src/script/scripting_pause_menu.cpp +++ b/src/script/scripting_pause_menu.cpp @@ -8,6 +8,7 @@ #include "filesys.h" #include "lua_api/l_client_common.h" #include "lua_api/l_menu_common.h" +#include "lua_api/l_pause_menu.h" #include "lua_api/l_settings.h" #include "lua_api/l_util.h" #include "porting.h" @@ -41,6 +42,7 @@ void PauseMenuScripting::initializeModApi(lua_State *L, int top) LuaSettings::Register(L); // Initialize mod API modules + ModApiPauseMenu::Initialize(L, top); ModApiMenuCommon::Initialize(L, top); ModApiClientCommon::Initialize(L, top); ModApiUtil::Initialize(L, top);