aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2023-02-27 22:58:41 +0000
committerGitHub <noreply@github.com>2023-02-27 22:58:41 +0000
commit39f4d26177ec1c8f246133c532a42ef7429bc36d (patch)
tree910b6a6635adf37eaba1d7410e83fad14f15bb90 /src/script
parentfbbdae93ee324584089efaf8e880a1378f6a2ad6 (diff)
downloadminetest-39f4d26177ec1c8f246133c532a42ef7429bc36d.tar.xz
Add minetest.get_player_window_information() (#12367)
Diffstat (limited to 'src/script')
-rw-r--r--src/script/common/c_converter.cpp9
-rw-r--r--src/script/common/c_converter.h1
-rw-r--r--src/script/lua_api/l_mainmenu.cpp38
-rw-r--r--src/script/lua_api/l_mainmenu.h4
-rw-r--r--src/script/lua_api/l_server.cpp39
-rw-r--r--src/script/lua_api/l_server.h3
6 files changed, 82 insertions, 12 deletions
diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp
index 90b78a081..22aa1c5d7 100644
--- a/src/script/common/c_converter.cpp
+++ b/src/script/common/c_converter.cpp
@@ -128,6 +128,15 @@ void push_v2s32(lua_State *L, v2s32 p)
lua_setfield(L, -2, "y");
}
+void push_v2u32(lua_State *L, v2u32 p)
+{
+ lua_createtable(L, 0, 2);
+ lua_pushinteger(L, p.X);
+ lua_setfield(L, -2, "x");
+ lua_pushinteger(L, p.Y);
+ lua_setfield(L, -2, "y");
+}
+
v2s32 read_v2s32(lua_State *L, int index)
{
v2s32 p;
diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h
index f1e4e47ec..90358147a 100644
--- a/src/script/common/c_converter.h
+++ b/src/script/common/c_converter.h
@@ -108,6 +108,7 @@ size_t read_stringlist (lua_State *L, int index,
void push_v2s16 (lua_State *L, v2s16 p);
void push_v2s32 (lua_State *L, v2s32 p);
+void push_v2u32 (lua_State *L, v2u32 p);
void push_v3s16 (lua_State *L, v3s16 p);
void push_aabb3f (lua_State *L, aabb3f box);
void push_ARGB8 (lua_State *L, video::SColor color);
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index e53ec5fed..e19156e22 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -40,6 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "network/networkprotocol.h"
#include "content/mod_configuration.h"
#include "threading/mutex_auto_lock.h"
+#include "common/c_converter.h"
/******************************************************************************/
std::string ModApiMainMenu::getTextData(lua_State *L, std::string name)
@@ -922,26 +923,40 @@ int ModApiMainMenu::l_gettext(lua_State *L)
}
/******************************************************************************/
-int ModApiMainMenu::l_get_screen_info(lua_State *L)
+int ModApiMainMenu::l_get_window_info(lua_State *L)
{
lua_newtable(L);
int top = lua_gettop(L);
- lua_pushstring(L,"density");
- lua_pushnumber(L,RenderingEngine::getDisplayDensity());
- lua_settable(L, top);
const v2u32 &window_size = RenderingEngine::getWindowSize();
- lua_pushstring(L,"window_width");
- lua_pushnumber(L, window_size.X);
+ f32 density = RenderingEngine::getDisplayDensity();
+ f32 gui_scaling = g_settings->getFloat("gui_scaling") * density;
+ f32 hud_scaling = g_settings->getFloat("hud_scaling") * density;
+
+ lua_pushstring(L, "size");
+ push_v2u32(L, window_size);
lua_settable(L, top);
- lua_pushstring(L,"window_height");
- lua_pushnumber(L, window_size.Y);
+ lua_pushstring(L, "max_formspec_size");
+ push_v2f(L, ClientDynamicInfo::calculateMaxFSSize(window_size));
lua_settable(L, top);
- lua_pushstring(L, "render_info");
- lua_pushstring(L, wide_to_utf8(RenderingEngine::get_video_driver()->getName()).c_str());
+ lua_pushstring(L, "real_gui_scaling");
+ lua_pushnumber(L, gui_scaling);
lua_settable(L, top);
+
+ lua_pushstring(L, "real_hud_scaling");
+ lua_pushnumber(L, hud_scaling);
+ lua_settable(L, top);
+
+ return 1;
+}
+
+/******************************************************************************/
+
+int ModApiMainMenu::l_get_active_renderer(lua_State *L)
+{
+ lua_pushstring(L, wide_to_utf8(RenderingEngine::get_video_driver()->getName()).c_str());
return 1;
}
@@ -1086,7 +1101,8 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(download_file);
API_FCT(gettext);
API_FCT(get_video_drivers);
- API_FCT(get_screen_info);
+ API_FCT(get_window_info);
+ API_FCT(get_active_renderer);
API_FCT(get_min_supp_proto);
API_FCT(get_max_supp_proto);
API_FCT(open_url);
diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h
index a731f77a8..bb5c93cd5 100644
--- a/src/script/lua_api/l_mainmenu.h
+++ b/src/script/lua_api/l_mainmenu.h
@@ -104,7 +104,9 @@ private:
static int l_set_formspec_prepend(lua_State *L);
- static int l_get_screen_info(lua_State *L);
+ static int l_get_window_info(lua_State *L);
+
+ static int l_get_active_renderer(lua_State *L);
//filesystem
diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp
index fb2018aac..eff212653 100644
--- a/src/script/lua_api/l_server.cpp
+++ b/src/script/lua_api/l_server.cpp
@@ -269,6 +269,44 @@ int ModApiServer::l_get_player_information(lua_State *L)
return 1;
}
+// get_player_window_information(name)
+int ModApiServer::l_get_player_window_information(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+
+ Server *server = getServer(L);
+
+ const char *name = luaL_checkstring(L, 1);
+ RemotePlayer *player = server->getEnv().getPlayer(name);
+ if (!player)
+ return 0;
+
+ auto dynamic = server->getClientDynamicInfo(player->getPeerId());
+
+ if (!dynamic || dynamic->render_target_size == v2u32())
+ return 0;
+
+ lua_newtable(L);
+ int dyn_table = lua_gettop(L);
+
+ lua_pushstring(L, "size");
+ push_v2u32(L, dynamic->render_target_size);
+ lua_settable(L, dyn_table);
+
+ lua_pushstring(L, "max_formspec_size");
+ push_v2f(L, dynamic->max_fs_size);
+ lua_settable(L, dyn_table);
+
+ lua_pushstring(L, "real_gui_scaling");
+ lua_pushnumber(L, dynamic->real_gui_scaling);
+ lua_settable(L, dyn_table);
+
+ lua_pushstring(L, "real_hud_scaling");
+ lua_pushnumber(L, dynamic->real_hud_scaling);
+ lua_settable(L, dyn_table);
+ return 1;
+}
+
// get_ban_list()
int ModApiServer::l_get_ban_list(lua_State *L)
{
@@ -635,6 +673,7 @@ void ModApiServer::Initialize(lua_State *L, int top)
API_FCT(dynamic_add_media);
API_FCT(get_player_information);
+ API_FCT(get_player_window_information);
API_FCT(get_player_privs);
API_FCT(get_player_ip);
API_FCT(get_ban_list);
diff --git a/src/script/lua_api/l_server.h b/src/script/lua_api/l_server.h
index 15d61669e..29fea7677 100644
--- a/src/script/lua_api/l_server.h
+++ b/src/script/lua_api/l_server.h
@@ -88,6 +88,9 @@ private:
// get_player_information(name)
static int l_get_player_information(lua_State *L);
+ // get_player_window_information(name)
+ static int l_get_player_window_information(lua_State *L);
+
// get_ban_list()
static int l_get_ban_list(lua_State *L);