aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--advtrains_interlocking/aspect.lua3
-rw-r--r--advtrains_interlocking/signal_aspect_ui.lua82
-rw-r--r--advtrains_signals_japan/init.lua58
3 files changed, 91 insertions, 52 deletions
diff --git a/advtrains_interlocking/aspect.lua b/advtrains_interlocking/aspect.lua
index 1575fb1..6d6cb93 100644
--- a/advtrains_interlocking/aspect.lua
+++ b/advtrains_interlocking/aspect.lua
@@ -149,7 +149,7 @@ function signal_aspect:to_group(group)
end
end
self.group = group
- self.name = group.aspects[newidx][1]
+ self.name = gdef.aspects[newidx][1]
return self
end
@@ -169,6 +169,7 @@ function signal_aspect:adjust_distant(dst, shift)
self.dst = dst.main
else
self.dst = nil
+ return self
end
local dgdef = registered_groups[dst.group]
if dgdef then
diff --git a/advtrains_interlocking/signal_aspect_ui.lua b/advtrains_interlocking/signal_aspect_ui.lua
index d36c6bc..a81b7fe 100644
--- a/advtrains_interlocking/signal_aspect_ui.lua
+++ b/advtrains_interlocking/signal_aspect_ui.lua
@@ -58,7 +58,7 @@ local function describe_supported_aspects(suppasp, isasp)
local selid = 0
local mainasps = suppasp.main
if type(mainasps) ~= "table" then
- mainasps = {mainasps or false}
+ mainasps = {mainasps}
end
for idx, spv in ipairs(mainasps) do
if isasp and spv == rawget(isasp, "main") then
@@ -85,16 +85,24 @@ local function describe_supported_aspects(suppasp, isasp)
end
t.shunt_const = suppasp.shunt ~= nil
- entries = {}
- selid = 1
- for idx, spv in ipairs(suppasp.dst or {}) do
- if isasp and spv == (isasp.dst or false) then
- selid = idx
+ if suppasp.group then
+ local gdef = advtrains.interlocking.aspect.get_group_definition(suppasp.group)
+ if gdef then
+ t.group = suppasp.group
+ t.groupdef = gdef
+ local entries = {}
+ local selid = 1
+ for idx, name in ipairs(suppasp.name or {}) do
+ entries[idx] = gdef.aspects[name].label
+ if suppasp.group == isasp.group and name == isasp.name then
+ selid = idx
+ end
+ end
+ t.name = entries
+ t.name_current = selid
end
- entries[idx] = describe_distant_aspect(spv)
end
- t.dst = entries
- t.dst_current = selid
+
return t
end
@@ -112,35 +120,35 @@ local function make_signal_aspect_selector(suppasp, purpose, isasp)
local form = {
"formspec_version[4]",
- string.format("size[8,%f]", ({5.75, 9.25})[formmode]),
+ string.format("size[8,%f]", ({5.75, 10.75})[formmode]),
F.S_label(0.5, 0.5, "Select signal aspect"),
}
+ local h0 = ({0, 1.5})[formmode]
+ form[#form+1] = F.S_label(0.5, 1.5+h0, "Main aspect")
+ form[#form+1] = F.S_label(0.5, 3+h0, "Shunt aspect")
+ form[#form+1] = F.S_button_exit(0.5, 4.5+h0, 7, "asp_save", "Save 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
-
- form[#form+1] = F.S_label(0.5, 1.5, "Main aspect")
- if formmode == 1 then
form[#form+1] = F.field(0.5, 2, 7, "asp_mainval", "", t.main_string)
- else
- form[#form+1] = F.dropdown(0.5, 2, 7, "asp_mainsel", t.main, t.main_current, true)
+ elseif formmode == 2 then
+ if t.group then
+ form[#form+1] = F.S_label(0.5, 1.5, "Signal aspect group: @1", t.groupdef.label)
+ form[#form+1] = F.dropdown(0.5, 2, 7, "asp_namesel", t.name, t.name_current, true)
+ else
+ form[#form+1] = F.S_label(0.5, 1.5, "This signal does not belong to a signal aspect group.")
+ form[#form+1] = F.S_label(0.5, 2, "You can not use a predefined signal aspect.")
+ end
+ form[#form+1] = F.S_label(0.5, 1, "Signal at @1", minetest.pos_to_string(pos))
+ form[#form+1] = F.dropdown(0.5, 3.5, 7, "asp_mainsel", t.main, t.main_current, true)
+ form[#form+1] = advtrains.interlocking.make_ip_formspec_component(pos, 0.5, 7, 7)
+ form[#form+1] = advtrains.interlocking.make_short_dst_formspec_component(pos, 0.5, 8.5, 7)
end
- form[#form+1] = F.S_label(0.5, 3, "Shunt aspect")
if formmode == 2 and t.shunt_const then
- form[#form+1] = F.label(0.5, 3.5, t.shunt[t.shunt_current])
- form[#form+1] = F.S_label(0.5, 4, "The shunt aspect cannot be changed.")
+ form[#form+1] = F.label(0.5, 3.5+h0, t.shunt[t.shunt_current])
+ form[#form+1] = F.S_label(0.5, 4+h0, "The shunt aspect cannot be changed.")
else
- form[#form+1] = F.dropdown(0.5, 3.5, 7, "asp_shunt", t.shunt, t.shunt_current, true)
- end
-
- form[#form+1] = F.S_button_exit(0.5, 4.5, 7, "asp_save", "Save signal aspect")
-
- if formmode == 2 then
- form[#form+1] = advtrains.interlocking.make_ip_formspec_component(pos, 0.5, 5.5, 7)
- form[#form+1] = advtrains.interlocking.make_short_dst_formspec_component(pos, 0.5, 7, 7)
+ form[#form+1] = F.dropdown(0.5, 3.5+h0, 7, "asp_shunt", t.shunt, t.shunt_current, true)
end
return table.concat(form)
@@ -186,12 +194,22 @@ local function usebool(sup, val, free)
end
local function get_aspect_from_formspec(suppasp, fields, psl)
+ local namei, group, name = tonumber(fields.asp_namesel), suppasp.group, nil
+ local gdef = advtrains.interlocking.aspect.get_group_definition(group)
+ if gdef then
+ local names = suppasp.name or {}
+ name = names[namei] or names[names]
+ else
+ group = nil
+ end
local maini = tonumber(fields.asp_mainsel)
- local main = suppasp.main[(maini or 0)-1]
+ local main = (suppasp.main or {})[(maini or 0)-1]
if not maini then
local mainval = fields.asp_mainval
if mainval == "-1" then
main = -1
+ elseif mainval == "x" then
+ main = false
elseif string.match(mainval, "^%d+$") then
main = tonumber(mainval)
else
@@ -209,11 +227,13 @@ local function get_aspect_from_formspec(suppasp, fields, psl)
if proceed_as_main == nil then
proceed_as_main = shunti == 3
end
- return {
+ return advtrains.interlocking.aspect {
main = main,
shunt = shunt,
proceed_as_main = proceed_as_main,
info = {},
+ name = name,
+ group = group,
}
end
diff --git a/advtrains_signals_japan/init.lua b/advtrains_signals_japan/init.lua
index 7d8dc1e..84373a9 100644
--- a/advtrains_signals_japan/init.lua
+++ b/advtrains_signals_japan/init.lua
@@ -275,6 +275,34 @@ minetest.register_node("advtrains_signals_japan:pole_0", {
drop = "advtrains_signals_japan:pole_0",
})
+advtrains.interlocking.aspect.register_group {
+ name = "advtrains_signals_japan:5a",
+ label = S("Japanese signal"),
+ aspects = {
+ danger = {
+ label = S"Danger (halt)",
+ main = 0,
+ },
+ restrictedspeed = {
+ label = S"Restricted speed",
+ },
+ caution = {
+ label = S"Caution",
+ },
+ reducedspeed = {
+ label = S"Reduced speed",
+ },
+ clear = {
+ label = S"Clear (proceed)",
+ },
+ "clear",
+ "reducedspeed",
+ "caution",
+ "restrictedspeed",
+ "danger",
+ }
+}
+
local sigdefs = {}
local lightcolors = {
red = "red",
@@ -282,22 +310,9 @@ local lightcolors = {
yellow = "orange",
distant = "purple",
}
-local aspnames = {
- danger = "Danger (halt)",
- restrictedspeed = "Restricted speed",
- caution = "Caution",
- reducedspeed = "Reduced speed",
- clear = "Clear (proceed)",
-}
local function process_signal(name, sigdata, isrpt)
- local typename = "advtrains_signals_japan:" .. name
- local groupdef = {}
- groupdef.name = typename
- groupdef.aspects = {}
- groupdef.label = S(string.format("Japanese signal (type %s)", string.upper(name)))
local def = {}
local tx = {}
- def.typename = typename
def.textures = tx
def.desc = sigdata.desc
def.isdst = isrpt
@@ -307,6 +322,7 @@ local function process_signal(name, sigdata, isrpt)
lightcount = lightcount+1
end
def.lightcount = lightcount
+ def.suppasp_names = {}
for idx, asp in ipairs(sigdata.aspects) do
local aspname = asp.name
local tt = {
@@ -322,8 +338,7 @@ local function process_signal(name, sigdata, isrpt)
tt[#tt+1] = string.format("0,%d=(advtrains_hud_bg.png\\^[colorize\\:%s)", lightcount-1, color)
end
tx[aspname] = table.concat(tt, ":")
- groupdef.aspects[idx] = {asp.name}
- groupdef.aspects[asp.name] = {label = S(aspnames[asp.name]), main = asp.main, proceed_as_main = true}
+ def.suppasp_names[idx] = aspname
end
local invimg = {
string.format("[combine:%dx%d", lightcount*4+1, lightcount*4+1),
@@ -337,9 +352,6 @@ local function process_signal(name, sigdata, isrpt)
invimg[lightcount+2] = string.format("%d,%d=(advtrains_hud_bg.png\\^[resize\\:3x3\\^[colorize\\:%s)", 2*lightcount-1, 4*lightcount-3, lightcolors.distant)
end
def.inventory_image = table.concat(invimg, ":")
- if not isrpt then
- advtrains.interlocking.aspect.register_group(groupdef)
- end
return def
end
for sigtype, sigdata in pairs {
@@ -401,11 +413,17 @@ for _, rtab in ipairs {
drop = "advtrains_signals_japan:"..sigtype.."_danger_0",
advtrains = {
supported_aspects = {
- group = siginfo.typename,
+ group = "advtrains_signals_japan:5a",
+ name = siginfo.suppasp_names,
dst_shift = siginfo.isdst and 0,
+ main = (not siginfo.isdst) and {} or false
},
get_aspect = function()
- return {group = siginfo.typename, name = asp}
+ local main
+ if siginfo.isdst then
+ main = false
+ end
+ return {group = "advtrains_signals_japan:5a", name = asp, main = main}
end,
set_aspect = function(pos, node, asp)
advtrains.ndb.swap_node(pos, {name = "advtrains_signals_japan:"..sigtype.."_"..(asp.name).."_"..rot, param2 = node.param2})