aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking/route_ui.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains_interlocking/route_ui.lua')
-rw-r--r--advtrains_interlocking/route_ui.lua83
1 files changed, 64 insertions, 19 deletions
diff --git a/advtrains_interlocking/route_ui.lua b/advtrains_interlocking/route_ui.lua
index a8fee83..478e8dc 100644
--- a/advtrains_interlocking/route_ui.lua
+++ b/advtrains_interlocking/route_ui.lua
@@ -3,6 +3,7 @@
local atil = advtrains.interlocking
local ildb = atil.db
+local F = advtrains.formspec
-- TODO duplicate
local lntrans = { "A", "B" }
@@ -33,7 +34,7 @@ function atil.show_route_edit_form(pname, sigd, routeid)
local function itab(t)
tab[#tab+1] = minetest.formspec_escape(string.gsub(t, ",", " "))
end
- itab("TCB "..sigd_to_string(sigd).." ("..tcbs.signal_name..") Route #"..routeid)
+ itab("("..(tcbs.signal_name or "+")..") Route #"..routeid)
-- this code is partially copy-pasted from routesetting.lua
-- we start at the tc designated by signal
@@ -56,13 +57,14 @@ function atil.show_route_edit_form(pname, sigd, routeid)
c_rseg = route[i]
c_lckp = {}
- itab(""..i.." Entry "..sigd_to_string(c_sigd).." -> Sec. "..(c_ts and c_ts.name or "-").." -> Exit "..(c_rseg.next and sigd_to_string(c_rseg.next) or "END"))
+ itab(""..i.." "..sigd_to_string(c_sigd))
+ itab("= "..(c_ts and c_ts.name or "-").." =")
if c_rseg.locks then
for pts, state in pairs(c_rseg.locks) do
local pos = minetest.string_to_pos(pts)
- itab(" Lock: "..pts.." -> "..state)
+ itab("L "..pts.." -> "..state)
if not advtrains.is_passive(pos) then
itab("-!- No passive component at "..pts..". Please reconfigure route!")
break
@@ -75,17 +77,43 @@ function atil.show_route_edit_form(pname, sigd, routeid)
end
if c_sigd then
local e_tcbs = ildb.get_tcbs(c_sigd)
- itab("Route end: "..sigd_to_string(c_sigd).." ("..(e_tcbs and e_tcbs.signal_name or "-")..")")
+ local signame = "-"
+ if e_tcbs and e_tcbs.signal then signame = e_tcbs.signal_name or "+" end
+ itab("E "..sigd_to_string(c_sigd).." ("..signame..")")
else
- itab("Route ends on dead-end")
+ itab("E (none)")
end
- form = form.."textlist[0.5,2;7.75,3.9;rtelog;"..table.concat(tab, ",").."]"
+ form = form.."textlist[0.5,2;3.5,3.9;rtelog;"..table.concat(tab, ",").."]"
- form = form.."button[0.5,6;3,1;back;<<< Back to signal]"
- form = form.."button[4.5,6;2,1;aspect;Signal Aspect]"
- form = form.."button[6.5,6;2,1;delete;Delete Route]"
-
+ -- to the right of rtelog a signal aspect selection for the start signal
+ form = form..F.label(4.5, 2, "Signal Aspect:")
+ -- main aspect list
+ local signalpos = tcbs.signal
+ local ndef = signalpos and advtrains.ndb.get_ndef(signalpos)
+ if ndef and ndef.advtrains and ndef.advtrains.main_aspects then
+ local entries = { "<Default Aspect>" }
+ local sel = 1
+ for i, mae in ipairs(ndef.advtrains.main_aspects) do
+ entries[i+1] = mae.description
+ if mae.name == route.main_aspect then
+ sel = i+1
+ end
+ end
+ form = form..F.dropdown(4.5, 3.0, 4, "sa_main_aspect", entries, sel, true)
+ -- checkbox for assign distant signal
+ form = form..string.format("checkbox[4.5,4.0;sa_distant;Announce distant signal;%s]", route.assign_dst)
+ end
+
+ form = form.."button[0.5,6;1,1;prev;<<<]"
+ form = form.."button[1.5,6;1,1;back;Back]"
+ form = form.."button[2.5,6;1,1;next;>>>]"
+
+
+ if route.smartroute_generated then
+ form = form.."button[3.5,6;2,1;noautogen;Clr Autogen]"
+ end
+ form = form.."button[5.5,6;3,1;delete;Delete Route]"
form = form.."button[5.5,7;3,1;newfrom;New From Route]"
--atdebug(route.ars)
@@ -120,21 +148,38 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local route = tcbs.routes[routeid]
if not route then return end
+ if fields.prev then
+ atil.show_route_edit_form(pname, sigd, routeid - 1)
+ return
+ end
+ if fields.next then
+ atil.show_route_edit_form(pname, sigd, routeid + 1)
+ return
+ end
+
if fields.setname and fields.name then
route.name = fields.name
end
- if fields.aspect then
- local suppasp = advtrains.interlocking.signal_get_supported_aspects(tcbs.signal)
-
- local callback = function(pname, asp)
- route.aspect = asp
- advtrains.interlocking.show_route_edit_form(pname, sigd, routeid)
+ if fields.sa_main_aspect then
+ local idx = tonumber(fields.sa_main_aspect)
+ route.main_aspect = nil
+ if idx > 1 then
+ local signalpos = tcbs.signal
+ local ndef = signalpos and advtrains.ndb.get_ndef(signalpos)
+ if ndef and ndef.advtrains and ndef.advtrains.main_aspects then
+ route.main_aspect = ndef.advtrains.main_aspects[idx - 1].name
+ end
end
-
- advtrains.interlocking.show_signal_aspect_selector(pname, suppasp, route.name, callback, route.aspect or advtrains.interlocking.GENERIC_FREE)
- return
end
+ if fields.sa_distant then
+ route.assign_dst = minetest.is_yes(fields.sa_distant)
+ end
+
+ if fields.noautogen then
+ route.smartroute_generated = nil
+ end
+
if fields.delete then
-- if something set the route in the meantime, make sure this doesn't break.
atil.route.update_route(sigd, tcbs, nil, true)