parent
87210d75c3
commit
4d4e9f3031
|
@ -25,6 +25,8 @@ To toggle its display, use the `//hud` command - it takes no arguments.
|
|||
- Ignore `wielded_light:*` nodes when raycasting
|
||||
- v0.4: 31st May 2021
|
||||
- Fix deprecation warning for `getpos` → `get_pos` (#2)
|
||||
- v0.5: 31st July 2021
|
||||
- Add `//hudoffset [<offset_in_pixels>]` chat command to adjust the vertical offset of the HUD (fixes #1)
|
||||
|
||||
|
||||
## More Screenshots
|
||||
|
|
13
commands.lua
13
commands.lua
|
@ -19,3 +19,16 @@ minetest.register_chatcommand("/hud", {
|
|||
worldedit_hud_helper.player_notify(player_name, message)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("/hudoffset", {
|
||||
params = "[<offset_in_pixels>]",
|
||||
description = "Sets the vertical offset of the HUD in pixels. Default: 0, If not specified, then the value is return to it's default value.",
|
||||
func = function(player_name, params_text)
|
||||
local new_offset = tonumber(params_text) or 0
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
|
||||
worldedit_hud_helper.update_hud_offset(player, new_offset)
|
||||
|
||||
worldedit_hud_helper.player_notify(player_name, "HUD offset set to "..new_offset.." pixels (default: 0).")
|
||||
end
|
||||
})
|
||||
|
|
45
hud.lua
45
hud.lua
|
@ -1,4 +1,12 @@
|
|||
local default_node_name_offset_y = -100
|
||||
local default_rotation_offset_y = -135
|
||||
|
||||
--- Initialises the HUD for a given player.
|
||||
-- May be called multiple times.
|
||||
-- If called more than once, this has the effect of cycling the HUD registration
|
||||
-- with Minetest for the given player.
|
||||
-- @param player Player The player object (as returned by minetest.get_player_by_name(player_name: string)).
|
||||
-- @returns nil
|
||||
function worldedit_hud_helper.initialise_hud(player)
|
||||
local player_name = player:get_player_name()
|
||||
local player_info = worldedit_hud_helper.info[player_name]
|
||||
|
@ -7,7 +15,9 @@ function worldedit_hud_helper.initialise_hud(player)
|
|||
player_info = {
|
||||
enabled = true,
|
||||
node_name = nil,
|
||||
rotation = nil
|
||||
rotation = nil,
|
||||
node_name_offset_y = default_node_name_offset_y,
|
||||
rotation_offset_y = default_rotation_offset_y
|
||||
}
|
||||
worldedit_hud_helper.info[player_name] = player_info
|
||||
end
|
||||
|
@ -17,7 +27,7 @@ function worldedit_hud_helper.initialise_hud(player)
|
|||
text = "",
|
||||
number = 0xFFFFFF,
|
||||
position = { x = 0.5, y = 1 },
|
||||
offset = { x = 0, y = -100 },
|
||||
offset = { x = 0, y = player_info.node_name_offset_y },
|
||||
|
||||
alignment = { x = 0, y = 0 }, -- Align to the centre
|
||||
scale = { x = 150, y = 30 }
|
||||
|
@ -28,7 +38,7 @@ function worldedit_hud_helper.initialise_hud(player)
|
|||
text = "",
|
||||
number = 0xFFFFFF,
|
||||
position = { x = 0.5, y = 1 },
|
||||
offset = { x = 0, y = -135 },
|
||||
offset = { x = 0, y = player_info.rotation_offset_y },
|
||||
|
||||
alignment = { x = 0, y = 0 }, -- Align to the centre
|
||||
scale = { x = 150, y = 30 }
|
||||
|
@ -36,6 +46,9 @@ function worldedit_hud_helper.initialise_hud(player)
|
|||
|
||||
end
|
||||
|
||||
--- Hides the HUD for a player without deleting their registration & settings.
|
||||
-- @param player Player The player object (as returned by minetest.get_player_by_name(player_name: string)).
|
||||
-- @returns nil
|
||||
function worldedit_hud_helper.hide_hud(player)
|
||||
local player_info = worldedit_hud_helper.info[player:get_player_name()]
|
||||
|
||||
|
@ -47,10 +60,36 @@ function worldedit_hud_helper.hide_hud(player)
|
|||
player_info.rotation = nil
|
||||
end
|
||||
|
||||
--- Deletes the HUD for a player.
|
||||
-- @param player Player The player object (as returned by minetest.get_player_by_name(player_name: string)).
|
||||
function worldedit_hud_helper.delete_hud(player)
|
||||
worldedit_hud_helper.info[player:get_player_name()] = nil
|
||||
end
|
||||
|
||||
--- Updates the HUD offset in pixels.
|
||||
-- Larger numbers move the HUD further upwards on the screen.
|
||||
-- Default: 0.
|
||||
-- @param player Player The player object (as returned by minetest.get_player_by_name(player_name: string)).
|
||||
-- @param new_offset number The new offset, as an integer.
|
||||
-- @returns bool Whether the update was successful or not. A HUD must be initialised for that player for it up have its offset updated.
|
||||
function worldedit_hud_helper.update_hud_offset(player, new_offset)
|
||||
if not new_offset then new_offset = 0 end
|
||||
|
||||
local player_info = worldedit_hud_helper.info[player:get_player_name()]
|
||||
|
||||
if not player_info then return false end
|
||||
|
||||
-- Update the new offset
|
||||
player_info.node_name_offset_y = default_node_name_offset_y + -new_offset
|
||||
player_info.rotation_offset_y = default_rotation_offset_y + -new_offset
|
||||
|
||||
-- Restart the HUD
|
||||
worldedit_hud_helper.hide_hud(player)
|
||||
worldedit_hud_helper.initialise_hud(player)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
minetest.register_on_joinplayer(worldedit_hud_helper.initialise_hud)
|
||||
minetest.register_on_leaveplayer(worldedit_hud_helper.delete_hud)
|
||||
|
|
Loading…
Reference in New Issue