Add ta4 fourfold button

This commit is contained in:
Joachim Stolberg 2021-09-24 22:19:36 +02:00
parent 9218c3097b
commit 032f59c11a
22 changed files with 317 additions and 17 deletions

View File

@ -191,6 +191,7 @@ techage.Items = {
ta4_electricmeter = "techage:ta4_electricmeter", ta4_electricmeter = "techage:ta4_electricmeter",
ta4_transformer = "techage:ta4_transformer", ta4_transformer = "techage:ta4_transformer",
power_reduction = "techage_power_reduction.png", power_reduction = "techage_power_reduction.png",
ta4_button_4x = "techage:ta4_button_4x",
--ta4_ "", --ta4_ "",
} }

View File

@ -183,6 +183,7 @@ techage.manual_DE.aTitel = {
"3,TA4 Lua Controller Terminal", "3,TA4 Lua Controller Terminal",
"2,TA4 Logik-/Schalt-Module", "2,TA4 Logik-/Schalt-Module",
"3,TA4 Taster/Schalter / Button/Switch", "3,TA4 Taster/Schalter / Button/Switch",
"3,TA4 4x Taster / 4x Button",
"3,TA4 Spieler Detektor / Player Detector", "3,TA4 Spieler Detektor / Player Detector",
"3,TA4 Zustandssammler / State Collector", "3,TA4 Zustandssammler / State Collector",
"3,TA4 Detektor / Detector", "3,TA4 Detektor / Detector",
@ -1559,6 +1560,10 @@ techage.manual_DE.aText = {
"\n".. "\n"..
"\n".. "\n"..
"\n", "\n",
"Dieser Block hat vier Taster\\, die über das Schraubenschlüssel-Menü individuell konfiguriert werden können. Für jeden Taster kann die Beschriftung und die Zielblockadresse konfiguriert werden. Zusätzlich kann für jeden Taster das Kommando konfiguriert werden\\, welches gesendet werden soll.\n"..
"\n"..
"\n"..
"\n",
"Beim TA4 Spieler Detektor hat sich nur das Aussehen geändert. Die Funktionalität ist gleich wie beim TA3 Spieler Detektor.\n".. "Beim TA4 Spieler Detektor hat sich nur das Aussehen geändert. Die Funktionalität ist gleich wie beim TA3 Spieler Detektor.\n"..
"\n".. "\n"..
"\n".. "\n"..
@ -1933,6 +1938,7 @@ techage.manual_DE.aItemName = {
"ta4_terminal", "ta4_terminal",
"", "",
"ta4_button", "ta4_button",
"ta4_button_4x",
"ta4_playerdetector", "ta4_playerdetector",
"ta4_collector", "ta4_collector",
"ta4_detector", "ta4_detector",
@ -2155,6 +2161,7 @@ techage.manual_DE.aPlanTable = {
"", "",
"", "",
"", "",
"",
"ta4_liquid_filter_base", "ta4_liquid_filter_base",
"ta4_liquid_filter_gravel", "ta4_liquid_filter_gravel",
"ta4_liquid_filter_top", "ta4_liquid_filter_top",

View File

@ -183,6 +183,7 @@ techage.manual_EN.aTitel = {
"3,TA4 Lua Controller Terminal", "3,TA4 Lua Controller Terminal",
"2,TA4 Logic/Switching Modules", "2,TA4 Logic/Switching Modules",
"3,TA4 Button/Switch", "3,TA4 Button/Switch",
"3,TA4 4x Button",
"3,TA4 Player Detector", "3,TA4 Player Detector",
"3,TA4 State Collector", "3,TA4 State Collector",
"3,TA4 Detector", "3,TA4 Detector",
@ -1557,6 +1558,10 @@ techage.manual_EN.aText = {
"\n".. "\n"..
"\n".. "\n"..
"\n", "\n",
"This block has four buttons that can be individually configured using the wrench menu. The labeling and the target block address can be configured for each button. In addition\\, the command that is to be sent can be configured for each button. \n"..
"\n"..
"\n"..
"\n",
"Only the appearance of the TA4 player detector has changed. The functionality is the same as with the TA3 player detector.\n".. "Only the appearance of the TA4 player detector has changed. The functionality is the same as with the TA3 player detector.\n"..
"\n".. "\n"..
"\n".. "\n"..
@ -1932,6 +1937,7 @@ techage.manual_EN.aItemName = {
"ta4_terminal", "ta4_terminal",
"", "",
"ta4_button", "ta4_button",
"ta4_button_4x",
"ta4_playerdetector", "ta4_playerdetector",
"ta4_collector", "ta4_collector",
"ta4_detector", "ta4_detector",
@ -2154,6 +2160,7 @@ techage.manual_EN.aPlanTable = {
"", "",
"", "",
"", "",
"",
"ta4_liquid_filter_base", "ta4_liquid_filter_base",
"ta4_liquid_filter_gravel", "ta4_liquid_filter_gravel",
"ta4_liquid_filter_top", "ta4_liquid_filter_top",

View File

@ -43,7 +43,7 @@ function techage.display.display_update(pos, objref)
"default", text, "default", text,
70, 70, NUM_ROWS, "top", "#000") 70, 70, NUM_ROWS, "top", "#000")
objref:set_properties({ textures = {texture}, objref:set_properties({ textures = {texture},
visual_size = {x=0.94, y=0.94} }) visual_size = {x=0.94, y=0.94} })
end end
function techage.display.display_updateXL(pos, objref) function techage.display.display_updateXL(pos, objref)
@ -54,7 +54,7 @@ function techage.display.display_updateXL(pos, objref)
"default", text, "default", text,
126, 70, NUM_ROWS, "top", "#000") 126, 70, NUM_ROWS, "top", "#000")
objref:set_properties({ textures = {texture}, objref:set_properties({ textures = {texture},
visual_size = {x=0.94*1.9, y=0.94} }) visual_size = {x=0.94*1.9, y=0.94} })
end end
function techage.display.on_timer(pos) function techage.display.on_timer(pos)

BIN
images/watermill.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 453 KiB

View File

@ -30,8 +30,8 @@ elseif minetest.global_exists("tubelib2") and tubelib2.version < 1.9 then
elseif minetest.global_exists("minecart") and minecart.version < 1.08 then elseif minetest.global_exists("minecart") and minecart.version < 1.08 then
minetest.log("error", "[techage] Techage requires minecart version 1.08 or newer!") minetest.log("error", "[techage] Techage requires minecart version 1.08 or newer!")
return return
elseif minetest.global_exists("lcdlib") and lcdlib.version < 1.0 then elseif minetest.global_exists("lcdlib") and lcdlib.version < 1.01 then
minetest.log("error", "[techage] Techage requires lcdlib version 1.0 or newer!") minetest.log("error", "[techage] Techage requires lcdlib version 1.01 or newer!")
return return
elseif minetest.global_exists("safer_lua") and safer_lua.version < 1.0 then elseif minetest.global_exists("safer_lua") and safer_lua.version < 1.0 then
minetest.log("error", "[techage] Techage requires safer_lua version 1.0 or newer!") minetest.log("error", "[techage] Techage requires safer_lua version 1.0 or newer!")
@ -274,6 +274,7 @@ dofile(MP.."/logic/doorblock.lua")
dofile(MP.."/logic/doorcontroller.lua") -- old dofile(MP.."/logic/doorcontroller.lua") -- old
dofile(MP.."/logic/doorcontroller2.lua") -- new dofile(MP.."/logic/doorcontroller2.lua") -- new
dofile(MP.."/logic/collector.lua") dofile(MP.."/logic/collector.lua")
dofile(MP.."/logic/button_4x.lua")
if minetest.global_exists("mesecon") then if minetest.global_exists("mesecon") then
dofile(MP.."/logic/mesecons_converter.lua") dofile(MP.."/logic/mesecons_converter.lua")
end end

View File

@ -134,6 +134,16 @@ Insert destination node number(s)=Gebe Zielnummer(n) ein
Save=Speichern Save=Speichern
### button_4x.lua ###
Access=Zugriff
Button protection=Tastenschutz
Command=Kommando
Command to be sent=Zu sendender Befehl
Destination block number=Zielblocknummer
Number=Nummer
TA4 4x Button=TA4 4x Taster
### cart_detector.lua ### ### cart_detector.lua ###
TA3 Cart Detector=TA3 Wagen Detektor TA3 Cart Detector=TA3 Wagen Detektor

View File

@ -134,6 +134,16 @@ Insert destination node number(s)=
Save= Save=
### button_4x.lua ###
Access=
Button protection=
Command=
Command to be sent=
Destination block number=
Number=
TA4 4x Button=
### cart_detector.lua ### ### cart_detector.lua ###
TA3 Cart Detector= TA3 Cart Detector=

222
logic/button_4x.lua Normal file
View File

@ -0,0 +1,222 @@
--[[
TechAge
=======
Copyright (C) 2017-2021 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
TA4 Logic fourfold button
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
local function get_button_num(pos, clicker, pointed_thing)
-- use the node behind the button to get better results
local offs = vector.subtract(pointed_thing.under, pointed_thing.above)
pointed_thing.under = vector.add(pointed_thing.under, offs)
pointed_thing.above = vector.add(pointed_thing.above, offs)
local pos1 = minetest.pointed_thing_to_face_pos(clicker, pointed_thing)
local y = pos1.y - pos.y
if y < -0.3 then
return 4
elseif y < -0.03 and y > -0.22 then
return 3
elseif y > 0.03 and y < 0.22 then
return 2
elseif y > 0.3 then
return 1
end
end
local WRENCH_MENU = {
{
type = "number",
name = "dest_number1",
label = S("Number") .. " 1",
tooltip = S("Destination block number"),
default = "",
},
{
type = "ascii",
name = "command1",
label = S("Command") .. " 1",
tooltip = S("Command to be sent"),
default = "1",
},
{
type = "number",
name = "dest_number2",
label = S("Number") .. " 2",
tooltip = S("Destination block number"),
default = "",
},
{
type = "ascii",
name = "command2",
label = S("Command") .. " 2",
tooltip = S("Command to be sent"),
default = "2",
},
{
type = "number",
name = "dest_number3",
label = S("Number") .. " 3",
tooltip = S("Destination block number"),
default = "",
},
{
type = "ascii",
name = "command3",
label = S("Command") .. " 3",
tooltip = S("Command to be sent"),
default = "3",
},
{
type = "number",
name = "dest_number4",
label = S("Number") .. " 4",
tooltip = S("Destination block number"),
default = "",
},
{
type = "ascii",
name = "command4",
label = S("Command") .. " 4",
tooltip = S("Command to be sent"),
default = "4",
},
{
type = "dropdown",
choices = "private,protected,public",
name = "access",
label = S("Access"),
tooltip = S("Button protection"),
default = "8",
},
}
local function send_cmnd(pos, num)
local meta = M(pos)
local own_num = meta:get_string("node_number")
local dest = meta:get_string("dest_number" .. num)
local cmnd = meta:get_string("command" .. num)
techage.send_single(own_num, dest, cmnd)
end
local function button_update(pos, objref)
pos = vector.round(pos)
local nvm = techage.get_nvm(pos)
nvm.button = nvm.button or {}
local text = "< " .. table.concat(nvm.text or {" "}, "\n< ")
local texture = lcdlib.make_multiline_texture("default", text, 96, 96, 7, "top", "#000", 6)
if nvm.button[1] then
texture = texture .. "^techage_smartline_button_4x_on1.png"
end
if nvm.button[2] then
texture = texture .. "^techage_smartline_button_4x_on2.png"
end
if nvm.button[3] then
texture = texture .. "^techage_smartline_button_4x_on3.png"
end
if nvm.button[4] then
texture = texture .. "^techage_smartline_button_4x_on4.png"
end
objref:set_properties({ textures = {texture}, visual_size = {x=1, y=1} })
end
local function switch_off(pos, num)
local nvm = techage.get_nvm(pos)
nvm.button[num] = nil
lcdlib.update_entities(pos)
end
local function switch_on(pos, num)
local nvm = techage.get_nvm(pos)
nvm.button = nvm.button or {}
nvm.button[num] = true
send_cmnd(pos, num)
lcdlib.update_entities(pos)
minetest.after(0.5, switch_off, pos, num)
minetest.sound_play("techage_button", {
pos = pos,
gain = 0.5,
max_hear_distance = 5,
})
end
local lcd_box = {-8/16, -8/16, 7.75/16, 8/16, 8/16, 8/16}
minetest.register_node("techage:ta4_button_4x", {
description = S("TA4 4x Button"),
inventory_image = 'techage_smartline_button_4x.png',
tiles = {'techage_smartline_button_4x.png'},
drawtype = "nodebox",
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
node_box = {
type = "fixed",
fixed = lcd_box,
},
light_source = 6,
display_entities = {
["techage:display_entity"] = { depth = 0.48,
on_display_update = button_update},
},
after_place_node = function(pos, placer)
local number = techage.add_node(pos, "techage:ta4_button_4x")
local meta = minetest.get_meta(pos)
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"}
lcdlib.update_entities(pos)
end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if clicker and clicker:is_player() then
local playername = clicker:get_player_name()
if minetest.is_protected(pos, playername) then
return
end
-- Check node settings in addition
local access = M(pos):get_string("access")
local owner = M(pos):get_string("owner")
if access == "private" and playername ~= owner then
return
end
local num = get_button_num(pos, clicker, pointed_thing)
if num then
switch_on(pos, num)
end
end
end,
after_dig_node = function(pos, oldnode, oldmetadata)
techage.remove_node(pos, oldnode, oldmetadata)
end,
ta3_formspec = WRENCH_MENU,
on_place = lcdlib.on_place,
on_construct = lcdlib.on_construct,
on_destruct = lcdlib.on_destruct,
on_rotate = lcdlib.on_rotate,
groups = {cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_glass_defaults(),
})

View File

@ -201,6 +201,7 @@ local function register_terminal(num, tiles, node_box, selection_box)
meta:set_string("command", S("commands like: help")) meta:set_string("command", S("commands like: help"))
meta:set_string("formspec", formspec2(meta)) meta:set_string("formspec", formspec2(meta))
meta:set_string("owner", placer:get_player_name()) meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", S("TA3 Terminal") .. " " .. number)
end, end,
on_receive_fields = function(pos, formname, fields, player) on_receive_fields = function(pos, formname, fields, player)

View File

@ -470,6 +470,12 @@ Beim TA4 Taster/Schalter hat sich nur das Aussehen geändert. Die Funktionalitä
[ta4_button|image] [ta4_button|image]
### TA4 4x Taster / 4x Button
Dieser Block hat vier Taster, die über das Schraubenschlüssel-Menü individuell konfiguriert werden können. Für jeden Taster kann die Beschriftung und die Zielblockadresse konfiguriert werden. Zusätzlich kann für jeden Taster das Kommando konfiguriert werden, welches gesendet werden soll.
[ta4_button_4x|image]
### TA4 Spieler Detektor / Player Detector ### TA4 Spieler Detektor / Player Detector
Beim TA4 Spieler Detektor hat sich nur das Aussehen geändert. Die Funktionalität ist gleich wie beim TA3 Spieler Detektor. Beim TA4 Spieler Detektor hat sich nur das Aussehen geändert. Die Funktionalität ist gleich wie beim TA3 Spieler Detektor.

View File

@ -463,6 +463,12 @@ Only the appearance of the TA4 button/switch has changed. The functionality is t
[ta4_button|image] [ta4_button|image]
### TA4 4x Button
This block has four buttons that can be individually configured using the wrench menu. The labeling and the target block address can be configured for each button. In addition, the command that is to be sent can be configured for each button.
[ta4_button_4x|image]
### TA4 Player Detector ### TA4 Player Detector
Only the appearance of the TA4 player detector has changed. The functionality is the same as with the TA3 player detector. Only the appearance of the TA4 player detector has changed. The functionality is the same as with the TA3 player detector.

View File

@ -182,6 +182,7 @@
- [TA4 Lua Controller Terminal](./manual_ta4_DE.md#ta4-lua-controller-terminal) - [TA4 Lua Controller Terminal](./manual_ta4_DE.md#ta4-lua-controller-terminal)
- [TA4 Logik-/Schalt-Module](./manual_ta4_DE.md#ta4-logik-schalt-module) - [TA4 Logik-/Schalt-Module](./manual_ta4_DE.md#ta4-logik-schalt-module)
- [TA4 Taster/Schalter / Button/Switch](./manual_ta4_DE.md#ta4-tasterschalter--buttonswitch) - [TA4 Taster/Schalter / Button/Switch](./manual_ta4_DE.md#ta4-tasterschalter--buttonswitch)
- [TA4 4x Taster / 4x Button](./manual_ta4_DE.md#ta4-4x-taster--4x-button)
- [TA4 Spieler Detektor / Player Detector](./manual_ta4_DE.md#ta4-spieler-detektor--player-detector) - [TA4 Spieler Detektor / Player Detector](./manual_ta4_DE.md#ta4-spieler-detektor--player-detector)
- [TA4 Zustandssammler / State Collector](./manual_ta4_DE.md#ta4-zustandssammler--state-collector) - [TA4 Zustandssammler / State Collector](./manual_ta4_DE.md#ta4-zustandssammler--state-collector)
- [TA4 Detektor / Detector](./manual_ta4_DE.md#ta4-detektor--detector) - [TA4 Detektor / Detector](./manual_ta4_DE.md#ta4-detektor--detector)

View File

@ -182,6 +182,7 @@
- [TA4 Lua Controller Terminal](./manual_ta4_EN.md#ta4-lua-controller-terminal) - [TA4 Lua Controller Terminal](./manual_ta4_EN.md#ta4-lua-controller-terminal)
- [TA4 Logic/Switching Modules](./manual_ta4_EN.md#ta4-logicswitching-modules) - [TA4 Logic/Switching Modules](./manual_ta4_EN.md#ta4-logicswitching-modules)
- [TA4 Button/Switch](./manual_ta4_EN.md#ta4-buttonswitch) - [TA4 Button/Switch](./manual_ta4_EN.md#ta4-buttonswitch)
- [TA4 4x Button](./manual_ta4_EN.md#ta4-4x-button)
- [TA4 Player Detector](./manual_ta4_EN.md#ta4-player-detector) - [TA4 Player Detector](./manual_ta4_EN.md#ta4-player-detector)
- [TA4 State Collector](./manual_ta4_EN.md#ta4-state-collector) - [TA4 State Collector](./manual_ta4_EN.md#ta4-state-collector)
- [TA4 Detector](./manual_ta4_EN.md#ta4-detector) - [TA4 Detector](./manual_ta4_EN.md#ta4-detector)

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

View File

@ -136,6 +136,16 @@ end
local context = {} local context = {}
local function settings_menu(pos, playername) local function settings_menu(pos, playername)
if minetest.is_protected(pos, playername) then
return
end
-- Check node settings in addition
local access = M(pos):get_string("access")
local owner = M(pos):get_string("owner")
if access == "private" and playername ~= owner then
return
end
local number = techage.get_node_number(pos) local number = techage.get_node_number(pos)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local ndef = minetest.registered_nodes[node.name] local ndef = minetest.registered_nodes[node.name]
@ -163,7 +173,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local form_def = ndef and (ndef.ta3_formspec or ndef.ta4_formspec) local form_def = ndef and (ndef.ta3_formspec or ndef.ta4_formspec)
if form_def then if form_def then
if menu.eval_input(pos, ndef, form_def, fields, playername) then if menu.eval_input(pos, form_def, fields, playername) then
--context[playername] = pos --context[playername] = pos
minetest.after(0.2, function() minetest.after(0.2, function()
minetest.show_formspec(playername, "techage:ta_formspec", minetest.show_formspec(playername, "techage:ta_formspec",

View File

@ -235,22 +235,39 @@ function menu.generate_formspec(pos, ndef, form_def, player_name)
"button[6.5,8.4;3,1;save;" .. S("Save") .. "]" "button[6.5,8.4;3,1;save;" .. S("Save") .. "]"
end end
return "size[10,9]" .. if #form_def > 8 then
default.gui_bg .. local size = (#form_def * 10) - 60
default.gui_bg_img .. return "size[10,9]" ..
default.gui_slots .. default.gui_bg ..
"box[0,-0.1;9.8,0.5;#c6e8ff]" .. default.gui_bg_img ..
"label[0.2,-0.1;" .. minetest.colorize( "#000000", title) .. "]" .. default.gui_slots ..
"label[9.5,-0.1;" .. minetest.colorize( "#000000", star) .. "]" .. "box[0,-0.1;9.8,0.5;#c6e8ff]" ..
"container[0,1]" .. "label[0.2,-0.1;" .. minetest.colorize( "#000000", title) .. "]" ..
text .. "label[9.5,-0.1;" .. minetest.colorize( "#000000", star) .. "]" ..
"container_end[]" .. "scrollbaroptions[max=" .. size .. "]" ..
buttons "scrollbar[9.4,0.6;0.4,7.7;vertical;wrenchmenu;]" ..
"scroll_container[0,1;12,9;wrenchmenu;vertical;]" ..
text ..
"scroll_container_end[]" ..
buttons
else
return "size[10,9]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"box[0,-0.1;9.8,0.5;#c6e8ff]" ..
"label[0.2,-0.1;" .. minetest.colorize( "#000000", title) .. "]" ..
"label[9.5,-0.1;" .. minetest.colorize( "#000000", star) .. "]" ..
"container[0,1]" ..
text ..
"container_end[]" ..
buttons
end
end end
return "" return ""
end end
function menu.eval_input(pos, ndef, form_def, fields, player_name) function menu.eval_input(pos, form_def, fields, player_name)
--print(dump(fields)) --print(dump(fields))
if fields.save then if fields.save then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)