Add 'on button' mode to the button
This commit is contained in:
parent
742fc51dc0
commit
4469dd128c
@ -16,8 +16,8 @@ local S = techage.S
|
||||
techage.menu = {}
|
||||
|
||||
local function index(list, x)
|
||||
for idx, v in ipairs(list) do
|
||||
if v == x then return idx end
|
||||
for idx, v in ipairs(list or {}) do
|
||||
if tostring(v) == x then return idx end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
@ -99,7 +99,6 @@ local function generate_formspec_substring(pos, meta, form_def, player_name)
|
||||
end
|
||||
tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]"
|
||||
elseif elem.type == "dropdown" then
|
||||
local l = elem.choices:split(",")
|
||||
if nvm.running or techage.is_running(nvm) then
|
||||
local val = elem.default or ""
|
||||
if meta:contains(elem.name) then
|
||||
@ -120,7 +119,13 @@ local function generate_formspec_substring(pos, meta, form_def, player_name)
|
||||
if meta:contains(elem.name) then
|
||||
val = meta:get_string(elem.name) or ""
|
||||
end
|
||||
local idx = index(l, val) or 1
|
||||
local idx
|
||||
if elem.values then
|
||||
idx = index(elem.values, val) or 1
|
||||
else
|
||||
local l = elem.choices:split(",")
|
||||
idx = index(l, val) or 1
|
||||
end
|
||||
tbl[#tbl+1] = "dropdown[4.72," .. (offs) .. ";5.5,1.4;" .. elem.name .. ";" .. elem.choices .. ";" .. idx .. "]"
|
||||
end
|
||||
elseif elem.type == "items" then -- inventory
|
||||
@ -203,7 +208,14 @@ local function evaluate_data(pos, meta, form_def, fields, player_name)
|
||||
end
|
||||
elseif elem.type == "dropdown" then
|
||||
if fields[elem.name] ~= nil then
|
||||
meta:set_string(elem.name, fields[elem.name])
|
||||
if elem.values then
|
||||
local l = elem.choices:split(",")
|
||||
local idx = index(l, fields[elem.name]) or 1
|
||||
local text = elem.values[idx]
|
||||
meta:set_string(elem.name, text)
|
||||
else
|
||||
meta:set_string(elem.name, fields[elem.name])
|
||||
end
|
||||
end
|
||||
elseif elem.type == "items" and player_name then
|
||||
local inv_name = minetest.formspec_escape(player_name) .. "_techage_wrench_menu"
|
||||
|
@ -1043,7 +1043,7 @@ techage.manual_DE.aText = {
|
||||
"\n"..
|
||||
"\n",
|
||||
"Der Taster/Schalter sendet 'on'/'off' Kommandos zu den Blöcken\\, die über die Nummern konfiguriert wurden.\n"..
|
||||
"Der Taster/Schalter kann als Taster (button) oder Schalter (switch) konfiguriert werden. Wird er als Taster konfiguriert\\, so kann die Zeit zwischen den 'on' und 'off' Kommandos eingestellt werden.\n"..
|
||||
"Der Taster/Schalter kann als Taster (button) oder Schalter (switch) konfiguriert werden. Wird er als Taster konfiguriert\\, so kann die Zeit zwischen den 'on' und 'off' Kommandos eingestellt werden. Mit der Betriebsart \"on button\" wird nur ein 'on' und kein 'off' Kommandos gesendet.\n"..
|
||||
"\n"..
|
||||
"Über die Checkbox \"public\" kann eingestellt werden\\, ob den Taster von jedem (gesetzt)\\, oder nur vom Besitzer selbst (nicht gesetzt) genutzt werden darf.\n"..
|
||||
"\n"..
|
||||
|
@ -1046,7 +1046,7 @@ techage.manual_EN.aText = {
|
||||
"\n"..
|
||||
"\n",
|
||||
"The button/switch sends 'on' / 'off' commands to the blocks that have been configured via the numbers.\n"..
|
||||
"The button/switch can be configured as a button or a switch. If it is configured as a button\\, the time between the 'on' and 'off' commands can be set.\n"..
|
||||
"The button/switch can be configured as a button or a switch. If it is configured as a button\\, the time between the 'on' and 'off' commands can be set. With the operating mode \"on button\" only an 'on' and no 'off' command is sent.\n"..
|
||||
"\n"..
|
||||
"The checkbox \"public\" can be used to set whether the button can be used by everyone (set) or only by the owner himself (not set).\n"..
|
||||
"\n"..
|
||||
|
@ -22,7 +22,7 @@ local logic = techage.logic
|
||||
local WRENCH_MENU = {
|
||||
{
|
||||
type = "dropdown",
|
||||
choices = "switch,button 1s,button 2s,button 4s,button 8s,button 16s,button 32s",
|
||||
choices = "switch,on button,button 1s,button 2s,button 4s,button 8s,button 16s,button 32s",
|
||||
name = "type",
|
||||
label = S("Type"),
|
||||
tooltip = S("Button or switch"),
|
||||
@ -87,7 +87,8 @@ local function switch_off(pos, is_button)
|
||||
logic.swap_node(pos, "techage:ta4_button_off")
|
||||
end
|
||||
local meta = M(pos)
|
||||
if not meta:contains("command") or meta:get_string("command") == "on" then
|
||||
if meta:get_string("off_command") ~= "true" and
|
||||
(not meta:contains("command") or meta:get_string("command") == "on") then
|
||||
logic.send_off(pos, M(pos))
|
||||
end
|
||||
if not is_button then
|
||||
@ -105,7 +106,7 @@ local function formspec(meta)
|
||||
if idx == 0 then idx = 1 end
|
||||
local access_idx = meta:get_string("public") == "true" and 3 or meta:get_string("protected") == "true" and 2 or 1
|
||||
return "size[7.5,6]"..
|
||||
"dropdown[0.2,0;3;type;switch,button 1s,button 2s,button 4s,button 8s,button 16s,button 32s;"..idx.."]"..
|
||||
"dropdown[0.2,0;3;type;switch,on button,button 1s,button 2s,button 4s,button 8s,button 16s,button 32s;"..idx.."]"..
|
||||
"field[0.5,2;7,1;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" ..
|
||||
"label[0.2,3;"..S("Access:").."]"..
|
||||
"dropdown[3,3;4;access;private,protected,public;"..access_idx.."]"..
|
||||
@ -115,6 +116,8 @@ end
|
||||
local function store_fields_data(pos, fields)
|
||||
local meta = M(pos)
|
||||
meta:set_string("numbers", fields.numbers)
|
||||
meta:set_string("off_command", "")
|
||||
|
||||
if fields.access == "protected" then
|
||||
meta:set_string("protected", "true")
|
||||
meta:set_string("public", "")
|
||||
@ -131,23 +134,27 @@ local function store_fields_data(pos, fields)
|
||||
if fields.type == "switch" then
|
||||
meta:set_int("cycle_idx", 1)
|
||||
cycle_time = 0
|
||||
elseif fields.type == "button 1s" then
|
||||
elseif fields.type == "on button" then
|
||||
meta:set_int("cycle_idx", 2)
|
||||
meta:set_string("off_command", "true")
|
||||
cycle_time = 1
|
||||
elseif fields.type == "button 1s" then
|
||||
meta:set_int("cycle_idx", 3)
|
||||
cycle_time = 1
|
||||
elseif fields.type == "button 2s" then
|
||||
meta:set_int("cycle_idx", 3)
|
||||
meta:set_int("cycle_idx", 4)
|
||||
cycle_time = 2
|
||||
elseif fields.type == "button 4s" then
|
||||
meta:set_int("cycle_idx", 4)
|
||||
meta:set_int("cycle_idx", 5)
|
||||
cycle_time = 4
|
||||
elseif fields.type == "button 8s" then
|
||||
meta:set_int("cycle_idx", 5)
|
||||
meta:set_int("cycle_idx", 6)
|
||||
cycle_time = 8
|
||||
elseif fields.type == "button 16s" then
|
||||
meta:set_int("cycle_idx", 6)
|
||||
meta:set_int("cycle_idx", 7)
|
||||
cycle_time = 16
|
||||
elseif fields.type == "button 32s" then
|
||||
meta:set_int("cycle_idx", 7)
|
||||
meta:set_int("cycle_idx", 8)
|
||||
cycle_time = 32
|
||||
end
|
||||
if cycle_time ~= nil then
|
||||
|
@ -46,21 +46,14 @@ local WRENCH_MENU = {
|
||||
label = S("Cycle time"),
|
||||
tooltip = S("Timer cycle time (default: 100 ms)"),
|
||||
default = "1",
|
||||
values = {0.1, 0.2, 0.5, 1.0, 2.0}
|
||||
},
|
||||
}
|
||||
|
||||
local CYCLE_TIMES = {
|
||||
["100ms"] = 0.1,
|
||||
["200ms"] = 0.2,
|
||||
["500ms"] = 0.5,
|
||||
["1s"] = 1.0,
|
||||
["2s"] = 2.0
|
||||
}
|
||||
|
||||
local function cycle_time(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
if not mem.cycletime then
|
||||
mem.cycletime = CYCLE_TIMES[M(pos):get_string("cycletime")] or 0.1
|
||||
mem.cycletime = tonumber(M(pos):get_string("cycletime")) or 0.1
|
||||
end
|
||||
return mem.cycletime
|
||||
end
|
||||
|
@ -527,7 +527,7 @@ Dieser Status und weitere Informationen werden auch ausgegeben, wenn mit dem Sch
|
||||
### TA3 Taster/Schalter / Button/Switch
|
||||
|
||||
Der Taster/Schalter sendet `on`/`off` Kommandos zu den Blöcken, die über die Nummern konfiguriert wurden.
|
||||
Der Taster/Schalter kann als Taster (button) oder Schalter (switch) konfiguriert werden. Wird er als Taster konfiguriert, so kann die Zeit zwischen den `on` und `off` Kommandos eingestellt werden.
|
||||
Der Taster/Schalter kann als Taster (button) oder Schalter (switch) konfiguriert werden. Wird er als Taster konfiguriert, so kann die Zeit zwischen den `on` und `off` Kommandos eingestellt werden. Mit der Betriebsart "on button" wird nur ein `on` und kein `off` Kommandos gesendet.
|
||||
|
||||
Über die Checkbox "public" kann eingestellt werden, ob den Taster von jedem (gesetzt), oder nur vom Besitzer selbst (nicht gesetzt) genutzt werden darf.
|
||||
|
||||
|
@ -526,7 +526,7 @@ This status and other information is also output when the wrench is clicked on t
|
||||
|
||||
### TA3 Button / Switch
|
||||
The button/switch sends `on` / `off` commands to the blocks that have been configured via the numbers.
|
||||
The button/switch can be configured as a button or a switch. If it is configured as a button, the time between the `on` and `off` commands can be set.
|
||||
The button/switch can be configured as a button or a switch. If it is configured as a button, the time between the `on` and `off` commands can be set. With the operating mode "on button" only an `on` and no `off` command is sent.
|
||||
|
||||
The checkbox "public" can be used to set whether the button can be used by everyone (set) or only by the owner himself (not set).
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user