private void RefreshPlanets()
{
mEntries = new Dictionary<CelestialBody, Entry>();
mRootEntry = new Entry();
mSelection = new Entry()
{
Text = "No Target",
Guid = new Guid(RTSettings.Instance.NoTargetGuid),
Color = Color.white,
Depth = 0,
};
mRootEntry.SubEntries.Add(mSelection);
if (Antenna == null) return;
var activeVesselEntry = new Entry()
{
Text = "Active Vessel",
Guid = NetworkManager.ActiveVesselGuid,
Color = Color.white,
Depth = 0,
};
mRootEntry.SubEntries.Add(activeVesselEntry);
if (Antenna.Target == activeVesselEntry.Guid)
{
mSelection = activeVesselEntry;
}
// Add the planets
foreach (var cb in RTCore.Instance.Network.Planets)
{
if (!mEntries.ContainsKey(cb.Value))
{
mEntries[cb.Value] = new Entry();
}
Entry current = mEntries[cb.Value];
current.Text = cb.Value.bodyName;
current.Guid = cb.Key;
current.Color = cb.Value.GetOrbitDriver() != null ? cb.Value.GetOrbitDriver().orbitColor : Color.yellow;
current.Color.a = 1.0f;
if (cb.Value.referenceBody != cb.Value)
{
CelestialBody parent = cb.Value.referenceBody;
if (!mEntries.ContainsKey(parent))
{
mEntries[parent] = new Entry();
}
mEntries[parent].SubEntries.Add(current);
}
else
{
mRootEntry.SubEntries.Add(current);
}
if (cb.Key == Antenna.Target)
{
mSelection = current;
}
}
// Sort the lists based on semi-major axis. In reverse because of how we render it.
foreach (var entryPair in mEntries)
{
entryPair.Value.SubEntries.Sort((b, a) =>
{
return RTCore.Instance.Network.Planets[a.Guid].orbit.semiMajorAxis.CompareTo(
RTCore.Instance.Network.Planets[b.Guid].orbit.semiMajorAxis);
});
}
mRootEntry.SubEntries.Reverse();
}