diff --git a/doc/items.lua b/doc/items.lua index f3e7161..4e15ca9 100644 --- a/doc/items.lua +++ b/doc/items.lua @@ -191,6 +191,7 @@ techage.Items = { ta4_electricmeter = "techage:ta4_electricmeter", ta4_transformer = "techage:ta4_transformer", power_reduction = "techage_power_reduction.png", + ta4_button_4x = "techage:ta4_button_4x", --ta4_ "", } diff --git a/doc/manual_DE.lua b/doc/manual_DE.lua index 62534fa..aeba4d7 100644 --- a/doc/manual_DE.lua +++ b/doc/manual_DE.lua @@ -183,6 +183,7 @@ techage.manual_DE.aTitel = { "3,TA4 Lua Controller Terminal", "2,TA4 Logik-/Schalt-Module", "3,TA4 Taster/Schalter / Button/Switch", + "3,TA4 4x Taster / 4x Button", "3,TA4 Spieler Detektor / Player Detector", "3,TA4 Zustandssammler / State Collector", "3,TA4 Detektor / Detector", @@ -1559,6 +1560,10 @@ techage.manual_DE.aText = { "\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".. "\n".. "\n".. @@ -1933,6 +1938,7 @@ techage.manual_DE.aItemName = { "ta4_terminal", "", "ta4_button", + "ta4_button_4x", "ta4_playerdetector", "ta4_collector", "ta4_detector", @@ -2155,6 +2161,7 @@ techage.manual_DE.aPlanTable = { "", "", "", + "", "ta4_liquid_filter_base", "ta4_liquid_filter_gravel", "ta4_liquid_filter_top", diff --git a/doc/manual_EN.lua b/doc/manual_EN.lua index 5660248..ebb6840 100644 --- a/doc/manual_EN.lua +++ b/doc/manual_EN.lua @@ -183,6 +183,7 @@ techage.manual_EN.aTitel = { "3,TA4 Lua Controller Terminal", "2,TA4 Logic/Switching Modules", "3,TA4 Button/Switch", + "3,TA4 4x Button", "3,TA4 Player Detector", "3,TA4 State Collector", "3,TA4 Detector", @@ -1557,6 +1558,10 @@ techage.manual_EN.aText = { "\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".. "\n".. "\n".. @@ -1932,6 +1937,7 @@ techage.manual_EN.aItemName = { "ta4_terminal", "", "ta4_button", + "ta4_button_4x", "ta4_playerdetector", "ta4_collector", "ta4_detector", @@ -2154,6 +2160,7 @@ techage.manual_EN.aPlanTable = { "", "", "", + "", "ta4_liquid_filter_base", "ta4_liquid_filter_gravel", "ta4_liquid_filter_top", diff --git a/icta_controller/display.lua b/icta_controller/display.lua index adbeabb..fa01b42 100644 --- a/icta_controller/display.lua +++ b/icta_controller/display.lua @@ -43,7 +43,7 @@ function techage.display.display_update(pos, objref) "default", text, 70, 70, NUM_ROWS, "top", "#000") objref:set_properties({ textures = {texture}, - visual_size = {x=0.94, y=0.94} }) + visual_size = {x=0.94, y=0.94} }) end function techage.display.display_updateXL(pos, objref) @@ -54,7 +54,7 @@ function techage.display.display_updateXL(pos, objref) "default", text, 126, 70, NUM_ROWS, "top", "#000") 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 function techage.display.on_timer(pos) diff --git a/images/watermill.png b/images/watermill.png new file mode 100644 index 0000000..8c3a8e2 Binary files /dev/null and b/images/watermill.png differ diff --git a/init.lua b/init.lua index f6414b5..1b271c3 100644 --- a/init.lua +++ b/init.lua @@ -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 minetest.log("error", "[techage] Techage requires minecart version 1.08 or newer!") return -elseif minetest.global_exists("lcdlib") and lcdlib.version < 1.0 then - minetest.log("error", "[techage] Techage requires lcdlib version 1.0 or newer!") +elseif minetest.global_exists("lcdlib") and lcdlib.version < 1.01 then + minetest.log("error", "[techage] Techage requires lcdlib version 1.01 or newer!") return 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!") @@ -274,6 +274,7 @@ dofile(MP.."/logic/doorblock.lua") dofile(MP.."/logic/doorcontroller.lua") -- old dofile(MP.."/logic/doorcontroller2.lua") -- new dofile(MP.."/logic/collector.lua") +dofile(MP.."/logic/button_4x.lua") if minetest.global_exists("mesecon") then dofile(MP.."/logic/mesecons_converter.lua") end diff --git a/locale/techage.de.tr b/locale/techage.de.tr index 599200d..61f3b21 100644 --- a/locale/techage.de.tr +++ b/locale/techage.de.tr @@ -134,6 +134,16 @@ Insert destination node number(s)=Gebe Zielnummer(n) ein 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 ### TA3 Cart Detector=TA3 Wagen Detektor diff --git a/locale/template.txt b/locale/template.txt index 6df8e8f..4e15cd6 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -134,6 +134,16 @@ Insert destination node number(s)= Save= +### button_4x.lua ### + +Access= +Button protection= +Command= +Command to be sent= +Destination block number= +Number= +TA4 4x Button= + ### cart_detector.lua ### TA3 Cart Detector= diff --git a/logic/button_4x.lua b/logic/button_4x.lua new file mode 100644 index 0000000..f9fbbfd --- /dev/null +++ b/logic/button_4x.lua @@ -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(), +}) diff --git a/logic/terminal.lua b/logic/terminal.lua index 212356c..7bf483f 100644 --- a/logic/terminal.lua +++ b/logic/terminal.lua @@ -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("formspec", formspec2(meta)) meta:set_string("owner", placer:get_player_name()) + meta:set_string("infotext", S("TA3 Terminal") .. " " .. number) end, on_receive_fields = function(pos, formname, fields, player) diff --git a/manuals/manual_ta4_DE.md b/manuals/manual_ta4_DE.md index 5294279..0bec657 100644 --- a/manuals/manual_ta4_DE.md +++ b/manuals/manual_ta4_DE.md @@ -470,6 +470,12 @@ Beim TA4 Taster/Schalter hat sich nur das Aussehen geändert. Die Funktionalitä [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 Beim TA4 Spieler Detektor hat sich nur das Aussehen geändert. Die Funktionalität ist gleich wie beim TA3 Spieler Detektor. diff --git a/manuals/manual_ta4_EN.md b/manuals/manual_ta4_EN.md index 6f5698d..a52bb53 100644 --- a/manuals/manual_ta4_EN.md +++ b/manuals/manual_ta4_EN.md @@ -463,6 +463,12 @@ Only the appearance of the TA4 button/switch has changed. The functionality is t [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 Only the appearance of the TA4 player detector has changed. The functionality is the same as with the TA3 player detector. diff --git a/manuals/toc_DE.md b/manuals/toc_DE.md index 6f95b60..2e7386f 100644 --- a/manuals/toc_DE.md +++ b/manuals/toc_DE.md @@ -182,6 +182,7 @@ - [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 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 Zustandssammler / State Collector](./manual_ta4_DE.md#ta4-zustandssammler--state-collector) - [TA4 Detektor / Detector](./manual_ta4_DE.md#ta4-detektor--detector) diff --git a/manuals/toc_EN.md b/manuals/toc_EN.md index 6c27745..b0426b9 100644 --- a/manuals/toc_EN.md +++ b/manuals/toc_EN.md @@ -182,6 +182,7 @@ - [TA4 Lua Controller Terminal](./manual_ta4_EN.md#ta4-lua-controller-terminal) - [TA4 Logic/Switching Modules](./manual_ta4_EN.md#ta4-logicswitching-modules) - [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 State Collector](./manual_ta4_EN.md#ta4-state-collector) - [TA4 Detector](./manual_ta4_EN.md#ta4-detector) diff --git a/textures/techage_inv_wrench.png b/textures/techage_inv_wrench.png new file mode 100644 index 0000000..f95cc55 Binary files /dev/null and b/textures/techage_inv_wrench.png differ diff --git a/textures/techage_smartline_button_4x.png b/textures/techage_smartline_button_4x.png new file mode 100644 index 0000000..5bc5286 Binary files /dev/null and b/textures/techage_smartline_button_4x.png differ diff --git a/textures/techage_smartline_button_4x_on1.png b/textures/techage_smartline_button_4x_on1.png new file mode 100644 index 0000000..95d27e3 Binary files /dev/null and b/textures/techage_smartline_button_4x_on1.png differ diff --git a/textures/techage_smartline_button_4x_on2.png b/textures/techage_smartline_button_4x_on2.png new file mode 100644 index 0000000..34cad03 Binary files /dev/null and b/textures/techage_smartline_button_4x_on2.png differ diff --git a/textures/techage_smartline_button_4x_on3.png b/textures/techage_smartline_button_4x_on3.png new file mode 100644 index 0000000..e587ed6 Binary files /dev/null and b/textures/techage_smartline_button_4x_on3.png differ diff --git a/textures/techage_smartline_button_4x_on4.png b/textures/techage_smartline_button_4x_on4.png new file mode 100644 index 0000000..1f6c6c2 Binary files /dev/null and b/textures/techage_smartline_button_4x_on4.png differ diff --git a/tools/repairkit.lua b/tools/repairkit.lua index f304851..8ee5ff3 100644 --- a/tools/repairkit.lua +++ b/tools/repairkit.lua @@ -136,6 +136,16 @@ end local context = {} 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 node = minetest.get_node(pos) 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) 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 minetest.after(0.2, function() minetest.show_formspec(playername, "techage:ta_formspec", diff --git a/tools/submenu.lua b/tools/submenu.lua index da30ffb..b443c06 100644 --- a/tools/submenu.lua +++ b/tools/submenu.lua @@ -235,22 +235,39 @@ function menu.generate_formspec(pos, ndef, form_def, player_name) "button[6.5,8.4;3,1;save;" .. S("Save") .. "]" end - 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 + if #form_def > 8 then + local size = (#form_def * 10) - 60 + 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) .. "]" .. + "scrollbaroptions[max=" .. size .. "]" .. + "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 return "" 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)) if fields.save then local meta = minetest.get_meta(pos)