Skip to content

Commit d0b80ed

Browse files
authored
Merge pull request #717 from cesarBLG/unlimited-tcs-controls
Allow unlimited number of TCS cabview controls
2 parents 7047b8c + 98221c0 commit d0b80ed

File tree

11 files changed

+178
-358
lines changed

11 files changed

+178
-358
lines changed

Source/Documentation/Manual/features-rollingstock.rst

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

17281728
MultiStateDisplay (
@@ -1766,7 +1766,7 @@ like e.g.::
17661766
single: Style
17671767
single: MouseControl
17681768

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

17711771
TwoState (
17721772
Type ( ORTS_TCS7 TWO_STATE )
@@ -1784,8 +1784,8 @@ The commands are received asynchronously by the script through this method:
17841784
public override void HandleEvent(TCSEvent evt, string message)
17851785
17861786
Where evt may be TCSEvent.GenericTCSButtonPressed or TCSEvent.GenericTCSButtonReleased
1787-
and message is a string ranging from "0" to "31", which correspond to controls from
1788-
ORTS_TCS1 to ORTS_TCS32.
1787+
and message is a string representing the control number with zero-base indexing
1788+
(e.g. "5" corresponds to ORTS_TCS6).
17891789
The commands may only be triggered by the mouse, except the first two which may also be
17901790
triggered by key combinations ``Ctrl,`` (comma) and ``Ctrl.`` (period).
17911791
Here's a code excerpt from the script which manages the commands:
@@ -1846,14 +1846,14 @@ To request a display of a cabview control, method:
18461846
18471847
public Action<int, float> SetCabDisplayControl;
18481848
1849-
has to be used, where ``int`` is the index of the cab control (from 0 to 47
1850-
corresponding from ORTS_TCS1 to ORTS_TCS48), and ``float`` is the value to be
1849+
has to be used, where ``int`` is the index of the cab control (starting from 0
1850+
which corresponds to ORTS_TCS1), and ``float`` is the value to be
18511851
used to select among frames.
18521852

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

18591859
.. code-block:: csharp

Source/Orts.Formats.Msts/CabViewFile.cs

Lines changed: 41 additions & 64 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
@@ -386,6 +339,30 @@ public enum DiscreteStates
386339
CAB_SIGNAL_DISPLAY
387340
}
388341

342+
public struct CabViewControlType
343+
{
344+
public CABViewControlTypes Type;
345+
public int Id;
346+
public CabViewControlType(string name)
347+
{
348+
Type = CABViewControlTypes.NONE;
349+
Id = 0;
350+
if (name != null && name.ToUpperInvariant().StartsWith("ORTS_TCS"))
351+
{
352+
if (int.TryParse(name.Substring(8), out Id))
353+
{
354+
Type = CABViewControlTypes.ORTS_TCS;
355+
}
356+
}
357+
else Enum.TryParse(name, true, out Type);
358+
}
359+
public override string ToString()
360+
{
361+
if (Type == CABViewControlTypes.ORTS_TCS) return Type.ToString() + Id;
362+
return Type.ToString();
363+
}
364+
}
365+
389366
public class CabViewControls : List<CabViewControl>
390367
{
391368
public CabViewControls(STFReader stf, string basepath)
@@ -451,7 +428,7 @@ public class CabViewControl
451428
public List<string> Screens;
452429
public int CabViewpoint;
453430

454-
public CABViewControlTypes ControlType = CABViewControlTypes.NONE;
431+
public CabViewControlType ControlType;
455432
public CABViewControlStyles ControlStyle = CABViewControlStyles.NONE;
456433
public CABViewControlUnits Units = CABViewControlUnits.NONE;
457434

@@ -463,15 +440,11 @@ public class CabViewControl
463440
protected void ParseType(STFReader stf)
464441
{
465442
stf.MustMatch("(");
466-
try
443+
string name = stf.ReadString();
444+
ControlType = new CabViewControlType(name);
445+
if (ControlType.Type == CABViewControlTypes.NONE)
467446
{
468-
ControlType = (CABViewControlTypes)Enum.Parse(typeof(CABViewControlTypes), stf.ReadString());
469-
}
470-
catch(ArgumentException)
471-
{
472-
stf.StepBackOneItem();
473-
STFException.TraceInformation(stf, "Skipped unknown ControlType " + stf.ReadString());
474-
ControlType = CABViewControlTypes.NONE;
447+
STFException.TraceInformation(stf, "Skipped unknown ControlType " + name);
475448
}
476449
//stf.ReadItem(); // Skip repeated Class Type
477450
stf.SkipRestOfBlock();
@@ -631,7 +604,11 @@ public CVCDial(CABViewControlTypes dialtype, int maxvalue, STFReader stf, string
631604
new STFReader.TokenProcessor("graphic", ()=>{ ParseGraphic(stf, basepath); }),
632605
new STFReader.TokenProcessor("pivot", ()=>{ Center = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
633606
});
634-
ControlType = dialtype;
607+
ControlType = new CabViewControlType()
608+
{
609+
Type = dialtype,
610+
Id = 0,
611+
};
635612
ControlStyle = CABViewControlStyles.NEEDLE;
636613
Direction = 0;
637614
MaxValue = maxvalue;
@@ -1318,15 +1295,15 @@ public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
13181295
}
13191296

13201297
// MSTS ignores/overrides various settings by the following exceptional cases:
1321-
if (ControlType == CABViewControlTypes.CP_HANDLE)
1298+
if (ControlType.Type == CABViewControlTypes.CP_HANDLE)
13221299
ControlStyle = CABViewControlStyles.NOT_SPRUNG;
1323-
if (ControlType == CABViewControlTypes.PANTOGRAPH || ControlType == CABViewControlTypes.PANTOGRAPH2 ||
1324-
ControlType == CABViewControlTypes.ORTS_PANTOGRAPH3 || ControlType == CABViewControlTypes.ORTS_PANTOGRAPH4)
1300+
if (ControlType.Type == CABViewControlTypes.PANTOGRAPH || ControlType.Type == CABViewControlTypes.PANTOGRAPH2 ||
1301+
ControlType.Type == CABViewControlTypes.ORTS_PANTOGRAPH3 || ControlType.Type == CABViewControlTypes.ORTS_PANTOGRAPH4)
13251302
ControlStyle = CABViewControlStyles.ONOFF;
1326-
if (ControlType == CABViewControlTypes.HORN || ControlType == CABViewControlTypes.SANDERS || ControlType == CABViewControlTypes.BELL
1327-
|| ControlType == CABViewControlTypes.RESET || ControlType == CABViewControlTypes.VACUUM_EXHAUSTER)
1303+
if (ControlType.Type == CABViewControlTypes.HORN || ControlType.Type == CABViewControlTypes.SANDERS || ControlType.Type == CABViewControlTypes.BELL
1304+
|| ControlType.Type == CABViewControlTypes.RESET || ControlType.Type == CABViewControlTypes.VACUUM_EXHAUSTER)
13281305
ControlStyle = CABViewControlStyles.WHILE_PRESSED;
1329-
if (ControlType == CABViewControlTypes.DIRECTION && Orientation == 0)
1306+
if (ControlType.Type == CABViewControlTypes.DIRECTION && Orientation == 0)
13301307
Direction = 1 - Direction;
13311308

13321309
switch (discreteState)

Source/Orts.Simulation/Simulation/RollingStocks/MSTSDieselLocomotive.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ public override float GetDataOf(CabViewControl cvc)
848848
{
849849
float data = 0;
850850

851-
switch (cvc.ControlType)
851+
switch (cvc.ControlType.Type)
852852
{
853853
case CABViewControlTypes.GEARS:
854854
if (DieselEngines.HasGearBox)
@@ -1442,7 +1442,7 @@ protected void NormalizeParams()
14421442
{
14431443
foreach ( var control in cabView.CVFFile.CabViewControls)
14441444
{
1445-
if (control is CVCDiscrete && control.ControlType == CABViewControlTypes.THROTTLE && (control as CVCDiscrete).Values.Count > 0 && (control as CVCDiscrete).Values[(control as CVCDiscrete).Values.Count - 1] > 1)
1445+
if (control is CVCDiscrete && control.ControlType.Type == CABViewControlTypes.THROTTLE && (control as CVCDiscrete).Values.Count > 0 && (control as CVCDiscrete).Values[(control as CVCDiscrete).Values.Count - 1] > 1)
14461446
{
14471447
var discreteControl = (CVCDiscrete)control;
14481448
for (var i = 0; i < discreteControl.Values.Count; i++)

Source/Orts.Simulation/Simulation/RollingStocks/MSTSElectricLocomotive.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public override float GetDataOf(CabViewControl cvc)
221221
{
222222
float data = 0;
223223

224-
switch (cvc.ControlType)
224+
switch (cvc.ControlType.Type)
225225
{
226226
case CABViewControlTypes.LINE_VOLTAGE:
227227
data = ElectricPowerSupply.PantographVoltageV;

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

Lines changed: 11 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -632,16 +632,16 @@ protected MSTSNotchController BuildDPDynamicBrakeController()
632632
{
633633
msDisplay = (CVCMultiStateDisplay) cabView.CVFFile.CabViewControls.Where(
634634
control => control is CVCMultiStateDisplay &&
635-
(((CVCMultiStateDisplay) control).ControlType == CABViewControlTypes.DYNAMIC_BRAKE_DISPLAY ||
636-
((CVCMultiStateDisplay) control).ControlType == CABViewControlTypes.CPH_DISPLAY)).First();
635+
(((CVCMultiStateDisplay) control).ControlType.Type == CABViewControlTypes.DYNAMIC_BRAKE_DISPLAY ||
636+
((CVCMultiStateDisplay) control).ControlType.Type == CABViewControlTypes.CPH_DISPLAY)).First();
637637
}
638638
catch
639639
{
640640

641641
}
642642
if (msDisplay != null)
643643
{
644-
if (msDisplay.ControlType == CABViewControlTypes.DYNAMIC_BRAKE_DISPLAY)
644+
if (msDisplay.ControlType.Type == CABViewControlTypes.DYNAMIC_BRAKE_DISPLAY)
645645
{
646646
foreach (var switchval in msDisplay.Values)
647647
dpDynController.AddNotch((float) switchval);
@@ -703,11 +703,8 @@ protected void GetPressureUnit()
703703
CabViewControls cvcList = CabViewList[0].CVFFile.CabViewControls;
704704
foreach (CabViewControl cvc in cvcList)
705705
{
706-
if (brakeSystemComponents.ContainsKey(cvc.ControlType) && pressureUnits.ContainsKey(cvc.Units))
706+
if (brakeSystemComponents.TryGetValue(cvc.ControlType.Type, out var component) && pressureUnits.TryGetValue(cvc.Units, out var unit))
707707
{
708-
BrakeSystemComponent component = brakeSystemComponents[cvc.ControlType];
709-
PressureUnit unit = pressureUnits[cvc.Units];
710-
711708
BrakeSystemPressureUnits[component] = unit;
712709
}
713710
}
@@ -4992,7 +4989,7 @@ public override void SignalEvent(Event evt)
49924989
public virtual float GetDataOf(CabViewControl cvc)
49934990
{
49944991
float data = 0;
4995-
switch (cvc.ControlType)
4992+
switch (cvc.ControlType.Type)
49964993
{
49974994
case CABViewControlTypes.SPEEDOMETER:
49984995
{
@@ -5090,7 +5087,7 @@ public virtual float GetDataOf(CabViewControl cvc)
50905087
if (DynamicBrakePercent > 0 && MaxDynamicBrakeForceN > 0)
50915088
{
50925089
float rangeFactor;
5093-
if (cvc.ControlType == CABViewControlTypes.AMMETER_ABS)
5090+
if (cvc.ControlType.Type == CABViewControlTypes.AMMETER_ABS)
50945091
{
50955092
if (DynamicBrakeMaxCurrentA == 0)
50965093
rangeFactor = direction == 0 ? (float)cvc.MaxValue : (float)cvc.MinValue;
@@ -5108,11 +5105,11 @@ public virtual float GetDataOf(CabViewControl cvc)
51085105
}
51095106
if (direction == 1)
51105107
data = -data;
5111-
if (cvc.ControlType == CABViewControlTypes.AMMETER_ABS) data = Math.Abs(data);
5108+
if (cvc.ControlType.Type == CABViewControlTypes.AMMETER_ABS) data = Math.Abs(data);
51125109
break;
51135110
}
51145111
data = this.MotiveForceN / MaxForceN * MaxCurrentA;
5115-
if (cvc.ControlType == CABViewControlTypes.AMMETER_ABS) data = Math.Abs(data);
5112+
if (cvc.ControlType.Type == CABViewControlTypes.AMMETER_ABS) data = Math.Abs(data);
51165113
break;
51175114
}
51185115
case CABViewControlTypes.LOAD_METER:
@@ -5780,7 +5777,7 @@ public virtual float GetDataOf(CabViewControl cvc)
57805777
case CABViewControlTypes.ORTS_LEFTDOOR:
57815778
case CABViewControlTypes.ORTS_RIGHTDOOR:
57825779
{
5783-
bool right = (cvc.ControlType == CABViewControlTypes.ORTS_RIGHTDOOR) ^ Flipped ^ GetCabFlipped();
5780+
bool right = (cvc.ControlType.Type == CABViewControlTypes.ORTS_RIGHTDOOR) ^ Flipped ^ GetCabFlipped();
57845781
var state = Train.DoorState(right ? DoorSide.Right : DoorSide.Left);
57855782
data = state >= DoorState.Opening ? 1 : 0;
57865783
}
@@ -5820,56 +5817,8 @@ public virtual float GetDataOf(CabViewControl cvc)
58205817
break;
58215818
}
58225819

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

58755824
case CABViewControlTypes.ORTS_BATTERY_SWITCH_COMMAND_SWITCH:

Source/Orts.Simulation/Simulation/RollingStocks/MSTSSteamLocomotive.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6177,7 +6177,7 @@ public override float GetDataOf(CabViewControl cvc)
61776177
{
61786178
float data;
61796179

6180-
switch (cvc.ControlType)
6180+
switch (cvc.ControlType.Type)
61816181
{
61826182
case CABViewControlTypes.WHISTLE:
61836183
data = Horn ? 1 : 0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ void SetTrainBrake(ref float brakePercent, float elapsedClockSeconds, float delt
14141414
public float GetDataOf(CabViewControl cvc)
14151415
{
14161416
float data = 0;
1417-
switch (cvc.ControlType)
1417+
switch (cvc.ControlType.Type)
14181418
{
14191419
case CABViewControlTypes.ORTS_SELECTED_SPEED:
14201420
case CABViewControlTypes.ORTS_SELECTED_SPEED_DISPLAY:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public override void Copy(MSTSWagon copy)
229229
public float GetDataOf(CabViewControl cvc)
230230
{
231231
float data = 0;
232-
switch (cvc.ControlType)
232+
switch (cvc.ControlType.Type)
233233
{
234234
case CABViewControlTypes.ORTS_EOT_ID:
235235
data = ID;

0 commit comments

Comments
 (0)