Skip to content

Commit 9a724d6

Browse files
committed
Fix: BrakeHose not sync when coupling cars
1 parent 1db6c13 commit 9a724d6

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed
Loading

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsViewerWindow.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public class TrainCarOperationsViewerWindow : Window
7575
internal static Texture2D RearAngleCockPartial;
7676
internal static Texture2D ResetBrakesOff;
7777
internal static Texture2D ResetBrakesOn;
78+
internal static Texture2D ResetBrakesWarning;
7879

7980
public List<bool> AngleCockAPartiallyOpened = new List<bool>();
8081
public List<bool> AngleCockBPartiallyOpened = new List<bool>();
@@ -85,6 +86,8 @@ public class TrainCarOperationsViewerWindow : Window
8586
public int RowsCount;
8687
public int SpacerRowCount;
8788
public int SymbolsRowCount;
89+
public bool BrakeHoseCarCoupling;
90+
8891
const int SymbolWidth = 32;
8992
public static bool FontChanged;
9093
public static bool FontToBold;
@@ -231,6 +234,7 @@ protected internal override void Initialize()
231234

232235
Rectangle ResetBrakesOffRect = new Rectangle(64, 256, 32, 32);
233236
Rectangle ResetBrakesOnRect = new Rectangle(96, 256, 32, 32);
237+
Rectangle ResetBrakesWarningRect = new Rectangle(96, 32, 32, 32);
234238

235239
var GraphicsDeviceRender = Owner.Viewer.RenderProcess.GraphicsDevice;
236240
var TrainOperationsPath = System.IO.Path.Combine(Owner.Viewer.ContentPath, "TrainOperations\\TrainOperationsMap32.png");
@@ -280,6 +284,7 @@ protected internal override void Initialize()
280284

281285
ResetBrakesOff = SharedTextureManager.Get(GraphicsDeviceRender, TrainOperationsPath, ResetBrakesOffRect);
282286
ResetBrakesOn = SharedTextureManager.Get(GraphicsDeviceRender, TrainOperationsPath, ResetBrakesOnRect);
287+
ResetBrakesWarning = SharedTextureManager.Get(GraphicsDeviceRender, TrainOperationsPath, ResetBrakesWarningRect);
283288

284289
PowerOn = SharedTextureManager.Get(GraphicsDeviceRender, TrainOperationsPath, PowerOnRect);
285290
PowerOff = SharedTextureManager.Get(GraphicsDeviceRender, TrainOperationsPath, PowerOffRect);
@@ -638,7 +643,7 @@ public buttonInitializeBrakes(int x, int y, int size, Viewer viewer, int carPosi
638643
Viewer = viewer;
639644
TrainCarViewer = Viewer.TrainCarOperationsViewerWindow;
640645
WarningCars = warningCars;
641-
Texture = WarningCars > 2 ? ResetBrakesOn : ResetBrakesOff;
646+
Texture = WarningCars > 2 ? ResetBrakesOn : WarningCars > 0 && WarningCars < 3 ? ResetBrakesWarning : ResetBrakesOff;
642647
Source = new Rectangle(0, 0, size, size);
643648
Click += new Action<Control, Point>(buttonInitializeBrakes_Click);
644649
}
@@ -815,7 +820,6 @@ class buttonFrontAngleCock : Image
815820
readonly TrainCarOperationsViewerWindow TrainCarViewer;
816821
readonly int CarPosition;
817822
readonly bool First;
818-
readonly float carAngleCockAOpenAmount;
819823
public buttonFrontAngleCock(int x, int y, int size, Viewer viewer, TrainCar car, int carPosition)
820824
: base(x, y, size, size)
821825
{

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsWindow.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public class TrainCarOperationsWindow : Window
8383
public int SeparatorCount;
8484
public int SpacerRowCount;
8585
public int SymbolsRowCount;
86+
public bool BrakeHoseCarCoupling;
8687

8788
public ControlLayout Client;
8889
public bool CarPositionChanged;
@@ -499,6 +500,8 @@ void AddSpace()
499500
// Allows to resize the window according to the carPosition value.
500501
if (RowsCount > carPosition) RowsCount = carPosition;
501502
if (SeparatorCount > carPosition -1) SeparatorCount = carPosition - 1;
503+
504+
BrakeHoseCarCoupling = false;// All brake hoses checked
502505
}
503506
}
504507
return Vbox;
@@ -603,14 +606,11 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
603606
PlayerTrain = Owner.Viewer.PlayerTrain;
604607
if (LastPlayerTrainCars != Owner.Viewer.PlayerTrain.Cars.Count || !LayoutUpdated)
605608
{
606-
// Updates BrakeHoses
609+
// Updates brake hoses
607610
if (LastPlayerTrainCars > 0 && PlayerTrain.Cars.Count > LastPlayerTrainCars && ((PlayerTrain.Cars[LastPlayerTrainCars] as MSTSWagon).BrakeSystem.FrontBrakeHoseConnected != (PlayerTrain.Cars[LastPlayerTrainCars - 1] as MSTSWagon).BrakeSystem.RearBrakeHoseConnected))
608611
{
609-
// When coupling cars. The front brake hose of the new car is unconnected, the brake hose of the previous car must also be unconnected.
610-
new WagonBrakeHoseRearConnectCommand(Owner.Viewer.Log, (PlayerTrain.Cars[LastPlayerTrainCars - 1] as MSTSWagon), !(PlayerTrain.Cars[LastPlayerTrainCars - 1] as MSTSWagon).BrakeSystem.RearBrakeHoseConnected);
611-
new WagonBrakeHoseRearConnectCommand(Owner.Viewer.Log, (PlayerTrain.Cars[LastPlayerTrainCars] as MSTSWagon), !(PlayerTrain.Cars[LastPlayerTrainCars] as MSTSWagon).BrakeSystem.FrontBrakeHoseConnected);
612+
BrakeHoseCarCoupling = true;// Enable to check all brake hoses when coupling cars
612613
}
613-
614614
LayoutUpdated = true;
615615
Layout();
616616
localScrollLayout(SelectedCarPosition);
@@ -837,6 +837,7 @@ class buttonFrontBrakeHose : Image
837837
{
838838
readonly Viewer Viewer;
839839
readonly TrainCarOperationsViewerWindow TrainCarViewer;
840+
readonly TrainCarOperationsWindow TrainCarOperations;
840841
readonly CarOperationsWindow CarOperations;
841842
readonly int CarPosition;
842843
readonly bool First;
@@ -845,10 +846,25 @@ public buttonFrontBrakeHose(int x, int y, int size, Viewer viewer, TrainCar car,
845846
{
846847
Viewer = viewer;
847848
TrainCarViewer = Viewer.TrainCarOperationsViewerWindow;
849+
TrainCarOperations = Viewer.TrainCarOperationsWindow;
848850
CarOperations = Viewer.CarOperationsWindow;
851+
var PlayerTrain = Viewer.PlayerTrain;
849852

850853
CarPosition = carPosition;
851854
First = car == viewer.PlayerTrain.Cars.First();
855+
if (CarPosition > 0 && TrainCarOperations.BrakeHoseCarCoupling)
856+
{ // Sometimes when coupling cars. The front brake hose of the new car and the brake hose of the previous car are not synchronised.
857+
var frontBrakeHoseCurrentCar = (PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.FrontBrakeHoseConnected;
858+
var rearBrakeHosePreviousCar = (PlayerTrain.Cars[CarPosition - 1] as MSTSWagon).BrakeSystem.RearBrakeHoseConnected;
859+
if (frontBrakeHoseCurrentCar && !rearBrakeHosePreviousCar)
860+
{
861+
new WagonBrakeHoseConnectCommand(Viewer.Log, (PlayerTrain.Cars[CarPosition] as MSTSWagon), !(PlayerTrain.Cars[CarPosition] as MSTSWagon).BrakeSystem.FrontBrakeHoseConnected);
862+
}
863+
else if (!frontBrakeHoseCurrentCar && rearBrakeHosePreviousCar)
864+
{
865+
new WagonBrakeHoseRearConnectCommand(Viewer.Log, (PlayerTrain.Cars[CarPosition - 1] as MSTSWagon), !(PlayerTrain.Cars[CarPosition - 1] as MSTSWagon).BrakeSystem.RearBrakeHoseConnected);
866+
}
867+
}
852868
Texture = First ? BrakeHoseFirstDis : (viewer.PlayerTrain.Cars[carPosition] as MSTSWagon).BrakeSystem.FrontBrakeHoseConnected ? BrakeHoseCon : BrakeHoseDis;
853869

854870
// Allows compatibility with CarOperationWindow

0 commit comments

Comments
 (0)