Allow using regular (non-formspec) HUD elements
parent
2235213e02
commit
f095267be0
23
README.md
23
README.md
|
@ -52,6 +52,26 @@ The following elements are supported:
|
|||
|
||||
All valid formspec elements not listed above are ignored.
|
||||
|
||||
### Using normal HUD element definitions
|
||||
|
||||
If you want features can't be implemented using formspecs, you can use a list
|
||||
of HUD elements (the tables sent to `hud_add`) instead. Example:
|
||||
|
||||
```lua
|
||||
hud_fs.show_hud(player, "waypoints", {
|
||||
{
|
||||
hud_elem_type = "waypoint",
|
||||
world_pos = {x = 0, y = 0, z = 0},
|
||||
name = "Waypoint 1"
|
||||
},
|
||||
{
|
||||
hud_elem_type = "waypoint",
|
||||
world_pos = {x = 1, y = 2, z = 3},
|
||||
name = "Waypoint 2"
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Advanced API
|
||||
|
||||
- `hud_fs.set_scale(formname, scale)`: Sets the scale of the HUD.
|
||||
|
@ -92,6 +112,9 @@ Then don't use this mod. There are plenty of other HUD library mods around such
|
|||
as [hudlib](https://github.com/octacian/hudlib) and
|
||||
[panel_lib](https://gitlab.com/zughy-friends-minetest/panel_lib).
|
||||
|
||||
Alternatively, the API provided by this mod accepts a list of HUD elements in
|
||||
place of a formspec.
|
||||
|
||||
## Performance
|
||||
|
||||
If this mod becomes a performance bottleneck you can try the following things:
|
||||
|
|
10
init.lua
10
init.lua
|
@ -251,9 +251,11 @@ local function render(tree, proto_ver, scale, z_index)
|
|||
end
|
||||
offset_x = -node.x * size_w
|
||||
offset_y = -node.y * size_h
|
||||
-- return render_error('anchor[] not implemented')
|
||||
elseif nodes[node_type] then
|
||||
add_node(node_type, node)
|
||||
elseif node_type == nil and node.hud_elem_type then
|
||||
-- Pass through plain HUD elements
|
||||
hud_elems[#hud_elems + 1] = node
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -280,9 +282,9 @@ local function compare_elems(old_elem, new_elem)
|
|||
for k, v in pairs(old_elem) do
|
||||
local v2 = new_elem[k]
|
||||
if type(v) == "table" and type(v2) == "table" then
|
||||
-- Tables are guaranteed to be 2-dimensional vectors at the moment,
|
||||
-- don't bother checking anything else to improve performance.
|
||||
if v.x ~= v2.x or v.y ~= v2.y then
|
||||
-- Tables are guaranteed to be vectors at the moment, don't bother
|
||||
-- checking anything else to improve performance.
|
||||
if v.x ~= v2.x or v.y ~= v2.y or v.z ~= v2.z then
|
||||
differences[#differences + 1] = k
|
||||
end
|
||||
elseif v ~= v2 then
|
||||
|
|
Loading…
Reference in New Issue