Skip to content

Commit 1306375

Browse files
committed
Allow unlimited number of cabview controls
1 parent a16da1f commit 1306375

File tree

5 files changed

+41
-231
lines changed

5 files changed

+41
-231
lines changed

Source/Documentation/Manual/features-rollingstock.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,8 +1680,8 @@ interface), which can include a (touch screen) display and buttons.
16801680
Being the display fields and icons and the buttons specific of every TCS,
16811681
a set of generic cabview controls are available, which can be customized
16821682
within the TCS script.
1683-
More precisely 48 generic cabview controls, named from ORTS_TCS1 to ORTS_TCS48
1684-
are available. All 48 may be used as two state or multistate controls,
1683+
Generic cabview controls, named ORTS_TCS1, ORTS_TCS2, and so on
1684+
are available. All of them may be used as two state or multistate controls,
16851685
like e.g.::
16861686

16871687
MultiStateDisplay (
@@ -1725,7 +1725,7 @@ like e.g.::
17251725
single: Style
17261726
single: MouseControl
17271727

1728-
Each one of the first 32 can be also used as Two-state commands/displays, like e.g.::
1728+
They can be also used as Two-state commands/displays, like e.g.::
17291729

17301730
TwoState (
17311731
Type ( ORTS_TCS7 TWO_STATE )
@@ -1743,8 +1743,8 @@ The commands are received asynchronously by the script through this method:
17431743
public override void HandleEvent(TCSEvent evt, string message)
17441744
17451745
Where evt may be TCSEvent.GenericTCSButtonPressed or TCSEvent.GenericTCSButtonReleased
1746-
and message is a string ranging from "0" to "31", which correspond to controls from
1747-
ORTS_TCS1 to ORTS_TCS32.
1746+
and message is a string representing the control number with zero-base indexing
1747+
(e.g. "5" corresponds to ORTS_TCS6).
17481748
The commands may only be triggered by the mouse, except the first two which may also be
17491749
triggered by key combinations ``Ctrl,`` (comma) and ``Ctrl.`` (period).
17501750
Here's a code excerpt from the script which manages the commands:
@@ -1805,14 +1805,14 @@ To request a display of a cabview control, method:
18051805
18061806
public Action<int, float> SetCabDisplayControl;
18071807
1808-
has to be used, where ``int`` is the index of the cab control (from 0 to 47
1809-
corresponding from ORTS_TCS1 to ORTS_TCS48), and ``float`` is the value to be
1808+
has to be used, where ``int`` is the index of the cab control (starting from 0
1809+
which corresponds to ORTS_TCS1), and ``float`` is the value to be
18101810
used to select among frames.
18111811

18121812
When the player moves the mouse over the cabview controls linked to commands,
18131813
the name of such control shortly appears on the display, like e.g. "speedometer",
18141814
as a reminder to the player.
1815-
In case of these generic commands, strings from "ORTS_TCS1" to "ORTS_TCS32" would
1815+
In case of these generic commands, strings like "ORTS_TCS1" or "ORTS_TCS32" would
18161816
appear, which aren't mnemonic at all. Therefore following method is available:
18171817

18181818
.. code-block:: csharp

Source/Orts.Formats.Msts/CabViewFile.cs

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -215,54 +215,7 @@ public enum CABViewControlTypes
215215
ORTS_EOT_EMERGENCY_BRAKE,
216216

217217
// TCS Controls
218-
ORTS_TCS1,
219-
ORTS_TCS2,
220-
ORTS_TCS3,
221-
ORTS_TCS4,
222-
ORTS_TCS5,
223-
ORTS_TCS6,
224-
ORTS_TCS7,
225-
ORTS_TCS8,
226-
ORTS_TCS9,
227-
ORTS_TCS10,
228-
ORTS_TCS11,
229-
ORTS_TCS12,
230-
ORTS_TCS13,
231-
ORTS_TCS14,
232-
ORTS_TCS15,
233-
ORTS_TCS16,
234-
ORTS_TCS17,
235-
ORTS_TCS18,
236-
ORTS_TCS19,
237-
ORTS_TCS20,
238-
ORTS_TCS21,
239-
ORTS_TCS22,
240-
ORTS_TCS23,
241-
ORTS_TCS24,
242-
ORTS_TCS25,
243-
ORTS_TCS26,
244-
ORTS_TCS27,
245-
ORTS_TCS28,
246-
ORTS_TCS29,
247-
ORTS_TCS30,
248-
ORTS_TCS31,
249-
ORTS_TCS32,
250-
ORTS_TCS33,
251-
ORTS_TCS34,
252-
ORTS_TCS35,
253-
ORTS_TCS36,
254-
ORTS_TCS37,
255-
ORTS_TCS38,
256-
ORTS_TCS39,
257-
ORTS_TCS40,
258-
ORTS_TCS41,
259-
ORTS_TCS42,
260-
ORTS_TCS43,
261-
ORTS_TCS44,
262-
ORTS_TCS45,
263-
ORTS_TCS46,
264-
ORTS_TCS47,
265-
ORTS_TCS48,
218+
ORTS_TCS,
266219
ORTS_ETCS,
267220

268221
// Cruise Control
@@ -452,6 +405,7 @@ public class CabViewControl
452405
public int CabViewpoint;
453406

454407
public CABViewControlTypes ControlType = CABViewControlTypes.NONE;
408+
public int ControlSubtype;
455409
public CABViewControlStyles ControlStyle = CABViewControlStyles.NONE;
456410
public CABViewControlUnits Units = CABViewControlUnits.NONE;
457411

@@ -463,7 +417,16 @@ protected void ParseType(STFReader stf)
463417
stf.MustMatch("(");
464418
try
465419
{
466-
ControlType = (CABViewControlTypes)Enum.Parse(typeof(CABViewControlTypes), stf.ReadString());
420+
string name = stf.ReadString();
421+
if (name != null && name.ToUpperInvariant().StartsWith("ORTS_TCS"))
422+
{
423+
ControlType = CABViewControlTypes.ORTS_TCS;
424+
ControlSubtype = int.Parse(name.Substring(8));
425+
}
426+
else
427+
{
428+
ControlType = (CABViewControlTypes)Enum.Parse(typeof(CABViewControlTypes), name);
429+
}
467430
}
468431
catch(ArgumentException)
469432
{

Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5818,56 +5818,8 @@ public virtual float GetDataOf(CabViewControl cvc)
58185818
break;
58195819
}
58205820

5821-
// Train Control System controls
5822-
case CABViewControlTypes.ORTS_TCS1:
5823-
case CABViewControlTypes.ORTS_TCS2:
5824-
case CABViewControlTypes.ORTS_TCS3:
5825-
case CABViewControlTypes.ORTS_TCS4:
5826-
case CABViewControlTypes.ORTS_TCS5:
5827-
case CABViewControlTypes.ORTS_TCS6:
5828-
case CABViewControlTypes.ORTS_TCS7:
5829-
case CABViewControlTypes.ORTS_TCS8:
5830-
case CABViewControlTypes.ORTS_TCS9:
5831-
case CABViewControlTypes.ORTS_TCS10:
5832-
case CABViewControlTypes.ORTS_TCS11:
5833-
case CABViewControlTypes.ORTS_TCS12:
5834-
case CABViewControlTypes.ORTS_TCS13:
5835-
case CABViewControlTypes.ORTS_TCS14:
5836-
case CABViewControlTypes.ORTS_TCS15:
5837-
case CABViewControlTypes.ORTS_TCS16:
5838-
case CABViewControlTypes.ORTS_TCS17:
5839-
case CABViewControlTypes.ORTS_TCS18:
5840-
case CABViewControlTypes.ORTS_TCS19:
5841-
case CABViewControlTypes.ORTS_TCS20:
5842-
case CABViewControlTypes.ORTS_TCS21:
5843-
case CABViewControlTypes.ORTS_TCS22:
5844-
case CABViewControlTypes.ORTS_TCS23:
5845-
case CABViewControlTypes.ORTS_TCS24:
5846-
case CABViewControlTypes.ORTS_TCS25:
5847-
case CABViewControlTypes.ORTS_TCS26:
5848-
case CABViewControlTypes.ORTS_TCS27:
5849-
case CABViewControlTypes.ORTS_TCS28:
5850-
case CABViewControlTypes.ORTS_TCS29:
5851-
case CABViewControlTypes.ORTS_TCS30:
5852-
case CABViewControlTypes.ORTS_TCS31:
5853-
case CABViewControlTypes.ORTS_TCS32:
5854-
case CABViewControlTypes.ORTS_TCS33:
5855-
case CABViewControlTypes.ORTS_TCS34:
5856-
case CABViewControlTypes.ORTS_TCS35:
5857-
case CABViewControlTypes.ORTS_TCS36:
5858-
case CABViewControlTypes.ORTS_TCS37:
5859-
case CABViewControlTypes.ORTS_TCS38:
5860-
case CABViewControlTypes.ORTS_TCS39:
5861-
case CABViewControlTypes.ORTS_TCS40:
5862-
case CABViewControlTypes.ORTS_TCS41:
5863-
case CABViewControlTypes.ORTS_TCS42:
5864-
case CABViewControlTypes.ORTS_TCS43:
5865-
case CABViewControlTypes.ORTS_TCS44:
5866-
case CABViewControlTypes.ORTS_TCS45:
5867-
case CABViewControlTypes.ORTS_TCS46:
5868-
case CABViewControlTypes.ORTS_TCS47:
5869-
case CABViewControlTypes.ORTS_TCS48:
5870-
data = TrainControlSystem.CabDisplayControls[(int)cvc.ControlType - (int)CABViewControlTypes.ORTS_TCS1];
5821+
case CABViewControlTypes.ORTS_TCS:
5822+
TrainControlSystem.CabDisplayControls.TryGetValue(cvc.ControlSubtype - 1, out data);
58715823
break;
58725824

58735825
case CABViewControlTypes.ORTS_BATTERY_SWITCH_COMMAND_SWITCH:

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/TrainControlSystem.cs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ public MonitoringDevice(MonitoringDevice other)
102102
}
103103
}
104104

105-
// Constants
106-
private const int TCSCabviewControlCount = 48;
107-
private const int TCSCommandCount = 48;
108-
109105
// Properties
110106
public bool VigilanceAlarm { get; set; }
111107
public bool VigilanceEmergency { get; set; }
@@ -157,13 +153,13 @@ protected set
157153
public float MaxThrottlePercent { get; private set; } = 100f;
158154
public bool FullDynamicBrakingOrder { get; private set; }
159155

160-
public float[] CabDisplayControls = new float[TCSCabviewControlCount];
156+
public Dictionary<int, float> CabDisplayControls = new Dictionary<int, float>();
161157

162158
// generic TCS commands
163-
public bool[] TCSCommandButtonDown = new bool[TCSCommandCount];
164-
public bool[] TCSCommandSwitchOn = new bool[TCSCommandCount];
159+
public Dictionary<int, bool> TCSCommandButtonDown = new Dictionary<int, bool>();
160+
public Dictionary<int, bool> TCSCommandSwitchOn = new Dictionary<int, bool>();
165161
// List of customized control strings;
166-
public string[] CustomizedCabviewControlNames = new string[TCSCabviewControlCount];
162+
public Dictionary<int, string> CustomizedCabviewControlNames = new Dictionary<int, string>();
167163
// TODO : Delete this when SetCustomizedTCSControlString is deleted
168164
protected int NextCabviewControlNameToEdit = 0;
169165

@@ -525,16 +521,13 @@ public void Initialize()
525521
Trace.TraceWarning("SetCustomizedTCSControlString is deprecated. Please use SetCustomizedCabviewControlName.");
526522
}
527523

528-
if (NextCabviewControlNameToEdit < TCSCabviewControlCount)
529-
{
530-
CustomizedCabviewControlNames[NextCabviewControlNameToEdit] = value;
531-
}
524+
CustomizedCabviewControlNames[NextCabviewControlNameToEdit] = value;
532525

533526
NextCabviewControlNameToEdit++;
534527
};
535528
Script.SetCustomizedCabviewControlName = (id, value) =>
536529
{
537-
if (id >= 0 && id < TCSCabviewControlCount)
530+
if (id >= 0)
538531
{
539532
CustomizedCabviewControlNames[id] = value;
540533
}
@@ -934,14 +927,10 @@ private T LoadParameter<T>(string sectionName, string keyName, T defaultValue)
934927

935928
// Converts the generic string (e.g. ORTS_TCS5) shown when browsing with the mouse on a TCS control
936929
// to a customized string defined in the script
937-
public string GetDisplayString(string originalString)
930+
public string GetDisplayString(int commandIndex)
938931
{
939-
if (originalString.Length < 9) return originalString;
940-
if (originalString.Substring(0, 8) != "ORTS_TCS") return originalString;
941-
var commandIndex = Convert.ToInt32(originalString.Substring(8));
942-
return commandIndex > 0 && commandIndex <= TCSCabviewControlCount && CustomizedCabviewControlNames[commandIndex - 1] != ""
943-
? CustomizedCabviewControlNames[commandIndex - 1]
944-
: originalString;
932+
if (CustomizedCabviewControlNames.TryGetValue(commandIndex - 1, out string name)) return name;
933+
return "ORTS_TCS"+commandIndex;
945934
}
946935

947936
public void Save(BinaryWriter outf)

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 10 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,57 +2239,7 @@ public virtual int GetDrawIndex()
22392239
index = ControlDiscrete.Values.FindIndex(ind => ind > (int)data) - 1;
22402240
if (index == -2) index = ControlDiscrete.Values.Count - 1;
22412241
break;
2242-
2243-
// Train Control System controls
2244-
case CABViewControlTypes.ORTS_TCS1:
2245-
case CABViewControlTypes.ORTS_TCS2:
2246-
case CABViewControlTypes.ORTS_TCS3:
2247-
case CABViewControlTypes.ORTS_TCS4:
2248-
case CABViewControlTypes.ORTS_TCS5:
2249-
case CABViewControlTypes.ORTS_TCS6:
2250-
case CABViewControlTypes.ORTS_TCS7:
2251-
case CABViewControlTypes.ORTS_TCS8:
2252-
case CABViewControlTypes.ORTS_TCS9:
2253-
case CABViewControlTypes.ORTS_TCS10:
2254-
case CABViewControlTypes.ORTS_TCS11:
2255-
case CABViewControlTypes.ORTS_TCS12:
2256-
case CABViewControlTypes.ORTS_TCS13:
2257-
case CABViewControlTypes.ORTS_TCS14:
2258-
case CABViewControlTypes.ORTS_TCS15:
2259-
case CABViewControlTypes.ORTS_TCS16:
2260-
case CABViewControlTypes.ORTS_TCS17:
2261-
case CABViewControlTypes.ORTS_TCS18:
2262-
case CABViewControlTypes.ORTS_TCS19:
2263-
case CABViewControlTypes.ORTS_TCS20:
2264-
case CABViewControlTypes.ORTS_TCS21:
2265-
case CABViewControlTypes.ORTS_TCS22:
2266-
case CABViewControlTypes.ORTS_TCS23:
2267-
case CABViewControlTypes.ORTS_TCS24:
2268-
case CABViewControlTypes.ORTS_TCS25:
2269-
case CABViewControlTypes.ORTS_TCS26:
2270-
case CABViewControlTypes.ORTS_TCS27:
2271-
case CABViewControlTypes.ORTS_TCS28:
2272-
case CABViewControlTypes.ORTS_TCS29:
2273-
case CABViewControlTypes.ORTS_TCS30:
2274-
case CABViewControlTypes.ORTS_TCS31:
2275-
case CABViewControlTypes.ORTS_TCS32:
2276-
case CABViewControlTypes.ORTS_TCS33:
2277-
case CABViewControlTypes.ORTS_TCS34:
2278-
case CABViewControlTypes.ORTS_TCS35:
2279-
case CABViewControlTypes.ORTS_TCS36:
2280-
case CABViewControlTypes.ORTS_TCS37:
2281-
case CABViewControlTypes.ORTS_TCS38:
2282-
case CABViewControlTypes.ORTS_TCS39:
2283-
case CABViewControlTypes.ORTS_TCS40:
2284-
case CABViewControlTypes.ORTS_TCS41:
2285-
case CABViewControlTypes.ORTS_TCS42:
2286-
case CABViewControlTypes.ORTS_TCS43:
2287-
case CABViewControlTypes.ORTS_TCS44:
2288-
case CABViewControlTypes.ORTS_TCS45:
2289-
case CABViewControlTypes.ORTS_TCS46:
2290-
case CABViewControlTypes.ORTS_TCS47:
2291-
case CABViewControlTypes.ORTS_TCS48:
2292-
2242+
case CABViewControlTypes.ORTS_TCS:
22932243
// Jindrich
22942244
case CABViewControlTypes.ORTS_RESTRICTED_SPEED_ZONE_ACTIVE:
22952245
case CABViewControlTypes.ORTS_SELECTED_SPEED_MODE:
@@ -2350,7 +2300,8 @@ public bool IsMouseWithin()
23502300

23512301
public string GetControlName()
23522302
{
2353-
return (Locomotive as MSTSLocomotive).TrainControlSystem.GetDisplayString(GetControlType().ToString());
2303+
if (ControlDiscrete.ControlType == CABViewControlTypes.ORTS_TCS) return (Locomotive as MSTSLocomotive).TrainControlSystem.GetDisplayString(ControlDiscrete.ControlSubtype);
2304+
return GetControlType().ToString();
23542305
}
23552306

23562307
public string ControlLabel => Control.Label;
@@ -2567,58 +2518,13 @@ public void HandleUserInput()
25672518
break;
25682519

25692520
// Train Control System controls
2570-
case CABViewControlTypes.ORTS_TCS1:
2571-
case CABViewControlTypes.ORTS_TCS2:
2572-
case CABViewControlTypes.ORTS_TCS3:
2573-
case CABViewControlTypes.ORTS_TCS4:
2574-
case CABViewControlTypes.ORTS_TCS5:
2575-
case CABViewControlTypes.ORTS_TCS6:
2576-
case CABViewControlTypes.ORTS_TCS7:
2577-
case CABViewControlTypes.ORTS_TCS8:
2578-
case CABViewControlTypes.ORTS_TCS9:
2579-
case CABViewControlTypes.ORTS_TCS10:
2580-
case CABViewControlTypes.ORTS_TCS11:
2581-
case CABViewControlTypes.ORTS_TCS12:
2582-
case CABViewControlTypes.ORTS_TCS13:
2583-
case CABViewControlTypes.ORTS_TCS14:
2584-
case CABViewControlTypes.ORTS_TCS15:
2585-
case CABViewControlTypes.ORTS_TCS16:
2586-
case CABViewControlTypes.ORTS_TCS17:
2587-
case CABViewControlTypes.ORTS_TCS18:
2588-
case CABViewControlTypes.ORTS_TCS19:
2589-
case CABViewControlTypes.ORTS_TCS20:
2590-
case CABViewControlTypes.ORTS_TCS21:
2591-
case CABViewControlTypes.ORTS_TCS22:
2592-
case CABViewControlTypes.ORTS_TCS23:
2593-
case CABViewControlTypes.ORTS_TCS24:
2594-
case CABViewControlTypes.ORTS_TCS25:
2595-
case CABViewControlTypes.ORTS_TCS26:
2596-
case CABViewControlTypes.ORTS_TCS27:
2597-
case CABViewControlTypes.ORTS_TCS28:
2598-
case CABViewControlTypes.ORTS_TCS29:
2599-
case CABViewControlTypes.ORTS_TCS30:
2600-
case CABViewControlTypes.ORTS_TCS31:
2601-
case CABViewControlTypes.ORTS_TCS32:
2602-
case CABViewControlTypes.ORTS_TCS33:
2603-
case CABViewControlTypes.ORTS_TCS34:
2604-
case CABViewControlTypes.ORTS_TCS35:
2605-
case CABViewControlTypes.ORTS_TCS36:
2606-
case CABViewControlTypes.ORTS_TCS37:
2607-
case CABViewControlTypes.ORTS_TCS38:
2608-
case CABViewControlTypes.ORTS_TCS39:
2609-
case CABViewControlTypes.ORTS_TCS40:
2610-
case CABViewControlTypes.ORTS_TCS41:
2611-
case CABViewControlTypes.ORTS_TCS42:
2612-
case CABViewControlTypes.ORTS_TCS43:
2613-
case CABViewControlTypes.ORTS_TCS44:
2614-
case CABViewControlTypes.ORTS_TCS45:
2615-
case CABViewControlTypes.ORTS_TCS46:
2616-
case CABViewControlTypes.ORTS_TCS47:
2617-
case CABViewControlTypes.ORTS_TCS48:
2618-
int commandIndex = (int)Control.ControlType - (int)CABViewControlTypes.ORTS_TCS1;
2619-
if (ChangedValue(1) > 0 ^ Locomotive.TrainControlSystem.TCSCommandButtonDown[commandIndex])
2620-
new TCSButtonCommand(Viewer.Log, !Locomotive.TrainControlSystem.TCSCommandButtonDown[commandIndex], commandIndex);
2621-
new TCSSwitchCommand(Viewer.Log, ChangedValue(Locomotive.TrainControlSystem.TCSCommandSwitchOn[commandIndex] ? 1 : 0) > 0, commandIndex);
2521+
case CABViewControlTypes.ORTS_TCS:
2522+
int commandIndex = (int)Control.ControlSubtype - 1;
2523+
Locomotive.TrainControlSystem.TCSCommandButtonDown.TryGetValue(commandIndex, out bool currentValue);
2524+
if (ChangedValue(1) > 0 ^ currentValue)
2525+
new TCSButtonCommand(Viewer.Log, !currentValue, commandIndex);
2526+
Locomotive.TrainControlSystem.TCSCommandSwitchOn.TryGetValue(commandIndex, out bool currentSwitchValue);
2527+
new TCSSwitchCommand(Viewer.Log, ChangedValue(currentSwitchValue ? 1 : 0) > 0, commandIndex);
26222528
break;
26232529

26242530
// Jindrich

0 commit comments

Comments
 (0)