Skip to content

Commit

Permalink
Add locomotive coloring by MU and engine status
Browse files Browse the repository at this point in the history
  • Loading branch information
mspielberg committed Dec 21, 2020
1 parent 06bf6cd commit 6f2ca39
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Overlay.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DV.Logic.Job;
using DV.MultipleUnit;
using DV.Simulation.Brake;
using System;
using System.Collections;
Expand Down Expand Up @@ -308,7 +309,11 @@ private void DrawCarList()
GUILayout.BeginVertical();
GUILayout.Label("ID", noWrap);
foreach (CarGroup group in groups)
{
GUI.contentColor = GetCarColor(group.cars[0]);
GUILayout.Label(group.cars[0].ID, noWrap);
}
GUI.contentColor = Color.white;
GUILayout.EndVertical();

if (Main.settings.showCarStress)
Expand All @@ -324,6 +329,33 @@ private void DrawCarList()
GUILayout.EndHorizontal();
}

private const float HueOrange = 30f/360f;
private Color GetCarColor(TrainCar car)
{
if (!car.IsLoco)
return Color.white;

var isMultipleUnitCapable = car.TryGetComponent<MultipleUnitModule>(out var muModule);
var frontMUDisconnected = isMultipleUnitCapable
&& car.frontCoupler.IsCoupled()
&& car.rearCoupler.coupledTo?.train?.carType == car.carType
&& !muModule.frontCable.IsConnected;
var rearMUDisconnected = isMultipleUnitCapable
&& car.rearCoupler.IsCoupled()
&& car.rearCoupler.coupledTo?.train?.carType == car.carType
&& !muModule.rearCable.IsConnected;
var hasDisconnectedMUCable = frontMUDisconnected || rearMUDisconnected;

var isRunning = car.carType switch
{
TrainCarType.LocoShunter => car.GetComponent<LocoControllerShunter>().GetEngineRunning(),
TrainCarType.LocoDiesel => car.GetComponent<LocoControllerDiesel>().GetEngineRunning(),
_ => true,
};

return Color.HSVToRGB(HueOrange, hasDisconnectedMUCable ? 1 : 0, isRunning ? 1 : 0.8f);
}

private void DrawCarStress(IEnumerable<CarGroup> groups)
{
var derailThreshold = SimManager.instance.derailBuildUpThreshold;
Expand Down

0 comments on commit 6f2ca39

Please sign in to comment.