Rename hud_elem_type to type (#14065)

This commit is contained in:
cx384 2023-12-29 21:51:02 +01:00 committed by GitHub
parent bc336480e6
commit 467d3a8c62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 15 deletions

@ -29,6 +29,7 @@ core.features = {
compress_zstd = true, compress_zstd = true,
sound_params_start_time = true, sound_params_start_time = true,
physics_overrides_v2 = true, physics_overrides_v2 = true,
hud_def_type_field = true,
} }
function core.has_feature(arg) function core.has_feature(arg)

@ -3,7 +3,7 @@ local enable_damage = core.settings:get_bool("enable_damage")
local bar_definitions = { local bar_definitions = {
hp = { hp = {
hud_elem_type = "statbar", type = "statbar",
position = {x = 0.5, y = 1}, position = {x = 0.5, y = 1},
text = "heart.png", text = "heart.png",
text2 = "heart_gone.png", text2 = "heart_gone.png",
@ -14,7 +14,7 @@ local bar_definitions = {
offset = {x = (-10 * 24) - 25, y = -(48 + 24 + 16)}, offset = {x = (-10 * 24) - 25, y = -(48 + 24 + 16)},
}, },
breath = { breath = {
hud_elem_type = "statbar", type = "statbar",
position = {x = 0.5, y = 1}, position = {x = 0.5, y = 1},
text = "bubble.png", text = "bubble.png",
text2 = "bubble_gone.png", text2 = "bubble_gone.png",
@ -139,7 +139,7 @@ end
function core.hud_replace_builtin(hud_name, definition) function core.hud_replace_builtin(hud_name, definition)
if type(definition) ~= "table" or if type(definition) ~= "table" or
definition.hud_elem_type ~= "statbar" then (definition.type or definition.hud_elem_type) ~= "statbar" then
return false return false
end end

@ -33,7 +33,7 @@ end)
core.after(1, function() core.after(1, function()
print("armor: " .. dump(core.localplayer:get_armor_groups())) print("armor: " .. dump(core.localplayer:get_armor_groups()))
id = core.localplayer:hud_add({ id = core.localplayer:hud_add({
hud_elem_type = "text", type = "text",
name = "example", name = "example",
number = 0xff0000, number = 0xff0000,
position = {x=0, y=1}, position = {x=0, y=1},

@ -1332,8 +1332,10 @@ It can be created via `Raycast(pos1, pos2, objects, liquids)` or
```lua ```lua
{ {
hud_elem_type = "image", -- see HUD element types, default "text" type = "image", -- see HUD element types, default "text"
-- ^ type of HUD element, can be either of "image", "text", "statbar", or "inventory" -- ^ type of HUD element, can be either of "image", "text", "statbar", or "inventory"
hud_elem_type = "image",
-- ^ Deprecated, same as `type`. In case both are specified `type` will be used.
position = {x=0.5, y=0.5}, position = {x=0.5, y=0.5},
-- ^ Left corner position of element, default `{x=0,y=0}`. -- ^ Left corner position of element, default `{x=0,y=0}`.
name = "<name>", -- default "" name = "<name>", -- default ""

@ -5278,6 +5278,8 @@ Utilities
-- liquid_fluidity, liquid_fluidity_smooth, liquid_sink, -- liquid_fluidity, liquid_fluidity_smooth, liquid_sink,
-- acceleration_default, acceleration_air (5.8.0) -- acceleration_default, acceleration_air (5.8.0)
physics_overrides_v2 = true, physics_overrides_v2 = true,
-- In HUD definitions the field `type` is used and `hud_elem_type` is deprecated (5.9.0)
hud_def_type_field = true,
} }
``` ```
@ -7790,7 +7792,7 @@ child will follow movement and rotation of that bone.
* `hud_change(id, stat, value)`: change a value of a previously added HUD * `hud_change(id, stat, value)`: change a value of a previously added HUD
element. element.
* `stat` supports the same keys as in the hud definition table except for * `stat` supports the same keys as in the hud definition table except for
`"hud_elem_type"`. `"type"` (or the deprecated `"hud_elem_type"`).
* `hud_get(id)`: gets the HUD element definition structure of the specified ID * `hud_get(id)`: gets the HUD element definition structure of the specified ID
* `hud_set_flags(flags)`: sets specified HUD flags of player. * `hud_set_flags(flags)`: sets specified HUD flags of player.
* `flags`: A table with the following fields set to boolean values * `flags`: A table with the following fields set to boolean values
@ -10050,9 +10052,14 @@ Used by `ObjectRef:hud_add`. Returned by `ObjectRef:hud_get`.
```lua ```lua
{ {
hud_elem_type = "image", type = "image",
-- Type of element, can be "image", "text", "statbar", "inventory", -- Type of element, can be "image", "text", "statbar", "inventory",
-- "waypoint", "image_waypoint", "compass" or "minimap" -- "waypoint", "image_waypoint", "compass" or "minimap"
-- If undefined "text" will be used.
hud_elem_type = "image",
-- Deprecated, same as `type`.
-- In case both are specified `type` will be used.
position = {x=0.5, y=0.5}, position = {x=0.5, y=0.5},
-- Top left corner position of element -- Top left corner position of element

@ -66,7 +66,7 @@ minetest.register_globalstep(function()
local ent = pointed_thing.ref:get_luaentity() local ent = pointed_thing.ref:get_luaentity()
if ent and ent.name == "testentities:selectionbox" then if ent and ent.name == "testentities:selectionbox" then
hud_ids[pname] = hud_id or player:hud_add({ hud_ids[pname] = hud_id or player:hud_add({
hud_elem_type = "text", -- See HUD element types type = "text", -- See HUD element types
position = {x=0.5, y=0.5}, position = {x=0.5, y=0.5},
text = "X", text = "X",
number = 0xFF0000, number = 0xFF0000,

@ -12,7 +12,7 @@ local font_states = {
local font_default_def = { local font_default_def = {
hud_elem_type = "text", type = "text",
position = {x = 0.5, y = 0.5}, position = {x = 0.5, y = 0.5},
scale = {x = 2, y = 2}, scale = {x = 2, y = 2},
alignment = { x = 0, y = 0 }, alignment = { x = 0, y = 0 },
@ -102,14 +102,14 @@ minetest.register_chatcommand("hudwaypoints", {
return false return false
end end
local regular = player:hud_add { local regular = player:hud_add {
hud_elem_type = "waypoint", type = "waypoint",
name = "regular waypoint", name = "regular waypoint",
text = "m", text = "m",
number = 0xFFFFFF, number = 0xFFFFFF,
world_pos = vector.add(player:get_pos(), {x = 0, y = 1.5, z = 0}) world_pos = vector.add(player:get_pos(), {x = 0, y = 1.5, z = 0})
} }
local reduced_precision = player:hud_add { local reduced_precision = player:hud_add {
hud_elem_type = "waypoint", type = "waypoint",
name = "imprecise waypoint", name = "imprecise waypoint",
text = "m (0.1 steps, precision = 10)", text = "m (0.1 steps, precision = 10)",
precision = 10, precision = 10,
@ -117,7 +117,7 @@ minetest.register_chatcommand("hudwaypoints", {
world_pos = vector.add(player:get_pos(), {x = 0, y = 1, z = 0}) world_pos = vector.add(player:get_pos(), {x = 0, y = 1, z = 0})
} }
local hidden_distance = player:hud_add { local hidden_distance = player:hud_add {
hud_elem_type = "waypoint", type = "waypoint",
name = "waypoint with hidden distance", name = "waypoint with hidden distance",
text = "this text is hidden as well (precision = 0)", text = "this text is hidden as well (precision = 0)",
precision = 0, precision = 0,
@ -149,7 +149,7 @@ minetest.register_chatcommand("hudwaypoints", {
minetest.after(0.5, change, player) minetest.after(0.5, change, player)
end end
local image_waypoint = player:hud_add { local image_waypoint = player:hud_add {
hud_elem_type = "image_waypoint", type = "image_waypoint",
text = "testhud_waypoint.png", text = "testhud_waypoint.png",
world_pos = player:get_pos(), world_pos = player:get_pos(),
scale = {x = 3, y = 3}, scale = {x = 3, y = 3},

@ -1959,8 +1959,28 @@ void push_objectRef(lua_State *L, const u16 id)
void read_hud_element(lua_State *L, HudElement *elem) void read_hud_element(lua_State *L, HudElement *elem)
{ {
elem->type = (HudElementType)getenumfield(L, 2, "hud_elem_type", std::string type_string;
es_HudElementType, HUD_ELEM_TEXT); bool has_type = getstringfield(L, 2, "type", type_string);
// Handle deprecated hud_elem_type
std::string deprecated_type_string;
if (getstringfield(L, 2, "hud_elem_type", deprecated_type_string)) {
if (has_type && deprecated_type_string != type_string) {
log_deprecated(L, "Ambiguous HUD element fields \"type\" and \"hud_elem_type\", "
"\"type\" will be used.", 1, true);
} else {
has_type = true;
type_string = deprecated_type_string;
log_deprecated(L, "Deprecated \"hud_elem_type\" field, use \"type\" instead.",
1, true);
}
}
int type_enum;
if (has_type && string_to_enum(es_HudElementType, type_enum, type_string))
elem->type = static_cast<HudElementType>(type_enum);
else
elem->type = HUD_ELEM_TEXT;
lua_getfield(L, 2, "position"); lua_getfield(L, 2, "position");
elem->pos = lua_istable(L, -1) ? read_v2f(L, -1) : v2f(); elem->pos = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();