diff --git a/SCANsat/SCAN_Unity/SCAN_UI_BigMap.cs b/SCANsat/SCAN_Unity/SCAN_UI_BigMap.cs index 36c0a907..54de55ae 100644 --- a/SCANsat/SCAN_Unity/SCAN_UI_BigMap.cs +++ b/SCANsat/SCAN_Unity/SCAN_UI_BigMap.cs @@ -30,6 +30,7 @@ using FinePrint; using FinePrint.Utilities; using palette = SCANsat.SCAN_UI.UI_Framework.SCANcolorUtil; +using KSPAchievements; namespace SCANsat.SCAN_Unity { @@ -1563,59 +1564,31 @@ public IList CelestialBodies { get { - List bodyList = new List(); var bodies = FlightGlobals.Bodies.Where(b => b.referenceBody == Planetarium.fetch.Sun && b.referenceBody != b); - var orderedBodies = bodies.OrderBy(b => b.orbit.semiMajorAxis).ToList(); - for (int i = 0; i < orderedBodies.Count; i++) - { - CelestialBody body = orderedBodies[i]; - - if (SCANcontroller.controller.getData(body.bodyName) != null) - bodyList.Add(body.displayName.LocalizeBodyName()); - - for (int j = 0; j < body.orbitingBodies.Count; j++) - { - CelestialBody moon = body.orbitingBodies[j]; - - if (SCANcontroller.controller.getData(moon.bodyName) != null) - bodyList.Add(moon.displayName.LocalizeBodyName()); - - for (int k = 0; k < moon.orbitingBodies.Count; k++) - { - CelestialBody subMoon = moon.orbitingBodies[k]; - - if (SCANcontroller.controller.getData(subMoon.bodyName) != null) - bodyList.Add(subMoon.displayName.LocalizeBodyName()); - - for (int l = 0; l < subMoon.orbitingBodies.Count; l++) - { - CelestialBody subSubMoon = subMoon.orbitingBodies[l]; + List bodyList = SCANUtil.RecursiveCelestialBodies(orderedBodies); - if (SCANcontroller.controller.getData(subSubMoon.bodyName) != null) - bodyList.Add(subSubMoon.displayName.LocalizeBodyName()); + bool missingHome = true; - for (int m = 0; m < subSubMoon.orbitingBodies.Count; m++) - { - CelestialBody subSubSubMoon = subSubMoon.orbitingBodies[m]; + for (int i = bodyList.Count - 1; i >= 0; i--) + { + string b = bodyList[i]; - if (SCANcontroller.controller.getData(subSubSubMoon.bodyName) != null) - bodyList.Add(subSubSubMoon.displayName.LocalizeBodyName()); + if (b == FlightGlobals.GetHomeBody().displayName.LocalizeBodyName()) + { + missingHome = false; + break; + } + } - for (int n = 0; n < subSubSubMoon.orbitingBodies.Count; n++) - { - CelestialBody subSubSubSubMoon = subSubSubMoon.orbitingBodies[n]; + if (missingHome) + { + List missingHomeBodies = SCANUtil.RecursiveCelestialBodies(new List() { FlightGlobals.GetHomeBody() }); - if (SCANcontroller.controller.getData(subSubSubSubMoon.bodyName) != null) - bodyList.Add(subSubSubSubMoon.displayName.LocalizeBodyName()); - } - } - } - } - } - } + bodyList.InsertRange(0, missingHomeBodies); + } if (HighLogic.LoadedSceneIsFlight) { @@ -1977,7 +1950,7 @@ private string mouseOverInfo(double lon, double lat) SCANUtil.getBiomeDisplayName(infoString, body, lon, lat); } - if (bigmap.ResourceActive && SCANconfigLoader.GlobalResource && bigmap.Resource != null) + if (SCANconfigLoader.GlobalResource && bigmap.Resource != null) { bool resources = false; bool fuzzy = false; diff --git a/SCANsat/SCAN_Unity/SCAN_UI_Color.cs b/SCANsat/SCAN_Unity/SCAN_UI_Color.cs index 40899d0e..329787ba 100644 --- a/SCANsat/SCAN_Unity/SCAN_UI_Color.cs +++ b/SCANsat/SCAN_Unity/SCAN_UI_Color.cs @@ -558,54 +558,30 @@ public IList CelestialBodies { get { - List bodyList = new List(); - var bodies = FlightGlobals.Bodies.Where(b => b.referenceBody == Planetarium.fetch.Sun && b.referenceBody != b); var orderedBodies = bodies.OrderBy(b => b.orbit.semiMajorAxis).ToList(); - for (int i = 0; i < orderedBodies.Count; i++) - { - CelestialBody body = orderedBodies[i]; - - bodyList.Add(body.displayName.LocalizeBodyName()); - - for (int j = 0; j < body.orbitingBodies.Count; j++) - { - CelestialBody moon = body.orbitingBodies[j]; - - bodyList.Add(moon.displayName.LocalizeBodyName()); - - for (int k = 0; k < moon.orbitingBodies.Count; k++) - { - CelestialBody subMoon = moon.orbitingBodies[k]; - - bodyList.Add(subMoon.displayName.LocalizeBodyName()); + List bodyList = SCANUtil.RecursiveCelestialBodies(orderedBodies); - for (int l = 0; l < subMoon.orbitingBodies.Count; l++) - { - CelestialBody subSubMoon = subMoon.orbitingBodies[l]; + bool missingHome = true; - bodyList.Add(subSubMoon.displayName.LocalizeBodyName()); - - for (int m = 0; m < subSubMoon.orbitingBodies.Count; m++) - { - CelestialBody subSubSubMoon = subSubMoon.orbitingBodies[m]; + for (int i = bodyList.Count - 1; i >= 0; i--) + { + string b = bodyList[i]; - if (SCANcontroller.controller.getData(subSubSubMoon.bodyName) != null) - bodyList.Add(subSubSubMoon.displayName.LocalizeBodyName()); + if (b == FlightGlobals.GetHomeBody().displayName.LocalizeBodyName()) + { + missingHome = false; + break; + } + } - for (int n = 0; n < subSubSubMoon.orbitingBodies.Count; n++) - { - CelestialBody subSubSubSubMoon = subSubSubMoon.orbitingBodies[n]; + if (missingHome) + { + List missingHomeBodies = SCANUtil.RecursiveCelestialBodies(new List() { FlightGlobals.GetHomeBody() }); - if (SCANcontroller.controller.getData(subSubSubSubMoon.bodyName) != null) - bodyList.Add(subSubSubSubMoon.displayName.LocalizeBodyName()); - } - } - } - } - } + bodyList.InsertRange(0, missingHomeBodies); } if (HighLogic.LoadedSceneIsFlight) diff --git a/SCANsat/SCAN_Unity/SCAN_UI_Settings.cs b/SCANsat/SCAN_Unity/SCAN_UI_Settings.cs index fc38e60d..ea39e2f3 100644 --- a/SCANsat/SCAN_Unity/SCAN_UI_Settings.cs +++ b/SCANsat/SCAN_Unity/SCAN_UI_Settings.cs @@ -589,58 +589,30 @@ public IList BackgroundBodies { get { - List bodyList = new List(); - var bodies = FlightGlobals.Bodies.Where(b => b.referenceBody == Planetarium.fetch.Sun && b.referenceBody != b); var orderedBodies = bodies.OrderBy(b => b.orbit.semiMajorAxis).ToList(); - for (int i = 0; i < orderedBodies.Count; i++) - { - CelestialBody body = orderedBodies[i]; - - if (SCANcontroller.controller.getData(body.bodyName) != null) - bodyList.Add(body.displayName.LocalizeBodyName()); - - for (int j = 0; j < body.orbitingBodies.Count; j++) - { - CelestialBody moon = body.orbitingBodies[j]; - - if (SCANcontroller.controller.getData(moon.bodyName) != null) - bodyList.Add(moon.displayName.LocalizeBodyName()); - - for (int k = 0; k < moon.orbitingBodies.Count; k++) - { - CelestialBody subMoon = moon.orbitingBodies[k]; - - if (SCANcontroller.controller.getData(subMoon.bodyName) != null) - bodyList.Add(subMoon.displayName.LocalizeBodyName()); + List bodyList = SCANUtil.RecursiveCelestialBodies(orderedBodies); - for (int l = 0; l < subMoon.orbitingBodies.Count; l++) - { - CelestialBody subSubMoon = subMoon.orbitingBodies[l]; + bool missingHome = true; - if (SCANcontroller.controller.getData(subSubMoon.bodyName) != null) - bodyList.Add(subSubMoon.displayName.LocalizeBodyName()); - - for (int m = 0; m < subSubMoon.orbitingBodies.Count; m++) - { - CelestialBody subSubSubMoon = subSubMoon.orbitingBodies[m]; + for (int i = bodyList.Count - 1; i >= 0; i--) + { + string b = bodyList[i]; - if (SCANcontroller.controller.getData(subSubSubMoon.bodyName) != null) - bodyList.Add(subSubSubMoon.displayName.LocalizeBodyName()); + if (b == FlightGlobals.GetHomeBody().displayName.LocalizeBodyName()) + { + missingHome = false; + break; + } + } - for (int n = 0; n < subSubSubMoon.orbitingBodies.Count; n++) - { - CelestialBody subSubSubSubMoon = subSubSubMoon.orbitingBodies[n]; + if (missingHome) + { + List missingHomeBodies = SCANUtil.RecursiveCelestialBodies(new List() { FlightGlobals.GetHomeBody() }); - if (SCANcontroller.controller.getData(subSubSubSubMoon.bodyName) != null) - bodyList.Add(subSubSubSubMoon.displayName.LocalizeBodyName()); - } - } - } - } - } + bodyList.InsertRange(0, missingHomeBodies); } SCANdata sun = SCANcontroller.controller.getData(Planetarium.fetch.Sun.bodyName); @@ -658,13 +630,7 @@ public IList MapDataTypes { List availableTypes = new List() { 0, 1, 3, 4, 5, 2, 6, 7, 8 }; - //if (SCAN_Settings_Config.Instance.DisableStockResource || !SCAN_Settings_Config.Instance.InstantScan) - // { - // availableTypes.Add(7); - // availableTypes.Add(8); - // } - - List types = new List() { "All Data" };//, "SCAN Data Types" }; + List types = new List() { "All Data" }; for (int i = 0; i < availableTypes.Count; i++) types.Add(((SCANtype)(1 << availableTypes[i])).ToString()); diff --git a/SCANsat/SCANutil.cs b/SCANsat/SCANutil.cs index 351b5024..7880585f 100644 --- a/SCANsat/SCANutil.cs +++ b/SCANsat/SCANutil.cs @@ -593,6 +593,60 @@ internal static Vector2d fixRetardCoordinates(Vector2d coords) return coords; } + internal static List RecursiveCelestialBodies(List bodies) + { + List bodyList = new List(); + + for (int i = 0; i < bodies.Count; i++) + { + CelestialBody body = bodies[i]; + if (SCANcontroller.controller.getData(body.bodyName) != null) + bodyList.Add(body.displayName.LocalizeBodyName()); + + for (int j = 0; j < body.orbitingBodies.Count; j++) + { + CelestialBody moon = body.orbitingBodies[j]; + + if (SCANcontroller.controller.getData(moon.bodyName) != null) + bodyList.Add(moon.displayName.LocalizeBodyName()); + + for (int k = 0; k < moon.orbitingBodies.Count; k++) + { + CelestialBody subMoon = moon.orbitingBodies[k]; + + if (SCANcontroller.controller.getData(subMoon.bodyName) != null) + bodyList.Add(subMoon.displayName.LocalizeBodyName()); + + for (int l = 0; l < subMoon.orbitingBodies.Count; l++) + { + CelestialBody subSubMoon = subMoon.orbitingBodies[l]; + + if (SCANcontroller.controller.getData(subSubMoon.bodyName) != null) + bodyList.Add(subSubMoon.displayName.LocalizeBodyName()); + + for (int m = 0; m < subSubMoon.orbitingBodies.Count; m++) + { + CelestialBody subSubSubMoon = subSubMoon.orbitingBodies[m]; + + if (SCANcontroller.controller.getData(subSubSubMoon.bodyName) != null) + bodyList.Add(subSubSubMoon.displayName.LocalizeBodyName()); + + for (int n = 0; n < subSubSubMoon.orbitingBodies.Count; n++) + { + CelestialBody subSubSubSubMoon = subSubSubMoon.orbitingBodies[n]; + + if (SCANcontroller.controller.getData(subSubSubSubMoon.bodyName) != null) + bodyList.Add(subSubSubSubMoon.displayName.LocalizeBodyName()); + } + } + } + } + } + } + + return bodyList; + } + internal static double getElevation(CelestialBody body, double lon, double lat) { if (body.pqsController == null) return 0;