aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking/signal_aspect_ui.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains_interlocking/signal_aspect_ui.lua')
-rw-r--r--advtrains_interlocking/signal_aspect_ui.lua127
1 files changed, 28 insertions, 99 deletions
diff --git a/advtrains_interlocking/signal_aspect_ui.lua b/advtrains_interlocking/signal_aspect_ui.lua
index 186d2fe..d36c6bc 100644
--- a/advtrains_interlocking/signal_aspect_ui.lua
+++ b/advtrains_interlocking/signal_aspect_ui.lua
@@ -1,7 +1,7 @@
local F = advtrains.formspec
local players_aspsel = {}
-local function describe_t1_main_aspect(spv)
+local function describe_main_aspect(spv)
if spv == 0 then
return attrans("Danger (halt)")
elseif spv == -1 then
@@ -13,7 +13,7 @@ local function describe_t1_main_aspect(spv)
end
end
-local function describe_t1_shunt_aspect(shunt)
+local function describe_shunt_aspect(shunt)
if shunt then
return attrans("Shunting allowed")
else
@@ -21,7 +21,7 @@ local function describe_t1_shunt_aspect(shunt)
end
end
-local function describe_t1_distant_aspect(spv)
+local function describe_distant_aspect(spv)
if spv == 0 then
return attrans("Expect to stop at the next signal")
elseif spv == -1 then
@@ -33,9 +33,9 @@ local function describe_t1_distant_aspect(spv)
end
end
-advtrains.interlocking.describe_t1_main_aspect = describe_t1_main_aspect
-advtrains.interlocking.describe_t1_shunt_aspect = describe_t1_shunt_aspect
-advtrains.interlocking.describe_t1_distant_aspect = describe_t1_distant_aspect
+advtrains.interlocking.describe_main_aspect = describe_main_aspect
+advtrains.interlocking.describe_shunt_aspect = describe_shunt_aspect
+advtrains.interlocking.describe_distant_aspect = describe_distant_aspect
local function dsel(p, q, x, y)
if p == nil then
@@ -51,19 +51,23 @@ local function dsel(p, q, x, y)
end
end
-local function describe_supported_aspects_t1(suppasp, isasp)
+local function describe_supported_aspects(suppasp, isasp)
local t = {}
- local entries = {}
- local selid = 1
- for idx, spv in ipairs(suppasp.main) do
- if isasp and spv == (isasp.main or false) then
+ local entries = {attrans("Use default value")}
+ local selid = 0
+ local mainasps = suppasp.main
+ if type(mainasps) ~= "table" then
+ mainasps = {mainasps or false}
+ end
+ for idx, spv in ipairs(mainasps) do
+ if isasp and spv == rawget(isasp, "main") then
selid = idx
end
- entries[idx] = describe_t1_main_aspect(spv)
+ entries[idx+1] = describe_main_aspect(spv)
end
t.main = entries
- t.main_current = selid
+ t.main_current = selid+1
t.main_string = tostring(isasp.main)
if t.main == nil then
t.main_string = ""
@@ -83,21 +87,21 @@ local function describe_supported_aspects_t1(suppasp, isasp)
entries = {}
selid = 1
- for idx, spv in ipairs(suppasp.dst) do
+ for idx, spv in ipairs(suppasp.dst or {}) do
if isasp and spv == (isasp.dst or false) then
selid = idx
end
- entries[idx] = describe_t1_distant_aspect(spv)
+ entries[idx] = describe_distant_aspect(spv)
end
t.dst = entries
t.dst_current = selid
return t
end
-advtrains.interlocking.describe_supported_aspects_t1 = describe_supported_aspects_t1
+advtrains.interlocking.describe_supported_aspects = describe_supported_aspects
-local function make_signal_aspect_selector_t1(suppasp, purpose, isasp)
- local t = describe_supported_aspects_t1(suppasp, isasp)
+local function make_signal_aspect_selector(suppasp, purpose, isasp)
+ local t = describe_supported_aspects(suppasp, isasp)
local formmode = 1
local pos
@@ -142,55 +146,6 @@ local function make_signal_aspect_selector_t1(suppasp, purpose, isasp)
return table.concat(form)
end
-local function make_signal_aspect_selector_t2(suppasp, purpose, isasp)
- local def = advtrains.interlocking.aspects.get_type2_definition(suppasp.group)
- if not def then
- return nil
- end
- local formmode = 1
-
- local pos
- if type(purpose) == "table" then
- formmode = 2
- pos = purpose.pos
- end
- local form = {
- "formspec_version[4]",
- string.format("size[8,%f]", ({4.25, 10.25})[formmode]),
- F.S_label(0.5, 0.5, "Select signal aspect")
- }
- if formmode == 1 then
- form[#form+1] = F.label(0.5, 1, purpose)
- else
- form[#form+1] = F.S_label(0.5, 1, "Signal at @1", minetest.pos_to_string(pos))
- end
-
- local entries = {}
- local selid = #def.main
- if isasp then
- if isasp.type2name ~= def.main[selid].name then
- selid = 1
- end
- end
- if selid > 1 then
- selid = 2
- end
- local entries = {
- def.main[1].label,
- def.main[#def.main].label,
- }
- form[#form+1] = F.S_label(0.5, 1.5, "Signal group: @1", def.label)
- form[#form+1] = F.dropdown(0.5, 2, 7, "asp_sel", entries, selid, true)
- form[#form+1] = F.S_button_exit(0.5, 3, 7, "asp_save", "Save signal aspect")
-
- if formmode == 2 then
- form[#form+1] = advtrains.interlocking.make_ip_formspec_component(pos, 0.5, 4, 7)
- form[#form+1] = advtrains.interlocking.make_dst_formspec_component(pos, 0.5, 5.5, 7, 4.25)
- end
-
- return table.concat(form)
-end
-
function advtrains.interlocking.show_signal_aspect_selector(pname, p_suppasp, p_purpose, callback, isasp)
local suppasp = p_suppasp or {
main = {0, -1},
@@ -205,18 +160,7 @@ function advtrains.interlocking.show_signal_aspect_selector(pname, p_suppasp, p_
purpose = {pname = pname, pos = pos}
end
- local form
- if suppasp.type == 2 then
- if suppasp.dst_shift then
- if pos then
- advtrains.interlocking.show_ip_form(pos, pname)
- end
- return
- end
- form = make_signal_aspect_selector_t2(suppasp, purpose, isasp)
- else
- form = make_signal_aspect_selector_t1(suppasp, purpose, isasp)
- end
+ local form = make_signal_aspect_selector(suppasp, purpose, isasp)
if not form then
return
end
@@ -241,9 +185,9 @@ local function usebool(sup, val, free)
end
end
-local function get_aspect_from_formspec_t1(suppasp, fields, psl)
+local function get_aspect_from_formspec(suppasp, fields, psl)
local maini = tonumber(fields.asp_mainsel)
- local main = suppasp.main[maini]
+ local main = suppasp.main[(maini or 0)-1]
if not maini then
local mainval = fields.asp_mainval
if mainval == "-1" then
@@ -253,6 +197,8 @@ local function get_aspect_from_formspec_t1(suppasp, fields, psl)
else
main = nil
end
+ elseif maini <= 1 then
+ main = nil
end
local shunti = tonumber(fields.asp_shunt)
local shunt = suppasp.shunt
@@ -271,19 +217,6 @@ local function get_aspect_from_formspec_t1(suppasp, fields, psl)
}
end
-local function get_aspect_from_formspec_t2(suppasp, fields, psl)
- local sel = tonumber(fields.asp_sel)
- local def = advtrains.interlocking.aspects.get_type2_definition(suppasp.group)
- if not (sel and def) then
- return
- end
- if sel ~= 1 then
- sel = #def.main
- end
- local asp = advtrains.interlocking.aspects.type2_to_type1(suppasp, sel)
- return asp
-end
-
minetest.register_on_player_receive_fields(function(player, formname, fields)
local pname = player:get_player_name()
local psl = players_aspsel[pname]
@@ -292,11 +225,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local suppasp = psl.suppasp
if fields.asp_save then
local asp
- if suppasp.type == 2 then
- asp = get_aspect_from_formspec_t2(suppasp, fields, psl)
- else
- asp = get_aspect_from_formspec_t1(suppasp, fields, psl)
- end
+ asp = get_aspect_from_formspec(suppasp, fields, psl)
if asp then
psl.callback(pname, asp)
end