diff options
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_mainmenu.cpp | 38 | ||||
-rw-r--r-- | src/script/lua_api/l_mainmenu.h | 4 | ||||
-rw-r--r-- | src/script/lua_api/l_server.cpp | 39 | ||||
-rw-r--r-- | src/script/lua_api/l_server.h | 3 |
4 files changed, 72 insertions, 12 deletions
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); |