Resize hearts on smaller screens

This commit is contained in:
Wuzzy 2024-01-09 21:58:33 +01:00
parent 6c46e90281
commit ec13cd6893

View File

@ -11,6 +11,9 @@ local DAMAGE_INDICATOR_COLOR = "#ff0000"
local DAMAGE_INDICATOR_ANGLE_STEP = 15
local DAMAGE_INDICATOR_SHOW_TIME = 2.0
local BIG_HP_STATBAR_WINDOW_WIDTH = 1200
local SMALL_HP_STATBAR_WINDOW_WIDTH = 750
local angles = {}
for a=0, 360, DAMAGE_INDICATOR_ANGLE_STEP do
local angle = a % 360
@ -183,6 +186,19 @@ local update_hp_display = function(player, hp)
return
end
local pname = player:get_player_name()
local window_info = minetest.get_player_window_information(pname)
local heart_size = { x = 64, y = 64 }
local heart_offset = { x = 24, y = -74 }
if window_info and window_info.size then
if window_info.size.x < SMALL_HP_STATBAR_WINDOW_WIDTH * window_info.real_hud_scaling then
heart_size = { x = 16, y = 16 }
heart_offset = { x = 12, y = -30 }
elseif window_info.size.x < BIG_HP_STATBAR_WINDOW_WIDTH * window_info.real_hud_scaling then
heart_size = { x = 32, y = 32 }
heart_offset = { x = 12, y = -50 }
end
end
local hp_max = player:get_properties().hp_max
if not hp_indicators[pname] then
local hud_id = player:hud_add({
@ -192,8 +208,8 @@ local update_hp_display = function(player, hp)
text2 = "heart_gone.png",
item = hp_max,
alignment = { x = 1, y = -1 },
offset = { x = 24, y = -74 },
size = { x = 64, y = 64 },
offset = heart_offset,
size = heart_size,
z_index = 0,
number = hp,
})
@ -201,6 +217,8 @@ local update_hp_display = function(player, hp)
else
player:hud_change(hp_indicators[pname], "number", hp)
player:hud_change(hp_indicators[pname], "item", hp_max)
player:hud_change(hp_indicators[pname], "offset", heart_offset)
player:hud_change(hp_indicators[pname], "size", heart_size)
end
end
@ -232,8 +250,19 @@ minetest.register_on_punchplayer(function(player, hitter, tflp, tc, dir, damage)
sf_hud.show_damage_indicator(player, yaw)
end)
local hp_update_timer = 0
minetest.register_globalstep(function(dtime)
hp_update_timer = hp_update_timer + dtime
if hp_update_timer < 3 then
return
end
hp_update_timer = 0
local players = minetest.get_connected_players()
for p=1, #players do
local player = players[p]
update_hp_display(player, player:get_hp())
end
end)
minetest.register_on_joinplayer(function(player)
player:hud_set_flags({