void GroupEditorWindow(int windowID) { var expand = GUILayout.ExpandWidth(true); var width20 = GUILayout.Width(20); var width40 = GUILayout.Width(40); var width60 = GUILayout.Width(60); var maxHeight = GUILayout.MaxHeight(Screen.height / 2); Vector2 mousePos = Input.mousePosition; mousePos.y = Screen.height - mousePos.y; editorScroll = GUILayout.BeginScrollView(editorScroll, false, false, maxHeight); //Kick off the window code GUIDragAndDrop.WindowBegin(groupEditorWinPos, editorScroll); GUILayout.BeginVertical(); if (ToolbarManager.ToolbarAvailable) { if (GUILayout.Button("Close")) { saveConfigXML(); groupEditorEnabled = false; } } GUILayout.BeginHorizontal(); //if we are showing the group handles then Pad the text so it still aligns with the text box if (GUIDragAndDrop.ShowGroupHandles) { GUIDragAndDrop.PadText(); } GUILayout.Label("Group Name", expand); GUILayout.Label("Keys", width40); if (servo_groups.Count > 1) { GUILayout.Space(60); } GUILayout.EndHorizontal(); for (int i = 0; i < servo_groups.Count; i++) { Group grp = servo_groups[i]; GUILayout.BeginHorizontal(); //Call the Add Group Handle code GUIDragAndDrop.DrawGroupHandle(grp.name, i); string tmp = GUILayout.TextField(grp.name, expand); if (grp.name != tmp) { grp.name = tmp; } tmp = GUILayout.TextField(grp.forwardKey, width20); if (grp.forwardKey != tmp) { grp.forwardKey = tmp; } tmp = GUILayout.TextField(grp.reverseKey, width20); if (grp.reverseKey != tmp) { grp.reverseKey = tmp; } if (i > 0) { //set a smaller height to align with text boxes if (GUILayout.Button("Remove", width60, GUILayout.Height(EditorButtonHeights))) { foreach (var servo in grp.servos) { move_servo(grp, servo_groups[i - 1], servo); } servo_groups.RemoveAt(i); resetWin = true; return; } } else { if (servo_groups.Count > 1) { GUILayout.Space(60); } } GUILayout.EndHorizontal(); if (useEC) { GUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.Label(string.Format("Estimated Power Draw: {0:#0.##} Ec/s", grp.groupTotalECRequirement), expand); GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); //Pad the text so it still aligns with the text box GUIDragAndDrop.PadText(); GUILayout.Label("Servo Name", expand); if (update14to15) { GUILayout.Label("Rotation", expand); } if (servo_groups.Count > 1) { GUILayout.Label("Group", width40); } GUILayout.EndHorizontal(); //foreach (var servo in grp.servos) for (int iS = 0; iS < grp.servos.Count; iS++) { var servo = grp.servos[iS]; if (!servo.freeMoving) { GUILayout.BeginHorizontal(); //Call the Add Servo Handle code GUIDragAndDrop.DrawServoHandle(servo.servoName, i, iS); //set a smaller height to align with text boxes if (GUILayout.Button("[]", GUILayout.Width(30), GUILayout.Height(EditorButtonHeights))) { tmpMin = servo.minTweak.ToString(); tmpMax = servo.maxTweak.ToString(); servoTweak = servo; guiTweakEnabled = true; } servo.servoName = GUILayout.TextField(servo.servoName, expand); //0.14 to 0.15 fix if (update14to15) { string tempRot = GUILayout.TextField(servo.rotation.ToString(), expand); servo.rotation = float.Parse(tempRot); } //0.14 to 0.15 fix servo.groupName = grp.name; servo.reverseKey = grp.reverseKey; servo.forwardKey = grp.forwardKey; if (groupEditorWinPos.Contains(mousePos)) { var last = GUILayoutUtility.GetLastRect(); var pos = Event.current.mousePosition; bool highlight = last.Contains(pos); servo.part.SetHighlight(highlight); } if (servo_groups.Count > 1) { if (i > 0) { //Changed these to actual arrows - and set a smaller height to align with text boxes if (GUILayout.Button("↑", width20, GUILayout.Height(EditorButtonHeights))) { move_servo(grp, servo_groups[i - 1], servo); } } else { GUILayout.Space(20); } if (i < (servo_groups.Count - 1)) { //Changed these to actual arrows - and set a smaller height to align with text boxes if (GUILayout.Button("↓", width20, GUILayout.Height(EditorButtonHeights))) { move_servo(grp, servo_groups[i + 1], servo); } } else { GUILayout.Space(20); } } GUILayout.EndHorizontal(); } } GUIDragAndDrop.EndDrawGroup(i); GUILayout.EndVertical(); GUILayout.EndHorizontal(); } if (GUILayout.Button("Add new Group")) { Group temp = new Group(); temp.name = "New Group" + (servo_groups.Count + 1).ToString(); servo_groups.Add(temp); } GUILayout.EndVertical(); GUILayout.EndScrollView(); //Was gonna add a footer so you can drag resize the window and have the option to turn on dragging control //GUILayout.BeginHorizontal(); //zTriggerTweaks.DragOn = GUILayout.Toggle(zTriggerTweaks.DragOn,new GUIContent(GameDatabase.Instance.GetTexture("MagicSmokeIndustries/Textures/icon_drag",false))); //GUILayout.EndHorizontal(); //Do the End of window Code for DragAnd Drop GUIDragAndDrop.WindowEnd(); //If we are dragging an item disable the windowdrag if (!GUIDragAndDrop.draggingItem) { GUI.DragWindow(); } }
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(); }