From 98b2626365b8c1c3a1af4ed4af8918ba73f07fd3 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sat, 25 Sep 2021 21:40:05 +0200 Subject: [PATCH] Add label field to button menu --- logic/button_4x.lua | 42 +++++++++++++++++++++++++++++++++++++++--- tools/repairkit.lua | 3 +++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/logic/button_4x.lua b/logic/button_4x.lua index 2b1fe69..770fae1 100644 --- a/logic/button_4x.lua +++ b/logic/button_4x.lua @@ -36,6 +36,13 @@ local function get_button_num(pos, clicker, pointed_thing) end local WRENCH_MENU = { + { + type = "ascii", + name = "label1", + label = S("Label") .. " 1", + tooltip = S("Label for the button"), + default = "1", + }, { type = "number", name = "dest_number1", @@ -50,6 +57,13 @@ local WRENCH_MENU = { tooltip = S("Command to be sent"), default = "1", }, + { + type = "ascii", + name = "label2", + label = S("Label") .. " 2", + tooltip = S("Label for the button"), + default = "1", + }, { type = "number", name = "dest_number2", @@ -64,6 +78,13 @@ local WRENCH_MENU = { tooltip = S("Command to be sent"), default = "2", }, + { + type = "ascii", + name = "label3", + label = S("Label") .. " 3", + tooltip = S("Label for the button"), + default = "1", + }, { type = "number", name = "dest_number3", @@ -78,6 +99,13 @@ local WRENCH_MENU = { tooltip = S("Command to be sent"), default = "3", }, + { + type = "ascii", + name = "label4", + label = S("Label") .. " 4", + tooltip = S("Label for the button"), + default = "1", + }, { type = "number", name = "dest_number4", @@ -114,10 +142,12 @@ local function send_cmnd(pos, num) end local function button_update(pos, objref) + local meta = M(pos) pos = vector.round(pos) local nvm = techage.get_nvm(pos) nvm.button = nvm.button or {} - local text = "< " .. table.concat(nvm.text or {" "}, "\n< ") + local tbl = {meta:get_string("label1"), " ", meta:get_string("label2"), " ", meta:get_string("label3"), " ", meta:get_string("label4")} + local text = "< " .. table.concat(tbl, "\n< ") local texture = lcdlib.make_multiline_texture("default", text, 96, 96, 7, "top", "#000", 6) if nvm.button[1] then @@ -185,8 +215,10 @@ minetest.register_node("techage:ta4_button_4x", { meta:set_string("node_number", number) meta:set_string("owner", placer:get_player_name()) meta:set_string("infotext", "TA4 4x Button " .. number) - local nvm = techage.get_nvm(pos) - nvm.text = {"1", "", "2", "", "3", "", "4"} + meta:set_string("label1", "B1") + meta:set_string("label2", "B2") + meta:set_string("label3", "B3") + meta:set_string("label4", "B4") lcdlib.update_entities(pos) end, @@ -210,6 +242,10 @@ minetest.register_node("techage:ta4_button_4x", { end end, + ta_after_formspec = function(pos, fields, playername) + lcdlib.update_entities(pos) + end, + after_dig_node = function(pos, oldnode, oldmetadata) techage.remove_node(pos, oldnode, oldmetadata) end, diff --git a/tools/repairkit.lua b/tools/repairkit.lua index 8ee5ff3..4b1a593 100644 --- a/tools/repairkit.lua +++ b/tools/repairkit.lua @@ -179,6 +179,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.show_formspec(playername, "techage:ta_formspec", menu.generate_formspec(pos, ndef, form_def, playername)) end) + if ndef.ta_after_formspec then + ndef.ta_after_formspec(pos, fields, playername) + end end end end