aboutsummaryrefslogtreecommitdiff
path: root/games/devtest/mods/util_commands
diff options
context:
space:
mode:
authorGaƫl C <gael-de-sailly@netc.eu>2022-02-08 19:30:49 +0100
committerGitHub <noreply@github.com>2022-02-08 19:30:49 +0100
commit0dd8e8c2427f12a8a7d080132e9c588c66baa41b (patch)
treef9558273ac88d84ad9d1393524f2463b4b27d0d7 /games/devtest/mods/util_commands
parentb9ee29a9456a66c3670b2a1389878e0896395f58 (diff)
Noise params serialization fixup
Diffstat (limited to 'games/devtest/mods/util_commands')
0 files changed, 0 insertions, 0 deletions
'>98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
local F = advtrains.formspec
local players_aspsel = {}

local function describe_t1_main_aspect(spv)
	if spv == 0 then
		return attrans("Danger (halt)")
	elseif spv == -1 then
		return attrans("Continue at maximum speed")
	elseif not spv then
		return attrans("Continue with current speed limit")
	else
		return attrans("Continue with the speed limit of @1", tostring(spv))
	end
end

local function describe_t1_shunt_aspect(shunt)
	if shunt then
		return attrans("Shunting allowed")
	else
		return attrans("No shunting")
	end
end

local function describe_t1_distant_aspect(spv)
	if spv == 0 then
		return attrans("Expect to stop at the next signal")
	elseif spv == -1 then
		return attrans("Expect to continue at maximum speed")
	elseif not spv then
		return attrans("No distant signal information")
	else
		return attrans("Expect to continue with a speed limit of @1", tostring(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

local function describe_supported_aspects_t1(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
			selid = idx
		end
		entries[idx] = describe_t1_main_aspect(spv)
	end
	t.main = entries
	t.main_current = selid

	if suppasp.shunt == nil then
		selid = 1
		if isasp and isasp.shunt then
			selid = 2
		end
		entries = {
			describe_t1_shunt_aspect(false),
			describe_t1_shunt_aspect(true),
		}
		t.shunt = entries
		t.shunt_current = selid
	end

	entries = {}
	selid = 1
	for idx, spv in ipairs(suppasp.dst) do
		if isasp and spv == (isasp.dst or false) then
			selid = idx
		end
		entries[idx] = describe_t1_distant_aspect(spv)
	end
	t.dst = entries
	t.dst_current = selid
	return t
end

advtrains.interlocking.describe_supported_aspects_t1 = describe_supported_aspects_t1

local signal_tabheader_map = {}

local function make_signal_formspec_tabheader(pname, pos, width, selid)
	signal_tabheader_map[pname] = pos
	local options = {
		attrans("Signal aspect"),
		attrans("Influence point"),
		attrans("Distant signalling"),
	}
	return F.tabheader(0, 0, nil, nil, "signal_tab", options, selid)
end

local function handle_signal_formspec_tabheader_fields(pname, fields)
	local n = tonumber(fields.signal_tab)
	local pos = signal_tabheader_map[pname]
	if not (n and pos) then
		return false
	end
	if n == 1 then
		local node = advtrains.ndb.get_node(pos)
		advtrains.interlocking.show_signal_form(pos, node, pname)
	elseif n == 2 then
		advtrains.interlocking.show_ip_form(pos, pname)
	elseif n == 3 then
		advtrains.interlocking.show_distant_signal_form(pos, pname)
	end
	return true
end

advtrains.interlocking.make_signal_formspec_tabheader = make_signal_formspec_tabheader
advtrains.interlocking.handle_signal_formspec_tabheader_fields = handle_signal_formspec_tabheader_fields

local function make_signal_aspect_selector_t1(suppasp, purpose, isasp)
	local form = {"size[7,7.25]"}
	local t = describe_supported_aspects_t1(suppasp, isasp)
	if type(purpose) == "table" then
		form[#form+1] = make_signal_formspec_tabheader(purpose.pname, purpose.pos, 7, 1)
		purpose = ""
	end
	form[#form+1] = F.S_label(0.5, 0.5, "Select signal aspect")
	form[#form+1] = F.label(0.5, 1, purpose)

	form[#form+1] = F.S_label(0.5, 1.5, "Main aspect")
	form[#form+1] = F.dropdown(0.5, 2, 6, "main", t.main, t.main_current, true)

	form[#form+1] = F.S_label(0.5, 3, "Shunt aspect")
	if t.shunt then
		form[#form+1] = F.dropdown(0.5, 3.5, 6, "shunt_free", t.shunt, t.shunt_current, true)
	else
		form[#form+1] = F.S_label(0.5, 3.5, "The shunt aspect cannot be changed")
	end

	form[#form+1] = F.S_label(0.5, 4.5, "Distant aspect")
	form[#form+1] = F.dropdown(0.5, 5, 6, "dst", t.dst, t.dst_current, true)

	form[#form+1] = F.S_button_exit(0.5, 6, 6, 1, "save", "Save signal aspect")
	return table.concat(form)
end

local function make_signal_aspect_selector_t2(suppasp, purpose, isasp)
	local form = {"size[7,4]"}
	local def = advtrains.interlocking.aspects.get_type2_definition(suppasp.group)
	if not def then
		return nil
	end
	if type(purpose) == "table" then
		form[#form+1] = make_signal_formspec_tabheader(purpose.pname, purpose.pos, 7, 1)
		purpose = ""
	end
	form[#form+1] = F.S_label(0.5, 0.5, "Select signal aspect")
	form[#form+1] = F.label(0.5, 1, purpose)

	local entries = {}
	local selid = 1
	for idx, spv in ipairs(def.main) do
		if isasp and isasp.type2name == spv.name then
			selid = idx
		end
		entries[idx] = spv.label
	end
	form[#form+1] = F.dropdown(0.5, 1.5, 6, "asp", entries, selid, true)
	form[#form+1] = F.S_button_exit(0.5, 2.5, 6, 1, "save", "Save signal aspect")
	return table.concat(form)
end

function advtrains.interlocking.show_signal_aspect_selector(pname, p_suppasp, p_purpose, callback, isasp)