From 52e8924a1b808c29981734eaa9f8d6f05d08d717 Mon Sep 17 00:00:00 2001 From: copygirl Date: Tue, 10 Oct 2023 17:49:48 +0200 Subject: [PATCH] Show HUD element only if looking at rotatable node --- hud.lua | 19 +++++++++++++++--- rotate.lua | 12 ++++++++--- ..._rotating_hud_rotate_counter_clockwise.png | Bin 4754 -> 4751 bytes 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/hud.lua b/hud.lua index 8acb454..b9a8341 100644 --- a/hud.lua +++ b/hud.lua @@ -4,6 +4,11 @@ local ipairs local minetest, vector = minetest, vector +local rotate = include("rotate") + +local TEX_ROTATE_CLOCKWISE = "nc_extended_rotating_hud_rotate_clockwise.png" +local TEX_ROTATE_COUNTER_CLOCKWISE = "nc_extended_rotating_hud_rotate_counter_clockwise.png" + local player_huds = {} local function do_player_rotating_checks(player) @@ -11,6 +16,7 @@ local function do_player_rotating_checks(player) local hud_index = player_huds[name] if hud_index then + -- FIXME: Only remove / update HUD elements when necessary. player:hud_remove(hud_index) player_huds[name] = nil end @@ -27,13 +33,20 @@ local function do_player_rotating_checks(player) local node = nil local ray = minetest.raycast(eye_pos, eye_pos + look_dir * reach, false, false) - for pointed_thing in ray do node = pointed_thing end + for pointed_thing in ray do + if pointed_thing.type == "node" then + node = minetest.get_node(pointed_thing.under) + break + end + end - if node then + if node and rotate.is_rotatable(node) then + local is_sneaking = player:get_player_control().sneak + local texture = is_sneaking and TEX_ROTATE_COUNTER_CLOCKWISE or TEX_ROTATE_CLOCKWISE hud_index = player:hud_add({ hud_elem_type = "image", name = "rotation hint", - text = "nc_extended_rotating_hud_rotate_clockwise.png", + text = texture, position = { x = 0.5, y = 0.5 }, offset = { x = 0, y = 0 }, alignment = { x = 0, y = 0 }, diff --git a/rotate.lua b/rotate.lua index cb6a164..caf193c 100644 --- a/rotate.lua +++ b/rotate.lua @@ -39,13 +39,19 @@ for up_index, up in ipairs(AXIS_LOOKUP) do end end +-- Returns whether the specified `node` is rotatable by this mod. +-- TODO: Register such that only certain nodes may be rotated. +local function is_rotatable(node) + local def = minetest.registered_nodes[node.name] + return def.paramtype2 == "facedir" +end +rotate.is_rotatable = is_rotatable + -- Rotates `node` at the specified `pos` around `axis` by `degrees` counter-clockwise. local function rotate_node(pos, node, axis, degrees) if degrees % 90 ~= 0 then error("degrees must be divisible by 90") end if axis_vector_to_index(axis) == nil then error("axis must be an axis vector") end - - local def = minetest.registered_nodes[node.name] - if def.paramtype2 ~= "facedir" then error("node's paramtype2 is not 'facedir'") end + if not is_rotatable(node) then error("node is not rotatable") end local up = AXIS_LOOKUP[1 + math.floor(node.param2 / 4)] local back = minetest.facedir_to_dir(node.param2) diff --git a/textures/nc_extended_rotating_hud_rotate_counter_clockwise.png b/textures/nc_extended_rotating_hud_rotate_counter_clockwise.png index 4ec901cc552e001693f4fd53c1094933aaf04683..ac66a8542d317dc0cf6124129c422ad6f1483c51 100644 GIT binary patch delta 951 zcmV;o14#UmC66VL;T$wFIyEu?0RRD@0{{U40003100000008V=l=QLvc>^RhW-&El zIW#vdG%{g1Ei_{^G%aB`Fk>w;IXN&nFf=!0V`gQOngkytG%#gkFgG|cEjeRmG%Yk_ zGB7P-Ic7F3Gh#DhI5jvoVq`cslidU-BQ<4aGdMIbW-T;fI4~_VG-Ww0IAb|tEjTe` zV`eaBWHMqmlP3jW3Nke}Gcq+ZH90bqkp*@IG%`9hGLsAjDFrk#IyEwrItGd)G-P69 zH)bWi>50IAl33G&N&5F*Rg2Vq!OAljsIe1vD}`H8Zn42W|)iA<@2F zldlgje=0T595!hH00NRpL_t(o!|j*9PZUuQ$3F{r3nIb+Ar~P;qKPIp7ZYRR#e`Vl zAE3s<(!zp&!H&d=5=$y`g$12PL%hO7LxYJ0THvn`jbL#>FJ}%9z7{teEbQJsc1g5g znz?;9GvAqcGw;oVBl_3mrBhcQowSAj#U>T6f11YlF-@s8&8Q;{KwfdQqVBd72sdIS z=BcF#;ncpBH$31iRki?8r{dMq0Cev8{=m5RbFWa_Ay#BA%-U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