Skip to content

Commit c1f443e

Browse files
committed
Do not use localized strings for core operations
1 parent bddc6e7 commit c1f443e

File tree

8 files changed

+109
-133
lines changed

8 files changed

+109
-133
lines changed

Source/Orts.Simulation/Common/Scripting/PowerSupply/ControlCarPowerSupply.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ protected override void SetCurrentMainPowerSupplyState(PowerSupplyState state) {
4949
protected override void SetCurrentAuxiliaryPowerSupplyState(PowerSupplyState state) {}
5050
protected override void SetCurrentElectricTrainSupplyState(PowerSupplyState state) {}
5151
protected override void SetCurrentDynamicBrakeAvailability(bool avail) {}
52+
public override PowerSupplyState GetPowerStatus() => PowerSupplyState.Unavailable;
5253
public void SignalEventToControlActiveLocomotive(PowerSupplyEvent evt)
5354
{
5455
ControlActiveLocomotive?.LocomotivePowerSupply.HandleEvent(evt);

Source/Orts.Simulation/Common/Scripting/PowerSupply/DieselPowerSupply.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,27 @@ public float DieselEngineMinRpm
9090
/// Closing authorization of the traction cut-off relay
9191
/// </summary>
9292
public bool TractionCutOffRelayClosingAuthorization() => TractionCutOffRelay.ClosingAuthorization;
93-
93+
94+
public override PowerSupplyState GetPowerStatus()
95+
{
96+
var status = base.GetPowerStatus();
97+
PowerSupplyState engineStatus;
98+
switch (CurrentDieselEnginesState())
99+
{
100+
case DieselEngineState.Running:
101+
engineStatus = PowerSupplyState.PowerOn;
102+
break;
103+
case DieselEngineState.Starting:
104+
engineStatus = PowerSupplyState.PowerOnOngoing;
105+
break;
106+
default:
107+
engineStatus = PowerSupplyState.PowerOff;
108+
break;
109+
}
110+
if (status == engineStatus) return status;
111+
return PowerSupplyState.PowerOnOngoing;
112+
}
113+
94114
/// <summary>
95115
/// Sends an event to all diesel engines
96116
/// </summary>

Source/Orts.Simulation/Common/Scripting/PowerSupply/ElectricPowerSupply.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,34 @@ protected float PantographVoltageVDC
128128
/// </summary>
129129
protected void SetFilterVoltageV(float voltage) => EpsHost.FilterVoltageV = voltage;
130130

131+
public override PowerSupplyState GetPowerStatus()
132+
{
133+
var status = base.GetPowerStatus();
134+
PowerSupplyState electricStatus;
135+
switch (CurrentPantographState())
136+
{
137+
case PantographState.Up:
138+
switch (CurrentCircuitBreakerState())
139+
{
140+
case CircuitBreakerState.Closed:
141+
electricStatus = PowerSupplyState.PowerOn;
142+
break;
143+
default:
144+
electricStatus = PowerSupplyState.PowerOnOngoing;
145+
break;
146+
}
147+
break;
148+
case PantographState.Raising:
149+
electricStatus = PowerSupplyState.PowerOnOngoing;
150+
break;
151+
default:
152+
electricStatus = PowerSupplyState.PowerOff;
153+
break;
154+
}
155+
if (status == electricStatus) return status;
156+
return PowerSupplyState.PowerOnOngoing;
157+
}
158+
131159
/// <summary>
132160
/// Sends an event to the circuit breaker
133161
/// </summary>

Source/Orts.Simulation/Common/Scripting/PowerSupply/LocomotivePowerSupply.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,20 @@ protected void SetCustomizedCabviewControlName(int index, string name)
293293
/// </summary>
294294
protected virtual void SetCurrentDynamicBrakeAvailability(bool avail) => LpsHost.DynamicBrakeAvailable = avail;
295295

296+
/// <summary>
297+
/// Called by other subsystems to determine whether the locomotive is powered
298+
/// </summary>
299+
/// <returns>
300+
/// PowerSupplyState.PowerOff if the locomotive is unpowered
301+
/// PowerSupplyState.PowerOnOngoing if the locomotive is in a power on sequence, but not all subsystems are ready
302+
/// PowerSupplyState.PowerOn if the locomotive is ready for service (all necessary subystems are connected)
303+
/// </returns>
304+
public virtual PowerSupplyState GetPowerStatus()
305+
{
306+
if (LpsHost.MainPowerSupplyState == LpsHost.AuxiliaryPowerSupplyState) return LpsHost.MainPowerSupplyState;
307+
return PowerSupplyState.PowerOnOngoing;
308+
}
309+
296310
/// <summary>
297311
/// Sends an event to the master switch
298312
/// </summary>

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/ILocomotivePowerSupply.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public interface ILocomotivePowerSupply : IPowerSupply
4747
bool ServiceRetentionCancellationButton { get; set; }
4848
bool ServiceRetentionActive { get; set; }
4949

50+
PowerSupplyState GetPowerStatus();
51+
5052
void HandleEventFromTcs(PowerSupplyEvent evt);
5153
void HandleEventFromTcs(PowerSupplyEvent evt, int id);
5254
void HandleEventFromTcs(PowerSupplyEvent evt, string message);

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/LocomotivePowerSupply.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ public virtual void Update(float elapsedClockSeconds)
266266
ElectricTrainSupplySwitch.Update(elapsedClockSeconds);
267267
}
268268

269+
public PowerSupplyState GetPowerStatus() => AbstractScript?.GetPowerStatus() ?? PowerSupplyState.Unavailable;
270+
269271
public void HandleEvent(PowerSupplyEvent evt)
270272
{
271273
AbstractScript?.HandleEvent(evt);

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsViewerWindow.cs

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
using Orts.Simulation.RollingStocks.SubSystems.PowerSupplies;
2828
using ORTS.Common;
2929
using ORTS.Common.Input;
30+
using ORTS.Scripting.Api;
3031
using System;
3132
using System.Collections.Generic;
3233
using System.IO;
3334
using System.Linq;
35+
using System.Windows.Forms;
3436

3537
namespace Orts.Viewer3D.Popups
3638
{
@@ -81,10 +83,9 @@ public class TrainCarOperationsViewerWindow : Window
8183

8284
public List<bool> AngleCockAPartiallyOpened = new List<bool>();
8385
public List<bool> AngleCockBPartiallyOpened = new List<bool>();
84-
public string BatteryStatus;
85-
string CircuitBreakerState;
86+
public bool BatterySwitchOn;
87+
public PowerSupplyState PowerSupplyStatus;
8688
public int LocoRowCount;
87-
public string PowerSupplyStatus;
8889
public int RowsCount;
8990
public int SpacerRowCount;
9091
public int SymbolsRowCount;
@@ -537,10 +538,8 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
537538
carOperations.CarOperationChanged = carOperations.Visible && carOperations.CarOperationChanged;
538539
}
539540
// Updates power supply status
540-
else if (isElectricDieselLocomotive &&
541-
(PowerSupplyStatus != null && PowerSupplyStatus != Owner.Viewer.PlayerTrain.Cars[CarPosition].GetStatus()
542-
|| (BatteryStatus != null && BatteryStatus != Owner.Viewer.PlayerTrain.Cars[CarPosition].GetStatus())
543-
|| (CircuitBreakerState != null && CircuitBreakerState != (trainCar as MSTSElectricLocomotive).ElectricPowerSupply.CircuitBreaker.State.ToString())))
541+
else if ((trainCar is MSTSWagon wagon && wagon.PowerSupply != null && BatterySwitchOn != wagon.PowerSupply.BatterySwitch.On)
542+
|| (isElectricDieselLocomotive && PowerSupplyStatus != (trainCar as MSTSLocomotive).LocomotivePowerSupply.GetPowerStatus()))
544543
{
545544
Layout();
546545
UpdateWindowSize();
@@ -1149,10 +1148,10 @@ void buttonTogglePower_Click(Control arg1, Point arg2)
11491148
if ((CurrentCar is MSTSElectricLocomotive) || (CurrentCar is MSTSDieselLocomotive))
11501149
{
11511150
MSTSLocomotive locomotive = CurrentCar as MSTSLocomotive;
1151+
bool powerOn = locomotive.LocomotivePowerSupply.GetPowerStatus() == PowerSupplyState.PowerOff;
11521152

1153-
new PowerCommand(Viewer.Log, locomotive, !locomotive.LocomotivePowerSupply.MainPowerSupplyOn);
1154-
var mainPowerSupplyOn = locomotive.LocomotivePowerSupply.MainPowerSupplyOn;
1155-
if (mainPowerSupplyOn)
1153+
new PowerCommand(Viewer.Log, locomotive, powerOn);
1154+
if (!powerOn)
11561155
Viewer.Simulator.Confirmer.Information(Viewer.Catalog.GetString("Power OFF command sent"));
11571156
else
11581157
Viewer.Simulator.Confirmer.Information(Viewer.Catalog.GetString("Power ON command sent"));
@@ -1165,36 +1164,9 @@ void buttonTogglePower_Click(Control arg1, Point arg2)
11651164
}
11661165
public Texture2D locomotiveStatusPower(int CarPosition)
11671166
{
1168-
string locomotiveStatus = CurrentCar.GetStatus();
1169-
foreach (string data in locomotiveStatus.Split('\n').Where((string d) => !string.IsNullOrWhiteSpace(d)))
1170-
{
1171-
string[] parts = data.Split(new string[] { " = " }, 2, StringSplitOptions.None);
1172-
string keyPart = parts[0];
1173-
string valuePart = parts?[1];
1174-
if (keyPart.Contains(Viewer.Catalog.GetParticularString("DieselEngine","Engine")))
1175-
{
1176-
TrainCarViewer.PowerSupplyStatus = locomotiveStatus;
1177-
Texture = valuePart.Contains(Viewer.Catalog.GetParticularString("DieselEngine", "Running")) ? PowerOn
1178-
: valuePart.Contains(Viewer.Catalog.GetParticularString("DieselEngine", "Stopped")) ? PowerOff
1179-
: PowerChanging;
1180-
break;
1181-
}
1182-
1183-
MSTSElectricLocomotive locomotive = CurrentCar as MSTSElectricLocomotive;
1184-
switch (locomotive.ElectricPowerSupply.CircuitBreaker.State)
1185-
{
1186-
case ORTS.Scripting.Api.CircuitBreakerState.Closed:
1187-
Texture = PowerOn;
1188-
break;
1189-
case ORTS.Scripting.Api.CircuitBreakerState.Closing:
1190-
Texture = PowerChanging;
1191-
break;
1192-
case ORTS.Scripting.Api.CircuitBreakerState.Open:
1193-
Texture = PowerOff;
1194-
break;
1195-
}
1196-
TrainCarViewer.CircuitBreakerState = locomotive.ElectricPowerSupply.CircuitBreaker.State.ToString();
1197-
}
1167+
var powerStatus = (CurrentCar as MSTSLocomotive).LocomotivePowerSupply.GetPowerStatus();
1168+
TrainCarViewer.PowerSupplyStatus = powerStatus;
1169+
Texture = powerStatus == PowerSupplyState.PowerOn ? PowerOn : powerStatus == PowerSupplyState.PowerOff ? PowerOff : PowerChanging;
11981170
return Texture;
11991171
}
12001172
}
@@ -1254,18 +1226,11 @@ void ToggleBatterySwitch_Click(Control arg1, Point arg2)
12541226
}
12551227
public Texture2D locomotiveStatusBattery(int CarPosition)
12561228
{
1257-
string locomotiveStatus = CurrentCar.GetStatus();
1258-
foreach (string data in locomotiveStatus.Split('\n').Where((string d) => !string.IsNullOrWhiteSpace(d)))
1229+
if (CurrentCar is MSTSWagon wagon && wagon.PowerSupply != null)
12591230
{
1260-
string[] parts = data.Split(new string[] { " = " }, 2, StringSplitOptions.None);
1261-
string keyPart = parts[0];
1262-
string valuePart = parts?[1];
1263-
if (keyPart.Contains(Viewer.Catalog.GetString("Battery switch")))
1264-
{
1265-
TrainCarViewer.BatteryStatus = locomotiveStatus;
1266-
Texture = valuePart.Contains(Viewer.Catalog.GetString("On")) ? BattOn32 : BattOff32;
1267-
break;
1268-
}
1231+
bool on = wagon.PowerSupply.BatterySwitch.On;
1232+
TrainCarViewer.BatterySwitchOn = on;
1233+
Texture = on ? BattOn32 : BattOff32;
12691234
}
12701235
return Texture;
12711236
}

0 commit comments

Comments
 (0)