Skip to content

Commit

Permalink
Adjust Train Driver Window to line up with HuD operation of derailmen…
Browse files Browse the repository at this point in the history
…t window.
  • Loading branch information
peternewell committed Oct 3, 2021
1 parent 562fe42 commit 69a70cb
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions Source/RunActivity/Viewer3D/Popups/TrainDrivingWindow.cs
Expand Up @@ -1178,47 +1178,58 @@ void AddLabel(ListLabel label)
}

//Derailment Coefficient. Changed the float value output by a text label.
var maxDerailCoeff = 0.0f;
var carIDerailCoeff = "";
var carDerailPossible = false;
var carDerailExpected = false;

for (var i = 0; i < train.Cars.Count; i++)
{
var carDerailCoeff = train.Cars[i].DerailmentCoefficient;
carDerailCoeff = float.IsInfinity(carDerailCoeff) || float.IsNaN(carDerailCoeff) ? 0 : carDerailCoeff;
if (carDerailCoeff > maxDerailCoeff)

carIDerailCoeff = train.Cars[i].CarID;

// Only record the first car that has derailed, stop looking for other derailed cars
carDerailExpected = train.Cars[i].DerailExpected;
if (carDerailExpected)
{
break;
}

// Only record first instance of a possible car derailment (warning)
if (train.Cars[i].DerailPossible && !carDerailPossible)
{
maxDerailCoeff = carDerailCoeff;
carIDerailCoeff = train.Cars[i].CarID;
carDerailPossible = train.Cars[i].DerailPossible;
}
}

if (maxDerailCoeff > 0.66)
if (carDerailPossible || carDerailExpected)
{
derailLabelVisible = true;
clockDerailTime = Owner.Viewer.Simulator.ClockTime;
}

if (maxDerailCoeff > 0.66)
// The most extreme instance of the derail coefficient will only be displayed in the TDW
if (carDerailExpected)
{
if (maxDerailCoeff > 1)
AddLabel(new ListLabel
{
AddLabel(new ListLabel
{
FirstCol = Viewer.Catalog.GetString("DerailCoeff"),
LastCol = $"{Viewer.Catalog.GetString("Derailed")} {carIDerailCoeff}" + ColorCode[Color.OrangeRed],
});
}
else if (maxDerailCoeff < 1 && maxDerailCoeff > 0.66)
FirstCol = Viewer.Catalog.GetString("DerailCoeff"),
LastCol = $"{Viewer.Catalog.GetString("Derailed")} {carIDerailCoeff}" + ColorCode[Color.OrangeRed],
});
}
else if (carDerailPossible)
{
AddLabel(new ListLabel
{
AddLabel(new ListLabel
{
FirstCol = Viewer.Catalog.GetString("DerailCoeff"),
LastCol = $"{Viewer.Catalog.GetString("Warning")} {carIDerailCoeff}" + ColorCode[Color.Yellow],
});
}
FirstCol = Viewer.Catalog.GetString("DerailCoeff"),
LastCol = $"{Viewer.Catalog.GetString("Warning")} {carIDerailCoeff}" + ColorCode[Color.Yellow],
});
}

else
{
// delay to hide the derailcoeff label
// delay to hide the derailcoeff label if normal
if (derailLabelVisible && clockDerailTime + 3 < Owner.Viewer.Simulator.ClockTime)
derailLabelVisible = false;

Expand Down

0 comments on commit 69a70cb

Please sign in to comment.