Ejemplo n.º 1
0
        /// <summary>
        /// Instance Editor window
        /// </summary>
        /// <param name="windowID"></param>
        void InstanceEditorWindow(int windowID)
        {
            UpdateVectors();

            GUILayout.BeginHorizontal();
            {
                GUI.enabled = false;
                GUILayout.Button("-KK-", UIMain.DeadButton, GUILayout.Height(21));

                GUILayout.FlexibleSpace();

                GUILayout.Button("Instance Editor", UIMain.DeadButton, GUILayout.Height(21));

                GUILayout.FlexibleSpace();

                GUI.enabled = true;

                if (GUILayout.Button("X", UIMain.DeadButtonRed, GUILayout.Height(21)))
                {
                    //KerbalKonstructs.instance.saveObjects();
                    KerbalKonstructs.DeselectObject(true, true);
                    //this.Close();
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, UIMain.BoxNoBorder, GUILayout.Height(4));

            GUILayout.Space(2);

            GUILayout.BeginHorizontal();

            GUILayout.Button(selectedInstance.model.title + " (" + selectedInstance.indexInGroup.ToString() + ")", GUILayout.Height(23));

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Position");
                GUILayout.FlexibleSpace();

                if (GUILayout.Button(new GUIContent(tCopyPos, "Copy Position"), GUILayout.Width(23), GUILayout.Height(23)))
                {
                    savedpos      = true;
                    savedPosition = selectedInstance.transform.localPosition;
                    savedRotation = selectedInstance.transform.localEulerAngles;
                    // Debug.Log("KK: Instance position copied");
                }
                if (GUILayout.Button(new GUIContent(tPastePos, "Paste Position"), GUILayout.Width(23), GUILayout.Height(23)))
                {
                    if (savedpos)
                    {
                        selectedInstance.transform.localPosition    = savedPosition;
                        selectedInstance.transform.localEulerAngles = savedRotation;
                        ApplySettings();
                        // Debug.Log("KK: Instance position pasted");
                    }
                }


                if (GUILayout.Button(new GUIContent(tSnap, "Snap to Target"), GUILayout.Width(23), GUILayout.Height(23)))
                {
                    if (StaticsEditorGUI.instance.snapTargetInstance == null)
                    {
                        Log.UserError("No Snaptarget selected");
                    }
                    else
                    {
                        selectedInstance.transform.localPosition    = StaticsEditorGUI.instance.snapTargetInstance.transform.localPosition;
                        selectedInstance.transform.localEulerAngles = StaticsEditorGUI.instance.snapTargetInstance.transform.localEulerAngles;

                        ApplySettings();
                    }
                }


                GUILayout.FlexibleSpace();

                GUILayout.Label("Increment");
                increment = float.Parse(GUILayout.TextField(increment.ToString(), 5, GUILayout.Width(48)));

                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("0.001", GUILayout.Height(18)))
                {
                    increment = 0.001f;
                }
                if (GUILayout.Button("0.01", GUILayout.Height(18)))
                {
                    increment = 0.01f;
                }
                if (GUILayout.Button("0.1", GUILayout.Height(18)))
                {
                    increment = 0.1f;
                }
                if (GUILayout.Button("1", GUILayout.Height(18)))
                {
                    increment = 1f;
                }
                if (GUILayout.Button("10", GUILayout.Height(18)))
                {
                    increment = 10f;
                }
                if (GUILayout.Button("25", GUILayout.Height(16)))
                {
                    increment = 25f;
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
            }
            GUILayout.EndHorizontal();


            //
            // Set reference butons
            //
            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Reference System: ");
                GUILayout.Label(referenceSystem.ToString(), UIMain.LabelWhite);
                GUILayout.FlexibleSpace();
                GUI.enabled = (referenceSystem == Reference.Center);

                if (GUILayout.Button(new GUIContent(UIMain.iconCubes.texture, "Model"), GUILayout.Height(23), GUILayout.Width(23)))
                {
                    referenceSystem = Reference.Model;
                    UpdateGizmo();
                    UpdateVectors();
                }

                GUI.enabled = (referenceSystem == Reference.Model);
                if (GUILayout.Button(new GUIContent(UIMain.iconWorld.texture, "Group Center"), GUILayout.Height(23), GUILayout.Width(23)))
                {
                    referenceSystem = Reference.Center;
                    UpdateGizmo();
                    UpdateVectors();
                }
                GUI.enabled = true;
            }
            GUILayout.EndHorizontal();
            //
            // Model Switching
            //
            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Selected Variant: ");
                GUI.enabled = (selectedInstance.model.hasVariants);
                string vaiantstring = (String.IsNullOrEmpty(selectedInstance.VariantName)) ? "N.A." : selectedInstance.VariantName;

                if (GUILayout.Button(vaiantstring, GUILayout.Width(150), GUILayout.Height(21)))
                {
                    VariantSelector.staticInstance = selectedInstance;
                    VariantSelector.Open();
                }
                GUI.enabled = true;
                GUILayout.FlexibleSpace();
            }
            GUILayout.EndHorizontal();
            //
            // Position editing
            //
            GUILayout.BeginHorizontal();


            GUILayout.Label("Back / Fwd:");
            GUILayout.FlexibleSpace();
            posZStr = (GUILayout.TextField(posZStr, 11, GUILayout.Width(fTempWidth)));

            if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
            {
                SetTransform(Vector3.back * increment);
            }
            if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
            {
                SetTransform(Vector3.forward * increment);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Left / Right:");
            GUILayout.FlexibleSpace();
            posXStr = (GUILayout.TextField(posXStr, 11, GUILayout.Width(fTempWidth)));
            if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
            {
                SetTransform(Vector3.left * increment);
            }
            if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
            {
                SetTransform(Vector3.right * increment);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Down / Up:");
            GUILayout.FlexibleSpace();
            posYStr = (GUILayout.TextField(posYStr, 11, GUILayout.Width(fTempWidth)));
            if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
            {
                SetTransform(Vector3.down * increment);
            }
            if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
            {
                SetTransform(Vector3.up * increment);
            }



            GUILayout.EndHorizontal();

            GUI.enabled = true;


            if (GUILayout.Button("Snap to Terrain", GUILayout.Height(21)))
            {
                Vector3 pos = selectedInstance.CelestialBody.GetWorldSurfacePosition(selectedInstance.RefLatitude, selectedInstance.RefLongitude, selectedInstance.surfaceHeight);
                selectedInstance.transform.position = pos;

                ApplySettings();
            }


            GUI.enabled = true;


            GUILayout.Space(5);



            //
            // Orientation quick preset
            //
            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, UIMain.BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(2);
            //GUILayout.BeginHorizontal();
            //{
            //    GUILayout.Label("Euler Rot.");
            //    GUILayout.FlexibleSpace();
            //    GUILayout.Label("X", GUILayout.Height(18));
            //    oriXStr = (GUILayout.TextField(oriXStr, 6, GUILayout.Width(48), GUILayout.Height(18)));
            //    GUILayout.Label("Y", GUILayout.Height(18));
            //    oriYStr = (GUILayout.TextField(oriYStr, 6, GUILayout.Width(48), GUILayout.Height(18)));
            //    GUILayout.Label("Z", GUILayout.Height(18));
            //    oriZStr = (GUILayout.TextField(oriZStr, 6, GUILayout.Width(48), GUILayout.Height(18)));

            //}
            //GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Orientation:");
                GUILayout.FlexibleSpace();
                if (GUILayout.Button(new GUIContent("Zero", "Zero Rotation"), GUILayout.Height(21), GUILayout.Width(50)))
                {
                    selectedInstance.transform.localEulerAngles = Vector3.zero;
                    ApplySettings();
                }

                if (GUILayout.Button(new GUIContent("C-U", "allign UP to GroupCenter Up-vector"), GUILayout.Height(21), GUILayout.Width(50)))
                {
                    Vector3    newfwd   = Vector3.ProjectOnPlane(selectedInstance.transform.forward, selectedInstance.transform.parent.up).normalized;
                    Quaternion rotation = new Quaternion();
                    rotation.SetLookRotation(newfwd, selectedInstance.transform.parent.up);

                    selectedInstance.transform.rotation = rotation;

                    ApplySettings();
                }
            }

            if (GUILayout.Button(new GUIContent("P-U", "alling UP to Position-Up"), GUILayout.Height(21), GUILayout.Width(50)))
            {
                Vector3    newfwd   = Vector3.ProjectOnPlane(selectedInstance.transform.forward, upVector).normalized;
                Quaternion rotation = new Quaternion();
                rotation.SetLookRotation(newfwd, upVector);

                selectedInstance.transform.rotation = rotation;

                ApplySettings();
            }

            GUILayout.EndHorizontal();

            //
            // Orientation adjustment
            //
            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Pitch:");
                GUILayout.FlexibleSpace();

                fTempWidth = 80f;
                oriXStr    = (GUILayout.TextField(oriXStr, 8, GUILayout.Width(fTempWidth)));
                if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
                {
                    SetRotation(Vector3.right, increment);
                }
                if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
                {
                    SetRotation(Vector3.left, increment);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Roll:");
                GUILayout.FlexibleSpace();
                oriZStr = (GUILayout.TextField(oriZStr, 8, GUILayout.Width(fTempWidth)));
                if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
                {
                    SetRotation(Vector3.forward, increment);
                }
                if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
                {
                    SetRotation(Vector3.back, increment);
                }
            }
            GUILayout.EndHorizontal();


            //
            // Rotation
            //
            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Yaw:");
                GUILayout.FlexibleSpace();
                //                    rotStr = GUILayout.TextField(rotStr, 9, GUILayout.Width(fTempWidth));
                //  GUILayout.Box(Vector3.Angle(Vector3.ProjectOnPlane(selectedInstance.gameObject.transform.forward, selectedInstance.gameObject.transform.up), selectedInstance.gameObject.transform.parent.forward).ToString(),  GUILayout.Width(fTempWidth));
                //GUILayout.Box(GetHeading(), GUILayout.Width(fTempWidth));
                oriYStr = (GUILayout.TextField(oriYStr, 8, GUILayout.Width(fTempWidth)));

                if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)))
                {
                    SetRotation(Vector3.up, -increment);
                }
                if (GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
                {
                    SetRotation(Vector3.up, -increment);
                }
                if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)))
                {
                    SetRotation(Vector3.up, increment);
                }
                if (GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
                {
                    SetRotation(Vector3.up, increment);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Heading: ", GUILayout.Height(23));
                GUILayout.Space(5);
                GUILayout.Button(instanceHeading.ToString(), UIMain.DeadButton, GUILayout.Height(23));
                GUILayout.FlexibleSpace();
            }
            GUILayout.EndHorizontal();


            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, UIMain.BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(2);
            //
            // Scale
            //
            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Model Scale: ");
                GUILayout.FlexibleSpace();
                selectedInstance.ModelScale = Math.Max(0.01f, float.Parse(GUILayout.TextField(selectedInstance.ModelScale.ToString(), 4, GUILayout.Width(fTempWidth))));

                if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)))
                {
                    selectedInstance.ModelScale = Math.Max(0.01f, selectedInstance.ModelScale - increment);
                    ApplySettings();
                }
                if (GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
                {
                    selectedInstance.ModelScale = Math.Max(0.01f, selectedInstance.ModelScale - increment);
                    ApplySettings();
                }
                if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)))
                {
                    selectedInstance.ModelScale += increment;
                    ApplySettings();
                }
                if (GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
                {
                    selectedInstance.ModelScale += increment;
                    ApplySettings();
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(5);



            GUI.enabled = true;



            if (GUILayout.Button("Facility Type: " + selectedInstance.facilityType.ToString(), GUILayout.Height(23)))
            {
                if (!FacilityEditor.instance.IsOpen())
                {
                    FacilityEditor.instance.Open();
                }
            }

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("GrasColor: ", GUILayout.Height(23));
                GUILayout.FlexibleSpace();

                GUI.enabled = ((grasColorEnabled || grassColor2Enabled) && (!UI2.GrassEditor.isOpen || GrassColorUI.instance.IsOpen()));
                if (GUILayout.Button("Preset", GUILayout.Width(90), GUILayout.Height(23)))
                {
                    if (grasColorEnabled)
                    {
                        GrassColorPresetUI.callBack   = GrassColorUI.instance.UpdateCallBack;
                        GrassColorUI.selectedInstance = selectedInstance;
                        GrassColorUI.instance.SetupFields();
                        GrassColorPresetUI.instance.Open();
                    }
                    if (grassColor2Enabled)
                    {
                        GrassColorPresetUI2.callBack = grassMod2.UpdateCallBack;
                        GrassColorPresetUI2.instance.Open();
                    }
                }

                if (GUILayout.Button("Edit", GUILayout.Width(90), GUILayout.Height(23)))
                {
                    if (grasColorEnabled)
                    {
                        GrassColorUI.instance.Open();
                    }
                    if (grassColor2Enabled)
                    {
                        UI2.GrassEditor.Open();
                    }
                }

                GUI.enabled = true;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Set Group: ", GUILayout.Height(23));
                GUILayout.FlexibleSpace();

                if (GUILayout.Button(selectedInstance.Group, GUILayout.Width(185), GUILayout.Height(23)))
                {
                    GroupSelectorUI.instance.Close();
                    GroupSelectorUI.showOnlyLocal = true;
                    GroupSelectorUI.titleText     = "Select a new Group";
                    GroupSelectorUI.callBack      = SetGroup;
                    GroupSelectorUI.instance.Open();
                }
            }
            GUILayout.EndHorizontal();



            GUILayout.Space(3);

            GUILayout.BeginHorizontal();
            {
                enableColliders = GUILayout.Toggle(enableColliders, "Enable Colliders", GUILayout.Width(140), GUILayout.Height(23));

                if (enableColliders != enableColliders2)
                {
                    selectedInstance.ToggleAllColliders(enableColliders);
                    enableColliders2 = enableColliders;
                }

                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Duplicate", GUILayout.Width(130), GUILayout.Height(23)))
                {
                    selectedInstance.SaveConfig();
                    KerbalKonstructs.DeselectObject(true, true);
                    SpawnInstance(selectedInstance.model, selectedInstance.groupCenter, selectedInstance.position, selectedInstance.Orientation);
                    MiscUtils.HUDMessage("Spawned duplicate " + selectedInstance.model.title, 10, 2);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(5);

            GUILayout.BeginHorizontal();
            {
                bool isScanable2 = GUILayout.Toggle(selectedInstance.isScanable, "Static will show up on anomaly scanners", GUILayout.Width(250), GUILayout.Height(23));
                if (isScanable2 != selectedInstance.isScanable)
                {
                    selectedInstance.isScanable = isScanable2;
                    ApplySettings();
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(6);



            GUI.enabled = true;

            GUI.enabled = !LaunchSiteEditor.instance.IsOpen();
            // Make a new LaunchSite here:

            if (!selectedInstance.hasLauchSites && string.IsNullOrEmpty(selectedInstance.model.DefaultLaunchPadTransform))
            {
                GUI.enabled = false;
            }

            if (GUILayout.Button((selectedInstance.hasLauchSites ? "Edit" : "Make") + " Launchsite", GUILayout.Height(23)))
            {
                LaunchSiteEditor.instance.Open();
            }
            GUILayout.FlexibleSpace();

            GUI.enabled = true;

            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Save", GUILayout.Width(110), GUILayout.Height(23)))
                {
                    selectedInstance.SaveConfig();
                    MiscUtils.HUDMessage("Saved changes to this object.", 10, 2);
                }
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Save&Close", GUILayout.Width(110), GUILayout.Height(23)))
                {
                    selectedInstance.SaveConfig();
                    MiscUtils.HUDMessage("Saved changes to this object.", 10, 2);
                    KerbalKonstructs.DeselectObject(true, true);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(10);


            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Revert changes", GUILayout.Height(21)))
                {
                    if (selectedInstance.groupCenter != origCenter)
                    {
                        StaticDatabase.ChangeGroup(selectedInstance, origCenter);
                    }
                    selectedInstance.RelativePosition           = origPosition;
                    selectedInstance.transform.localPosition    = origPosition;
                    selectedInstance.transform.localEulerAngles = origRotation;
                    selectedInstance.Orientation = origRotation;
                    selectedInstance.ModelScale  = origScale;
                    ApplySettings();
                }
                if (GUILayout.Button("Delete Instance", GUILayout.Height(21)))
                {
                    DeleteInstance();
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(5);



            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, UIMain.BoxNoBorder, GUILayout.Height(4));

            GUILayout.Space(2);

            if (GUI.tooltip != "")
            {
                var labelSize = GUI.skin.GetStyle("Label").CalcSize(new GUIContent(GUI.tooltip));
                GUI.Box(new Rect(Event.current.mousePosition.x - (25 + (labelSize.x / 2)), Event.current.mousePosition.y - 40, labelSize.x + 10, labelSize.y + 5), GUI.tooltip);
            }

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
        /// <summary>
        /// Facility Editor window
        /// </summary>
        /// <param name="id"></param>
        void drawFacilityEditorWindow(int id)
        {
            GUILayout.BeginHorizontal();
            {
                GUI.enabled = false;
                GUILayout.Button("-KK-", DeadButton, GUILayout.Height(21));

                GUILayout.FlexibleSpace();

                GUILayout.Button("Facility Editor", DeadButton, GUILayout.Height(21));

                GUILayout.FlexibleSpace();

                GUI.enabled = true;

                if (GUILayout.Button("X", DeadButtonRed, GUILayout.Height(21)))
                {
                    this.Close();
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));

            GUILayout.Space(2);

            GUILayout.Box((string)selectedObject.model.title);
            GUILayout.Space(1);
            if (GUILayout.Button("Facility Type: " + facType, GUILayout.Height(23)))
            {
                bChangeFacilityType = true;
            }

            if (bChangeFacilityType)
            {
                facilityscroll = GUILayout.BeginScrollView(facilityscroll);
                {
                    if (GUILayout.Button("Cancel - No change", GUILayout.Height(23)))
                    {
                        bChangeFacilityType = false;
                    }

                    foreach (string facility in Enum.GetNames(typeof(KKFacilityType)))
                    {
                        if (hiddenFacilities.Contains(facility))
                        {
                            continue;
                        }

                        if (GUILayout.Button(facility, GUILayout.Height(23)))
                        {
                            facType             = facility;
                            bChangeFacilityType = false;
                        }
                    }
                }
                GUILayout.EndScrollView();
            }

            if (selectedObject.FacilityType != facType)
            {
                ChangeFacility();
                updateSelection();
            }
            if (facType != "None")
            {
                OpenCloseFields();
            }

            switch (selectedObject.facilityType)
            {
            case KKFacilityType.Barracks:
            {
                MaxStaffFields();
            }
            break;

            case KKFacilityType.Business:
            {
                BusinessFields();
            }
            break;

            case KKFacilityType.FuelTanks:
            {
                FuelTankFields();
            }
            break;

            case KKFacilityType.GroundStation:
            {
                GroundStationFields();
            }
            break;

            case KKFacilityType.Hangar:
            {
                HangarFields();
            }
            break;

            case KKFacilityType.Research:
            {
                ResearchFields();
            }
            break;

            case KKFacilityType.Merchant:
            {
                MerchantFields();
            }
            break;

            case KKFacilityType.Storage:
            {
                StorageFields();
            }
            break;

            default:
                break;
            }

            GUILayout.FlexibleSpace();
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));

            GUILayout.Space(2);

            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Save Facility", GUILayout.Width(115), GUILayout.Height(23)))
                {
                    MiscUtils.HUDMessage("Applied changes to object.", 10, 2);
                    updateSettings();
                    updateSelection();
                    selectedObject.SaveConfig();
                    this.Close();
                }
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Cancel", GUILayout.Width(115), GUILayout.Height(23)))
                {
                    Close();
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(2);
            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
Ejemplo n.º 3
0
        internal void SaveSettings()
        {
            bool addToDB = false;

            if (!selectedObject.hasLauchSites)
            {
                Log.Normal("Creating LaunchSite");
                KKLaunchSite lsite = new KKLaunchSite();
                selectedObject.launchSite = lsite;
                Log.Normal("created; lsite = " + lsite + "; launch site = " + selectedObject.launchSite);
                selectedObject.hasLauchSites   = true;
                lsite.staticInstance           = selectedObject;
                selectedObject.launchSite.body = selectedObject.CelestialBody;
                addToDB = true;
            }

            string             oldName     = selectedObject.launchSite.LaunchSiteName;
            LaunchSiteCategory oldCategory = category;
            bool oldState = selectedObject.launchSite.ILSIsActive;

            selectedObject.launchSite.LaunchSiteName        = siteName;
            selectedObject.launchSite.LaunchSiteLength      = float.Parse(stLength);
            selectedObject.launchSite.LaunchSiteWidth       = float.Parse(stWidth);
            selectedObject.launchSite.LaunchSiteType        = siteType;
            selectedObject.launchSite.LaunchPadTransform    = siteTrans;
            selectedObject.launchSite.LaunchSiteDescription = siteDesc;
            selectedObject.launchSite.OpenCost              = float.Parse(stOpenCost);
            selectedObject.launchSite.CloseValue            = float.Parse(stCloseValue);
            selectedObject.launchSite.LaunchSiteIsHidden    = bool.Parse(siteHidden);
            selectedObject.launchSite.ILSIsActive           = bool.Parse(ILSActive);
            selectedObject.launchSite.LaunchSiteAuthor      = siteAuthor;
            selectedObject.launchSite.refLat                = (float)selectedObject.RefLatitude;
            selectedObject.launchSite.refLon                = (float)selectedObject.RefLongitude;
            selectedObject.launchSite.refAlt                = selectedObject.RadiusOffset;
            selectedObject.launchSite.sitecategory          = category;
            selectedObject.launchSite.InitialCameraRotation = float.Parse(initialCameraRotation);

            if (ILSConfig.DetectNavUtils())
            {
                Log.Normal("NavUtils detected");
                Log.Debug("object: " + selectedObject);
                Log.Debug("launchsite: " + selectedObject.launchSite);
                Log.Debug("body: " + selectedObject.launchSite.body);

                bool regenerateILSConfig = false;
                Log.Debug("old name: " + oldName);
                Log.Debug("new name: " + selectedObject.launchSite.LaunchSiteName);
                if (oldName != null && !oldName.Equals(siteName))
                {
                    ILSConfig.RenameSite(selectedObject.launchSite.LaunchSiteName, siteName);
                    regenerateILSConfig = true;
                }

                Log.Debug("old category: " + oldCategory);
                if ((oldCategory != category))
                {
                    ILSConfig.HandleCategoryChange(selectedObject);
                    regenerateILSConfig = true;
                }

                bool state = bool.Parse(ILSActive);
                Log.Normal("new state: " + state + "; old state: " + oldState);
                if (oldState != state || regenerateILSConfig)
                {
                    if (state)
                    {
                        ILSConfig.GenerateFullILSConfig(selectedObject);
                    }
                    else
                    {
                        ILSConfig.DropILSConfig(selectedObject.launchSite.LaunchSiteName, true);
                    }
                }
            }


            if (addToDB)
            {
                selectedObject.launchSite.ParseLSConfig(selectedObject, null);
                selectedObject.SaveConfig();
                EditorGUI.instance.enableColliders = true;
                selectedObject.ToggleAllColliders(true);
                LaunchSiteManager.RegisterLaunchSite(selectedObject.launchSite);
            }
            selectedObject.SaveConfig();
        }