New hud_elem_type field

This commit is contained in:
Wuzzy 2024-10-24 18:54:35 +02:00
parent 4739958926
commit c80648b8cd
7 changed files with 60 additions and 11 deletions

View File

@ -38,6 +38,13 @@ local ICON_FRAME_SIZE = 2.2
local S = minetest.get_translator("rp_achievements")
local NS = function(s) return s end
local hud_def_type_field
if minetest.features.hud_def_type_field then
hud_def_type_field = "type"
else
hud_def_type_field = "hud_elem_type"
end
achievements = {}
achievements.ACHIEVEMENT_GOTTEN = 1
achievements.ACHIEVEMENT_IN_PROGRESS = 2
@ -209,7 +216,7 @@ local achievement_popup = function(player_name, icon_type, icon, caption, messag
-- Background
local hud_bg = player:hud_add({
hud_elem_type = "image",
[hud_def_type_field] = "image",
text = "rp_achievements_hud_bg.png",
position = { x = 0.5, y = 0 },
alignment = { x = 0, y = 1 },
@ -237,7 +244,7 @@ local achievement_popup = function(player_name, icon_type, icon, caption, messag
end
local hud_icon = player:hud_add({
hud_elem_type = "image",
[hud_def_type_field] = "image",
text = "("..icon_texture..")^[resize:"..HUD_ICON_SIZE.."x"..HUD_ICON_SIZE,
position = { x = 0.5, y = 0 },
alignment = { x = 1, y = 1 },
@ -248,7 +255,7 @@ local achievement_popup = function(player_name, icon_type, icon, caption, messag
-- Caption text
local hud_caption = player:hud_add({
hud_elem_type = "text",
[hud_def_type_field] = "text",
number = caption_color or 0xFFFFFF,
text = caption,
position = { x = 0.5, y = 0 },
@ -262,7 +269,7 @@ local achievement_popup = function(player_name, icon_type, icon, caption, messag
-- Message text
local hud_message = player:hud_add({
hud_elem_type = "text",
[hud_def_type_field] = "text",
number = message_color or 0xFFFFFF,
text = message,
position = { x = 0.5, y = 0 },

View File

@ -8,6 +8,13 @@ local NS = function(s) return s end
local mod_player_skins = minetest.get_modpath("rp_player_skins") ~= nil
local hud_def_type_field
if minetest.features.hud_def_type_field then
hud_def_type_field = "type"
else
hud_def_type_field = "hud_elem_type"
end
-- Gain for equip/unequip sounds
local SOUND_GAIN = 0.4
@ -392,7 +399,7 @@ local armor_icon_definitions = {}
for a=1, #armor.slots do
armor_icon_definitions[a] = {
hud_elem_type = "image",
[hud_def_type_field] = "image",
position = { x=0.5, y=1 },
text = "blank.png",
direction = 0,

View File

@ -4,6 +4,13 @@ rp_hud = {}
rp_hud.registered_statbars = {}
local hud_def_type_field
if minetest.features.hud_def_type_field then
hud_def_type_field = "type"
else
hud_def_type_field = "hud_elem_type"
end
-- time in seconds the breath bar will still show after going full again
local BREATH_KEEP_TIME = 2.05
@ -304,7 +311,7 @@ end
-- * z_index: Statbar Z-index (see lua_api.md)
rp_hud.register_statbar = function(name, def)
local statbar_definition = {
hud_elem_type = "statbar",
[hud_def_type_fields] = "statbar",
position = { x=0.5, y=1 },
text = def.image,
text2 = def.image_gone,

View File

@ -40,6 +40,13 @@ local EATING_SPEED_DURATION = 2.0
local mod_achievements = minetest.get_modpath("rp_achievements") ~= nil
local mod_death_messages = minetest.get_modpath("rp_death_messages") ~= nil
local hud_def_type_field
if minetest.features.hud_def_type_field then
hud_def_type_field = "type"
else
hud_def_type_field = "hud_elem_type"
end
-- Per-player userdata
local userdata = {}
@ -180,7 +187,7 @@ local function update_bar(player)
else
player_debughud[name] = player:hud_add(
{
hud_elem_type = "text",
[hud_def_type_field] = "text",
position = {x=0.75,y=1.0},
text = text,
number = 0xFFFFFFFF,
@ -201,7 +208,7 @@ local function update_bar(player)
else
player_bar[name] = player:hud_add(
{
hud_elem_type = "statbar",
[hud_def_type_field] = "statbar",
position = {x=0.5,y=1.0},
text = "hunger.png",
text2 = "hunger_gone.png",

View File

@ -5,6 +5,13 @@
local S = minetest.get_translator("rp_player_effects")
local DISPLAY_ICONS = false
local hud_def_type_field
if minetest.features.hud_def_type_field then
hud_def_type_field = "type"
else
hud_def_type_field = "hud_elem_type"
end
player_effects = {}
player_effects.effects = {}
@ -51,7 +58,7 @@ local function display_effect_icons(player)
local effect = player_effects.get_registered_effect(en)
if effect.icon then
local id = player:hud_add({
hud_elem_type = "image",
[hud_def_type_field] = "image",
position = { x = 1, y = 0 },
offset = { x = -52 - i*52, y = 270 },
text = effect.icon,

View File

@ -12,6 +12,13 @@ local settings = {
}
local spyglass_users = {}
local hud_def_type_field
if minetest.features.hud_def_type_field then
hud_def_type_field = "type"
else
hud_def_type_field = "hud_elem_type"
end
rp_spyglass = {}
-- check if player is using spyglass
@ -57,7 +64,7 @@ local function use_spyglass(player)
local data = {
hud = settings.use_hud and player:hud_add({
name = "tph_spyglass",
hud_elem_type = "image",
[hud_def_type_field] = "image",
text = "tph_spyglass_hud.png", -- image is 52x32, any texture pack or edit to the image should have a resolution that properly factors to said resolution or width = height*1.625
position = {x = 0.5, y = 0.5},
scale = { x = -100, y = -100},

View File

@ -4,9 +4,16 @@
local enable_vignette = minetest.settings:get_bool("vignette_enable")
local hud_def_type_field
if minetest.features.hud_def_type_field then
hud_def_type_field = "type"
else
hud_def_type_field = "hud_elem_type"
end
if enable_vignette then
local vignette_definition = {
hud_elem_type = "image",
[hud_def_type_field] = "image",
position = {x = 0.5, y = 0.5},
scale = {x = -100, y = -100},
alignment = 0,