protected override void OnGUI() { var rect = Rectangle; GUI.Box(rect, "", ExtendedGUI.DefaultWindowStyle); if (Progress > 0 && ErrorType == ErrorType.None) { GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width * Progress, 15), Assets["progressBar"]); } Texture2D errorTex = null; switch (ErrorType) { case ErrorType.Execute: errorTex = Assets["genericException"]; break; case ErrorType.Arugment: errorTex = Assets["argumentException"]; break; case ErrorType.PreExecute: errorTex = Assets["genericException"]; break; case ErrorType.PostExecute: errorTex = Assets["genericException"]; break; } if (errorTex) { GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width, 15), errorTex); } var topRect = new Rect(rect.x, rect.y, rect.width, 16); GUI.Label(topRect, name, headerStyle); if (Input.ButtonReleased(EMouseButton.Left) && topRect.Contains(Input.MousePosition)) { var n = DateTime.Now.Ticks; var t = n - previousTicks; if (t <= 5000000) { (Window as AutomatronEditor).LookAtAutomationSmooth(this); n = 0; } previousTicks = n; } if (!Globals.IsError && Input.ButtonReleased(EMouseButton.Right) && topRect.Contains(Input.MousePosition)) { var gm = GenericMenuBuilder.CreateMenu(); gm.AddItem("Remove Incoming Lines", false, RemoveIncomingLines); gm.AddItem("Remove Outgoing Lines", false, RemoveOutgoingLines); gm.ShowAsContext(); } if (showCloseButton && !Globals.IsExecuting) { var cRect = new Rect(rect.x + rect.width - 14, rect.y + 1, 13, 13); if (cRect.Contains(Input.MousePosition)) { GUI.DrawTexture(cRect, Assets["crossActive"]); if (Input.ButtonReleased(EMouseButton.Left)) { Remove(); Input.Use(); } } else { GUI.DrawTexture(cRect, Assets["crossNormal"]); } } var lArrow = new Rect(rect.x - 15, rect.y, 15, 15); var rArrow = new Rect(rect.x + rect.width, rect.y, 15, 15); if (showInArrow) { GUI.DrawTexture(lArrow, Assets["arrowleft"]); if (!Globals.IsExecuting) { if (Input.ButtonReleased(EMouseButton.Left)) { if (lArrow.Contains(Input.MousePosition)) { var line = AutomationLine.HookLineIn(this); if (LinesIn.Contains(line)) { LinesIn.Remove(line); } LinesIn.Add(line); Window.AddControl(line); Input.Use(); } } else if (Input.ButtonReleased(EMouseButton.Right)) { if (lArrow.Contains(Input.MousePosition)) { if (LinesIn.Count > 0) { for (int i = LinesIn.Count - 1; i >= 0; i--) { LinesIn[i].Remove(); } } Input.Use(); } } } } if (showOutArrow) { GUI.DrawTexture(rArrow, Assets["arrowright"]); if (!Globals.IsExecuting) { if (Input.ButtonReleased(EMouseButton.Left)) { if (rArrow.Contains(Input.MousePosition)) { if (LineOut != null) { LineOut.Remove(); LineOut = null; } LineOut = AutomationLine.HookLineOut(this); Window.AddControl(LineOut); Input.Use(); } } else if (Input.ButtonReleased(EMouseButton.Right)) { if (rArrow.Contains(Input.MousePosition)) { if (LineOut != null) { LineOut.Remove(); LineOut = null; } Input.Use(); } } } } if (!Globals.IsExecuting) { if (Input.ButtonPressed(EMouseButton.Left)) { dragger = null; switch (SortingOrder) { case ESortingOrder.Automation: if (rect.Contains(Input.MousePosition)) { SortingOrder = ESortingOrder.AutomationSelected; } break; case ESortingOrder.AutomationSelected: if (!rect.Contains(Input.MousePosition)) { SortingOrder = ESortingOrder.Automation; } break; } } if (Input.ButtonDown(EMouseButton.Left)) { if (dragger == null) { var dragRect = new Rect(rect.x, rect.y, rect.width - 16, 16); if (dragRect.Contains(Input.MousePosition)) { dragger = this; GUIUtility.keyboardControl = 0; } } } if (Input.ButtonReleased(EMouseButton.Left)) { dragger = null; } if (dragger == this) { Position += Input.DragDelta; } } var fieldRect = new Rect(rect.x, rect.y + 18, rect.width, rect.height); foreach (var item in fields) { var height = item.GetHeight(); fieldRect.height = height; item.OnGUI(fieldRect); fieldRect.y += height; } if (Input.ButtonReleased(EMouseButton.Right) && rect.Contains(Input.MousePosition)) { Input.Use(); } if (Input.ButtonDown(EMouseButton.Middle) && rect.Contains(Input.MousePosition)) { Input.Use(); } UpdateSize(); }
protected override void OnGUI() { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); EditorGUI.BeginDisabledGroup(Globals.IsExecuting); if (GUILayout.Button("File", EditorStyles.toolbarDropDown)) { var gm = GenericMenuBuilder.CreateMenu(); gm.AddItem("New Automatron", false, () => { AddWindow(new AutomatronMenu(1)); Remove(); }); gm.AddItem("Open Automatron", false, () => { AddWindow(new AutomatronMenu()); Remove(); }); gm.AddSeparator(); gm.AddItem("Save Automatron", false, () => { AutomatronSerializer.Save(this); ShowNotification("Automatron saved"); }); gm.AddItem("Save Automatron As...", false, () => { ShowPopup(new InputBox( "Save Automatron As...", "Please insert a new name for the Automatron", (EDialogResult result, string input) => { if (result == EDialogResult.OK && !string.IsNullOrEmpty(input)) { Name = input; Save(); ShowNotification(string.Format("Automatron saved as '{0}'", input)); } })); }); gm.AddSeparator(); gm.AddItem("Create.../Automation", false, () => { ShowPopup(new InputBox( "Create Automation", "Please insert the name for your Automation", (EDialogResult result, string input) => { if (result == EDialogResult.OK && !string.IsNullOrEmpty(input)) { templator.CreateAutomation(input); } })); }); gm.AddItem("Create.../Conditional Automation", false, () => { ShowPopup(new InputBox( "Create Conditional Automation", "Please insert the name for your Automation", (EDialogResult result, string input) => { if (result == EDialogResult.OK && !string.IsNullOrEmpty(input)) { templator.CreateConditionalAutomation(input); } })); }); gm.AddItem("Create.../Loopable Automation", false, () => { ShowPopup(new InputBox( "Create Loopable Automation", "Please insert the name for your Automation", (EDialogResult result, string input) => { if (result == EDialogResult.OK && !string.IsNullOrEmpty(input)) { templator.CreateLoopableAutomation(input); } })); }); gm.AddSeparator("Create.../"); gm.AddItem("Create.../Generator", false, () => { Generation.Generator.CreateMe(); }); gm.AddSeparator(); gm.AddItem("Exit", false, () => { Editor.Close(); }); gm.ShowAsContext(); } if (GUILayout.Button("Automations", EditorStyles.toolbarDropDown)) { ShowAutomationPopup(); } EditorGUI.EndDisabledGroup(); // Spacer GUILayout.Button("", EditorStyles.toolbarButton); if (Globals.IsExecuting) { if (GUILayout.Button(stopContent, EditorStyles.toolbarButton)) { executionRoutine.Stop(); executionRoutine = null; Globals.IsExecuting = false; } } else { if (GUILayout.Button(executeContent, EditorStyles.toolbarButton)) { ExecuteAutomations(); } } EditorGUI.BeginDisabledGroup(Globals.IsExecuting); if (GUILayout.Button(resetContent, EditorStyles.toolbarButton)) { var list = GetControls <Automation>(); foreach (var item in list) { item.Reset(); item.ResetFields(); } } if (GUILayout.Button(trashContent, EditorStyles.toolbarButton)) { ShowPopup(new MessageBox("Caution!", "You're about to empty this Automatron...\nAre you sure you want to do this?", EMessageBoxButtons.YesNo, ( EDialogResult result ) => { if (result == EDialogResult.Yes) { var controls = GetControls <ExtendedControl>(); for (int i = controls.Count - 1; i >= 0; i--) { var item = controls[i]; if (item != entryPoint) { item.Remove(); } } entryPoint.Reset(); Globals.Camera = new Vector2(); entryPoint.Position = WindowRect.center; } })); } EditorGUI.EndDisabledGroup(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Help", EditorStyles.toolbarButton)) { Application.OpenURL("http://tnrd.net/automatron"); } EditorGUILayout.EndHorizontal(); if (Input.KeyReleased(KeyCode.F1)) { Application.OpenURL("http://tnrd.net/automatron"); } if (Event.current.keyCode == KeyCode.Space) { if (Event.current.type == EventType.KeyDown) { spacePan = true; Event.current.Use(); } else if (Event.current.type == EventType.KeyUp) { spacePan = false; Event.current.Use(); } } if (Input.ButtonPressed(EMouseButton.Middle)) { mousePan = true; } else if (Input.ButtonDown(EMouseButton.Middle)) { Globals.Camera += Input.DragDelta; } else if (Input.ButtonReleased(EMouseButton.Middle) || Input.ButtonUp(EMouseButton.Middle)) { mousePan = false; } if (spacePan || mousePan) { EditorGUIUtility.AddCursorRect(new Rect(0, 0, Size.x, Size.y), MouseCursor.Pan); if (!mousePan && (Input.ButtonDown(EMouseButton.Left) || Input.ButtonDown(EMouseButton.Right))) { Globals.Camera += Input.DragDelta; } } else if (Input.ButtonReleased(EMouseButton.Right)) { ShowAutomationPopup(); Input.Use(); } if (AutomatronSettings.AutoSave) { if (Input.ButtonReleased(EMouseButton.Left)) { Save(); Input.Use(); } } Repaint(); }