From ecf535ee83fc5b1820b5092f5573a3830e0d10c8 Mon Sep 17 00:00:00 2001 From: grorp Date: Sat, 31 Aug 2024 18:11:56 +0200 Subject: [PATCH] Restore proportional minimap scaling (#15022) --- builtin/game/hud.lua | 11 ++++++++--- doc/lua_api.md | 5 +++++ src/client/hud.cpp | 13 ++++++++++--- src/network/networkprotocol.h | 5 ++++- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/builtin/game/hud.lua b/builtin/game/hud.lua index 1bc4b48d7..6f313340d 100644 --- a/builtin/game/hud.lua +++ b/builtin/game/hud.lua @@ -251,11 +251,16 @@ register_builtin_hud_element("minimap", { position = {x = 1, y = 0}, alignment = {x = -1, y = 1}, offset = {x = -10, y = 10}, - size = {x = 256, y = 256}, + size = {x = 0, y = -25}, }, show_elem = function(player, flags) + local proto_ver = core.get_player_information(player:get_player_name()).protocol_version -- Don't add a minimap for clients which already have it hardcoded in C++. - return flags.minimap and - core.get_player_information(player:get_player_name()).protocol_version >= 44 + return flags.minimap and proto_ver >= 44 + end, + update_def = function(player, elem_def) + local proto_ver = core.get_player_information(player:get_player_name()).protocol_version + -- Only use percentage when the client supports it. + elem_def.size = proto_ver >= 45 and {x = 0, y = -25} or {x = 256, y = 256} end, }) diff --git a/doc/lua_api.md b/doc/lua_api.md index 710c44a41..46bdd09ce 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -1802,6 +1802,11 @@ Displays a minimap on the HUD. * `size`: Size of the minimap to display. Minimap should be a square to avoid distortion. + * Negative values represent percentages of the screen. If either `x` or `y` + is specified as a percentage, the resulting pixel size will be used for + both `x` and `y`. Example: On a 1920x1080 screen, `{x = 0, y = -25}` will + result in a 270x270 minimap. + * Negative values are supported starting with protocol version 45. * `alignment`: The alignment of the minimap. * `offset`: offset in pixels from position. diff --git a/src/client/hud.cpp b/src/client/hud.cpp index c5e71b853..c971d9558 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -544,14 +544,21 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) } break; } case HUD_ELEM_MINIMAP: { - if (e->size.X <= 0 || e->size.Y <= 0) - break; if (!client->getMinimap()) break; // Draw a minimap of size "size" v2s32 dstsize(e->size.X * m_scale_factor, e->size.Y * m_scale_factor); - // (no percent size as minimap would likely be anamorphosed) + + // Only one percentage is supported to avoid distortion. + if (e->size.X < 0) + dstsize.X = dstsize.Y = m_screensize.X * (e->size.X * -0.01); + else if (e->size.Y < 0) + dstsize.X = dstsize.Y = m_screensize.Y * (e->size.Y * -0.01); + + if (dstsize.X <= 0 || dstsize.Y <= 0) + return; + v2s32 offset((e->align.X - 1.0) * dstsize.X / 2, (e->align.Y - 1.0) * dstsize.Y / 2); core::rect rect(0, 0, dstsize.X, dstsize.Y); diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index e3618042f..cd9396e63 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -224,9 +224,12 @@ with this program; if not, write to the Free Software Foundation, Inc., Add TOCLIENT_MOVE_PLAYER_REL Move default minimap from client-side C++ to server-side builtin Lua [scheduled bump for 5.9.0] + PROTOCOL VERSION 45: + Minimap HUD element supports negative size values as percentages + [bump for 5.9.1] */ -#define LATEST_PROTOCOL_VERSION 44 +#define LATEST_PROTOCOL_VERSION 45 #define LATEST_PROTOCOL_VERSION_STRING TOSTRING(LATEST_PROTOCOL_VERSION) // Server's supported network protocol range