From 69a70cb7fb2aea028b52e086eb854d32d3598762 Mon Sep 17 00:00:00 2001 From: peternewell Date: Sun, 3 Oct 2021 17:01:05 +1100 Subject: [PATCH] Adjust Train Driver Window to line up with HuD operation of derailment window. --- .../Viewer3D/Popups/TrainDrivingWindow.cs | 53 +++++++++++-------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/Source/RunActivity/Viewer3D/Popups/TrainDrivingWindow.cs b/Source/RunActivity/Viewer3D/Popups/TrainDrivingWindow.cs index 09e0214174..f8b529d1ef 100644 --- a/Source/RunActivity/Viewer3D/Popups/TrainDrivingWindow.cs +++ b/Source/RunActivity/Viewer3D/Popups/TrainDrivingWindow.cs @@ -1178,47 +1178,58 @@ void AddSeparator() => AddLabel(new ListLabel } //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;