Skip to content

Commit 23578e9

Browse files
authored
Merge pull request #995 from mbm-OR/bugfix/Fix-TrainCarOperations-TrainOperationsViewer-overlap
Fix: TrainCarOperations and TrainOperationsViewer windows overlap.
2 parents 5d79907 + 95da33b commit 23578e9

File tree

2 files changed

+88
-13
lines changed

2 files changed

+88
-13
lines changed

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsViewerWindow.cs

+79-13
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public string CurrentCarID
104104
set;
105105
get;
106106
}
107-
public int NewCarPosition
107+
public int NewCarPosition
108108
{
109109
set;
110110
get;
@@ -314,7 +314,14 @@ private void ModifyWindowSize()
314314

315315
// Display window
316316
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);
318325
}
319326
}
320327
public ControlLayoutVertical Vbox;
@@ -368,7 +375,7 @@ void AddSpace(bool full)
368375
var car = PlayerTrain.Cars[CarPosition];
369376
//Reset brakes
370377
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));
372379

373380
if (car != PlayerTrain.Cars.First())
374381
AddSpace(false);
@@ -448,6 +455,11 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
448455
else if (UserInput.IsPressed(UserCommand.CameraCarLast))
449456
CarPosition = Owner.Viewer.PlayerTrain.Cars.Count - 1;
450457

458+
if (Owner.Viewer.TrainCarOperationsWindow.LayoutMoved)
459+
{
460+
UpdateWindowSize();
461+
}
462+
451463
if (updateFull)
452464
{
453465
var carOperations = Owner.Viewer.CarOperationsWindow;
@@ -460,16 +472,16 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
460472
PlayerTrain = Owner.Viewer.PlayerTrain;
461473

462474
LastPlayerTrainCars = Owner.Viewer.PlayerTrain.Cars.Count;
463-
CarPosition = CarPosition >= LastPlayerTrainCars? LastPlayerTrainCars - 1: CarPosition;
475+
CarPosition = CarPosition >= LastPlayerTrainCars ? LastPlayerTrainCars - 1 : CarPosition;
464476
if (Owner.Viewer.PlayerLocomotive != null) LastPlayerLocomotiveFlippedState = Owner.Viewer.PlayerLocomotive.Flipped;
465-
477+
466478
Layout();
467479
UpdateWindowSize();
468480
}
469481

470482
TrainCar trainCar = Owner.Viewer.PlayerTrain.Cars[CarPosition];
471483
bool isElectricDieselLocomotive = (trainCar is MSTSElectricLocomotive) || (trainCar is MSTSDieselLocomotive);
472-
484+
473485
if (OldCarPosition != CarPosition || TrainCarOperationsChanged || carOperations.CarOperationChanged
474486
|| trainCarOperations.CarIdClicked || carOperations.RearBrakeHoseChanged || carOperations.FrontBrakeHoseChanged)
475487
{
@@ -507,7 +519,7 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
507519
TrainCarOperationsChanged = true;
508520
}
509521

510-
for (var position = 0 ; position < Owner.Viewer.PlayerTrain.Cars.Count; position++)
522+
for (var position = 0; position < Owner.Viewer.PlayerTrain.Cars.Count; position++)
511523
{
512524
if (trainCarOperations.WarningCarPosition.Count > position && trainCarOperations.WarningCarPosition[position])
513525
{
@@ -534,7 +546,7 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
534546
windowHeight = Vbox != null ? Vbox.Position.Height : 0;
535547
}
536548
}
537-
549+
538550
class buttonLoco : Image
539551
{
540552
readonly Viewer Viewer;
@@ -643,7 +655,7 @@ class buttonInitializeBrakes : Image
643655
readonly Viewer Viewer;
644656
readonly TrainCarOperationsViewerWindow TrainCarViewer;
645657
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)
647659
: base(x, y, size, size)
648660
{
649661
Viewer = viewer;
@@ -826,7 +838,6 @@ class buttonFrontAngleCock : Image
826838
readonly TrainCarOperationsViewerWindow TrainCarViewer;
827839
readonly int CarPosition;
828840
readonly bool First;
829-
readonly float carAngleCockAOpenAmount;
830841
public buttonFrontAngleCock(int x, int y, int size, Viewer viewer, TrainCar car, int carPosition)
831842
: base(x, y, size, size)
832843
{
@@ -894,8 +905,8 @@ void buttonRearAngleCock_Click(Control arg1, Point arg2)
894905
if (Last) return;
895906

896907
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+
899910
if ((Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.AngleCockBOpen && carAngleCockBOpenAmount >= 1)
900911
{
901912
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)
10221033
var multipleUnitsConfiguration = Viewer.PlayerLocomotive.GetMultipleUnitsConfiguration();
10231034
if (Viewer.PlayerTrain.Cars[CarPosition] is MSTSDieselLocomotive && multipleUnitsConfiguration != null)
10241035
{
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;
10261037
}
10271038
else
10281039
{
@@ -1202,5 +1213,60 @@ public Texture2D locomotiveStatus(int CarPosition)
12021213
return Texture;
12031214
}
12041215
}
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+
}
12051271
}
12061272
}

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsWindow.cs

+9
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ public class TrainCarOperationsWindow : Window
9898
public bool IsFullScreen;
9999
public int OldPositionHeight;
100100
public int RowHeight;
101+
public Rectangle LayoutLocation;
102+
public Rectangle OldLocation;
103+
public bool LayoutMoved;
101104
public bool UpdateTrainCarOperation;
102105
public int WindowHeightMax;
103106
public int WindowHeightMin;
@@ -565,6 +568,12 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
565568
if (UserInput.IsPressed(UserCommand.CameraCarNext) || UserInput.IsPressed(UserCommand.CameraCarPrevious) || UserInput.IsPressed(UserCommand.CameraCarFirst) || UserInput.IsPressed(UserCommand.CameraCarLast))
566569
CarPositionChanged = true;
567570

571+
if (OldLocation != Location)
572+
{
573+
OldLocation = Location;
574+
LayoutMoved = true;
575+
}
576+
568577
if (updateFull)
569578
{
570579
var trainCarViewer = Owner.Viewer.TrainCarOperationsViewerWindow;

0 commit comments

Comments
 (0)