From 322a9c2f74a83603b709497c34ca03edf43c7bfd 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 | 3 ++- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/builtin/game/hud.lua b/builtin/game/hud.lua index a2a046848..eaf037e68 100644 --- a/builtin/game/hud.lua +++ b/builtin/game/hud.lua @@ -251,12 +251,17 @@ 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 2e9c57c9e..e6a351918 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -1809,6 +1809,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 261d01c8e..007421f7a 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -568,14 +568,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 0ad82835e..467124f60 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -225,7 +225,8 @@ with this program; if not, write to the Free Software Foundation, Inc., Move default minimap from client-side C++ to server-side builtin Lua [scheduled bump for 5.9.0] PROTOCOL VERSION 45: - Reserved for minimap size change + Minimap HUD element supports negative size values as percentages + [bump for 5.9.1] PROTOCOL VERSION 46: Move default hotbar from client-side C++ to server-side builtin Lua [scheduled bump for 5.10.0]