@@ -104,7 +104,7 @@ public string CurrentCarID
104
104
set ;
105
105
get ;
106
106
}
107
- public int NewCarPosition
107
+ public int NewCarPosition
108
108
{
109
109
set ;
110
110
get ;
@@ -314,7 +314,14 @@ private void ModifyWindowSize()
314
314
315
315
// Display window
316
316
SizeTo ( newWidth , newHeight ) ;
317
- MoveTo ( Location . X , newTop ) ;
317
+ var locationX = Location . X ;
318
+ var locationY = newTop ;
319
+ if ( Owner . Viewer . TrainCarOperationsWindow . LayoutMoved )
320
+ {
321
+ CkeckCollision ( newWidth , newHeight , ref locationX , ref locationY ) ;
322
+ Owner . Viewer . TrainCarOperationsWindow . LayoutMoved = false ;
323
+ }
324
+ MoveTo ( locationX , locationY ) ;
318
325
}
319
326
}
320
327
public ControlLayoutVertical Vbox ;
@@ -368,7 +375,7 @@ void AddSpace(bool full)
368
375
var car = PlayerTrain . Cars [ CarPosition ] ;
369
376
//Reset brakes
370
377
var warningCarPos = Owner . Viewer . TrainCarOperationsWindow . WarningCarPosition . Where ( x => x == true ) . Count ( ) ;
371
- line . Add ( new buttonInitializeBrakes ( 0 , 0 , textHeight , Owner . Viewer , CarPosition , warningCarPos ) ) ;
378
+ line . Add ( new buttonInitializeBrakes ( 0 , 0 , textHeight , Owner . Viewer , warningCarPos ) ) ;
372
379
373
380
if ( car != PlayerTrain . Cars . First ( ) )
374
381
AddSpace ( false ) ;
@@ -448,6 +455,11 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
448
455
else if ( UserInput . IsPressed ( UserCommand . CameraCarLast ) )
449
456
CarPosition = Owner . Viewer . PlayerTrain . Cars . Count - 1 ;
450
457
458
+ if ( Owner . Viewer . TrainCarOperationsWindow . LayoutMoved )
459
+ {
460
+ UpdateWindowSize ( ) ;
461
+ }
462
+
451
463
if ( updateFull )
452
464
{
453
465
var carOperations = Owner . Viewer . CarOperationsWindow ;
@@ -460,16 +472,16 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
460
472
PlayerTrain = Owner . Viewer . PlayerTrain ;
461
473
462
474
LastPlayerTrainCars = Owner . Viewer . PlayerTrain . Cars . Count ;
463
- CarPosition = CarPosition >= LastPlayerTrainCars ? LastPlayerTrainCars - 1 : CarPosition ;
475
+ CarPosition = CarPosition >= LastPlayerTrainCars ? LastPlayerTrainCars - 1 : CarPosition ;
464
476
if ( Owner . Viewer . PlayerLocomotive != null ) LastPlayerLocomotiveFlippedState = Owner . Viewer . PlayerLocomotive . Flipped ;
465
-
477
+
466
478
Layout ( ) ;
467
479
UpdateWindowSize ( ) ;
468
480
}
469
481
470
482
TrainCar trainCar = Owner . Viewer . PlayerTrain . Cars [ CarPosition ] ;
471
483
bool isElectricDieselLocomotive = ( trainCar is MSTSElectricLocomotive ) || ( trainCar is MSTSDieselLocomotive ) ;
472
-
484
+
473
485
if ( OldCarPosition != CarPosition || TrainCarOperationsChanged || carOperations . CarOperationChanged
474
486
|| trainCarOperations . CarIdClicked || carOperations . RearBrakeHoseChanged || carOperations . FrontBrakeHoseChanged )
475
487
{
@@ -507,7 +519,7 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
507
519
TrainCarOperationsChanged = true ;
508
520
}
509
521
510
- for ( var position = 0 ; position < Owner . Viewer . PlayerTrain . Cars . Count ; position ++ )
522
+ for ( var position = 0 ; position < Owner . Viewer . PlayerTrain . Cars . Count ; position ++ )
511
523
{
512
524
if ( trainCarOperations . WarningCarPosition . Count > position && trainCarOperations . WarningCarPosition [ position ] )
513
525
{
@@ -534,7 +546,7 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
534
546
windowHeight = Vbox != null ? Vbox . Position . Height : 0 ;
535
547
}
536
548
}
537
-
549
+
538
550
class buttonLoco : Image
539
551
{
540
552
readonly Viewer Viewer ;
@@ -643,7 +655,7 @@ class buttonInitializeBrakes : Image
643
655
readonly Viewer Viewer ;
644
656
readonly TrainCarOperationsViewerWindow TrainCarViewer ;
645
657
readonly int WarningCars ;
646
- public buttonInitializeBrakes ( int x , int y , int size , Viewer viewer , int carPosition , int warningCars )
658
+ public buttonInitializeBrakes ( int x , int y , int size , Viewer viewer , int warningCars )
647
659
: base ( x , y , size , size )
648
660
{
649
661
Viewer = viewer ;
@@ -826,7 +838,6 @@ class buttonFrontAngleCock : Image
826
838
readonly TrainCarOperationsViewerWindow TrainCarViewer ;
827
839
readonly int CarPosition ;
828
840
readonly bool First ;
829
- readonly float carAngleCockAOpenAmount ;
830
841
public buttonFrontAngleCock ( int x , int y , int size , Viewer viewer , TrainCar car , int carPosition )
831
842
: base ( x , y , size , size )
832
843
{
@@ -894,8 +905,8 @@ void buttonRearAngleCock_Click(Control arg1, Point arg2)
894
905
if ( Last ) return ;
895
906
896
907
new ToggleAngleCockBCommand ( Viewer . Log , ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) , ! ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) . BrakeSystem . AngleCockBOpen ) ;
897
- var carAngleCockBOpenAmount = ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) . BrakeSystem . AngleCockBOpenAmount ;
898
-
908
+ var carAngleCockBOpenAmount = ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) . BrakeSystem . AngleCockBOpenAmount ;
909
+
899
910
if ( ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) . BrakeSystem . AngleCockBOpen && carAngleCockBOpenAmount >= 1 )
900
911
{
901
912
Viewer . Simulator . Confirmer . Information ( Viewer . Catalog . GetString ( "Rear angle cock opened" ) ) ;
@@ -1022,7 +1033,7 @@ public buttonToggleMU(int x, int y, int size, Viewer viewer, int carPosition)
1022
1033
var multipleUnitsConfiguration = Viewer . PlayerLocomotive . GetMultipleUnitsConfiguration ( ) ;
1023
1034
if ( Viewer . PlayerTrain . Cars [ CarPosition ] is MSTSDieselLocomotive && multipleUnitsConfiguration != null )
1024
1035
{
1025
- Texture = Viewer . TrainCarOperationsWindow . ModifiedSetting || ( ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSLocomotive ) . RemoteControlGroup == 0 && multipleUnitsConfiguration != "1" ) ? MUconnected : MUdisconnected ;
1036
+ Texture = Viewer . TrainCarOperationsWindow . ModifiedSetting || ( ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSLocomotive ) . RemoteControlGroup == 0 && multipleUnitsConfiguration != "1" ) ? MUconnected : MUdisconnected ;
1026
1037
}
1027
1038
else
1028
1039
{
@@ -1202,5 +1213,60 @@ public Texture2D locomotiveStatus(int CarPosition)
1202
1213
return Texture ;
1203
1214
}
1204
1215
}
1216
+ public void CkeckCollision ( int newWidth , int newHeight , ref int locationX , ref int locationY )
1217
+ {
1218
+ var trainCarOperations = Owner . Viewer . TrainCarOperationsWindow ;
1219
+ var trainOperationsViewer = Owner . Viewer . TrainCarOperationsViewerWindow ;
1220
+ var tcoX = trainCarOperations . Location . X ;
1221
+ var tcoY = trainCarOperations . Location . Y ;
1222
+ var tcoWidth = trainCarOperations . Location . Width ;
1223
+ var tcoHeight = trainCarOperations . Location . Height ;
1224
+ var tcoLocation = new Rectangle ( tcoX , tcoY , tcoWidth , tcoHeight ) ;
1225
+ var tovLocation = new Rectangle ( trainOperationsViewer . Location . X , trainOperationsViewer . Location . Y , newWidth , newHeight ) ;
1226
+ var newX = trainOperationsViewer . Location . X ;
1227
+ var newY = trainOperationsViewer . Location . Y ;
1228
+
1229
+ // logic to apply
1230
+ var displaySizeX = Owner . Viewer . DisplaySize . X ;
1231
+ var DisplaySizeY = Owner . Viewer . DisplaySize . Y ;
1232
+ var halfDisplaySizeY = DisplaySizeY / 2 ;
1233
+ var topMarging = tcoLocation . Y ;
1234
+ var bottomMarging = DisplaySizeY - ( tcoLocation . Y + tcoLocation . Height ) ;
1235
+ var leftMarging = tcoLocation . X ;
1236
+ var rightMarging = displaySizeX - tcoLocation . X - tcoLocation . Width ;
1237
+
1238
+ if ( topMarging >= tovLocation . Height && halfDisplaySizeY > tcoLocation . Y ) // Top marging available
1239
+ {
1240
+ //StepCode = "Left00";
1241
+ newY = tcoLocation . Y - tovLocation . Height ;
1242
+ newX = tcoLocation . X ;
1243
+ }
1244
+ else if ( bottomMarging >= tovLocation . Height && halfDisplaySizeY < tcoLocation . Y ) // Bottom marging available
1245
+ {
1246
+ //StepCode = "Left01";
1247
+ newY = tcoLocation . Y + tcoLocation . Height ;
1248
+ newX = tcoLocation . X ;
1249
+ }
1250
+ else if ( leftMarging > rightMarging && leftMarging >= tovLocation . Width )
1251
+ {
1252
+ //StepCode = "Right02";
1253
+ newX = tcoLocation . X - tovLocation . Width ;
1254
+ newY = halfDisplaySizeY > tcoLocation . Y ? tcoLocation . Y : tcoLocation . Y + tcoLocation . Height - tovLocation . Height ;
1255
+ }
1256
+ else if ( leftMarging < rightMarging && rightMarging >= tovLocation . Width )
1257
+ {
1258
+ //StepCode = "Left03";
1259
+ newX = tcoLocation . X + tcoLocation . Width ;
1260
+ newY = halfDisplaySizeY < tcoLocation . Y ? tcoLocation . Y + tcoLocation . Height - tovLocation . Height : tcoLocation . Y ;
1261
+ }
1262
+ else if ( leftMarging <= tovLocation . Width && rightMarging <= tovLocation . Width )
1263
+ {
1264
+ //StepCode = "NoEspace00";
1265
+ newX = tcoLocation . X ;
1266
+ newY = halfDisplaySizeY > tcoLocation . Y ? tcoLocation . Y + tcoLocation . Height : tcoLocation . Y - tovLocation . Height ;
1267
+ }
1268
+ locationX = newX ;
1269
+ locationY = newY ;
1270
+ }
1205
1271
}
1206
1272
}
0 commit comments