private void topBar(int id)
        {
            growE();
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
            {
                GUILayout.Label("", GUILayout.Width(70));
            }
            else
            {
                if (v != null)
                {
                    showOrbit = GUILayout.Toggle(showOrbit, textWithTT("", "Toggle Orbit"));

                    Rect d = GUILayoutUtility.GetLastRect();
                    d.x     += 30;
                    d.y     += 2;
                    d.width  = 40;
                    d.height = 20;

                    if (GUI.Button(d, iconWithTT(SCANskins.SCAN_OrbitIcon, "Toggle Orbit"), SCANskins.SCAN_buttonBorderless))
                    {
                        showOrbit = !showOrbit;
                    }
                }
                else
                {
                    GUILayout.Label("", GUILayout.Width(10));
                }

                if (SCANcontroller.controller.mechJebTargetSelection)
                {
                    if (SCANcontroller.controller.MechJebLoaded && SCANcontroller.controller.LandingTargetBody == b)
                    {
                        fillS(50);
                        if (GUILayout.Button(textWithTT("", "Set MechJeb Target"), SCANskins.SCAN_buttonBorderless, GUILayout.Width(24), GUILayout.Height(24)))
                        {
                            SCANcontroller.controller.TargetSelecting = !SCANcontroller.controller.TargetSelecting;
                        }
                        Rect  r   = GUILayoutUtility.GetLastRect();
                        Color old = GUI.color;
                        GUI.color = palette.red;
                        GUI.DrawTexture(r, SCANskins.SCAN_MechJebIcon);
                        GUI.color = old;
                    }
                    else
                    {
                        GUILayout.Label("", GUILayout.Width(70));
                    }
                }
                else
                {
                    fillS(50);
                    if (GUILayout.Button(textWithTT("", "Set Landing Target"), SCANskins.SCAN_buttonBorderless, GUILayout.Width(24), GUILayout.Height(24)))
                    {
                        SCANcontroller.controller.TargetSelecting = !SCANcontroller.controller.TargetSelecting;
                    }
                    Rect  r   = GUILayoutUtility.GetLastRect();
                    Color old = GUI.color;
                    GUI.color = palette.xkcd_PukeGreen;
                    GUI.DrawTexture(r, SCANskins.SCAN_TargetIcon);
                    GUI.color = old;
                }
            }

            fillS();

            if (GUILayout.Button(iconWithTT(SCANskins.SCAN_ZoomOutIcon, "Zoom Out"), SCANskins.SCAN_buttonBorderless, GUILayout.Width(26), GUILayout.Height(26)))
            {
                spotmap.MapScale = spotmap.MapScale / 1.25f;
                if (spotmap.MapScale < 2)
                {
                    spotmap.MapScale = 2;
                }
                resetMap();
            }

            if (GUILayout.Button(textWithTT(spotmap.MapScale.ToString("N1") + " X", "Sync To Big Map"), SCANskins.SCAN_buttonBorderless, GUILayout.Width(50), GUILayout.Height(24)))
            {
                SCANcontroller.controller.TargetSelecting       = false;
                SCANcontroller.controller.TargetSelectingActive = false;

                if (bigmap.Projection == MapProjection.Polar)
                {
                    spotmap.setProjection(MapProjection.Polar);
                }
                else
                {
                    spotmap.setProjection(MapProjection.Rectangular);
                }

                if (bigmap.Body != b)
                {
                    SCANdata dat = SCANUtil.getData(bigmap.Body);
                    if (dat == null)
                    {
                        dat = new SCANdata(bigmap.Body);
                    }

                    data = dat;
                    b    = data.Body;

                    spotmap.setBody(b);
                }

                if (SCANconfigLoader.GlobalResource && narrowBand)
                {
                    spotmap.Resource = bigmap.Resource;
                    spotmap.Resource.CurrentBodyConfig(b.name);
                }

                spotmap.centerAround(spotmap.CenteredLong, spotmap.CenteredLat);
                if (SCANcontroller.controller.needsNarrowBand && SCANcontroller.controller.map_ResourceOverlay)
                {
                    checkForScanners();
                }
                spotmap.resetMap(bigmap.MType, false, narrowBand);
            }

            if (GUILayout.Button(iconWithTT(SCANskins.SCAN_ZoomInIcon, "Zoom In"), SCANskins.SCAN_buttonBorderless, GUILayout.Width(26), GUILayout.Height(26)))
            {
                spotmap.MapScale = spotmap.MapScale * 1.25f;
                resetMap();
            }

            fillS();

            if (HighLogic.LoadedScene != GameScenes.SPACECENTER)
            {
                showWaypoints = GUILayout.Toggle(showWaypoints, textWithTT("", "Toggle Waypoints"));

                Rect w = GUILayoutUtility.GetLastRect();
                w.x     += 28;
                w.y     += 2;
                w.width  = 20;
                w.height = 20;

                if (GUI.Button(w, iconWithTT(SCANskins.SCAN_WaypointIcon, "Toggle Waypoints"), SCANskins.SCAN_buttonBorderless))
                {
                    showWaypoints = !showWaypoints;
                }

                fillS(16);
            }
            else
            {
                GUILayout.Label("", GUILayout.Width(40));
            }

            showAnomaly = GUILayout.Toggle(showAnomaly, textWithTT("", "Toggle Anomalies"));

            Rect a = GUILayoutUtility.GetLastRect();

            a.x     += 26;
            a.y     += 2;
            a.width  = 20;
            a.height = 20;

            if (GUI.Button(a, textWithTT(SCANcontroller.controller.anomalyMarker, "Toggle Anomalies"), SCANskins.SCAN_buttonBorderless))
            {
                showAnomaly = !showAnomaly;
            }

            fillS(16);

            stopE();
        }
Beispiel #2
0
        /* MAP: constructor */
        internal SCANdata(CelestialBody b)
        {
            body = b;
            float?clamp = null;

            if (b.ocean)
            {
                clamp = 0;
            }

            terrainConfig = SCANcontroller.getTerrainNode(b.name);

            if (terrainConfig == null)
            {
                terrainConfig = new SCANterrainConfig(SCANconfigLoader.SCANNode.DefaultMinHeightRange, SCANconfigLoader.SCANNode.DefaultMaxHeightRange, clamp, SCANUtil.paletteLoader(SCANconfigLoader.SCANNode.DefaultPalette, 7), 7, false, false, body);
                SCANcontroller.addToTerrainConfigData(body.name, terrainConfig);
            }
        }
        public override bool RequirementMet(ConfiguredContract contract)
        {
            double coverageInPercentage = SCANUtil.GetCoverage((int)scanType, targetBody);

            return(coverageInPercentage >= minCoverage && coverageInPercentage <= maxCoverage);
        }
Beispiel #4
0
 internal int GetSCANtype(string s_type)
 {
     return(SCANUtil.GetSCANtype(s_type));
 }
Beispiel #5
0
 //Draws the actual map texture
 internal void drawHeightScanline(SCANtype type)
 {
     Color[] cols_height_map_small = map_small.GetPixels(0, scanline, 360, 1);
     for (int ilon = 0; ilon < 360; ilon += 1)
     {
         int   scheme = SCANcontroller.controller.colours;
         float val    = heightmap[ilon, scanline];
         if (val == 0)
         {                 //Some preparation for bigger changes in map caching, automatically calculate elevation for every point on the small map, only display scanned areas
             if (body.pqsController == null)
             {
                 heightmap[ilon, scanline]   = 0;
                 cols_height_map_small[ilon] = palette.lerp(palette.black, palette.white, UnityEngine.Random.value);
                 continue;
             }
             else
             {
                 // convert to radial vector
                 val = (float)SCANUtil.getElevation(body, ilon - 180, scanline - 90);
                 if (val == 0)
                 {
                     val = -0.001f;                             // this is terrible
                 }
                 heightmap[ilon, scanline] = val;
             }
         }
         Color c = palette.black;
         if (SCANUtil.isCovered(ilon, scanline, this, SCANtype.Altimetry))
         {                 //We check for coverage down here now, after elevation data is collected
             if (SCANUtil.isCovered(ilon, scanline, this, SCANtype.AltimetryHiRes))
             {
                 c = palette.heightToColor(val, scheme, this);
             }
             else
             {
                 c = palette.heightToColor(val, 1, this);
             }
         }
         else
         {
             c = palette.grey;
             if (scanline % 30 == 0 && ilon % 3 == 0)
             {
                 c = palette.white;
             }
             else if (ilon % 30 == 0 && scanline % 3 == 0)
             {
                 c = palette.white;
             }
         }
         if (type != SCANtype.Nothing)
         {
             if (!SCANUtil.isCoveredByAll(ilon, scanline, this, type))
             {
                 c = palette.lerp(c, palette.black, 0.5f);
             }
         }
         cols_height_map_small[ilon] = c;
     }
     map_small.SetPixels(0, scanline, 360, 1, cols_height_map_small);
     scanline = scanline + 1;
     if (scanline >= 180)
     {
         scanstep += 1;
         scanline  = 0;
     }
 }
        //Display the current vessel altitude
        private void altInfo(int id)
        {
            if ((sensors & SCANtype.Altimetry) != SCANtype.Nothing)
            {
                double h   = v.altitude;
                double pqs = 0;
                if (v.mainBody.pqsController != null)
                {
                    pqs = v.PQSAltitude();
                    if (pqs > 0 || !v.mainBody.ocean)
                    {
                        h -= pqs;
                    }
                }
                if (h < 0)
                {
                    h = v.altitude;
                }

                if (v.situation == Vessel.Situations.LANDED || v.situation == Vessel.Situations.SPLASHED || v.situation == Vessel.Situations.PRELAUNCH)
                {
                    GUILayout.Label(string.Format("Terrain: {0:N1}m", pqs), SCANskins.SCAN_insColorLabel);
                }
                else
                {
                    GUILayout.Label(string.Format("Altitude: {0}", SCANuiUtil.distanceString(h, 100000)), SCANskins.SCAN_insColorLabel);
                }
                fillS(-10);

                //Calculate slope less frequently; the rapidly changing value makes it difficult to read otherwise
                if (v.mainBody.pqsController != null)
                {
                    float deltaTime = 1f;
                    if (Time.deltaTime != 0)
                    {
                        deltaTime = TimeWarp.deltaTime / Time.deltaTime;
                    }
                    if (deltaTime > 5)
                    {
                        deltaTime = 5;
                    }
                    if (((Time.time * deltaTime) - lastUpdate) > updateInterval)
                    {
                        lastUpdate = Time.time;

                        /* Slope is calculated using a nine point grid centered 5m around the vessel location
                         * The rise between the vessel location's elevation and each point on the grid is calculated, converted to slope in degrees, and averaged;
                         * Note: Averageing is not the most accurate method
                         */

                        double   latOffset = degreeOffset * Math.Cos(Mathf.Deg2Rad * vlat);
                        double[] e         = new double[9];
                        double[] s         = new double[8];
                        e[0] = pqs;
                        e[1] = SCANUtil.getElevation(v.mainBody, vlon + latOffset, vlat);
                        e[2] = SCANUtil.getElevation(v.mainBody, vlon - latOffset, vlat);
                        e[3] = SCANUtil.getElevation(v.mainBody, vlon, vlat + degreeOffset);
                        e[4] = SCANUtil.getElevation(v.mainBody, vlon, vlat - degreeOffset);
                        e[5] = SCANUtil.getElevation(v.mainBody, vlon + latOffset, vlat + degreeOffset);
                        e[6] = SCANUtil.getElevation(v.mainBody, vlon + latOffset, vlat - degreeOffset);
                        e[7] = SCANUtil.getElevation(v.mainBody, vlon - latOffset, vlat + degreeOffset);
                        e[8] = SCANUtil.getElevation(v.mainBody, vlon - latOffset, vlat - degreeOffset);

                        /* Calculate rise for each point on the grid
                         * The distance is 5m for adjacent points and 7.071m for the points on the corners
                         * Rise is converted to slope; i.e. a 5m elevation change over a 5m distance is a rise of 1
                         * Converted to slope using the inverse tangent this gives a slope of 45°
                         * */
                        for (int i = 1; i <= 4; i++)
                        {
                            s[i - 1] = Math.Atan((Math.Abs(e[i] - e[0])) / 5) * Mathf.Rad2Deg;
                        }
                        for (int i = 5; i <= 8; i++)
                        {
                            s[i - 1] = Math.Atan((Math.Abs(e[i] - e[0])) / 7.071) * Mathf.Rad2Deg;
                        }

                        slopeAVG = s.Sum() / 8;
                    }

                    GUILayout.Label(string.Format("Slope: {0:F2}°", slopeAVG), SCANskins.SCAN_insColorLabel);
                    fillS(-10);
                }
            }
        }
Beispiel #7
0
        protected override void LateUpdate()
        {
            if (shutdown)
            {
                return;
            }

            if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ready)
            {
                return;
            }

            if (SCANcontroller.controller == null)
            {
                way = null;
                return;
            }

            if (!SCANcontroller.controller.mechJebTargetSelection)
            {
                way = null;
                return;
            }

            v = FlightGlobals.ActiveVessel;

            if (v == null)
            {
                SCANcontroller.controller.MechJebLoaded = false;
                way = null;
                return;
            }

            if (v.mainBody != SCANcontroller.controller.LandingTargetBody)
            {
                SCANcontroller.controller.LandingTargetBody = v.mainBody;
            }

            data = SCANUtil.getData(v.mainBody);

            if (data == null)
            {
                SCANcontroller.controller.MechJebLoaded = false;
                way = null;
                return;
            }

            if (v.FindPartModulesImplementing <MechJebCore>().Count <= 0)
            {
                SCANcontroller.controller.MechJebLoaded = false;
                way = null;
                return;
            }

            core = v.GetMasterMechJeb();

            if (core == null)
            {
                SCANcontroller.controller.MechJebLoaded = false;
                way = null;
                return;
            }

            if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX)
            {
                if (guidanceModule == null)
                {
                    guidanceModule = (DisplayModule)core.GetComputerModule("MechJebModuleLandingGuidance");
                }

                if (guidanceModule == null)
                {
                    SCANcontroller.controller.MechJebLoaded = false;
                    way = null;
                    return;
                }

                if (!guidanceModule.unlockChecked)
                {
                    return;
                }

                if (guidanceModule.hidden)
                {
                    SCANcontroller.controller.MechJebLoaded = false;
                    shutdown = true;
                    way      = null;
                    return;
                }
            }

            target = core.target;

            if (target == null)
            {
                SCANcontroller.controller.MechJebLoaded = false;
                way = null;
                return;
            }

            if (!SCANcontroller.controller.MechJebLoaded)
            {
                SCANcontroller.controller.MechJebLoaded = true;
                RenderingManager.AddToPostDrawQueue(1, drawTarget);
            }

            if (SCANcontroller.controller.LandingTarget != null)
            {
                way = SCANcontroller.controller.LandingTarget;
            }

            if (SCANcontroller.controller.TargetSelecting)
            {
                way             = null;
                selectingTarget = true;
                if (SCANcontroller.controller.TargetSelectingActive)
                {
                    selectingInMap = true;
                }
                else
                {
                    selectingInMap = false;
                }
                coords = SCANcontroller.controller.LandingTargetCoords;
                return;
            }
            else if (selectingTarget)
            {
                selectingTarget = false;
                if (selectingInMap)
                {
                    selectingInMap = false;
                    coords         = SCANcontroller.controller.LandingTargetCoords;
                    way            = new SCANwaypoint(coords.y, coords.x, siteName);
                    target.SetPositionTarget(SCANcontroller.controller.LandingTargetBody, way.Latitude, way.Longitude);
                }
            }

            selectingInMap  = false;
            selectingTarget = false;

            if (target.Target == null)
            {
                way = null;
                return;
            }

            if (target.targetBody != v.mainBody)
            {
                way = null;
                return;
            }

            if (!(target.Target is PositionTarget))
            {
                way = null;
                return;
            }

            coords.x = target.targetLongitude;
            coords.y = target.targetLatitude;

            if (way != null)
            {
                if (!SCANUtil.ApproxEq(coords.x, way.Longitude) || !SCANUtil.ApproxEq(coords.y, way.Latitude))
                {
                    way = new SCANwaypoint(coords.y, coords.x, siteName);
                    SCANcontroller.controller.LandingTarget = way;
                    data.addToWaypoints();
                }
            }
            else
            {
                way = new SCANwaypoint(coords.y, coords.x, siteName);
                SCANcontroller.controller.LandingTarget = way;
                data.addToWaypoints();
            }
        }
Beispiel #8
0
        protected override void Start()
        {
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                kscMapObj = (SCANkscMap)SCANcontroller.controller.kscMap;
                if (SCANkscMap.BigMap != null)
                {
                    bigMap = SCANkscMap.BigMap;
                }
                if (kscMapObj.Data != null)
                {
                    data = kscMapObj.Data;
                }
            }
            else if (HighLogic.LoadedSceneIsFlight)
            {
                bigMapObj = (SCANBigMap)SCANcontroller.controller.BigMap;
                if (SCANBigMap.BigMap != null)
                {
                    bigMap = SCANBigMap.BigMap;
                }
                if (bigMapObj.Data != null)
                {
                    data = bigMapObj.Data;
                }
            }

            if (data == null)
            {
                data = SCANUtil.getData(Planetarium.fetch.Home);
                if (data == null)
                {
                    data = new SCANdata(Planetarium.fetch.Home);
                    SCANcontroller.controller.addToBodyData(Planetarium.fetch.Home, data);
                }
            }

            currentTerrain = new SCANterrainConfig(data.TerrainConfig);

            stockBiomes = SCANcontroller.controller.useStockBiomes;

            minTerrainSlider   = new SCANuiSlider(data.TerrainConfig.DefaultMinHeight - SCANconfigLoader.SCANNode.RangeBelowMinHeight, data.TerrainConfig.MaxTerrain - 100, data.TerrainConfig.MinTerrain, "Min: ", "m", -2);
            maxTerrainSlider   = new SCANuiSlider(data.TerrainConfig.MinTerrain + 100, data.TerrainConfig.DefaultMaxHeight + SCANconfigLoader.SCANNode.RangeAboveMaxHeight, data.TerrainConfig.MaxTerrain, "Max: ", "m", -2);
            clampTerrainSlider = new SCANuiSlider(data.TerrainConfig.MinTerrain + 10, data.TerrainConfig.MaxTerrain - 10, data.TerrainConfig.ClampTerrain ?? data.TerrainConfig.MinTerrain + 10, "Clamp: ", "m", -1);
            paletteSizeSlider  = new SCANuiSlider(3, 12, data.TerrainConfig.PalSize, "Palette Size: ", "", 0);

            slopeColorPickerLow  = new SCANuiColorPicker(SCANcontroller.controller.lowSlopeColorOne, SCANcontroller.controller.highSlopeColorOne, true);
            slopeColorPickerHigh = new SCANuiColorPicker(SCANcontroller.controller.lowSlopeColorTwo, SCANcontroller.controller.highSlopeColorTwo, true);

            slopeColorPickerLow.updateOldSwatches();
            slopeColorPickerHigh.updateOldSwatches();

            bTrans           = SCANcontroller.controller.biomeTransparency;
            biomeTransSlider = new SCANuiSlider(0, 80, bTrans, "Ter. Trans: ", "%", 0);

            biomeColorPicker = new SCANuiColorPicker(SCANcontroller.controller.lowBiomeColor, SCANcontroller.controller.highBiomeColor, true);

            biomeColorPicker.updateOldSwatches();

            if (SCANconfigLoader.GlobalResource)
            {
                loadedResources = SCANcontroller.setLoadedResourceList();
                currentResource = new SCANresourceGlobal(loadedResources[0]);
                currentResource.CurrentBodyConfig(data.Body.name);

                if (currentResource != null)
                {
                    resourceMinSlider   = new SCANuiSlider(0, currentResource.CurrentBody.MinValue - 0.1f, currentResource.CurrentBody.MinValue, "Min: ", "%", 1);
                    resourceMaxSlider   = new SCANuiSlider(currentResource.CurrentBody.MinValue + 0.1f, 100, currentResource.CurrentBody.MaxValue, "Max: ", "%", 1);
                    resourceTransSlider = new SCANuiSlider(0, 80, currentResource.Transparency, "Trans: ", "%", 0);

                    resourceColorPicker = new SCANuiColorPicker(currentResource.MinColor, currentResource.MaxColor, true);
                }
            }

            bodyIndex = data.Body.flightGlobalsIndex;

            if (windowMode > 3 || (windowMode > 2 && !SCANconfigLoader.GlobalResource))
            {
                windowMode = 0;
            }

            setSizeSlider(currentTerrain.ColorPal.kind);
        }
Beispiel #9
0
        protected override void DrawWindowPost(int id)
        {
            if (dropDown && Event.current.type == EventType.mouseDown && !ddRect.Contains(Event.current.mousePosition))
            {
                dropDown = false;
            }

            //These methods update all of the UI elements whenever any of the options are changed
            if (windowMode == 0)
            {
                if (currentTerrain.PalRev != oldReverseState)
                {
                    oldReverseState = currentTerrain.PalRev;
                    drawPreviewLegend();
                }

                if (minTerrainSlider.valueChanged() || maxTerrainSlider.valueChanged())
                {
                    setTerrainSliders();
                }

                if (currentTerrain.PalDis != oldDiscreteState)
                {
                    oldDiscreteState = currentTerrain.PalDis;
                    drawPreviewLegend();
                }

                if (clampState != oldClampState)
                {
                    oldClampState = clampState;
                    drawPreviewLegend();
                }

                if (paletteSizeSlider.valueChanged())
                {
                    regenPaletteSets();
                    currentTerrain.ColorPal = palette.CurrentPalettes.availablePalettes[paletteIndex];
                    drawPreviewLegend();
                }
            }
            else if (windowMode == 1)
            {
                slopeColorPickerLow.colorStateChanged();
                slopeColorPickerLow.brightnessChanged();
                slopeColorPickerHigh.colorStateChanged();
                slopeColorPickerHigh.brightnessChanged();
            }
            else if (windowMode == 2)
            {
                biomeColorPicker.colorStateChanged();
                biomeColorPicker.brightnessChanged();
            }
            else if (windowMode == 3)
            {
                if (resourceMinSlider.valueChanged() || resourceMaxSlider.valueChanged())
                {
                    setResourceSliders();
                }

                if (bodyIndex != data.Body.flightGlobalsIndex)
                {
                    SCANUtil.SCANdebugLog("Trigger Body Change");
                    bodyIndex = data.Body.flightGlobalsIndex;

                    currentResource.CurrentBodyConfig(data.Body.name);

                    lowRCutoff  = currentResource.CurrentBody.MinValue;
                    highRCutoff = currentResource.CurrentBody.MaxValue;

                    oldFineControl = fineControlMode = false;

                    setResourceSliders();
                }

                if (oldFineControl != fineControlMode)
                {
                    oldFineControl = fineControlMode;
                    if (fineControlMode)
                    {
                        if (lowRCutoff < 5f)
                        {
                            resourceMinSlider.MinValue = 0f;
                        }
                        else
                        {
                            resourceMinSlider.MinValue = lowRCutoff - 5;
                        }

                        if (lowRCutoff > 95f)
                        {
                            resourceMinSlider.MaxValue = 100f;
                        }
                        else if (highRCutoff < lowRCutoff + 5f)
                        {
                            resourceMinSlider.MaxValue = highRCutoff - 0.1f;
                        }
                        else
                        {
                            resourceMinSlider.MaxValue = lowRCutoff + 5f;
                        }

                        if (highRCutoff < 5f)
                        {
                            resourceMaxSlider.MinValue = 0f;
                        }
                        else if (lowRCutoff > highRCutoff - 5f)
                        {
                            resourceMaxSlider.MinValue = lowRCutoff + 0.1f;
                        }
                        else
                        {
                            resourceMaxSlider.MinValue = highRCutoff - 5f;
                        }

                        if (highRCutoff > 95f)
                        {
                            resourceMaxSlider.MaxValue = 100f;
                        }
                        else
                        {
                            resourceMaxSlider.MaxValue = highRCutoff + 5f;
                        }
                    }
                    else
                    {
                        setResourceSliders();
                    }
                }

                resourceColorPicker.colorStateChanged();
                resourceColorPicker.brightnessChanged();
            }

            sessionRect = WindowRect;
        }
Beispiel #10
0
        protected override void DrawWindowPre(int id)
        {
            //Some clumsy logic is used here to ensure that the color selection fields always remain in sync with the current map in each scene
            if (HighLogic.LoadedSceneIsFlight)
            {
                if (data == null)
                {
                    data = SCANUtil.getData(FlightGlobals.currentMainBody);
                    if (data == null)
                    {
                        data = new SCANdata(FlightGlobals.currentMainBody);
                        SCANcontroller.controller.addToBodyData(FlightGlobals.currentMainBody, data);
                    }
                }

                if (bigMapObj.Visible && SCANBigMap.BigMap != null)
                {
                    data   = bigMapObj.Data;
                    bigMap = SCANBigMap.BigMap;
                }
                else if (data.Body != FlightGlobals.currentMainBody)
                {
                    data = SCANUtil.getData(FlightGlobals.currentMainBody);
                    if (data == null)
                    {
                        data = new SCANdata(FlightGlobals.currentMainBody);
                        SCANcontroller.controller.addToBodyData(FlightGlobals.currentMainBody, data);
                    }
                }

                if (bigMap == null)
                {
                    if (SCANBigMap.BigMap != null)
                    {
                        bigMap = SCANBigMap.BigMap;
                    }
                }
            }

            //Lock space center click through - Sync SCANdata
            else if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
            {
                if (data == null)
                {
                    data = SCANUtil.getData(Planetarium.fetch.Home);
                    if (data == null)
                    {
                        data = new SCANdata(Planetarium.fetch.Home);
                        SCANcontroller.controller.addToBodyData(Planetarium.fetch.Home, data);
                    }
                }
                if (kscMapObj.Visible)
                {
                    data   = kscMapObj.Data;
                    bigMap = SCANkscMap.BigMap;
                }
                else if (data.Body != Planetarium.fetch.Home)
                {
                    data = SCANUtil.getData(Planetarium.fetch.Home);
                    if (data == null)
                    {
                        data = new SCANdata(Planetarium.fetch.Home);
                        SCANcontroller.controller.addToBodyData(Planetarium.fetch.Home, data);
                    }
                }
                if (bigMap == null)
                {
                    if (SCANkscMap.BigMap != null)
                    {
                        bigMap = SCANkscMap.BigMap;
                    }
                }
                Vector2 mousePos = Input.mousePosition;
                mousePos.y = Screen.height - mousePos.y;
                if (WindowRect.Contains(mousePos) && !controlLock)
                {
                    InputLockManager.SetControlLock(ControlTypes.CAMERACONTROLS | ControlTypes.KSC_ALL, lockID);
                    controlLock = true;
                }
                else if (!WindowRect.Contains(mousePos) && controlLock)
                {
                    removeControlLocks();
                }
            }

            //Lock tracking scene click through - Sync SCANdata
            else if (HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                if (data == null)
                {
                    data = SCANUtil.getData(Planetarium.fetch.Home);
                    if (data == null)
                    {
                        data = new SCANdata(Planetarium.fetch.Home);
                        SCANcontroller.controller.addToBodyData(Planetarium.fetch.Home, data);
                    }
                }
                if (kscMapObj.Visible)
                {
                    data   = kscMapObj.Data;
                    bigMap = SCANkscMap.BigMap;
                }
                else if (data.Body != Planetarium.fetch.Home)
                {
                    data = SCANUtil.getData(Planetarium.fetch.Home);
                    if (data == null)
                    {
                        data = new SCANdata(Planetarium.fetch.Home);
                        SCANcontroller.controller.addToBodyData(Planetarium.fetch.Home, data);
                    }
                }
                if (bigMap == null)
                {
                    if (SCANkscMap.BigMap != null)
                    {
                        bigMap = SCANkscMap.BigMap;
                    }
                }
                Vector2 mousePos = Input.mousePosition;
                mousePos.y = Screen.height - mousePos.y;
                if (WindowRect.Contains(mousePos) && !controlLock)
                {
                    InputLockManager.SetControlLock(ControlTypes.TRACKINGSTATION_UI, lockID);
                    controlLock = true;
                }
                else if (!WindowRect.Contains(mousePos) && controlLock)
                {
                    removeControlLocks();
                }
            }

            //This updates all of the fields whenever the palette selection is changed
            if (windowMode == 0 && (currentLegend == null || bodyIndex != data.Body.flightGlobalsIndex))
            {
                currentTerrain = new SCANterrainConfig(data.TerrainConfig);

                SCANUtil.SCANdebugLog("Trigger Body Change");
                bodyIndex = data.Body.flightGlobalsIndex;

                currentTerrain = new SCANterrainConfig(data.TerrainConfig);

                updateUI();
            }

            if (windowMode == 0 && previewLegend == null)
            {
                drawPreviewLegend();
            }

            if (!dropDown)
            {
                paletteBox  = false;
                resourceBox = false;
                saveWarning = false;
            }
        }