Skip to content

Commit e92be5a

Browse files
committed
Fix front-coupler bug.
1 parent 3132306 commit e92be5a

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

Source/RunActivity/Viewer3D/Cameras.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,7 @@ protected override void OnActivate(bool sameCamera)
10661066
var isDownCameraOutsideFront = UserInput.IsDown(UserCommand.CameraOutsideFront);
10671067
var isDownCameraOutsideRear = UserInput.IsDown(UserCommand.CameraOutsideRear);
10681068
var isVisibleTrainCarViewer = Viewer.TrainCarOperationsViewerWindow.Visible;
1069+
var trainCars = GetCameraCars();
10691070

10701071
if (attachedCar == null || attachedCar.Train != Viewer.SelectedTrain || carPosition != oldCarPosition || isDownCameraOutsideFront || isDownCameraOutsideRear)
10711072
{
@@ -1076,9 +1077,8 @@ protected override void OnActivate(bool sameCamera)
10761077
SetCameraCar(GetCameraCars().First());
10771078
oldCarPosition = 0;
10781079
}
1079-
else if (isVisibleTrainCarViewer && carPosition >= 0)
1080-
{
1081-
var trainCars = GetCameraCars();
1080+
else if (isVisibleTrainCarViewer && carPosition >= 0 && carPosition < trainCars.Count())
1081+
{
10821082
SetCameraCar(trainCars[carPosition]);
10831083
oldCarPosition = carPosition;
10841084
}
@@ -1092,13 +1092,12 @@ protected override void OnActivate(bool sameCamera)
10921092
}
10931093
else
10941094
{
1095-
var trainCars = GetCameraCars();
10961095
if (!isVisibleTrainCarViewer && isDownCameraOutsideRear)
10971096
{
10981097
SetCameraCar(GetCameraCars().Last());
10991098
oldCarPosition = 0;
11001099
}
1101-
else if (isVisibleTrainCarViewer && carPosition >= 0)
1100+
else if (isVisibleTrainCarViewer && carPosition >= 0 && carPosition < trainCars.Count())
11021101
{
11031102
SetCameraCar(trainCars[carPosition]);
11041103
oldCarPosition = carPosition;

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsViewerWindow.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using Orts.Simulation.RollingStocks.SubSystems.Brakes;
2626
using Orts.Simulation.RollingStocks.SubSystems.Brakes.MSTS;
2727
using Orts.Simulation.RollingStocks.SubSystems.PowerSupplies;
28+
using Orts.Viewer3D.RollingStock;
2829
using ORTS.Common;
2930
using ORTS.Common.Input;
3031
using ORTS.Scripting.Api;
@@ -123,6 +124,7 @@ public struct ListLabel
123124
int LastPlayerTrainCars;
124125
bool LastPlayerLocomotiveFlippedState;
125126
int carPosition;
127+
bool couplerFront = false;
126128
public TrainCarOperationsViewerWindow(WindowManager owner)
127129
: base(owner, Window.DecorationSize.X + CarListPadding + ((owner.TextFontDefault.Height + 12) * 20), Window.DecorationSize.Y + ((owner.TextFontDefault.Height + 12) * 2), Viewer.Catalog.GetString("Train Operations Viewer"))
128130
{
@@ -335,7 +337,7 @@ void AddSpace(bool full)
335337
AddSpace(false);
336338
if ((wagon != null) && (wagon.PowerSupply is IPowerSupply))
337339
{
338-
line.Add(new ToggleBatterySwitch(0, 0, textHeight, Owner.Viewer, carPosition));
340+
line.Add(new ToggleBatterySwitch(0, 0, textHeight, Owner.Viewer, CarPosition));
339341
AddSpace(false);
340342
}
341343
}
@@ -361,24 +363,27 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
361363
if (updateFull)
362364
{
363365
var carOperations = Owner.Viewer.CarOperationsWindow;
364-
var trainCarOperations = Owner.Viewer.TrainCarOperationsWindow;
365-
TrainCar trainCar = Owner.Viewer.PlayerTrain.Cars[CarPosition];
366-
bool isElectricDieselLocomotive = (trainCar is MSTSElectricLocomotive) || (trainCar is MSTSDieselLocomotive);
366+
var trainCarOperations = Owner.Viewer.TrainCarOperationsWindow;
367367

368-
if (PlayerTrain != Owner.Viewer.PlayerTrain || Owner.Viewer.PlayerTrain.Cars.Count != LastPlayerTrainCars || (Owner.Viewer.PlayerLocomotive != null &&
368+
if (couplerFront || PlayerTrain != Owner.Viewer.PlayerTrain || Owner.Viewer.PlayerTrain.Cars.Count != LastPlayerTrainCars || (Owner.Viewer.PlayerLocomotive != null &&
369369
LastPlayerLocomotiveFlippedState != Owner.Viewer.PlayerLocomotive.Flipped))
370370
{
371+
couplerFront = false;
371372
PlayerTrain = Owner.Viewer.PlayerTrain;
372373

373-
if (LastPlayerTrainCars != Owner.Viewer.PlayerTrain.Cars.Count) { Visible = false; }
374+
if (LastPlayerTrainCars != Owner.Viewer.PlayerTrain.Cars.Count){ Visible = false; }
374375

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

378380
Layout();
379381
UpdateWindowSize();
380382
}
381383

384+
TrainCar trainCar = Owner.Viewer.PlayerTrain.Cars[CarPosition];
385+
bool isElectricDieselLocomotive = (trainCar is MSTSElectricLocomotive) || (trainCar is MSTSDieselLocomotive);
386+
382387
if (carPosition != CarPosition || TrainCarOperationsChanged || carOperations.CarOperationChanged
383388
|| trainCarOperations.modifiedSetting || carOperations.RearBrakeHoseChanged || carOperations.FrontBrakeHoseChanged)
384389
{
@@ -453,8 +458,9 @@ void TrainCarOperationsCouplerFront_Click(Control arg1, Point arg2)
453458
}
454459
else
455460
{
456-
new UncoupleCommand(Viewer.Log, CarPosition);
457-
if (Viewer.CarOperationsWindow.CarPosition > CarPosition)
461+
new UncoupleCommand(Viewer.Log, CarPosition - 1);
462+
TrainCarViewer.couplerFront = true;
463+
if (Viewer.CarOperationsWindow.CarPosition > CarPosition - 1)
458464
Viewer.CarOperationsWindow.Visible = false;
459465
}
460466
}

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
526526
localScrollLayout(selectedCarPosition);
527527
}
528528

529-
UserCommand? controlDiesel = GetPressedKey(UserCommand.ControlDieselHelper, UserCommand.ControlDieselPlayer);
530-
if (controlDiesel == UserCommand.ControlDieselHelper || controlDiesel == UserCommand.ControlDieselPlayer)
529+
UserCommand ? controlDiesel = GetPressedKey(UserCommand.ControlDieselHelper, UserCommand.ControlDieselPlayer, UserCommand.ControlInitializeBrakes);
530+
if (controlDiesel == UserCommand.ControlDieselHelper || controlDiesel == UserCommand.ControlDieselPlayer || controlDiesel == UserCommand.ControlInitializeBrakes)
531531
{
532532
Layout();
533533
powerSupplyStatus = Owner.Viewer.PlayerTrain.Cars[CarPosition].GetStatus();

0 commit comments

Comments
 (0)