Example #1
0
        void OnGUI()
        {
            // This particular test isn't needed due to the GUI being enabled
            // and disabled as appropriate, but it saves potential NREs.
            if (servo_groups == null)
            {
                return;
            }
            if (InputLockManager.IsLocked(ControlTypes.LINEAR))
            {
                return;
            }

            if (useEC)
            {
                if (!initialGroupECUpdate)
                {
                    foreach (var servoGroup in servo_groups)
                    {
                        updateGroupECRequirement(servoGroup);
                    }
                    initialGroupECUpdate = true;
                }
            }

            if (controlWinPos.x == 0 && controlWinPos.y == 0)
            {
                controlWinPos = new Rect(Screen.width - 510, 70, 10, 10);
            }
            if (editorWinPos.x == 0 && editorWinPos.y == 0)
            {
                editorWinPos = new Rect(Screen.width - 260, 50, 10, 10);
            }

            if (groupEditorWinPos.x == 0 && groupEditorWinPos.y == 0)
            {
                groupEditorWinPos = new Rect(Screen.width - 260, 50, 10, 10);
            }

            if (tweakWinPos.x == 0 && tweakWinPos.y == 0)
            {
                tweakWinPos = new Rect(Screen.width - 410, 220, 145, 130);
            }

            if (resetWin)
            {
                controlWinPos = new Rect(controlWinPos.x, controlWinPos.y,
                                         10, 10);
                editorWinPos = new Rect(editorWinPos.x, editorWinPos.y,
                                        10, 10);
                groupEditorWinPos = new Rect(groupEditorWinPos.x, groupEditorWinPos.y,
                                             10, 10);

                tweakWinPos = new Rect(tweakWinPos.x, tweakWinPos.y,
                                       10, 10);
                resetWin = false;
            }
            GUI.skin = MuUtils.DefaultSkin;
            var scene = HighLogic.LoadedScene;

            //Call the DragAndDrop GUI Setup stuff
            GUIDragAndDrop.OnGUIOnceOnly();

            if (scene == GameScenes.FLIGHT)
            {
                var height = GUILayout.Height(Screen.height / 2);
                if (guiEnabled)
                {
                    //{
                    controlWinPos = GUILayout.Window(956, controlWinPos,
                                                     ControlWindow,
                                                     "Servo Control",
                                                     GUILayout.Width(300),
                                                     GUILayout.Height(80));
                }
                if (groupEditorEnabled)
                {
                    groupEditorWinPos = GUILayout.Window(958, groupEditorWinPos,
                                                         GroupEditorWindow,
                                                         "Servo Group Editor",
                                                         GUILayout.Width(EditorWidth - 48), //Using a variable here
                                                         height);
                }
                if (guiTweakEnabled)
                {
                    tweakWinPos = GUILayout.Window(959, tweakWinPos,
                                                   tweakWindow,
                                                   servoTweak.servoName,
                                                   GUILayout.Width(100),
                                                   GUILayout.Height(80));
                }
                //}
                refreshKeysFromGUI();
            }
            else if (scene == GameScenes.EDITOR || scene == GameScenes.SPH)
            {
                var height = GUILayout.Height(Screen.height / 2);
                if (guiEnabled)
                {
                    editorWinPos = GUILayout.Window(957, editorWinPos,
                                                    EditorWindow,
                                                    "Servo Configuration",
                                                    GUILayout.Width(EditorWidth),  //Using a variable here
                                                    height);
                }
                if (guiTweakEnabled)
                {
                    tweakWinPos = GUILayout.Window(959, tweakWinPos,
                                                   tweakWindow,
                                                   servoTweak.servoName,
                                                   GUILayout.Width(100),
                                                   GUILayout.Height(80));
                }
                EditorLock(guiEnabled && editorWinPos.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)));
            }

            GUIDragAndDrop.OnGUIEvery();
        }