From e2a844f5bfb1b8e88951ddb66ed9d0ae0d40256b Mon Sep 17 00:00:00 2001 From: orwell96 Date: Mon, 19 Nov 2018 23:53:42 +0100 Subject: Permit basic signal aspect setting (basically only usable with Ks signals, because they're the only signals supporting slow move and/or shunt move --- advtrains_interlocking/routesetting.lua | 3 +- advtrains_interlocking/signal_api.lua | 120 +++++++++++++++++++++++++++++++- advtrains_interlocking/tcb_ts_ui.lua | 15 +++- 3 files changed, 135 insertions(+), 3 deletions(-) (limited to 'advtrains_interlocking') diff --git a/advtrains_interlocking/routesetting.lua b/advtrains_interlocking/routesetting.lua index f13fcea..1edc631 100644 --- a/advtrains_interlocking/routesetting.lua +++ b/advtrains_interlocking/routesetting.lua @@ -51,6 +51,7 @@ function ilrs.set_route(signal, route, try) return false, trsn, cbts, cblk end end + -- we start at the tc designated by signal local c_sigd = signal @@ -122,7 +123,7 @@ function ilrs.set_route(signal, route, try) } if c_tcbs.signal then c_tcbs.route_committed = true - c_tcbs.aspect = asp_generic_free + c_tcbs.aspect = route.aspect or asp_generic_free c_tcbs.route_origin = signal advtrains.interlocking.update_signal_aspect(c_tcbs) end diff --git a/advtrains_interlocking/signal_api.lua b/advtrains_interlocking/signal_api.lua index 8d78709..4d75f28 100644 --- a/advtrains_interlocking/signal_api.lua +++ b/advtrains_interlocking/signal_api.lua @@ -102,7 +102,6 @@ advtrains = { }, shunt = { free = , - proceed_as_main = , }, info = { call_on = , @@ -303,6 +302,18 @@ function advtrains.interlocking.signal_get_aspect(pos) return nil end +-- Returns the "supported_aspects" of the signal at position, as returned by the nodedef. +-- returns nil when there's no signal at the position +function advtrains.interlocking.signal_get_supported_aspects(pos) + local node=advtrains.ndb.get_node(pos) + local ndef=minetest.registered_nodes[node.name] + if ndef and ndef.advtrains and ndef.advtrains.supported_aspects then + local asp = ndef.advtrains.supported_aspects + return asp + end + return nil +end + local players_assign_ip = {} -- shows small info form for signal IP state/assignment @@ -413,3 +424,110 @@ minetest.register_on_punchnode(function(pos, node, player, pointed_thing) players_assign_ip[pname] = nil end end) + + +--== aspect selector ==-- + +local players_aspsel = {} + +--[[ +suppasp: "supported_aspects" table +purpose: form title string +callback: func(pname, aspect) called on form submit +]] +function advtrains.interlocking.show_signal_aspect_selector(pname, p_suppasp, p_purpose, callback, p_isasp) + local suppasp = p_suppasp or { + main = {}, dst = {}, shunt = {}, info = {}, + } + local purpose = p_purpose or "" + local isasp = p_isasp and fillout_aspect(p_isasp) + + local form = "size[7,5]label[0.5,0.5;Select Signal Aspect:]" + form = form.."label[0.5,1;"..purpose.."]" + + form = form.."label[0.5,1.5;== Main Signal ==]" + if suppasp.main.free == nil then + local st = 2 + if isasp and not isasp.main.free then st=1 end + form = form.."dropdown[0.5,2;2;main_free;danger,free;"..st.."]" + end + if suppasp.main.speed then + local selid = 1 + if isasp and isasp.main.speed then + for idx, spv in ipairs(suppasp.main.speed) do + if spv == isasp.main.speed then + selid = idx + break + end + end + end + form = form.."label[2.3,1;Speed:]" + form = form.."dropdown[3,2;2;main_speed;"..table.concat(suppasp.main.speed, ",")..";"..selid.."]" + end + + form = form.."label[0.5,3;== Shunting ==]" + if suppasp.shunt.free == nil then + local st = 1 + if isasp and isasp.shunt.free then st=2 end + form = form.."dropdown[0.5,3.5;2;shunt_free;---,allowed;"..st.."]" + end + + form = form.."button_exit[0.5,4.5; 5,1;save;OK]" + + local token = advtrains.random_id() + + minetest.show_formspec(pname, "at_il_sigaspdia_"..token, form) + + minetest.after(1, function() + players_aspsel[pname] = { + suppasp = suppasp, + callback = callback, + token = token, + } + end) +end + +local function usebool(sup, val, free) + if sup == nil then + return val==free + else + return sup + end +end +local function usespeed(sup, val) + if sup then + return tonumber(val) + else + return nil + end +end + +-- TODO use non-hacky way to parse outputs + +minetest.register_on_player_receive_fields(function(player, formname, fields) + local pname = player:get_player_name() + local psl = players_aspsel[pname] + if psl then + if formname == "at_il_sigaspdia_"..psl.token then + if fields.save then + local asp = { + main = { + free = usebool(psl.suppasp.main.free, fields.main_free, "free"), + speed = usespeed(psl.suppasp.main.speed, fields.main_speed), + }, + dst = { + free = true, speed = -1, + }, + shunt = { + free = usebool(psl.suppasp.shunt.free, fields.shunt_free, "allowed"), + }, + info = {} + } + psl.callback(pname, asp) + end + else + players_aspsel[pname] = nil + end + end + +end) diff --git a/advtrains_interlocking/tcb_ts_ui.lua b/advtrains_interlocking/tcb_ts_ui.lua index 203e0b1..c149a44 100644 --- a/advtrains_interlocking/tcb_ts_ui.lua +++ b/advtrains_interlocking/tcb_ts_ui.lua @@ -577,7 +577,8 @@ function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte) form = form.."button[0.5,7;2,1;dsproute;Show]" if hasprivs then form = form.."button[2.5,7;1,1;delroute;Delete]" - form = form.."button[3.5,7;2,1;editroute;Edit]" + form = form.."button[3.5,7;1,1;editroute;Rename]" + form = form.."button[4.5,7;1,1;asproute;Aspect]" end end if hasprivs then @@ -660,6 +661,18 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.show_formspec(pname, formname.."_renroute_"..sel_rte, "field[name;Enter new route name;"..rte.name.."]") return end + if fields.asproute and hasprivs then + local rte = tcbs.routes[sel_rte] + local suppasp = advtrains.interlocking.signal_get_supported_aspects(tcbs.signal) + + local callback = function(pname, asp) + rte.aspect = asp + advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte) + end + + advtrains.interlocking.show_signal_aspect_selector(pname, suppasp, rte.name, callback, rte.aspect) + return + end if fields.delroute and hasprivs then table.remove(tcbs.routes, sel_rte) sel_rte = nil -- cgit v1.2.3