Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename hud_elem_type to type #14065

Merged
merged 14 commits into from
Dec 29, 2023
1 change: 1 addition & 0 deletions builtin/game/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ core.features = {
compress_zstd = true,
sound_params_start_time = true,
physics_overrides_v2 = true,
hud_def_type_field = true,
}

function core.has_feature(arg)
Expand Down
6 changes: 3 additions & 3 deletions builtin/game/statbars.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local enable_damage = core.settings:get_bool("enable_damage")

local bar_definitions = {
hp = {
hud_elem_type = "statbar",
type = "statbar",
position = {x = 0.5, y = 1},
text = "heart.png",
text2 = "heart_gone.png",
Expand All @@ -14,7 +14,7 @@ local bar_definitions = {
offset = {x = (-10 * 24) - 25, y = -(48 + 24 + 16)},
},
breath = {
hud_elem_type = "statbar",
type = "statbar",
position = {x = 0.5, y = 1},
text = "bubble.png",
text2 = "bubble_gone.png",
Expand Down Expand Up @@ -139,7 +139,7 @@ end

function core.hud_replace_builtin(hud_name, definition)
if type(definition) ~= "table" or
definition.hud_elem_type ~= "statbar" then
(definition.type or definition.hud_elem_type) ~= "statbar" then
return false
end

Expand Down
2 changes: 1 addition & 1 deletion clientmods/preview/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ end)
core.after(1, function()
print("armor: " .. dump(core.localplayer:get_armor_groups()))
id = core.localplayer:hud_add({
hud_elem_type = "text",
type = "text",
name = "example",
number = 0xff0000,
position = {x=0, y=1},
Expand Down
4 changes: 3 additions & 1 deletion doc/client_lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1332,8 +1332,10 @@ It can be created via `Raycast(pos1, pos2, objects, liquids)` or

```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"
hud_elem_type = "image",
-- ^ Deprecated, same as `type`. In case both are specified `type` will be used.
position = {x=0.5, y=0.5},
-- ^ Left corner position of element, default `{x=0,y=0}`.
name = "<name>", -- default ""
Expand Down
11 changes: 9 additions & 2 deletions doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5278,6 +5278,8 @@ Utilities
-- liquid_fluidity, liquid_fluidity_smooth, liquid_sink,
-- acceleration_default, acceleration_air (5.8.0)
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,
}
```

Expand Down Expand Up @@ -7791,7 +7793,7 @@ child will follow movement and rotation of that bone.
* `hud_change(id, stat, value)`: change a value of a previously added HUD
element.
* `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_set_flags(flags)`: sets specified HUD flags of player.
* `flags`: A table with the following fields set to boolean values
Expand Down Expand Up @@ -10051,9 +10053,14 @@ Used by `ObjectRef:hud_add`. Returned by `ObjectRef:hud_get`.

```lua
{
hud_elem_type = "image",
type = "image",
-- Type of element, can be "image", "text", "statbar", "inventory",
-- "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},
-- Top left corner position of element
Expand Down
2 changes: 1 addition & 1 deletion games/devtest/mods/testentities/selectionbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ minetest.register_globalstep(function()
local ent = pointed_thing.ref:get_luaentity()
if ent and ent.name == "testentities:selectionbox" then
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},
text = "X",
number = 0xFF0000,
Expand Down
10 changes: 5 additions & 5 deletions games/devtest/mods/testhud/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local font_states = {


local font_default_def = {
hud_elem_type = "text",
type = "text",
position = {x = 0.5, y = 0.5},
scale = {x = 2, y = 2},
alignment = { x = 0, y = 0 },
Expand Down Expand Up @@ -102,22 +102,22 @@ minetest.register_chatcommand("hudwaypoints", {
return false
end
local regular = player:hud_add {
hud_elem_type = "waypoint",
type = "waypoint",
name = "regular waypoint",
text = "m",
number = 0xFFFFFF,
world_pos = vector.add(player:get_pos(), {x = 0, y = 1.5, z = 0})
}
local reduced_precision = player:hud_add {
hud_elem_type = "waypoint",
type = "waypoint",
name = "imprecise waypoint",
text = "m (0.1 steps, precision = 10)",
precision = 10,
number = 0xFFFFFF,
world_pos = vector.add(player:get_pos(), {x = 0, y = 1, z = 0})
}
local hidden_distance = player:hud_add {
hud_elem_type = "waypoint",
type = "waypoint",
name = "waypoint with hidden distance",
text = "this text is hidden as well (precision = 0)",
precision = 0,
Expand Down Expand Up @@ -149,7 +149,7 @@ minetest.register_chatcommand("hudwaypoints", {
minetest.after(0.5, change, player)
end
local image_waypoint = player:hud_add {
hud_elem_type = "image_waypoint",
type = "image_waypoint",
text = "testhud_waypoint.png",
world_pos = player:get_pos(),
scale = {x = 3, y = 3},
Expand Down
24 changes: 22 additions & 2 deletions src/script/common/c_content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1959,8 +1959,28 @@ void push_objectRef(lua_State *L, const u16 id)

void read_hud_element(lua_State *L, HudElement *elem)
{
elem->type = (HudElementType)getenumfield(L, 2, "hud_elem_type",
es_HudElementType, HUD_ELEM_TEXT);
std::string type_string;
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");
elem->pos = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
Expand Down
Loading