2525using Orts . Simulation . RollingStocks . SubSystems . Brakes ;
2626using Orts . Simulation . RollingStocks . SubSystems . Brakes . MSTS ;
2727using Orts . Simulation . RollingStocks . SubSystems . PowerSupplies ;
28+ using Orts . Viewer3D . RollingStock ;
2829using ORTS . Common ;
2930using ORTS . Common . Input ;
3031using ORTS . Scripting . Api ;
@@ -123,6 +124,7 @@ public struct ListLabel
123124 int LastPlayerTrainCars ;
124125 bool LastPlayerLocomotiveFlippedState ;
125126 int carPosition ;
127+ bool couplerFront = false ;
126128 public TrainCarOperationsViewerWindow ( WindowManager owner )
127129 : 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" ) )
128130 {
@@ -335,7 +337,7 @@ void AddSpace(bool full)
335337 AddSpace ( false ) ;
336338 if ( ( wagon != null ) && ( wagon . PowerSupply is IPowerSupply ) )
337339 {
338- line . Add ( new ToggleBatterySwitch ( 0 , 0 , textHeight , Owner . Viewer , carPosition ) ) ;
340+ line . Add ( new ToggleBatterySwitch ( 0 , 0 , textHeight , Owner . Viewer , CarPosition ) ) ;
339341 AddSpace ( false ) ;
340342 }
341343 }
@@ -361,24 +363,27 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
361363 if ( updateFull )
362364 {
363365 var carOperations = Owner . Viewer . CarOperationsWindow ;
364- var trainCarOperations = Owner . Viewer . TrainCarOperationsWindow ;
365- TrainCar trainCar = Owner . Viewer . PlayerTrain . Cars [ CarPosition ] ;
366- bool isElectricDieselLocomotive = ( trainCar is MSTSElectricLocomotive ) || ( trainCar is MSTSDieselLocomotive ) ;
366+ var trainCarOperations = Owner . Viewer . TrainCarOperationsWindow ;
367367
368- if ( PlayerTrain != Owner . Viewer . PlayerTrain || Owner . Viewer . PlayerTrain . Cars . Count != LastPlayerTrainCars || ( Owner . Viewer . PlayerLocomotive != null &&
368+ if ( couplerFront || PlayerTrain != Owner . Viewer . PlayerTrain || Owner . Viewer . PlayerTrain . Cars . Count != LastPlayerTrainCars || ( Owner . Viewer . PlayerLocomotive != null &&
369369 LastPlayerLocomotiveFlippedState != Owner . Viewer . PlayerLocomotive . Flipped ) )
370370 {
371+ couplerFront = false ;
371372 PlayerTrain = Owner . Viewer . PlayerTrain ;
372373
373- if ( LastPlayerTrainCars != Owner . Viewer . PlayerTrain . Cars . Count ) { Visible = false ; }
374+ if ( LastPlayerTrainCars != Owner . Viewer . PlayerTrain . Cars . Count ) { Visible = false ; }
374375
375376 LastPlayerTrainCars = Owner . Viewer . PlayerTrain . Cars . Count ;
377+ CarPosition = CarPosition >= LastPlayerTrainCars ? LastPlayerTrainCars - 1 : CarPosition ;
376378 if ( Owner . Viewer . PlayerLocomotive != null ) LastPlayerLocomotiveFlippedState = Owner . Viewer . PlayerLocomotive . Flipped ;
377379
378380 Layout ( ) ;
379381 UpdateWindowSize ( ) ;
380382 }
381383
384+ TrainCar trainCar = Owner . Viewer . PlayerTrain . Cars [ CarPosition ] ;
385+ bool isElectricDieselLocomotive = ( trainCar is MSTSElectricLocomotive ) || ( trainCar is MSTSDieselLocomotive ) ;
386+
382387 if ( carPosition != CarPosition || TrainCarOperationsChanged || carOperations . CarOperationChanged
383388 || trainCarOperations . modifiedSetting || carOperations . RearBrakeHoseChanged || carOperations . FrontBrakeHoseChanged )
384389 {
@@ -453,8 +458,9 @@ void TrainCarOperationsCouplerFront_Click(Control arg1, Point arg2)
453458 }
454459 else
455460 {
456- new UncoupleCommand ( Viewer . Log , CarPosition ) ;
457- if ( Viewer . CarOperationsWindow . CarPosition > CarPosition )
461+ new UncoupleCommand ( Viewer . Log , CarPosition - 1 ) ;
462+ TrainCarViewer . couplerFront = true ;
463+ if ( Viewer . CarOperationsWindow . CarPosition > CarPosition - 1 )
458464 Viewer . CarOperationsWindow . Visible = false ;
459465 }
460466 }
0 commit comments