1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add minetest.get_player_window_information() (#12367)

This commit is contained in:
rubenwardy 2023-02-27 22:58:41 +00:00 committed by GitHub
parent fbbdae93ee
commit 39f4d26177
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 345 additions and 35 deletions

View file

@ -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, "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());
lua_settable(L, top);
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);

View file

@ -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

View file

@ -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);

View file

@ -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);