@@ -103,7 +103,7 @@ public string CurrentCarID
103103 set ;
104104 get ;
105105 }
106- public int NewCarPosition
106+ public int NewCarPosition
107107 {
108108 set ;
109109 get ;
@@ -311,7 +311,14 @@ private void ModifyWindowSize()
311311
312312 // Display window
313313 SizeTo ( newWidth , newHeight ) ;
314- MoveTo ( Location . X , newTop ) ;
314+ var locationX = Location . X ;
315+ var locationY = newTop ;
316+ if ( Owner . Viewer . TrainCarOperationsWindow . LayoutMoved )
317+ {
318+ CkeckCollision ( newWidth , newHeight , newTop , ref locationX , ref locationY ) ;
319+ Owner . Viewer . TrainCarOperationsWindow . LayoutMoved = false ;
320+ }
321+ MoveTo ( locationX , locationY ) ;
315322 }
316323 }
317324 public ControlLayoutVertical Vbox ;
@@ -445,6 +452,11 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
445452 else if ( UserInput . IsPressed ( UserCommand . CameraCarLast ) )
446453 CarPosition = Owner . Viewer . PlayerTrain . Cars . Count - 1 ;
447454
455+ if ( Owner . Viewer . TrainCarOperationsWindow . LayoutMoved )
456+ {
457+ UpdateWindowSize ( ) ;
458+ }
459+
448460 if ( updateFull )
449461 {
450462 var carOperations = Owner . Viewer . CarOperationsWindow ;
@@ -457,22 +469,22 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
457469 PlayerTrain = Owner . Viewer . PlayerTrain ;
458470
459471 LastPlayerTrainCars = Owner . Viewer . PlayerTrain . Cars . Count ;
460- CarPosition = CarPosition >= LastPlayerTrainCars ? LastPlayerTrainCars - 1 : CarPosition ;
472+ CarPosition = CarPosition >= LastPlayerTrainCars ? LastPlayerTrainCars - 1 : CarPosition ;
461473 if ( Owner . Viewer . PlayerLocomotive != null ) LastPlayerLocomotiveFlippedState = Owner . Viewer . PlayerLocomotive . Flipped ;
462-
474+
463475 Layout ( ) ;
464476 UpdateWindowSize ( ) ;
465477 }
466478
467479 TrainCar trainCar = Owner . Viewer . PlayerTrain . Cars [ CarPosition ] ;
468480 bool isElectricDieselLocomotive = ( trainCar is MSTSElectricLocomotive ) || ( trainCar is MSTSDieselLocomotive ) ;
469-
481+
470482 if ( OldCarPosition != CarPosition || TrainCarOperationsChanged || carOperations . CarOperationChanged
471483 || trainCarOperations . CarIdClicked || carOperations . RearBrakeHoseChanged || carOperations . FrontBrakeHoseChanged )
472484 {
473485 // Updates CarPosition
474486 CarPosition = CouplerChanged ? NewCarPosition : CarPosition ;
475-
487+
476488 if ( OldCarPosition != CarPosition || ( trainCarOperations . CarIdClicked && CarPosition == 0 ) )
477489 {
478490 Owner . Viewer . FrontCamera . Activate ( ) ;
@@ -496,7 +508,7 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
496508 TrainCarOperationsChanged = true ;
497509 }
498510
499- for ( var position = 0 ; position < Owner . Viewer . PlayerTrain . Cars . Count ; position ++ )
511+ for ( var position = 0 ; position < Owner . Viewer . PlayerTrain . Cars . Count ; position ++ )
500512 {
501513 if ( trainCarOperations . WarningCarPosition [ position ] )
502514 {
@@ -523,7 +535,7 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
523535 windowHeight = Vbox != null ? Vbox . Position . Height : 0 ;
524536 }
525537 }
526-
538+
527539 class buttonLoco : Image
528540 {
529541 readonly Viewer Viewer ;
@@ -883,8 +895,8 @@ void buttonRearAngleCock_Click(Control arg1, Point arg2)
883895 if ( Last ) return ;
884896
885897 new ToggleAngleCockBCommand ( Viewer . Log , ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) , ! ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) . BrakeSystem . AngleCockBOpen ) ;
886- var carAngleCockBOpenAmount = ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) . BrakeSystem . AngleCockBOpenAmount ;
887-
898+ var carAngleCockBOpenAmount = ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) . BrakeSystem . AngleCockBOpenAmount ;
899+
888900 if ( ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) . BrakeSystem . AngleCockBOpen && carAngleCockBOpenAmount >= 1 )
889901 {
890902 Viewer . Simulator . Confirmer . Information ( Viewer . Catalog . GetString ( "Rear angle cock opened" ) ) ;
@@ -1011,7 +1023,7 @@ public buttonToggleMU(int x, int y, int size, Viewer viewer, int carPosition)
10111023 var multipleUnitsConfiguration = Viewer . PlayerLocomotive . GetMultipleUnitsConfiguration ( ) ;
10121024 if ( Viewer . PlayerTrain . Cars [ CarPosition ] is MSTSDieselLocomotive && multipleUnitsConfiguration != null )
10131025 {
1014- Texture = Viewer . TrainCarOperationsWindow . ModifiedSetting || ( ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSLocomotive ) . RemoteControlGroup == 0 && multipleUnitsConfiguration != "1" ) ? MUconnected : MUdisconnected ;
1026+ Texture = Viewer . TrainCarOperationsWindow . ModifiedSetting || ( ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSLocomotive ) . RemoteControlGroup == 0 && multipleUnitsConfiguration != "1" ) ? MUconnected : MUdisconnected ;
10151027 }
10161028 else
10171029 {
@@ -1191,5 +1203,61 @@ public Texture2D locomotiveStatus(int CarPosition)
11911203 return Texture ;
11921204 }
11931205 }
1206+ public void CkeckCollision ( int newWidth , int newHeight , int newTop , ref int locationX , ref int locationY )
1207+ {
1208+ var trainCarOperations = Owner . Viewer . TrainCarOperationsWindow ;
1209+ var trainOperationsViewer = Owner . Viewer . TrainCarOperationsViewerWindow ;
1210+ var tcoX = trainCarOperations . Location . X ;
1211+ var tcoY = trainCarOperations . Location . Y ;
1212+ var tcoWidth = trainCarOperations . Location . Width ;
1213+ var tcoHeight = trainCarOperations . Location . Height ;
1214+ var tcoLocation = new Rectangle ( tcoX , tcoY , tcoWidth , tcoHeight ) ;
1215+ var tovLocation = new Rectangle ( trainOperationsViewer . Location . X , trainOperationsViewer . Location . Y , newWidth , newHeight ) ;
1216+ var newX = trainOperationsViewer . Location . X ;
1217+ var newY = trainOperationsViewer . Location . Y ;
1218+
1219+ // logic to apply
1220+ var displaySizeX = Owner . Viewer . DisplaySize . X ;
1221+ var halfDisplaySizeX = displaySizeX / 2 ;
1222+ var DisplaySizeY = Owner . Viewer . DisplaySize . Y ;
1223+ var halfDisplaySizeY = DisplaySizeY / 2 ;
1224+ var topMarging = tcoLocation . Y ;
1225+ var bottomMarging = DisplaySizeY - ( tcoLocation . Y + tcoLocation . Height ) ;
1226+ var leftMarging = tcoLocation . X ;
1227+ var rightMarging = displaySizeX - tcoLocation . X - tcoLocation . Width ;
1228+
1229+ if ( topMarging >= tovLocation . Height && halfDisplaySizeY > tcoLocation . Y ) // Top marging available
1230+ {
1231+ //StepCode = "Left00";
1232+ newY = tcoLocation . Y - tovLocation . Height ;
1233+ newX = tcoLocation . X ;
1234+ }
1235+ else if ( bottomMarging >= tovLocation . Height && halfDisplaySizeY < tcoLocation . Y ) // Bottom marging available
1236+ {
1237+ //StepCode = "Left01";
1238+ newY = tcoLocation . Y + tcoLocation . Height ;
1239+ newX = tcoLocation . X ;
1240+ }
1241+ else if ( leftMarging > rightMarging && leftMarging >= tovLocation . Width )
1242+ {
1243+ //StepCode = "Right02";
1244+ newX = tcoLocation . X - tovLocation . Width ;
1245+ newY = halfDisplaySizeY > tcoLocation . Y ? tcoLocation . Y : tcoLocation . Y + tcoLocation . Height - tovLocation . Height ;
1246+ }
1247+ else if ( leftMarging < rightMarging && rightMarging >= tovLocation . Width )
1248+ {
1249+ //StepCode = "Left03";
1250+ newX = tcoLocation . X + tcoLocation . Width ;
1251+ newY = halfDisplaySizeY < tcoLocation . Y ? tcoLocation . Y + tcoLocation . Height - tovLocation . Height : tcoLocation . Y ;
1252+ }
1253+ else if ( leftMarging <= tovLocation . Width && rightMarging <= tovLocation . Width )
1254+ {
1255+ //StepCode = "NoEspace00";
1256+ newX = tcoLocation . X ;
1257+ newY = halfDisplaySizeY > tcoLocation . Y ? tcoLocation . Y + tcoLocation . Height : tcoLocation . Y - tovLocation . Height ;
1258+ }
1259+ locationX = newX ;
1260+ locationY = newY ;
1261+ }
11941262 }
11951263}
0 commit comments