@@ -75,18 +75,17 @@ public class TrainCarOperationsViewerWindow : Window
75
75
public int WindowHeightMax ;
76
76
public int WindowWidthMin ;
77
77
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 ;
85
85
const int SymbolWidth = 32 ;
86
86
public static bool FontChanged ;
87
87
public static bool FontToBold ;
88
88
public int windowHeight { get ; set ; } //required by TrainCarWindow
89
-
90
89
public int CarPosition
91
90
{
92
91
set ;
@@ -127,7 +126,7 @@ public struct ListLabel
127
126
Train PlayerTrain ;
128
127
int LastPlayerTrainCars ;
129
128
bool LastPlayerLocomotiveFlippedState ;
130
- int carPosition ;
129
+ int OldCarPosition ;
131
130
132
131
public TrainCarOperationsViewerWindow ( WindowManager owner )
133
132
: 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()
224
223
/// </summary>
225
224
private void ModifyWindowSize ( )
226
225
{
227
- if ( symbolsRowCount > 0 )
226
+ if ( SymbolsRowCount > 0 )
228
227
{
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 ) ) ;
232
231
233
232
var newHeight = ( int ) MathHelper . Clamp ( desiredHeight , 80 , WindowHeightMax ) ;
234
233
var newWidth = ( int ) MathHelper . Clamp ( desiredWidth , 100 , WindowWidthMax ) ;
@@ -241,13 +240,13 @@ private void ModifyWindowSize()
241
240
MoveTo ( Location . X , newTop ) ;
242
241
}
243
242
}
244
- public ControlLayoutVertical vbox ;
243
+ public ControlLayoutVertical Vbox ;
245
244
protected override ControlLayout Layout ( ControlLayout layout )
246
245
{
247
246
Label buttonClose ;
248
247
var textHeight = Owner . TextFontDefault . Height ;
249
248
textHeight = MathHelper . Clamp ( textHeight , SymbolWidth , Owner . TextFontDefault . Height ) ;
250
- vbox = base . Layout ( layout ) . AddLayoutVertical ( ) ;
249
+ Vbox = base . Layout ( layout ) . AddLayoutVertical ( ) ;
251
250
252
251
if ( PlayerTrain != null && PlayerTrain . Cars . Count ( ) > CarPosition )
253
252
{
@@ -266,15 +265,15 @@ protected override ControlLayout Layout(ControlLayout layout)
266
265
var wagonType = isEngine ? $ " { Viewer . Catalog . GetString ( locomotive . WagonType . ToString ( ) ) } " + $ ":{ Viewer . Catalog . GetString ( locomotive . EngineType . ToString ( ) ) } "
267
266
: $ " { Viewer . Catalog . GetString ( wagon . WagonType . ToString ( ) ) } ";
268
267
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 ) ) ;
270
269
buttonClose . Click += new Action < Control , Point > ( buttonClose_Click ) ;
271
270
buttonClose . Color = Owner . Viewer . TrainCarOperationsWindow . WarningCarPosition . Find ( x => x == true ) ? Color . Cyan : Color . White ;
272
- vbox . AddHorizontalSeparator ( ) ;
271
+ Vbox . AddHorizontalSeparator ( ) ;
273
272
}
274
273
275
- spacerRowCount = symbolsRowCount = 0 ;
274
+ SpacerRowCount = SymbolsRowCount = 0 ;
276
275
277
- var line = vbox . AddLayoutHorizontal ( vbox . RemainingHeight ) ;
276
+ var line = Vbox . AddLayoutHorizontal ( Vbox . RemainingHeight ) ;
278
277
var addspace = 0 ;
279
278
void AddSpace ( bool full )
280
279
{
@@ -347,17 +346,17 @@ void AddSpace(bool full)
347
346
}
348
347
buttonClose . Color = Owner . Viewer . TrainCarOperationsWindow . WarningCarPosition . Find ( x => x == true ) ? Color . Cyan : Color . White ;
349
348
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 ;
354
353
}
355
354
}
356
- return vbox ;
355
+ return Vbox ;
357
356
}
358
357
void buttonClose_Click ( Control arg1 , Point arg2 )
359
358
{
360
- carPosition = CarPosition ;
359
+ OldCarPosition = CarPosition ;
361
360
Visible = false ;
362
361
}
363
362
public override void PrepareFrame ( ElapsedTime elapsedTime , bool updateFull )
@@ -375,8 +374,6 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
375
374
CouplerChanged = false ;
376
375
PlayerTrain = Owner . Viewer . PlayerTrain ;
377
376
378
- //if (LastPlayerTrainCars != Owner.Viewer.PlayerTrain.Cars.Count){ Visible = false; }
379
-
380
377
LastPlayerTrainCars = Owner . Viewer . PlayerTrain . Cars . Count ;
381
378
CarPosition = CarPosition >= LastPlayerTrainCars ? LastPlayerTrainCars - 1 : CarPosition ;
382
379
if ( Owner . Viewer . PlayerLocomotive != null ) LastPlayerLocomotiveFlippedState = Owner . Viewer . PlayerLocomotive . Flipped ;
@@ -388,41 +385,39 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
388
385
TrainCar trainCar = Owner . Viewer . PlayerTrain . Cars [ CarPosition ] ;
389
386
bool isElectricDieselLocomotive = ( trainCar is MSTSElectricLocomotive ) || ( trainCar is MSTSDieselLocomotive ) ;
390
387
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 )
393
390
{
394
391
// Updates CarPosition
395
392
CarPosition = CouplerChanged ? NewCarPosition : CarPosition ;
396
-
397
- if ( carPosition != CarPosition || ( trainCarOperations . carIdClicked && CarPosition == 0 ) )
393
+
394
+ if ( OldCarPosition != CarPosition || ( trainCarOperations . CarIdClicked && CarPosition == 0 ) )
398
395
{
399
396
Owner . Viewer . FrontCamera . Activate ( ) ;
400
397
}
401
- carPosition = CarPosition ;
398
+ OldCarPosition = CarPosition ;
402
399
Layout ( ) ;
403
400
UpdateWindowSize ( ) ;
404
401
TrainCarOperationsChanged = false ;
405
402
406
403
// Avoids bug
407
- carOperations . CarOperationChanged = carOperations . Visible && carOperations . CarOperationChanged ? true : false ;
404
+ carOperations . CarOperationChanged = carOperations . Visible && carOperations . CarOperationChanged ;
408
405
}
409
406
// Updates power supply status
410
407
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 ( ) ) )
414
411
{
415
412
Layout ( ) ;
416
413
UpdateWindowSize ( ) ;
417
414
TrainCarOperationsChanged = true ;
418
415
}
419
416
//required by traincarwindow to ModifyWindowSize()
420
- windowHeight = vbox != null ? vbox . Position . Height : 0 ;
417
+ windowHeight = Vbox != null ? Vbox . Position . Height : 0 ;
421
418
}
422
419
}
423
- private static UserCommand ? GetPressedKey ( params UserCommand [ ] keysToTest ) => keysToTest
424
- . Where ( ( UserCommand key ) => UserInput . IsDown ( key ) )
425
- . FirstOrDefault ( ) ;
420
+
426
421
class buttonLoco : Image
427
422
{
428
423
readonly Viewer Viewer ;
@@ -476,14 +471,12 @@ void TrainCarOperationsCouplerFront_Click(Control arg1, Point arg2)
476
471
class buttonCouplerRear : Image
477
472
{
478
473
readonly Viewer Viewer ;
479
- readonly TrainCarOperationsViewerWindow TrainCarViewer ;
480
474
readonly int CarPosition ;
481
475
readonly bool Last ;
482
476
public buttonCouplerRear ( int x , int y , int size , Viewer viewer , TrainCar car , int carPosition )
483
477
: base ( x , y , size , size )
484
478
{
485
479
Viewer = viewer ;
486
- TrainCarViewer = Viewer . TrainCarOperationsViewerWindow ;
487
480
CarPosition = carPosition ;
488
481
Last = car == Viewer . PlayerTrain . Cars . Last ( ) ;
489
482
Texture = Last ? CouplerRear : Coupler ;
@@ -605,7 +598,7 @@ public buttonFrontBrakeHose(int x, int y, int size, Viewer viewer, TrainCar car,
605
598
new WagonBrakeHoseRearConnectCommand ( Viewer . Log , ( Viewer . PlayerTrain . Cars [ CarOperations . CarPosition - 1 ] as MSTSWagon ) , ! ( Viewer . PlayerTrain . Cars [ CarOperations . CarPosition - 1 ] as MSTSWagon ) . BrakeSystem . RearBrakeHoseConnected ) ;
606
599
CarOperations . FrontBrakeHoseChanged = false ;
607
600
}
608
- TrainCar . modifiedSetting = true ;
601
+ TrainCar . ModifiedSetting = true ;
609
602
TrainCarViewer . TrainCarOperationsChanged = true ;
610
603
}
611
604
@@ -856,7 +849,7 @@ public buttonToggleMU(int x, int y, int size, Viewer viewer, int carPosition)
856
849
var multipleUnitsConfiguration = Viewer . PlayerLocomotive . GetMultipleUnitsConfiguration ( ) ;
857
850
if ( Viewer . PlayerTrain . Cars [ CarPosition ] is MSTSDieselLocomotive && multipleUnitsConfiguration != null )
858
851
{
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 ;
860
853
}
861
854
else
862
855
{
@@ -938,7 +931,7 @@ public Texture2D locomotiveStatus1(int CarPosition)
938
931
string valuePart = parts ? [ 1 ] ;
939
932
if ( keyPart . Contains ( Viewer . Catalog . GetString ( "Engine" ) ) )
940
933
{
941
- TrainCarViewer . powerSupplyStatus = locomotiveStatus ;
934
+ TrainCarViewer . PowerSupplyStatus = locomotiveStatus ;
942
935
Texture = valuePart . Contains ( Viewer . Catalog . GetString ( "Running" ) ) ? PowerOn
943
936
: valuePart . Contains ( Viewer . Catalog . GetString ( "Stopped" ) ) ? PowerOff
944
937
: PowerChanging ;
@@ -948,17 +941,17 @@ public Texture2D locomotiveStatus1(int CarPosition)
948
941
MSTSElectricLocomotive locomotive = Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSElectricLocomotive ;
949
942
switch ( locomotive . ElectricPowerSupply . CircuitBreaker . State )
950
943
{
951
- case CircuitBreakerState . Closed :
944
+ case ORTS . Scripting . Api . CircuitBreakerState . Closed :
952
945
Texture = PowerOn ;
953
946
break ;
954
- case CircuitBreakerState . Closing :
947
+ case ORTS . Scripting . Api . CircuitBreakerState . Closing :
955
948
Texture = PowerChanging ;
956
949
break ;
957
- case CircuitBreakerState . Open :
950
+ case ORTS . Scripting . Api . CircuitBreakerState . Open :
958
951
Texture = PowerOff ;
959
952
break ;
960
953
}
961
- TrainCarViewer . circuitBreakerState = locomotive . ElectricPowerSupply . CircuitBreaker . State . ToString ( ) ;
954
+ TrainCarViewer . CircuitBreakerState = locomotive . ElectricPowerSupply . CircuitBreaker . State . ToString ( ) ;
962
955
}
963
956
return Texture ;
964
957
}
@@ -1028,7 +1021,7 @@ public Texture2D locomotiveStatus(int CarPosition)
1028
1021
string valuePart = parts ? [ 1 ] ;
1029
1022
if ( keyPart . Contains ( Viewer . Catalog . GetString ( "Battery" ) ) )
1030
1023
{
1031
- TrainCarViewer . batteryStatus = locomotiveStatus ;
1024
+ TrainCarViewer . BatteryStatus = locomotiveStatus ;
1032
1025
Texture = valuePart . Contains ( Viewer . Catalog . GetString ( "On" ) ) ? BattOn32 : BattOff32 ;
1033
1026
break ;
1034
1027
}
0 commit comments