From 5c8962b39bd4f6871ec87a988ac43d7bfad04d2b Mon Sep 17 00:00:00 2001 From: "Y. Wang" Date: Mon, 11 Apr 2022 16:55:50 +0200 Subject: Implement basic route signaling with Japanese signals for demo --- advtrains/formspec.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 advtrains/formspec.lua (limited to 'advtrains/formspec.lua') diff --git a/advtrains/formspec.lua b/advtrains/formspec.lua new file mode 100644 index 0000000..91e300d --- /dev/null +++ b/advtrains/formspec.lua @@ -0,0 +1,37 @@ +local sformat = string.format +local fsescape = minetest.formspec_escape + +local function f_button_exit(x, y, w, h, id, text) + return sformat("button_exit[%f,%f;%f,%f;%s;%s]", x, y, w, h, id, text) +end + +local function S_button_exit(x, y, w, h, id, ...) + return f_button_exit(x, y, w, h, id, attrans(...)) +end + +local function f_dropdown(x, y, w, id, entries, sel, indexed) + local t = {} + for k, v in pairs(entries) do + t[k] = fsescape(v) + end + return sformat("dropdown[%f,%f;%f;%s;%s;%d%s]", + x, y, w, id, table.concat(t, ","), + sel or 1, + indexed and ";true" or "") +end + +local function f_label(x, y, text) + return sformat("label[%f,%f;%s]", x, y, fsescape(text)) +end + +local function S_label(x, y, ...) + return f_label(x, y, attrans(...)) +end + +return { + button_exit = f_button_exit, + S_button_exit = S_button_exit, + dropdown = f_dropdown, + label = f_label, + S_label = S_label, +} -- cgit v1.2.3 From d1a0d8f2654d6ee64c1a43de7958b1eadfaff6b0 Mon Sep 17 00:00:00 2001 From: "Y. Wang" Date: Fri, 10 Jun 2022 22:21:54 +0200 Subject: Use tabs to switch between signaling and IP forms --- advtrains/formspec.lua | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'advtrains/formspec.lua') diff --git a/advtrains/formspec.lua b/advtrains/formspec.lua index 91e300d..aa5aa69 100644 --- a/advtrains/formspec.lua +++ b/advtrains/formspec.lua @@ -1,6 +1,14 @@ local sformat = string.format local fsescape = minetest.formspec_escape +local function make_list(entries) + local t = {} + for k, v in ipairs(entries) do + t[k] = fsescape(v) + end + return table.concat(t, ",") +end + local function f_button_exit(x, y, w, h, id, text) return sformat("button_exit[%f,%f;%f,%f;%s;%s]", x, y, w, h, id, text) end @@ -10,12 +18,8 @@ local function S_button_exit(x, y, w, h, id, ...) end local function f_dropdown(x, y, w, id, entries, sel, indexed) - local t = {} - for k, v in pairs(entries) do - t[k] = fsescape(v) - end return sformat("dropdown[%f,%f;%f;%s;%s;%d%s]", - x, y, w, id, table.concat(t, ","), + x, y, w, id, make_list(entries), sel or 1, indexed and ";true" or "") end @@ -28,10 +32,32 @@ local function S_label(x, y, ...) return f_label(x, y, attrans(...)) end +local function f_tabheader(x, y, w, h, id, entries, sel, transparent, border) + local st = {string.format("%f,%f",x, y)} + if h then + if w then + st[#st+1] = string.format("%f,%f", w, h) + else + st[#st+1] = tostring(h) + end + end + st[#st+1] = tostring(id) + st[#st+1] = make_list(entries) + st[#st+1] = tostring(sel) + if transparent ~= nil then + st[#st+1] = tostring(transparent) + if border ~= nil then + st[#st+1] = tostring(border) + end + end + return string.format("tabheader[%s]", table.concat(st, ";")) +end + return { button_exit = f_button_exit, S_button_exit = S_button_exit, dropdown = f_dropdown, label = f_label, S_label = S_label, + tabheader = f_tabheader, } -- cgit v1.2.3 From 98c37108762c6d7c9f1d691b84f49bfa65b81b28 Mon Sep 17 00:00:00 2001 From: "Y. Wang" Date: Sat, 11 Jun 2022 18:07:00 +0200 Subject: Implement primitive distant signaling --- advtrains/formspec.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'advtrains/formspec.lua') diff --git a/advtrains/formspec.lua b/advtrains/formspec.lua index aa5aa69..20dab59 100644 --- a/advtrains/formspec.lua +++ b/advtrains/formspec.lua @@ -9,6 +9,14 @@ local function make_list(entries) return table.concat(t, ",") end +local function f_button(x, y, w, h, id, text) + return sformat("button[%f,%f;%f,%f;%s;%s]", x, y, w, h, id, text) +end + +local function S_button(x, y, w, h, id, ...) + return f_button(x, y, w, h, id, attrans(...)) +end + local function f_button_exit(x, y, w, h, id, text) return sformat("button_exit[%f,%f;%f,%f;%s;%s]", x, y, w, h, id, text) end @@ -54,6 +62,8 @@ local function f_tabheader(x, y, w, h, id, entries, sel, transparent, border) end return { + button = f_button, + S_button = S_button, button_exit = f_button_exit, S_button_exit = S_button_exit, dropdown = f_dropdown, -- cgit v1.2.3 From 34405b8431b7c758988b56cc09d21d6de74b727b Mon Sep 17 00:00:00 2001 From: "Y. Wang" Date: Sat, 13 Aug 2022 21:16:15 +0200 Subject: Allow assigning distant signals from the main signal --- advtrains/formspec.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'advtrains/formspec.lua') diff --git a/advtrains/formspec.lua b/advtrains/formspec.lua index 20dab59..58968da 100644 --- a/advtrains/formspec.lua +++ b/advtrains/formspec.lua @@ -32,6 +32,21 @@ local function f_dropdown(x, y, w, id, entries, sel, indexed) indexed and ";true" or "") end +local function f_image_button(x, y, w, h, texture, id, label, noclip, drawborder, pressed) + local st = {string.format("%f,%f;%f,%f;%s;%s;%s", x, y, w, h, fsescape(texture), fsescape(id), fsescape(label))} + if pressed then + st[#st+1] = tostring(noclip or false) + st[#st+1] = tostring(drawborder or false) + st[#st+1] = fsescape(pressed) + end + return sformat("image_button[%s]", table.concat(st, ";")) +end + +local function f_image_button_exit(x, y, w, h, texture, id, label) + local st = {string.format("%f,%f;%f,%f;%s;%s;%s", x, y, w, h, fsescape(texture), fsescape(id), fsescape(label))} + return sformat("image_button_exit[%s]", table.concat(st, ";")) +end + local function f_label(x, y, text) return sformat("label[%f,%f;%s]", x, y, fsescape(text)) end @@ -61,13 +76,25 @@ local function f_tabheader(x, y, w, h, id, entries, sel, transparent, border) return string.format("tabheader[%s]", table.concat(st, ";")) end +local function f_textlist(x, y, w, h, id, entries, sel, transparent) + local st = {string.format("%f,%f;%f,%f;%s;%s", x, y, w, h, id, make_list(entries))} + if sel then + st[#st+1] = tostring(sel) + st[#st+1] = tostring(transparent or false) + end + return string.format("textlist[%s]", table.concat(st, ";")) +end + return { button = f_button, S_button = S_button, button_exit = f_button_exit, S_button_exit = S_button_exit, dropdown = f_dropdown, + image_button = f_image_button, + image_button_exit = f_image_button_exit, label = f_label, S_label = S_label, tabheader = f_tabheader, + textlist = f_textlist, } -- cgit v1.2.3 From 67efae9c9ad6f93aaa418d512c4ae1817eed6d24 Mon Sep 17 00:00:00 2001 From: "Y. Wang" Date: Sun, 18 Dec 2022 11:01:26 +0100 Subject: Adjust signal aspect formspecs to be of similar size --- advtrains/formspec.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'advtrains/formspec.lua') diff --git a/advtrains/formspec.lua b/advtrains/formspec.lua index 58968da..743d3f3 100644 --- a/advtrains/formspec.lua +++ b/advtrains/formspec.lua @@ -17,6 +17,14 @@ local function S_button(x, y, w, h, id, ...) return f_button(x, y, w, h, id, attrans(...)) end +local function f_checkbox(x, y, name, selected, label) + return sformat("checkbox[%f,%f;%s;%s;%s]", x, y, name, label, selected and "true" or "false") +end + +local function S_checkbox(x, y, name, selected, ...) + return f_checkbox(x, y, name, selected, attrans(...)) +end + local function f_button_exit(x, y, w, h, id, text) return sformat("button_exit[%f,%f;%f,%f;%s;%s]", x, y, w, h, id, text) end @@ -88,6 +96,8 @@ end return { button = f_button, S_button = S_button, + checkbox = f_checkbox, + S_checkbox = S_checkbox, button_exit = f_button_exit, S_button_exit = S_button_exit, dropdown = f_dropdown, -- cgit v1.2.3 From 2d072cdc67ec3018eaba36b7c79c2b19e574a94d Mon Sep 17 00:00:00 2001 From: "Y. Wang" Date: Fri, 6 Jan 2023 14:45:03 +0100 Subject: Rework formspecs; add description to JP signal group --- advtrains/formspec.lua | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'advtrains/formspec.lua') diff --git a/advtrains/formspec.lua b/advtrains/formspec.lua index 743d3f3..8894354 100644 --- a/advtrains/formspec.lua +++ b/advtrains/formspec.lua @@ -9,32 +9,28 @@ local function make_list(entries) return table.concat(t, ",") end -local function f_button(x, y, w, h, id, text) - return sformat("button[%f,%f;%f,%f;%s;%s]", x, y, w, h, id, text) +local function S_wrapper(f, i0) + return function(...) + local args = {...} + args[i0] = attrans(unpack(args,i0)) + return f(unpack(args,1,i0)) + end end -local function S_button(x, y, w, h, id, ...) - return f_button(x, y, w, h, id, attrans(...)) +local function f_button(x, y, w, id, text) + return sformat("button[%f,%f;%f,0.75;%s;%s]", x, y, w, id, text) end local function f_checkbox(x, y, name, selected, label) - return sformat("checkbox[%f,%f;%s;%s;%s]", x, y, name, label, selected and "true" or "false") -end - -local function S_checkbox(x, y, name, selected, ...) - return f_checkbox(x, y, name, selected, attrans(...)) + return sformat("checkbox[%f,%f;%s;%s;%s]", x, y+0.25, name, label, selected and "true" or "false") end -local function f_button_exit(x, y, w, h, id, text) - return sformat("button_exit[%f,%f;%f,%f;%s;%s]", x, y, w, h, id, text) -end - -local function S_button_exit(x, y, w, h, id, ...) - return f_button_exit(x, y, w, h, id, attrans(...)) +local function f_button_exit(x, y, w, id, text) + return sformat("button_exit[%f,%f;%f,0.75;%s;%s]", x, y, w, id, text) end local function f_dropdown(x, y, w, id, entries, sel, indexed) - return sformat("dropdown[%f,%f;%f;%s;%s;%d%s]", + return sformat("dropdown[%f,%f;%f,0.75;%s;%s;%d%s]", x, y, w, id, make_list(entries), sel or 1, indexed and ";true" or "") @@ -56,11 +52,15 @@ local function f_image_button_exit(x, y, w, h, texture, id, label) end local function f_label(x, y, text) - return sformat("label[%f,%f;%s]", x, y, fsescape(text)) + return sformat("label[%f,%f;%s]", x, y+0.25, fsescape(text)) +end + +local function f_field_aux(x, y, w, id, default) + return sformat("field[%f,%f;%f,0.75;%s;;%s]", x, y, w, id, default) end -local function S_label(x, y, ...) - return f_label(x, y, attrans(...)) +local function f_field(x, y, w, id, label, default) + return f_label(x, y-0.5, label) .. f_field_aux(x, y, w, id, default) end local function f_tabheader(x, y, w, h, id, entries, sel, transparent, border) @@ -95,16 +95,17 @@ end return { button = f_button, - S_button = S_button, + S_button = S_wrapper(f_button, 5), checkbox = f_checkbox, - S_checkbox = S_checkbox, + S_checkbox = S_wrapper(f_checkbox, 5), button_exit = f_button_exit, - S_button_exit = S_button_exit, + S_button_exit = S_wrapper(f_button_exit, 5), dropdown = f_dropdown, + field = f_field, image_button = f_image_button, image_button_exit = f_image_button_exit, label = f_label, - S_label = S_label, + S_label = S_wrapper(f_label, 3), tabheader = f_tabheader, textlist = f_textlist, } -- cgit v1.2.3