diff options
author | 1F616EMO <root@1f616emo.xyz> | 2024-09-30 19:37:18 +0800 |
---|---|---|
committer | orwell <orwell@bleipb.de> | 2024-11-09 22:18:14 +0100 |
commit | d83d06ecdd8a23e5c36826f150c72d0ff8b644f9 (patch) | |
tree | ab86d9ba64ee5f0419bb2a17e2caa03304fded63 | |
parent | 8b9eb2a96d9c1c425ff9014fdf27c82526d8376b (diff) | |
download | advtrains-d83d06ecdd8a23e5c36826f150c72d0ff8b644f9.tar.gz advtrains-d83d06ecdd8a23e5c36826f150c72d0ff8b644f9.tar.bz2 advtrains-d83d06ecdd8a23e5c36826f150c72d0ff8b644f9.zip |
Add "New From Route" function into route editing form
This patch allows creating new routes based on what was done on another route. This can be useful to fix minor mistakes on a route, or to create similar routes. Note that the route buffer created "steps back" one section, but with turnouts kept.
The new button is placed above the "Save ARS" button - I know it is ugly, so please suggest a better place for it.
-rw-r--r-- | advtrains_interlocking/route_prog.lua | 27 | ||||
-rw-r--r-- | advtrains_interlocking/route_ui.lua | 15 |
2 files changed, 32 insertions, 10 deletions
diff --git a/advtrains_interlocking/route_prog.lua b/advtrains_interlocking/route_prog.lua index 6abe431..e8f5e8e 100644 --- a/advtrains_interlocking/route_prog.lua +++ b/advtrains_interlocking/route_prog.lua @@ -214,19 +214,32 @@ end local player_rte_prog = {} -function advtrains.interlocking.init_route_prog(pname, sigd) +function advtrains.interlocking.init_route_prog(pname, sigd, default_route) if not minetest.check_player_privs(pname, "interlocking") then minetest.chat_send_player(pname, "Insufficient privileges to use this!") return end - player_rte_prog[pname] = { + local rp = { origin = sigd, - route = { - name = "PROG["..pname.."]", - }, - tmp_lcks = {}, } - advtrains.interlocking.visualize_route(sigd, player_rte_prog[pname].route, "prog_"..pname, player_rte_prog[pname].tmp_lcks, pname) + if default_route then + rp.route = table.copy(default_route) + + -- "Step back one section", but keeping turnouts + local last_route = rp.route[#rp.route] + if last_route then + rp.tmp_lcks = last_route.locks + rp.route[#rp.route] = nil + end + rp.route.name = "PROG["..pname.."]" + else + rp.route = { + name = "PROG["..pname.."]" + } + rp.tmp_lcks = {} + end + player_rte_prog[pname] = rp + advtrains.interlocking.visualize_route(sigd, rp.route, "prog_"..pname, rp.tmp_lcks, pname) minetest.chat_send_player(pname, "Route programming mode active. Punch TCBs to add route segments, punch turnouts to lock them.") end diff --git a/advtrains_interlocking/route_ui.lua b/advtrains_interlocking/route_ui.lua index 1999941..a8fee83 100644 --- a/advtrains_interlocking/route_ui.lua +++ b/advtrains_interlocking/route_ui.lua @@ -24,7 +24,7 @@ function atil.show_route_edit_form(pname, sigd, routeid) local route = tcbs.routes[routeid] if not route then return end - local form = "size[9,10]label[0.5,0.2;Route overview]" + local form = "size[9,11]label[0.5,0.2;Route overview]" form = form.."field[0.8,1.2;6.5,1;name;Route name;"..minetest.formspec_escape(route.name).."]" form = form.."button[7.0,0.9;1.5,1;setname;Set]" @@ -85,11 +85,13 @@ function atil.show_route_edit_form(pname, sigd, routeid) 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]" + + form = form.."button[5.5,7;3,1;newfrom;New From Route]" --atdebug(route.ars) form = form.."style[ars;font=mono]" - form = form.."textarea[0.8,7.3;5,3;ars;ARS Rule List;"..atil.ars_to_text(route.ars).."]" - form = form.."button[5.5,7.23;3,1;savears;Save ARS List]" + form = form.."textarea[0.8,8.3;5,3;ars;ARS Rule List;"..atil.ars_to_text(route.ars).."]" + form = form.."button[5.5,8.23;3,1;savears;Save ARS List]" minetest.show_formspec(pname, "at_il_routeedit_"..minetest.pos_to_string(sigd.p).."_"..sigd.s.."_"..routeid, form) @@ -139,6 +141,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) table.remove(tcbs.routes, routeid) advtrains.interlocking.show_signalling_form(sigd, pname) end + + if fields.newfrom then + advtrains.interlocking.init_route_prog(pname, sigd, route) + minetest.close_formspec(pname, formname) + tcbs.ars_ignore_next = nil + return + end if fields.ars and fields.savears then route.ars = atil.text_to_ars(fields.ars) |