Add label field to button menu

master
Joachim Stolberg 2021-09-25 21:40:05 +02:00
parent 48f0235f3b
commit 98b2626365
2 changed files with 42 additions and 3 deletions

View File

@ -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,

View File

@ -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