Skip to content

Commit

Permalink
Merge pull request #995 from mbm-OR/bugfix/Fix-TrainCarOperations-Tra…
Browse files Browse the repository at this point in the history
…inOperationsViewer-overlap

Fix: TrainCarOperations and TrainOperationsViewer windows overlap.
  • Loading branch information
mbm-OR authored Nov 28, 2024
2 parents 5d79907 + 95da33b commit 23578e9
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public string CurrentCarID
set;
get;
}
public int NewCarPosition
public int NewCarPosition
{
set;
get;
Expand Down Expand Up @@ -314,7 +314,14 @@ private void ModifyWindowSize()

// Display window
SizeTo(newWidth, newHeight);
MoveTo(Location.X, newTop);
var locationX = Location.X;
var locationY = newTop;
if (Owner.Viewer.TrainCarOperationsWindow.LayoutMoved)
{
CkeckCollision(newWidth, newHeight, ref locationX, ref locationY);
Owner.Viewer.TrainCarOperationsWindow.LayoutMoved = false;
}
MoveTo(locationX, locationY);
}
}
public ControlLayoutVertical Vbox;
Expand Down Expand Up @@ -368,7 +375,7 @@ void AddSpace(bool full)
var car = PlayerTrain.Cars[CarPosition];
//Reset brakes
var warningCarPos = Owner.Viewer.TrainCarOperationsWindow.WarningCarPosition.Where(x => x == true).Count();
line.Add(new buttonInitializeBrakes(0, 0, textHeight, Owner.Viewer, CarPosition, warningCarPos));
line.Add(new buttonInitializeBrakes(0, 0, textHeight, Owner.Viewer, warningCarPos));

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

if (Owner.Viewer.TrainCarOperationsWindow.LayoutMoved)
{
UpdateWindowSize();
}

if (updateFull)
{
var carOperations = Owner.Viewer.CarOperationsWindow;
Expand All @@ -460,16 +472,16 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
PlayerTrain = Owner.Viewer.PlayerTrain;

LastPlayerTrainCars = Owner.Viewer.PlayerTrain.Cars.Count;
CarPosition = CarPosition >= LastPlayerTrainCars? LastPlayerTrainCars - 1: CarPosition;
CarPosition = CarPosition >= LastPlayerTrainCars ? LastPlayerTrainCars - 1 : CarPosition;
if (Owner.Viewer.PlayerLocomotive != null) LastPlayerLocomotiveFlippedState = Owner.Viewer.PlayerLocomotive.Flipped;

Layout();
UpdateWindowSize();
}

TrainCar trainCar = Owner.Viewer.PlayerTrain.Cars[CarPosition];
bool isElectricDieselLocomotive = (trainCar is MSTSElectricLocomotive) || (trainCar is MSTSDieselLocomotive);

if (OldCarPosition != CarPosition || TrainCarOperationsChanged || carOperations.CarOperationChanged
|| trainCarOperations.CarIdClicked || carOperations.RearBrakeHoseChanged || carOperations.FrontBrakeHoseChanged)
{
Expand Down Expand Up @@ -507,7 +519,7 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
TrainCarOperationsChanged = true;
}

for (var position = 0 ; position < Owner.Viewer.PlayerTrain.Cars.Count; position++)
for (var position = 0; position < Owner.Viewer.PlayerTrain.Cars.Count; position++)
{
if (trainCarOperations.WarningCarPosition.Count > position && trainCarOperations.WarningCarPosition[position])
{
Expand All @@ -534,7 +546,7 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
windowHeight = Vbox != null ? Vbox.Position.Height : 0;
}
}

class buttonLoco : Image
{
readonly Viewer Viewer;
Expand Down Expand Up @@ -643,7 +655,7 @@ class buttonInitializeBrakes : Image
readonly Viewer Viewer;
readonly TrainCarOperationsViewerWindow TrainCarViewer;
readonly int WarningCars;
public buttonInitializeBrakes(int x, int y, int size, Viewer viewer, int carPosition, int warningCars)
public buttonInitializeBrakes(int x, int y, int size, Viewer viewer, int warningCars)
: base(x, y, size, size)
{
Viewer = viewer;
Expand Down Expand Up @@ -826,7 +838,6 @@ class buttonFrontAngleCock : Image
readonly TrainCarOperationsViewerWindow TrainCarViewer;
readonly int CarPosition;
readonly bool First;
readonly float carAngleCockAOpenAmount;
public buttonFrontAngleCock(int x, int y, int size, Viewer viewer, TrainCar car, int carPosition)
: base(x, y, size, size)
{
Expand Down Expand Up @@ -894,8 +905,8 @@ void buttonRearAngleCock_Click(Control arg1, Point arg2)
if (Last) return;

new ToggleAngleCockBCommand(Viewer.Log, (Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon), !(Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.AngleCockBOpen);
var carAngleCockBOpenAmount = (Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.AngleCockBOpenAmount;
var carAngleCockBOpenAmount = (Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.AngleCockBOpenAmount;

if ((Viewer.PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.AngleCockBOpen && carAngleCockBOpenAmount >= 1)
{
Viewer.Simulator.Confirmer.Information(Viewer.Catalog.GetString("Rear angle cock opened"));
Expand Down Expand Up @@ -1022,7 +1033,7 @@ public buttonToggleMU(int x, int y, int size, Viewer viewer, int carPosition)
var multipleUnitsConfiguration = Viewer.PlayerLocomotive.GetMultipleUnitsConfiguration();
if (Viewer.PlayerTrain.Cars[CarPosition] is MSTSDieselLocomotive && multipleUnitsConfiguration != null)
{
Texture = Viewer.TrainCarOperationsWindow.ModifiedSetting || ((Viewer.PlayerTrain.Cars[CarPosition] as MSTSLocomotive).RemoteControlGroup == 0 && multipleUnitsConfiguration != "1")? MUconnected : MUdisconnected;
Texture = Viewer.TrainCarOperationsWindow.ModifiedSetting || ((Viewer.PlayerTrain.Cars[CarPosition] as MSTSLocomotive).RemoteControlGroup == 0 && multipleUnitsConfiguration != "1") ? MUconnected : MUdisconnected;
}
else
{
Expand Down Expand Up @@ -1202,5 +1213,60 @@ public Texture2D locomotiveStatus(int CarPosition)
return Texture;
}
}
public void CkeckCollision(int newWidth, int newHeight, ref int locationX, ref int locationY)
{
var trainCarOperations = Owner.Viewer.TrainCarOperationsWindow;
var trainOperationsViewer = Owner.Viewer.TrainCarOperationsViewerWindow;
var tcoX = trainCarOperations.Location.X;
var tcoY = trainCarOperations.Location.Y;
var tcoWidth = trainCarOperations.Location.Width;
var tcoHeight = trainCarOperations.Location.Height;
var tcoLocation = new Rectangle(tcoX, tcoY, tcoWidth, tcoHeight);
var tovLocation = new Rectangle(trainOperationsViewer.Location.X, trainOperationsViewer.Location.Y, newWidth, newHeight);
var newX = trainOperationsViewer.Location.X;
var newY = trainOperationsViewer.Location.Y;

// logic to apply
var displaySizeX = Owner.Viewer.DisplaySize.X;
var DisplaySizeY = Owner.Viewer.DisplaySize.Y;
var halfDisplaySizeY = DisplaySizeY / 2;
var topMarging = tcoLocation.Y;
var bottomMarging = DisplaySizeY - (tcoLocation.Y + tcoLocation.Height);
var leftMarging = tcoLocation.X;
var rightMarging = displaySizeX - tcoLocation.X - tcoLocation.Width;

if (topMarging >= tovLocation.Height && halfDisplaySizeY > tcoLocation.Y)// Top marging available
{
//StepCode = "Left00";
newY = tcoLocation.Y - tovLocation.Height;
newX = tcoLocation.X;
}
else if (bottomMarging >= tovLocation.Height && halfDisplaySizeY < tcoLocation.Y)// Bottom marging available
{
//StepCode = "Left01";
newY = tcoLocation.Y + tcoLocation.Height;
newX = tcoLocation.X;
}
else if (leftMarging > rightMarging && leftMarging >= tovLocation.Width)
{
//StepCode = "Right02";
newX = tcoLocation.X - tovLocation.Width;
newY = halfDisplaySizeY > tcoLocation.Y ? tcoLocation.Y : tcoLocation.Y + tcoLocation.Height - tovLocation.Height;
}
else if (leftMarging < rightMarging && rightMarging >= tovLocation.Width)
{
//StepCode = "Left03";
newX = tcoLocation.X + tcoLocation.Width;
newY = halfDisplaySizeY < tcoLocation.Y ? tcoLocation.Y + tcoLocation.Height - tovLocation.Height : tcoLocation.Y;
}
else if (leftMarging <= tovLocation.Width && rightMarging <= tovLocation.Width)
{
//StepCode = "NoEspace00";
newX = tcoLocation.X;
newY = halfDisplaySizeY > tcoLocation.Y ? tcoLocation.Y + tcoLocation.Height : tcoLocation.Y - tovLocation.Height;
}
locationX = newX;
locationY = newY;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public class TrainCarOperationsWindow : Window
public bool IsFullScreen;
public int OldPositionHeight;
public int RowHeight;
public Rectangle LayoutLocation;
public Rectangle OldLocation;
public bool LayoutMoved;
public bool UpdateTrainCarOperation;
public int WindowHeightMax;
public int WindowHeightMin;
Expand Down Expand Up @@ -565,6 +568,12 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
if (UserInput.IsPressed(UserCommand.CameraCarNext) || UserInput.IsPressed(UserCommand.CameraCarPrevious) || UserInput.IsPressed(UserCommand.CameraCarFirst) || UserInput.IsPressed(UserCommand.CameraCarLast))
CarPositionChanged = true;

if (OldLocation != Location)
{
OldLocation = Location;
LayoutMoved = true;
}

if (updateFull)
{
var trainCarViewer = Owner.Viewer.TrainCarOperationsViewerWindow;
Expand Down

0 comments on commit 23578e9

Please sign in to comment.