2727using Orts . Simulation . RollingStocks . SubSystems . PowerSupplies ;
2828using ORTS . Common ;
2929using ORTS . Common . Input ;
30+ using ORTS . Scripting . Api ;
3031using System ;
3132using System . Collections . Generic ;
3233using System . IO ;
3334using System . Linq ;
35+ using System . Windows . Forms ;
3436
3537namespace 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