Add //hud commad to toggle
parent
8c9ab0e394
commit
dc5c9f5b71
|
@ -0,0 +1,21 @@
|
|||
|
||||
minetest.register_chatcommand("/hud", {
|
||||
params = "",
|
||||
description = "Toggles the helper heads-up display.",
|
||||
func = function(player_name, params_text)
|
||||
worldedit_hud_helper.info[player_name].enabled = not worldedit_hud_helper.info[player_name].enabled
|
||||
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
local message = "HUD "
|
||||
|
||||
if worldedit_hud_helper.info[player_name].enabled then
|
||||
worldedit_hud_helper.initialise_hud(player)
|
||||
message = message .. "shown"
|
||||
else
|
||||
worldedit_hud_helper.hide_hud(player)
|
||||
message = message .. "hidden"
|
||||
end
|
||||
|
||||
worldedit_hud_helper.player_notify(player_name, message)
|
||||
end
|
||||
})
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
function worldedit_hud_helper.player_notify(player_name, message)
|
||||
minetest.chat_send_player(player_name, "WorldEdit -!- " .. message, false)
|
||||
end
|
17
hud.lua
17
hud.lua
|
@ -5,14 +5,16 @@ function worldedit_hud_helper.initialise_hud(player)
|
|||
|
||||
if not player_info then
|
||||
player_info = {
|
||||
enabled = true
|
||||
enabled = true,
|
||||
node_name = nil,
|
||||
rotation = nil
|
||||
}
|
||||
worldedit_hud_helper.info[player_name] = player_info
|
||||
end
|
||||
|
||||
player_info.id_node_name = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
text = "(unknown)",
|
||||
text = "",
|
||||
number = 0xFFFFFF,
|
||||
position = { x = 0.5, y = 1 },
|
||||
offset = { x = 0, y = -100 },
|
||||
|
@ -34,6 +36,17 @@ function worldedit_hud_helper.initialise_hud(player)
|
|||
|
||||
end
|
||||
|
||||
function worldedit_hud_helper.hide_hud(player)
|
||||
local player_info = worldedit_hud_helper.info[player:get_player_name()]
|
||||
|
||||
|
||||
player:hud_remove(player_info.id_node_name)
|
||||
player:hud_remove(player_info.id_rotation)
|
||||
|
||||
player_info.node_name = nil
|
||||
player_info.rotation = nil
|
||||
end
|
||||
|
||||
function worldedit_hud_helper.delete_hud(player)
|
||||
worldedit_hud_helper.info[player:get_player_name()] = nil
|
||||
end
|
||||
|
|
32
hud_info.lua
32
hud_info.lua
|
@ -5,17 +5,11 @@
|
|||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ██ ████ ██████ ██████ ███████ ██ ████ ██ ██ ██ ██ ███████
|
||||
|
||||
local function handle_node_name(dt)
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
handle_node_name_player(player)
|
||||
end
|
||||
end
|
||||
|
||||
local function handle_node_name_player(player)
|
||||
local player_name = player:get_player_name()
|
||||
|
||||
-- Don't bother if it's disabled for this player
|
||||
if not worldedit_hud_helper[player_name].enabled then
|
||||
if not worldedit_hud_helper.info[player_name].enabled then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -32,6 +26,12 @@ local function handle_node_name_player(player)
|
|||
worldedit_hud_helper.info[player_name].node_name = node_name
|
||||
end
|
||||
|
||||
local function handle_node_name(dt)
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
handle_node_name_player(player)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_globalstep(handle_node_name)
|
||||
|
||||
|
||||
|
@ -53,12 +53,6 @@ local function calc_rotation_text(rotation)
|
|||
end
|
||||
end
|
||||
|
||||
local function handle_rotation(dt)
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
handle_rotation_player(player)
|
||||
end
|
||||
end
|
||||
|
||||
local function handle_rotation_player(player)
|
||||
local player_name = player:get_player_name()
|
||||
|
||||
|
@ -68,14 +62,14 @@ local function handle_rotation_player(player)
|
|||
end
|
||||
|
||||
local rotation = player:get_look_horizontal()
|
||||
local old_rotation = worldedit_hud_helper.info[player_name].look_direction
|
||||
local old_rotation = worldedit_hud_helper.info[player_name].rotation
|
||||
|
||||
-- Bad practice! Lua doesn't have a contineu statement though (O.o),
|
||||
-- so we've got to make do :-/
|
||||
if rotation ~= old_rotation then
|
||||
local rotation_text = calc_rotation_text(rotation)
|
||||
|
||||
if old_rotation ~= nil and rotation_text ~= calc_rotation_text(old_rotation) then
|
||||
if old_rotation == nil or (old_rotation ~= nil and rotation_text ~= calc_rotation_text(old_rotation)) then
|
||||
player:hud_change(
|
||||
worldedit_hud_helper.info[player_name].id_rotation,
|
||||
"text",
|
||||
|
@ -84,7 +78,13 @@ local function handle_rotation_player(player)
|
|||
end
|
||||
end
|
||||
|
||||
worldedit_hud_helper.info[player:get_player_name()].look_direction = rotation
|
||||
worldedit_hud_helper.info[player:get_player_name()].rotation = rotation
|
||||
end
|
||||
|
||||
local function handle_rotation(dt)
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
handle_rotation_player(player)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_globalstep(handle_rotation)
|
||||
|
|
Loading…
Reference in New Issue