@@ -117,7 +117,7 @@ public class TrainCarOperationsWindow : Window
117117 public bool updatingPowerSupply = false ;
118118
119119 public bool warningEnabled = false ;
120-
120+ public bool carIdClicked = false ;
121121 public bool modifiedSetting
122122 {
123123 set ;
@@ -440,29 +440,21 @@ public void topCarPositionVisible()
440440 { // Allows to find the last carposition, visible at the window bottom.
441441 if ( ( ! lastRowVisible && labelTop >= 0 ) || labelTop > DisplaySizeY )
442442 {
443- if ( DisplaySizeY > desiredHeight )
444- {
445- lastRowVisible = true ;
446- carPositionVisible = rowsCount ;
447- oldPositionHeight = vbox . Position . Height ;
448- }
449- else
443+ for ( int carPosition = 0 ; carPosition < rowsCount ; carPosition ++ )
450444 {
451- for ( int carPosition = 0 ; carPosition < rowsCount ; carPosition ++ )
445+ var labelTop = carPosition * rowHeight ;
446+ if ( labelTop > vbox . Position . Height - Owner . TextFontDefault . Height )
452447 {
453- var labelTop = carPosition * rowHeight ;
454- if ( labelTop > vbox . Position . Height - Owner . TextFontDefault . Height )
448+ if ( ! lastRowVisible && labelTop > 0 )
455449 {
456- if ( ! lastRowVisible && labelTop > 0 )
457- {
458- lastRowVisible = true ;
459- carPositionVisible = carPosition - 1 ;
460- oldPositionHeight = vbox . Position . Height ;
461- break ;
462- }
450+ lastRowVisible = true ;
451+ carPositionVisible = carPosition - 1 ;
452+ oldPositionHeight = vbox . Position . Height ;
453+ var carid = PlayerTrain . Cars [ carPositionVisible ] . CarID ;
454+ break ;
463455 }
464456 }
465- }
457+ }
466458 }
467459 }
468460 public void localScrollLayout ( int selectedCarPosition )
@@ -512,7 +504,7 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
512504 trainCarViewer . TrainCarOperationsChanged = ! trainCarViewer . Visible && trainCarViewer . TrainCarOperationsChanged ? false : trainCarViewer . TrainCarOperationsChanged ;
513505
514506 currentDisplaySizeY = DisplaySizeY ;
515- if ( Owner . Viewer . DisplaySize . Y != DisplaySizeY || modifiedSetting )
507+ if ( Owner . Viewer . DisplaySize . Y != DisplaySizeY || modifiedSetting || trainCarViewer . CouplerChanged )
516508 {
517509 lastRowVisible = false ;
518510 supplyStatusChanged = false ;
@@ -568,13 +560,14 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
568560 }
569561 }
570562 }
571- if ( trainCarViewer . TrainCarOperationsChanged || trainCarViewer . RearBrakeHoseChanged
572- || trainCarViewer . FrontBrakeHoseChanged || modifiedSetting || carOperations . CarOperationChanged )
563+ if ( trainCarViewer . TrainCarOperationsChanged || trainCarViewer . TrainCarOperationsChanged || trainCarViewer . RearBrakeHoseChanged
564+ || trainCarViewer . FrontBrakeHoseChanged || modifiedSetting || carIdClicked || carOperations . CarOperationChanged )
573565 {
574566 Layout ( ) ;
575567 localScrollLayout ( selectedCarPosition ) ;
576568 updateLayoutSize ( ) ;
577569 modifiedSetting = false ;
570+ carIdClicked = false ;
578571 // Avoids bug
579572 trainCarViewer . TrainCarOperationsChanged = warningEnabled ;
580573 carOperations . CarOperationChanged = carOperations . Visible && carOperations . CarOperationChanged ;
@@ -613,7 +606,17 @@ public buttonArrowRight(int x, int y, int size, Viewer viewer, int carPosition)
613606 TrainCarViewer = Viewer . TrainCarOperationsViewerWindow ;
614607 CarPosition = carPosition ;
615608
616- Texture = TrainCarViewer . Visible && TrainCarViewer . CarPosition == CarPosition ? Viewer . TrainCarOperationsWindow . allSymbolsMode ? ArrowRight : ArrowLeft : Empty ;
609+ // Coupler changed requires to modify the arrow position
610+ var trainCarViewerCarPosition = TrainCarViewer . CouplerChanged ? TrainCarViewer . NewCarPosition : TrainCarViewer . CarPosition ;
611+ if ( TrainCarViewer . CouplerChanged && trainCarViewerCarPosition == CarPosition )
612+ {
613+ Texture = TrainCarViewer . Visible ? Viewer . TrainCarOperationsWindow . allSymbolsMode ? ArrowRight : ArrowLeft : Empty ;
614+ Viewer . TrainCarOperationsWindow . carIdClicked = true ;
615+ TrainCarViewer . CarPosition = trainCarViewerCarPosition ;
616+ }
617+ else
618+ Texture = TrainCarViewer . Visible && trainCarViewerCarPosition == CarPosition ? Viewer . TrainCarOperationsWindow . allSymbolsMode ? ArrowRight : ArrowLeft : Empty ;
619+
617620 Source = new Rectangle ( 0 , 0 , size , size ) ;
618621 Click += new Action < Control , Point > ( buttonArrowRight_Click ) ;
619622 }
@@ -639,7 +642,17 @@ public buttonArrowLeft(int x, int y, int size, Viewer viewer, int carPosition)
639642 TrainCarViewer = Viewer . TrainCarOperationsViewerWindow ;
640643 CarPosition = carPosition ;
641644 Texture = Empty ;
642- Texture = TrainCarViewer . CarPosition == CarPosition ? ArrowLeft : Empty ;
645+ // Coupler changed requires to modify arrow position
646+ var trainCarViewerCarPosition = TrainCarViewer . CouplerChanged ? TrainCarViewer . NewCarPosition : TrainCarViewer . CarPosition ;
647+ if ( TrainCarViewer . CouplerChanged && trainCarViewerCarPosition == CarPosition )
648+ {
649+ Texture = trainCarViewerCarPosition == CarPosition ? ArrowLeft : Empty ;
650+ Viewer . TrainCarOperationsWindow . carIdClicked = true ;
651+ TrainCarViewer . CarPosition = trainCarViewerCarPosition ;
652+ }
653+ else
654+ Texture = trainCarViewerCarPosition == CarPosition ? ArrowLeft : Empty ;
655+
643656 Source = new Rectangle ( 0 , 0 , size , size ) ;
644657 Click += new Action < Control , Point > ( buttonArrowLeft_Click ) ;
645658 }
@@ -700,10 +713,9 @@ public void buttonLabel_Click(Control arg1, Point arg2)
700713 Control control = arg1 ;
701714
702715 TrainCar . carLabelText = Text ;
703- TrainCarViewer . YPosition = control . Position . Y ;
704716 TrainCarViewer . CarPosition = CarPosition ;
705717 TrainCarViewer . Visible = true ;
706- TrainCar . modifiedSetting = true ;
718+ TrainCar . carIdClicked = true ;
707719
708720 // required by localScrollLayout()
709721 TrainCar . selectedCarPosition = CarPosition ;
0 commit comments