@@ -103,7 +103,7 @@ public string CurrentCarID
103
103
set ;
104
104
get ;
105
105
}
106
- public int NewCarPosition
106
+ public int NewCarPosition
107
107
{
108
108
set ;
109
109
get ;
@@ -311,7 +311,14 @@ private void ModifyWindowSize()
311
311
312
312
// Display window
313
313
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 ) ;
315
322
}
316
323
}
317
324
public ControlLayoutVertical Vbox ;
@@ -445,6 +452,11 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
445
452
else if ( UserInput . IsPressed ( UserCommand . CameraCarLast ) )
446
453
CarPosition = Owner . Viewer . PlayerTrain . Cars . Count - 1 ;
447
454
455
+ if ( Owner . Viewer . TrainCarOperationsWindow . LayoutMoved )
456
+ {
457
+ UpdateWindowSize ( ) ;
458
+ }
459
+
448
460
if ( updateFull )
449
461
{
450
462
var carOperations = Owner . Viewer . CarOperationsWindow ;
@@ -457,22 +469,22 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
457
469
PlayerTrain = Owner . Viewer . PlayerTrain ;
458
470
459
471
LastPlayerTrainCars = Owner . Viewer . PlayerTrain . Cars . Count ;
460
- CarPosition = CarPosition >= LastPlayerTrainCars ? LastPlayerTrainCars - 1 : CarPosition ;
472
+ CarPosition = CarPosition >= LastPlayerTrainCars ? LastPlayerTrainCars - 1 : CarPosition ;
461
473
if ( Owner . Viewer . PlayerLocomotive != null ) LastPlayerLocomotiveFlippedState = Owner . Viewer . PlayerLocomotive . Flipped ;
462
-
474
+
463
475
Layout ( ) ;
464
476
UpdateWindowSize ( ) ;
465
477
}
466
478
467
479
TrainCar trainCar = Owner . Viewer . PlayerTrain . Cars [ CarPosition ] ;
468
480
bool isElectricDieselLocomotive = ( trainCar is MSTSElectricLocomotive ) || ( trainCar is MSTSDieselLocomotive ) ;
469
-
481
+
470
482
if ( OldCarPosition != CarPosition || TrainCarOperationsChanged || carOperations . CarOperationChanged
471
483
|| trainCarOperations . CarIdClicked || carOperations . RearBrakeHoseChanged || carOperations . FrontBrakeHoseChanged )
472
484
{
473
485
// Updates CarPosition
474
486
CarPosition = CouplerChanged ? NewCarPosition : CarPosition ;
475
-
487
+
476
488
if ( OldCarPosition != CarPosition || ( trainCarOperations . CarIdClicked && CarPosition == 0 ) )
477
489
{
478
490
Owner . Viewer . FrontCamera . Activate ( ) ;
@@ -496,7 +508,7 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
496
508
TrainCarOperationsChanged = true ;
497
509
}
498
510
499
- for ( var position = 0 ; position < Owner . Viewer . PlayerTrain . Cars . Count ; position ++ )
511
+ for ( var position = 0 ; position < Owner . Viewer . PlayerTrain . Cars . Count ; position ++ )
500
512
{
501
513
if ( trainCarOperations . WarningCarPosition [ position ] )
502
514
{
@@ -523,7 +535,7 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
523
535
windowHeight = Vbox != null ? Vbox . Position . Height : 0 ;
524
536
}
525
537
}
526
-
538
+
527
539
class buttonLoco : Image
528
540
{
529
541
readonly Viewer Viewer ;
@@ -883,8 +895,8 @@ void buttonRearAngleCock_Click(Control arg1, Point arg2)
883
895
if ( Last ) return ;
884
896
885
897
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
+
888
900
if ( ( Viewer . PlayerTrain . Cars [ CarPosition ] as MSTSWagon ) . BrakeSystem . AngleCockBOpen && carAngleCockBOpenAmount >= 1 )
889
901
{
890
902
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)
1011
1023
var multipleUnitsConfiguration = Viewer . PlayerLocomotive . GetMultipleUnitsConfiguration ( ) ;
1012
1024
if ( Viewer . PlayerTrain . Cars [ CarPosition ] is MSTSDieselLocomotive && multipleUnitsConfiguration != null )
1013
1025
{
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 ;
1015
1027
}
1016
1028
else
1017
1029
{
@@ -1191,5 +1203,61 @@ public Texture2D locomotiveStatus(int CarPosition)
1191
1203
return Texture ;
1192
1204
}
1193
1205
}
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
+ }
1194
1262
}
1195
1263
}
0 commit comments