@@ -75,18 +75,17 @@ public class TrainCarOperationsViewerWindow : Window
7575 public int WindowHeightMax ;
7676 public int WindowWidthMin ;
7777 public int WindowWidthMax ;
78- public string powerSupplyStatus ;
79- public string batteryStatus ;
80- string circuitBreakerState ;
81- public int spacerRowCount ;
82- public int symbolsRowCount ;
83- public int locoRowCount ;
84- public int rowsCount ;
78+ public string PowerSupplyStatus ;
79+ public string BatteryStatus ;
80+ string CircuitBreakerState ;
81+ public int SpacerRowCount ;
82+ public int SymbolsRowCount ;
83+ public int LocoRowCount ;
84+ public int RowsCount ;
8585 const int SymbolWidth = 32 ;
8686 public static bool FontChanged ;
8787 public static bool FontToBold ;
8888 public int windowHeight { get ; set ; } //required by TrainCarWindow
89-
9089 public int CarPosition
9190 {
9291 set ;
@@ -127,7 +126,7 @@ public struct ListLabel
127126 Train PlayerTrain ;
128127 int LastPlayerTrainCars ;
129128 bool LastPlayerLocomotiveFlippedState ;
130- int carPosition ;
129+ int OldCarPosition ;
131130
132131 public TrainCarOperationsViewerWindow ( WindowManager owner )
133132 : base ( owner , Window . DecorationSize . X + CarListPadding + ( ( owner . TextFontDefault . Height + 12 ) * 20 ) , Window . DecorationSize . Y + ( ( owner . TextFontDefault . Height + 12 ) * 2 ) , Viewer . Catalog . GetString ( "Train Operations Viewer" ) )
@@ -224,11 +223,11 @@ private void UpdateWindowSize()
224223 /// </summary>
225224 private void ModifyWindowSize ( )
226225 {
227- if ( symbolsRowCount > 0 )
226+ if ( SymbolsRowCount > 0 )
228227 {
229- var desiredHeight = FontToBold ? Owner . TextFontDefaultBold . Height * rowsCount
230- : Owner . TextFontDefault . Height * rowsCount + SymbolWidth ;
231- var desiredWidth = ( symbolsRowCount * SymbolWidth ) + ( spacerRowCount * ( SymbolWidth / 2 ) ) + ( locoRowCount * ( SymbolWidth * 2 ) ) ;
228+ var desiredHeight = FontToBold ? Owner . TextFontDefaultBold . Height * RowsCount
229+ : Owner . TextFontDefault . Height * RowsCount + SymbolWidth ;
230+ var desiredWidth = ( SymbolsRowCount * SymbolWidth ) + ( SpacerRowCount * ( SymbolWidth / 2 ) ) + ( LocoRowCount * ( SymbolWidth * 2 ) ) ;
232231
233232 var newHeight = ( int ) MathHelper . Clamp ( desiredHeight , 80 , WindowHeightMax ) ;
234233 var newWidth = ( int ) MathHelper . Clamp ( desiredWidth , 100 , WindowWidthMax ) ;
@@ -241,13 +240,13 @@ private void ModifyWindowSize()
241240 MoveTo ( Location . X , newTop ) ;
242241 }
243242 }
244- public ControlLayoutVertical vbox ;
243+ public ControlLayoutVertical Vbox ;
245244 protected override ControlLayout Layout ( ControlLayout layout )
246245 {
247246 Label buttonClose ;
248247 var textHeight = Owner . TextFontDefault . Height ;
249248 textHeight = MathHelper . Clamp ( textHeight , SymbolWidth , Owner . TextFontDefault . Height ) ;
250- vbox = base . Layout ( layout ) . AddLayoutVertical ( ) ;
249+ Vbox = base . Layout ( layout ) . AddLayoutVertical ( ) ;
251250
252251 if ( PlayerTrain != null && PlayerTrain . Cars . Count ( ) > CarPosition )
253252 {
@@ -266,15 +265,15 @@ protected override ControlLayout Layout(ControlLayout layout)
266265 var wagonType = isEngine ? $ " { Viewer . Catalog . GetString ( locomotive . WagonType . ToString ( ) ) } " + $ ":{ Viewer . Catalog . GetString ( locomotive . EngineType . ToString ( ) ) } "
267266 : $ " { Viewer . Catalog . GetString ( wagon . WagonType . ToString ( ) ) } ";
268267
269- vbox . Add ( buttonClose = new Label ( vbox . RemainingWidth , Owner . TextFontDefault . Height , $ "{ Viewer . Catalog . GetString ( "Car ID" ) } { ( CarPosition >= PlayerTrain . Cars . Count ? " " : PlayerTrain . Cars [ CarPosition ] . CarID + wagonType ) } ", LabelAlignment . Center ) ) ;
268+ Vbox . Add ( buttonClose = new Label ( Vbox . RemainingWidth , Owner . TextFontDefault . Height , $ "{ Viewer . Catalog . GetString ( "Car ID" ) } { ( CarPosition >= PlayerTrain . Cars . Count ? " " : PlayerTrain . Cars [ CarPosition ] . CarID + wagonType ) } ", LabelAlignment . Center ) ) ;
270269 buttonClose . Click += new Action < Control , Point > ( buttonClose_Click ) ;
271270 buttonClose . Color = Owner . Viewer . TrainCarOperationsWindow . WarningCarPosition . Find ( x => x == true ) ? Color . Cyan : Color . White ;
272- vbox . AddHorizontalSeparator ( ) ;
271+ Vbox . AddHorizontalSeparator ( ) ;
273272 }
274273
275- spacerRowCount = symbolsRowCount = 0 ;
274+ SpacerRowCount = SymbolsRowCount = 0 ;
276275
277- var line = vbox . AddLayoutHorizontal ( vbox . RemainingHeight ) ;
276+ var line = Vbox . AddLayoutHorizontal ( Vbox . RemainingHeight ) ;
278277 var addspace = 0 ;
279278 void AddSpace ( bool full )
280279 {
@@ -347,17 +346,17 @@ void AddSpace(bool full)
347346 }
348347 buttonClose . Color = Owner . Viewer . TrainCarOperationsWindow . WarningCarPosition . Find ( x => x == true ) ? Color . Cyan : Color . White ;
349348
350- rowsCount = vbox . Controls . Count ( ) ;
351- spacerRowCount = line . Controls . Where ( c => c is Orts . Viewer3D . Popups . Spacer ) . Count ( ) ;
352- locoRowCount = line . Controls . Where ( c => c is Orts . Viewer3D . Popups . TrainCarOperationsViewerWindow . buttonLoco ) . Count ( ) + 1 ;
353- symbolsRowCount = line . Controls . Count ( ) - spacerRowCount - locoRowCount ;
349+ RowsCount = Vbox . Controls . Count ( ) ;
350+ SpacerRowCount = line . Controls . Where ( c => c is Orts . Viewer3D . Popups . Spacer ) . Count ( ) ;
351+ LocoRowCount = line . Controls . Where ( c => c is Orts . Viewer3D . Popups . TrainCarOperationsViewerWindow . buttonLoco ) . Count ( ) + 1 ;
352+ SymbolsRowCount = line . Controls . Count ( ) - SpacerRowCount - LocoRowCount ;
354353 }
355354 }
356- return vbox ;
355+ return Vbox ;
357356 }
358357 void buttonClose_Click ( Control arg1 , Point arg2 )
359358 {
360- carPosition = CarPosition ;
359+ OldCarPosition = CarPosition ;
361360 Visible = false ;
362361 }
363362 public override void PrepareFrame ( ElapsedTime elapsedTime , bool updateFull )
@@ -375,8 +374,6 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
375374 CouplerChanged = false ;
376375 PlayerTrain = Owner . Viewer . PlayerTrain ;
377376
378- //if (LastPlayerTrainCars != Owner.Viewer.PlayerTrain.Cars.Count){ Visible = false; }
379-
380377 LastPlayerTrainCars = Owner . Viewer . PlayerTrain . Cars . Count ;
381378 CarPosition = CarPosition >= LastPlayerTrainCars ? LastPlayerTrainCars - 1 : CarPosition ;
382379 if ( Owner . Viewer . PlayerLocomotive != null ) LastPlayerLocomotiveFlippedState = Owner . Viewer . PlayerLocomotive . Flipped ;
@@ -388,41 +385,39 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
388385 TrainCar trainCar = Owner . Viewer . PlayerTrain . Cars [ CarPosition ] ;
389386 bool isElectricDieselLocomotive = ( trainCar is MSTSElectricLocomotive ) || ( trainCar is MSTSDieselLocomotive ) ;
390387
391- if ( carPosition != CarPosition || TrainCarOperationsChanged || carOperations . CarOperationChanged
392- || trainCarOperations . carIdClicked || carOperations . RearBrakeHoseChanged || carOperations . FrontBrakeHoseChanged )
388+ if ( OldCarPosition != CarPosition || TrainCarOperationsChanged || carOperations . CarOperationChanged
389+ || trainCarOperations . CarIdClicked || carOperations . RearBrakeHoseChanged || carOperations . FrontBrakeHoseChanged )
393390 {
394391 // Updates CarPosition
395392 CarPosition = CouplerChanged ? NewCarPosition : CarPosition ;
396-
397- if ( carPosition != CarPosition || ( trainCarOperations . carIdClicked && CarPosition == 0 ) )
393+
394+ if ( OldCarPosition != CarPosition || ( trainCarOperations . CarIdClicked && CarPosition == 0 ) )
398395 {
399396 Owner . Viewer . FrontCamera . Activate ( ) ;
400397 }
401- carPosition = CarPosition ;
398+ OldCarPosition = CarPosition ;
402399 Layout ( ) ;
403400 UpdateWindowSize ( ) ;
404401 TrainCarOperationsChanged = false ;
405402
406403 // Avoids bug
407- carOperations . CarOperationChanged = carOperations . Visible && carOperations . CarOperationChanged ? true : false ;
404+ carOperations . CarOperationChanged = carOperations . Visible && carOperations . CarOperationChanged ;
408405 }
409406 // Updates power supply status
410407 else if ( isElectricDieselLocomotive &&
411- ( powerSupplyStatus != null && powerSupplyStatus != Owner . Viewer . PlayerTrain . Cars [ CarPosition ] . GetStatus ( )
412- || batteryStatus != null && batteryStatus != Owner . Viewer . PlayerTrain . Cars [ CarPosition ] . GetStatus ( )
413- || circuitBreakerState != null && circuitBreakerState != ( trainCar as MSTSElectricLocomotive ) . ElectricPowerSupply . CircuitBreaker . State . ToString ( ) ) )
408+ ( PowerSupplyStatus != null && PowerSupplyStatus != Owner . Viewer . PlayerTrain . Cars [ CarPosition ] . GetStatus ( )
409+ || BatteryStatus != null && BatteryStatus != Owner . Viewer . PlayerTrain . Cars [ CarPosition ] . GetStatus ( )
410+ || CircuitBreakerState != null && CircuitBreakerState != ( trainCar as MSTSElectricLocomotive ) . ElectricPowerSupply . CircuitBreaker . State . ToString ( ) ) )
414411 {
415412 Layout ( ) ;
416413 UpdateWindowSize ( ) ;
417414 TrainCarOperationsChanged = true ;
418415 }
419416 //required by traincarwindow to ModifyWindowSize()
420- windowHeight = vbox != null ? vbox . Position . Height : 0 ;
417+ windowHeight = Vbox != null ? Vbox . Position . Height : 0 ;
421418 }
422419 }
423- private static UserCommand ? GetPressedKey ( params UserCommand [ ] keysToTest ) => keysToTest
424- . Where ( ( UserCommand key ) => UserInput . IsDown ( key ) )
425- . FirstOrDefault ( ) ;
420+
426421 class buttonLoco : Image
427422 {
428423 readonly Viewer Viewer ;
@@ -476,14 +471,12 @@ void TrainCarOperationsCouplerFront_Click(Control arg1, Point arg2)
476471 class buttonCouplerRear : Image
477472 {
478473 readonly Viewer Viewer ;
479- readonly TrainCarOperationsViewerWindow TrainCarViewer ;
480474 readonly int CarPosition ;
481475 readonly bool Last ;
482476 public buttonCouplerRear ( int x , int y , int size , Viewer viewer , TrainCar car , int carPosition )
483477 : base ( x , y , size , size )
484478 {
485479 Viewer = viewer ;
486- TrainCarViewer = Viewer . TrainCarOperationsViewerWindow ;
487480 CarPosition = carPosition ;
488481 Last = car == Viewer . PlayerTrain . Cars . Last ( ) ;
489482 Texture = Last ? CouplerRear : Coupler ;
@@ -605,7 +598,7 @@ public buttonFrontBrakeHose(int x, int y, int size, Viewer viewer, TrainCar car,
605598 new WagonBrakeHoseRearConnectCommand ( Viewer . Log , ( Viewer . PlayerTrain . Cars [ CarOperations . CarPosition - 1 ] as MSTSWagon ) , ! ( Viewer . PlayerTrain . Cars [ CarOperations . CarPosition - 1 ] as MSTSWagon ) . BrakeSystem . RearBrakeHoseConnected ) ;
606599 CarOperations . FrontBrakeHoseChanged = false ;
607600 }
608- TrainCar . modifiedSetting = true ;
601+ TrainCar . ModifiedSetting = true ;
609602 TrainCarViewer . TrainCarOperationsChanged = true ;
610603 }
611604
@@ -856,7 +849,7 @@ public buttonToggleMU(int x, int y, int size, Viewer viewer, int carPosition)
856849 var multipleUnitsConfiguration = Viewer . PlayerLocomotive . GetMultipleUnitsConfiguration ( ) ;
857850 if ( Viewer . PlayerTrain . Cars [ CarPosition ] is MSTSDieselLocomotive && multipleUnitsConfiguration != null )
858851 {
859- Texture = Viewer . TrainCarOperationsWindow . modifiedSetting || ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSLocomotive ) . RemoteControlGroup == 0 && multipleUnitsConfiguration != "1" ? MUconnected : MUdisconnected ;
852+ Texture = Viewer . TrainCarOperationsWindow . ModifiedSetting || ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSLocomotive ) . RemoteControlGroup == 0 && multipleUnitsConfiguration != "1" ? MUconnected : MUdisconnected ;
860853 }
861854 else
862855 {
@@ -938,7 +931,7 @@ public Texture2D locomotiveStatus1(int CarPosition)
938931 string valuePart = parts ? [ 1 ] ;
939932 if ( keyPart . Contains ( Viewer . Catalog . GetString ( "Engine" ) ) )
940933 {
941- TrainCarViewer . powerSupplyStatus = locomotiveStatus ;
934+ TrainCarViewer . PowerSupplyStatus = locomotiveStatus ;
942935 Texture = valuePart . Contains ( Viewer . Catalog . GetString ( "Running" ) ) ? PowerOn
943936 : valuePart . Contains ( Viewer . Catalog . GetString ( "Stopped" ) ) ? PowerOff
944937 : PowerChanging ;
@@ -948,17 +941,17 @@ public Texture2D locomotiveStatus1(int CarPosition)
948941 MSTSElectricLocomotive locomotive = Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSElectricLocomotive ;
949942 switch ( locomotive . ElectricPowerSupply . CircuitBreaker . State )
950943 {
951- case CircuitBreakerState . Closed :
944+ case ORTS . Scripting . Api . CircuitBreakerState . Closed :
952945 Texture = PowerOn ;
953946 break ;
954- case CircuitBreakerState . Closing :
947+ case ORTS . Scripting . Api . CircuitBreakerState . Closing :
955948 Texture = PowerChanging ;
956949 break ;
957- case CircuitBreakerState . Open :
950+ case ORTS . Scripting . Api . CircuitBreakerState . Open :
958951 Texture = PowerOff ;
959952 break ;
960953 }
961- TrainCarViewer . circuitBreakerState = locomotive . ElectricPowerSupply . CircuitBreaker . State . ToString ( ) ;
954+ TrainCarViewer . CircuitBreakerState = locomotive . ElectricPowerSupply . CircuitBreaker . State . ToString ( ) ;
962955 }
963956 return Texture ;
964957 }
@@ -1028,7 +1021,7 @@ public Texture2D locomotiveStatus(int CarPosition)
10281021 string valuePart = parts ? [ 1 ] ;
10291022 if ( keyPart . Contains ( Viewer . Catalog . GetString ( "Battery" ) ) )
10301023 {
1031- TrainCarViewer . batteryStatus = locomotiveStatus ;
1024+ TrainCarViewer . BatteryStatus = locomotiveStatus ;
10321025 Texture = valuePart . Contains ( Viewer . Catalog . GetString ( "On" ) ) ? BattOn32 : BattOff32 ;
10331026 break ;
10341027 }
0 commit comments