Beispiel #1
0
        public void ToggleEditor()
        {
            if (KerbalKonstructs.selectedInstance != null)
            {
                KerbalKonstructs.DeselectObject(true, true);
            }

            this.Toggle();

            if (snapTargetInstance != null)
            {
                snapTargetInstance.HighlightObject(Color.clear);
                snapTargetInstance = null;
            }
        }
        /// <summary>
        /// Selects Object under the mouse curser.
        /// </summary>
        internal void SelectMouseObject()
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            int layerMask = ~0;

            if (!Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, layerMask))
            {
                return;
            }

            StaticInstance myHitinstance = GetRootFromHit(hit.collider.gameObject);

            if (myHitinstance == null)
            {
                Log.Normal("No RootObject found");
                return;
            }
            else
            {
                if (KerbalKonstructs.selectedInstance != null)
                {
                    KerbalKonstructs.DeselectObject(true, true);
                }
                //Log.Normal("Try to select Object: " + myHitinstance.mesh.name);
                myHitinstance.HighlightObject(XKCDColors.Green_Yellow);
                KerbalKonstructs.SelectInstance(myHitinstance, true);
                if (!EditorGUI.instance.IsOpen())
                {
                    EditorGUI.instance.Open();
                }
            }
        }
        public void ToggleEditor()
        {
            if (KerbalKonstructs.instance.selectedObject != null)
            {
                KerbalKonstructs.instance.deselectObject(true, true);
            }

            this.Toggle();

            if (snapTargetInstance != null)
            {
                Color highlightColor = new Color(0, 0, 0, 0);
                snapTargetInstance.HighlightObject(highlightColor);
                snapTargetInstance = null;
            }
        }
        /// <summary>
        /// Selects Object under the mouse curser.
        /// </summary>
        internal void SelectMouseObject()
        {
            Ray ray       = Camera.main.ScreenPointToRay(Input.mousePosition);;
            int layerMask = ~0;

            RaycastHit hit;

            if (!Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
            {
                return;
            }

            StaticInstance myHitinstance = GetRootFromHit(hit.collider.gameObject);

            if (myHitinstance == null)
            {
                Log.Normal("No RootObject found");
                return;
            }
            else
            {
                Log.Normal("Try to select Object: " + myHitinstance.gameObject.name);
                myHitinstance.HighlightObject(XKCDColors.Green_Yellow);
                KerbalKonstructs.instance.selectObject(myHitinstance, true, true, false);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Spawns an Instance of an defined StaticModel
        /// </summary>
        /// <param name="model"></param>
        /// <param name="fOffset"></param>
        /// <param name="vPosition"></param>
        /// <param name="fAngle"></param>
        /// <returns></returns>
        public string SpawnInstance(StaticModel model, float fOffset, Vector3 vPosition)
        {
            StaticInstance instance = new StaticInstance();

            instance.Orientation     = Vector3.up;
            instance.heighReference  = HeightReference.Terrain;
            instance.VisibilityRange = (PhysicsGlobals.Instance.VesselRangesDefault.flying.unload + 3000);

            instance.Group          = "SaveGame";
            instance.RadialPosition = vPosition;

            instance.model = model;

            if (instance.model == null)
            {
                Log.UserError("LoadFromSave: Canot find model named: " + model.name);
                instance = null;
            }
            //instance.mesh = UnityEngine.Object.Instantiate(instance.model.prefab);


            instance.CelestialBody = KerbalKonstructs.instance.GetCurrentBody();

            instance.RadiusOffset  = fOffset;
            instance.RotationAngle = 0;

            instance.RefLatitude  = KKMath.GetLatitudeInDeg(instance.RadialPosition);
            instance.RefLongitude = KKMath.GetLongitudeInDeg(instance.RadialPosition);

            InstanceUtil.CreateGroupCenterIfMissing(instance);


            bool oldLegacySpawn = KerbalKonstructs.convertLegacyConfigs;

            instance.Orientate();
            instance.Activate();

            KerbalKonstructs.convertLegacyConfigs = oldLegacySpawn;

            KerbalKonstructs.SelectInstance(instance, true);

            selectedInstance = instance;
            startPosition    = selectedInstance.position;

            instance.Update();
            instance.isInSavegame = true;

            instance.HighlightObject(XKCDColors.FreshGreen);

            this.Open();

            return(instance.UUID);
        }
Beispiel #6
0
 internal static void Open()
 {
     KKStyle.Init();
     staticInstance = EditorGUI.selectedInstance;
     staticInstance.HighlightObject(Color.clear);
     selectedMod = EditorGUI.selectedInstance.mesh.GetComponents <GrassColor2>()[0];
     ReadMod(selectedMod);
     //windowRect = new Rect(CreateBesidesMainwindow(), new Vector2(windowWidth, windowHeight));
     content = new List <DialogGUIBase>();
     KKTitle();
     CreateContent();
     CreateMultiOptionDialog();
     CreatePopUp();
 }
        void OnSetAsSnap(InstanceItem item)
        {
            if (snapTargetInstance != null)
            {
                snapTargetInstancePrevious = snapTargetInstance;
                Color highlightColor3 = new Color(0, 0, 0, 0);
                snapTargetInstance.HighlightObject(highlightColor3);
            }

            snapTargetInstance = item.instance;

            Color highlightColor4 = XKCDColors.RedPink;

            snapTargetInstance.HighlightObject(highlightColor4);
        }
Beispiel #8
0
        internal static void Close()
        {
            if (EditorGUI.instance.IsOpen() && (EditorGUI.selectedInstance == staticInstance))
            {
                staticInstance.HighlightObject(XKCDColors.Green_Yellow);
            }

            if (dialog != null)
            {
                WindowManager.SavePosition(dialog);
                dialog.Dismiss();
            }

            dialog       = null;
            optionDialog = null;
        }
Beispiel #9
0
        public override void Draw()
        {
            if (MapView.MapIsEnabled)
            {
                return;
            }

            if (!StaticsEditorGUI.instance.IsOpen() || !EditorGUI.instance.IsOpen() || !EditorGUI.grasColorEnabled || EditorGUI.selectedInstance == null)
            {
                this.Close();
            }

            if (EditorGUI.selectedInstance != selectedInstance)
            {
                selectedInstance = EditorGUI.selectedInstance;
                selectedInstance.HighlightObject(Color.clear);
                SetupFields();
            }

            drawGrasColorUI();
        }
        /// <summary>
        /// Spawns an Instance of an defined StaticModel
        /// </summary>
        /// <param name="model"></param>
        /// <param name="fOffset"></param>
        /// <param name="vPosition"></param>
        /// <param name="fAngle"></param>
        /// <returns></returns>
        public string SpawnInstance(StaticModel model, float fOffset, Vector3 vPosition)
        {
            StaticInstance instance = new StaticInstance();

            instance.isInSavegame = true;

            instance.heighReference = HeightReference.Terrain;

            instance.gameObject      = UnityEngine.Object.Instantiate(model.prefab);
            instance.RadiusOffset    = fOffset;
            instance.CelestialBody   = KerbalKonstructs.instance.getCurrentBody();
            instance.Group           = "Ungrouped";
            instance.RadialPosition  = vPosition;
            instance.RotationAngle   = 0;
            instance.Orientation     = Vector3.up;
            instance.VisibilityRange = (PhysicsGlobals.Instance.VesselRangesDefault.flying.unload + 3000);
            instance.RefLatitude     = KKMath.GetLatitudeInDeg(instance.RadialPosition);
            instance.RefLongitude    = KKMath.GetLongitudeInDeg(instance.RadialPosition);

            instance.model      = model;
            instance.configPath = null;
            instance.configUrl  = null;

            instance.SpawnObject(true);

            KerbalKonstructs.instance.selectedObject = instance;

            selectedObject = instance;
            startPosition  = selectedObject.gameObject.transform.position;

            instance.HighlightObject(XKCDColors.FreshGreen);

            this.Open();

            return(instance.UUID);
        }
        void OnSelect(InstanceItem item)
        {
            var instance = item.instance;

            EditorGUI.CloseEditors();
            if (!EditorGUI.instance.IsOpen())
            {
                EditorGUI.instance.Open();
            }

            if (selectedObject != null)
            {
                selectedObject.HighlightObject(UnityEngine.Color.clear);
                selectedObject = instance;
            }

            if (snapTargetInstance == instance)
            {
                snapTargetInstance = null;
            }
            KerbalKonstructs.SelectInstance(instance, false);

            instance.HighlightObject(XKCDColors.Green_Yellow);
        }
Beispiel #12
0
 public override void Close()
 {
     selectedInstance.HighlightObject(XKCDColors.YellowGreen);
     selectedInstance = null;
     base.Close();
 }
Beispiel #13
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("Mod 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);
                }
            }
            GUILayout.EndHorizontal();

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

            GUILayout.Space(2);

            GUILayout.BeginHorizontal();

            if (isInRange)
            {
                GUILayout.Button(selectedInstance.model.title + " (" + selectedInstance.indexInGroup.ToString() + ")", GUILayout.Height(23));
            }
            else
            {
                GUILayout.Button("Out of Range", UIMain.ButtonRed, GUILayout.Height(23));
            }

            if (wasInRange && !isInRange)
            {
                wasInRange = false;
                selectedInstance.HighlightObject(XKCDColors.Reddish);
            }

            if (!wasInRange && isInRange)
            {
                wasInRange = true;
                selectedInstance.HighlightObject(XKCDColors.FreshGreen);
            }


            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.FlexibleSpace();
                if (!foldedIn)
                {
                    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();
                }
                else
                {
                    GUILayout.Label("i");
                    increment = float.Parse(GUILayout.TextField(increment.ToString(), 3, GUILayout.Width(25)));

                    if (GUILayout.Button("0.1", GUILayout.Height(23)))
                    {
                        increment = 0.1f;
                    }
                    if (GUILayout.Button("1", GUILayout.Height(23)))
                    {
                        increment = 1f;
                    }
                    if (GUILayout.Button("10", GUILayout.Height(23)))
                    {
                        increment = 10f;
                    }
                }
            }
            GUILayout.EndHorizontal();

            //
            // Set reference butons
            //
            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Reference System: ");
                GUILayout.FlexibleSpace();
                GUI.enabled = (referenceSystem == Space.World);

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

                GUI.enabled = (referenceSystem == Space.Self);
                if (GUILayout.Button(new GUIContent(UIMain.iconWorld.texture, "World"), GUILayout.Height(23), GUILayout.Width(23)))
                {
                    referenceSystem = Space.World;
                    UpdateGizmo();
                    UpdateVectors();
                }
                GUI.enabled = true;

                GUILayout.Label(referenceSystem.ToString());
            }
            GUILayout.EndHorizontal();
            float fTempWidth = 80f;

            //
            // Position editing
            //
            GUILayout.BeginHorizontal();


            GUILayout.Label("Back / Forward:");
            GUILayout.FlexibleSpace();
            ;

            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();
            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.EndHorizontal();

            GUI.enabled = true;



            //
            // Altitude editing
            //
            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Alt.");
                GUILayout.FlexibleSpace();
                selectedInstance.RadiusOffset = float.Parse(GUILayout.TextField(selectedInstance.RadiusOffset.ToString(), 25, 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;

            GUILayout.Space(5);


            fTempWidth = 80f;

            GUI.enabled = true;



            //
            // Rotation
            //
            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Heading:");
                GUILayout.FlexibleSpace();
                GUILayout.TextField(heading.ToString(), 9, GUILayout.Width(fTempWidth));

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

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



            GUI.enabled = true;



            GUI.enabled = true;
            GUILayout.FlexibleSpace();

            GUILayout.BeginHorizontal();
            {
                GUI.enabled = isInRange;
                if (GUILayout.Button("Save&Close", GUILayout.Width(110), GUILayout.Height(23)))
                {
                    selectedInstance.ToggleAllColliders(true);
                    KerbalKonstructs.DeselectObject(true, true);
                    selectedInstance.HighlightObject(Color.clear);
                }
                GUI.enabled = true;
                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Destroy", GUILayout.Height(21)))
                {
                    DeleteInstance();
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(15);

            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));
        }