Use HUD instead of chat messages

master
entuland 2018-06-20 11:10:35 +02:00
parent cbf1c137b6
commit 7f3ed66682
2 changed files with 63 additions and 17 deletions

View File

@ -74,8 +74,14 @@ Rhotator Testing Cube: a Rhotator Screwdriver and any wool block
# Usage feedback
At the beginning of [init.lua](/init.lua) there is a line reading `local enable_chat_notifications = false` - set it to `true` if you want the tool to send you chat messages about the operations it performs and in particular about nodes that aren't currently supported (if you enable the chat notifications you'll receive messages like these:
An HUD message will show usage feedback, in particular it will inform you about nodes that aren't currently supported.
Here are possible messages you can receive:
- Rotated pointed face clockwise (right click)
- Rotated pointed face counter-clockwise (sneak + right click)
- Pushed closest edge (left click)
- Rotated pointed face (right click)
- Pulled closest edge (sneak + left click)
- Cannot rotate node with paramtype2 == glasslikeliquidlevel
- Unsupported node type: modname:nodename

View File

@ -4,8 +4,6 @@ rhotator.mod_path = minetest.get_modpath(minetest.get_current_modname())
local matrix = dofile(rhotator.mod_path .. "/lib/matrix.lua")
local enable_chat_notifications = false
-- constants
local POS = {}
@ -20,11 +18,14 @@ NEG.Y = 5
PRIMARY_BTN = 1
SECONDARY_BTN = 2
-- helper tables
-- helper variables
local rot_matrices = {}
local dir_matrices = {}
local huds = {}
local hud_timeout_seconds = 3
-- init
local function init_transforms()
@ -172,12 +173,6 @@ local function matrix_to_facedir(mtx)
return rhotator._matrix_to_facedir[key]
end
local function notify(playername, message)
if enable_chat_notifications then
minetest.chat_send_player(playername, "[rhotator] " .. message)
end
end
local function vector_to_dir_index(vec)
local main_axis = extract_main_axis(vec)
if main_axis == "x" then return (vec.x > 0) and POS.X or NEG.X end
@ -185,6 +180,51 @@ local function vector_to_dir_index(vec)
return (vec.y > 0) and POS.Y or NEG.Y
end
-- hud functions
local function hud_remove(player)
local playername = player:get_player_name()
local hud = huds[playername]
if not hud then return end
if os.time() < hud_duration_time + hud.time then
return
end
player:hud_remove(hud.id)
huds[playername] = nil
end
local function hud_create(player, message)
local playername = player:get_player_name()
local id = player:hud_add({
text = message,
hud_elem_type = "text",
name = "rhotator_feedback",
direction = 0,
position = { x = 0.1, y = 0.9},
alignment = { x = 1, y = -1},
number = 0xFFFFFF,
})
huds[playername] = {
id = id,
time = os.time(),
}
end
local function notify(player, message)
message = "[rhotator] " .. message
local playername = player:get_player_name()
local hud = huds[playername]
if not hud then
hud_create(player, message)
else
player:hud_change(hud.id, "text", message)
hud.time = os.time()
end
minetest.after(hud_timeout_seconds, function()
hud_remove(player)
end)
end
-- rhotator main
local function interact(itemstack, player, pointed_thing, click)
@ -196,12 +236,12 @@ local function interact(itemstack, player, pointed_thing, click)
local def = minetest.registered_nodes[node.name]
if not node or not def then
notify(player:get_player_name(), "Unsupported node type: " .. node.name)
notify(player, "Unsupported node type: " .. node.name)
return
end
if def.paramtype2 ~= "facedir" then
notify(player:get_player_name(), "Cannot rotate node with paramtype2 == " .. def.paramtype2)
notify(player, "Cannot rotate node with paramtype2 == " .. def.paramtype2)
return
end
@ -216,17 +256,17 @@ local function interact(itemstack, player, pointed_thing, click)
transform = dir_matrices[vector_to_dir_index(unit.thumb)]
if controls.sneak then
rotation = rot_matrices[3]
notify(player:get_player_name(), "Pulled closest edge (sneak + left click)")
notify(player, "Pulled closest edge (sneak + left click)")
else
notify(player:get_player_name(), "Pushed closest edge (left click)")
notify(player, "Pushed closest edge (left click)")
end
else
transform = dir_matrices[vector_to_dir_index(unit.back)]
if controls.sneak then
rotation = rot_matrices[3]
notify(player:get_player_name(), "Rotated pointed face counter-clockwise (sneak + right click)")
notify(player, "Rotated pointed face counter-clockwise (sneak + right click)")
else
notify(player:get_player_name(), "Rotated pointed face clockwise (right click)")
notify(player, "Rotated pointed face clockwise (right click)")
end
end