Fix hud_elem_type deprecation warning (MT 5.9.0)

This commit is contained in:
Wuzzy 2024-09-04 20:40:53 +02:00
parent 15c8cbb63e
commit 20fd9f6c22
4 changed files with 49 additions and 9 deletions

View File

@ -1,5 +1,15 @@
sf_hud = {}
-- Legacy support: Name of the HUD type field for 'hud_add'.
local hud_type_field_name
if minetest.features.hud_def_type_field then
-- Minetest 5.9.0 and later
hud_type_field_name = "type"
else
-- All Minetest versions before 5.9.0
hud_type_field_name = "hud_elem_type"
end
-- experimental dirty/shadowy screen when damaged
local USE_DAMAGE_SCREEN = false
local EDITOR = minetest.settings:get_bool("sf_editor", false) or minetest.settings:get_bool("creative_mode", false)
@ -82,7 +92,7 @@ sf_hud.show_damage_indicator = function(player, angle)
local base_texture = angles[min_diff_index].texture
local hud_id = player:hud_add({
hud_elem_type = "compass",
[hud_type_field_name] = "compass",
size = { x = 256, y = 256 },
text = "("..base_texture..")^[multiply:"..DAMAGE_INDICATOR_COLOR..":100",
alignment = { x = 0, y = 0 },
@ -162,7 +172,7 @@ local update_damage_screen = function(player, hp)
for d=1, damage do
if not damage_screens[pname][d] then
local hud_id = player:hud_add({
hud_elem_type = "image",
[hud_type_field_name] = "image",
position = damage_screen_positions[d],
scale = { x = -30, y = -30 },
text = "sf_player_damage_screen.png",
@ -202,7 +212,7 @@ local update_hp_display = function(player, hp)
local hp_max = player:get_properties().hp_max
if not hp_indicators[pname] then
local hud_id = player:hud_add({
hud_elem_type = "statbar",
[hud_type_field_name] = "statbar",
position = { x=0,y=1},
text = "heart.png",
text2 = "heart_gone.png",

View File

@ -1,6 +1,16 @@
local S = minetest.get_translator("sf_loot")
local EDITOR = minetest.settings:get_bool("sf_editor", false) or minetest.settings:get_bool("creative_mode", false)
-- Legacy support: Name of the HUD type field for 'hud_add'.
local hud_type_field_name
if minetest.features.hud_def_type_field then
-- Minetest 5.9.0 and later
hud_type_field_name = "type"
else
-- All Minetest versions before 5.9.0
hud_type_field_name = "hud_elem_type"
end
-- CHEAT: If enabled, shows vases near you
local vase_radar = false
@ -86,7 +96,7 @@ minetest.register_globalstep(function(dtime)
for v=1, #vases do
local vnode = minetest.get_node(vases[v])
local id = players[p]:hud_add({
hud_elem_type = "waypoint",
[hud_type_field_name] = "waypoint",
name = S("Vase (@1)", vnode.param2),
precision = 1,
text = S("m"),

View File

@ -18,6 +18,16 @@ local BUBBLE_OFFSET_X_TOTAL = BUBBLE_OFFSET_X
local SPEAKER_OFFSET_X_TOTAL = BUBBLE_OFFSET_X + SPEAKER_OFFSET_X
local TEXT_OFFSET_X_TOTAL = BUBBLE_OFFSET_X + SPEAKER_OFFSET_X + TEXT_OFFSET_X
-- Legacy support: Name of the HUD type field for 'hud_add'.
local hud_type_field_name
if minetest.features.hud_def_type_field then
-- Minetest 5.9.0 and later
hud_type_field_name = "type"
else
-- All Minetest versions before 5.9.0
hud_type_field_name = "hud_elem_type"
end
-- HACK:
-- Word-wrap a translatable string
-- * player: player to wrap the text for
@ -92,7 +102,7 @@ sf_messages.show_speech = function(to_player, text, icon, sound, duration)
end
local id_bg = to_player:hud_add({
hud_elem_type = "image",
[hud_type_field_name] = "image",
position = { x = 1, y = 0 },
scale = { x = -41, y = 10 },
text = "sf_messages_speech_bubble.png",
@ -103,7 +113,7 @@ sf_messages.show_speech = function(to_player, text, icon, sound, duration)
local id_icon
if icon then
id_icon = to_player:hud_add({
hud_elem_type = "image",
[hud_type_field_name] = "image",
position = { x = 1, y = 0 },
scale = { x = 2, y = 2 },
text = "sf_messages_portrait_bg.png^("..icon..")",
@ -124,7 +134,7 @@ sf_messages.show_speech = function(to_player, text, icon, sound, duration)
text = hacky_word_wrap(to_player, text, chars)
local id_text = to_player:hud_add({
hud_elem_type = "text",
[hud_type_field_name] = "text",
position = { x = 1, y = 0 },
scale = { x = 100, y = 100 },
text = text,

View File

@ -2,6 +2,16 @@ local S = minetest.get_translator("sf_resources")
sf_resources = {}
-- Legacy support: Name of the HUD type field for 'hud_add'.
local hud_type_field_name
if minetest.features.hud_def_type_field then
-- Minetest 5.9.0 and later
hud_type_field_name = "type"
else
-- All Minetest versions before 5.9.0
hud_type_field_name = "hud_elem_type"
end
local GRAVITY = 9.81
local LIFE_TIMER = 300
local MAGNET_RANGE = 0.8
@ -198,7 +208,7 @@ end
local init_hud = function(player)
local pname = player:get_player_name()
local id_icon = player:hud_add({
hud_elem_type = "image",
[hud_type_field_name] = "image",
position = { x = 0, y = 1 },
scale = { x = 4, y = 4 },
text = "blank.png",
@ -207,7 +217,7 @@ local init_hud = function(player)
z_index = 101,
})
local id_num = player:hud_add({
hud_elem_type = "text",
[hud_type_field_name] = "text",
position = { x = 0, y = 1 },
scale = { x = 100, y = 100 },
text = "",