Restore proportional minimap scaling (#15022)

This commit is contained in:
grorp 2024-08-31 18:11:56 +02:00 committed by SmallJoker
parent f79a51c265
commit ecf535ee83
4 changed files with 27 additions and 7 deletions

@ -251,11 +251,16 @@ register_builtin_hud_element("minimap", {
position = {x = 1, y = 0}, position = {x = 1, y = 0},
alignment = {x = -1, y = 1}, alignment = {x = -1, y = 1},
offset = {x = -10, y = 10}, offset = {x = -10, y = 10},
size = {x = 256, y = 256}, size = {x = 0, y = -25},
}, },
show_elem = function(player, flags) 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++. -- Don't add a minimap for clients which already have it hardcoded in C++.
return flags.minimap and return flags.minimap and proto_ver >= 44
core.get_player_information(player:get_player_name()).protocol_version >= 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, end,
}) })

@ -1802,6 +1802,11 @@ Displays a minimap on the HUD.
* `size`: Size of the minimap to display. Minimap should be a square to avoid * `size`: Size of the minimap to display. Minimap should be a square to avoid
distortion. 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. * `alignment`: The alignment of the minimap.
* `offset`: offset in pixels from position. * `offset`: offset in pixels from position.

@ -544,14 +544,21 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
} }
break; } break; }
case HUD_ELEM_MINIMAP: { case HUD_ELEM_MINIMAP: {
if (e->size.X <= 0 || e->size.Y <= 0)
break;
if (!client->getMinimap()) if (!client->getMinimap())
break; break;
// Draw a minimap of size "size" // Draw a minimap of size "size"
v2s32 dstsize(e->size.X * m_scale_factor, v2s32 dstsize(e->size.X * m_scale_factor,
e->size.Y * 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, v2s32 offset((e->align.X - 1.0) * dstsize.X / 2,
(e->align.Y - 1.0) * dstsize.Y / 2); (e->align.Y - 1.0) * dstsize.Y / 2);
core::rect<s32> rect(0, 0, dstsize.X, dstsize.Y); core::rect<s32> rect(0, 0, dstsize.X, dstsize.Y);

@ -224,9 +224,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Add TOCLIENT_MOVE_PLAYER_REL Add TOCLIENT_MOVE_PLAYER_REL
Move default minimap from client-side C++ to server-side builtin Lua Move default minimap from client-side C++ to server-side builtin Lua
[scheduled bump for 5.9.0] [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) #define LATEST_PROTOCOL_VERSION_STRING TOSTRING(LATEST_PROTOCOL_VERSION)
// Server's supported network protocol range // Server's supported network protocol range