private void CreateGUI() { var area = new Rect(54 - ((1 - anim) * Size.x), 125, Size.x - 100, Size.y - 200); GUILayout.BeginArea(area); GUILayout.BeginArea(new Rect(area.width - 129, 35, 125, 16)); ExtendedGUI.HorizontalLine(); GUILayout.EndArea(); var cbr = new Rect(area.width - 119, 7.5f, 50, 20); var isHover = cbr.Contains(Input.MousePosition); if (Event.current.type == EventType.Repaint) { EditorGUI.BeginDisabledGroup(isInvalid); buttonStyle.Draw(cbr, "Create", isHover, isHover, false, false); EditorGUI.EndDisabledGroup(); } if (!isInvalid && isHover) { EditorGUIUtility.AddCursorRect(new Rect(0, 0, Size.x, Size.y), MouseCursor.Link); if (Input.ButtonReleased(EMouseButton.Left)) { if (!string.IsNullOrEmpty(automatronName)) { createAutomatron = true; } } } var obr = new Rect(area.width - 64, 7.5f, 50, 20); isHover = obr.Contains(Input.MousePosition); if (Event.current.type == EventType.Repaint) { buttonStyle.Draw(obr, "Cancel", isHover, isHover, false, false); } if (isHover) { EditorGUIUtility.AddCursorRect(new Rect(0, 0, Size.x, Size.y), MouseCursor.Link); if (Input.ButtonReleased(EMouseButton.Left)) { target = 0; automatronName = ""; GUIUtility.keyboardControl = -1; } } GUILayout.Space(55); EditorGUILayout.LabelField("Name", labelStyle, GUILayout.Height(28)); var nId = GUIUtility.GetControlID(FocusType.Passive) + 1; automatronName = EditorGUILayout.TextField(automatronName, textboxStyle, GUILayout.Height(24), GUILayout.Width(area.width / 2)); if (GUIUtility.keyboardControl == nId && anim == 1 && !isInvalid) { if (Input.KeyReleased(KeyCode.KeypadEnter) || Input.KeyReleased(KeyCode.Return)) { createAutomatron = true; } } isInvalid = false; if (Regex.IsMatch(automatronName, invalidChars)) { isInvalid = true; EditorGUILayout.LabelField(string.Format("'{0}' contains invalid characters", automatronName), subLabelStyle, GUILayout.Height(20)); } else if (string.IsNullOrEmpty(automatronName)) { isInvalid = true; EditorGUILayout.LabelField("Name cannot be empty", subLabelStyle, GUILayout.Height(20)); } else { try { var path = Path.Combine(automatronPath, automatronName + ".acfg"); if (File.Exists(path)) { EditorGUILayout.LabelField(string.Format("'{0}' already exists. Proceeding will overwrite it", automatronName), subLabelStyle, GUILayout.Height(20)); } else { GUILayout.Space(22); } } catch (System.Exception) { EditorGUILayout.LabelField(string.Format("'{0}' contains invalid characters", automatronName), subLabelStyle, GUILayout.Height(20)); } } EditorGUILayout.LabelField("Path", labelStyle, GUILayout.Height(28)); var r = EditorGUILayout.GetControlRect(GUILayout.Height(24), GUILayout.Width(area.width / 2)); automatronPath = EditorGUI.TextField(r, automatronPath, textboxStyle); r.x += r.width + 5; r.width = 50; isHover = r.Contains(Input.MousePosition); if (Event.current.type == EventType.Repaint) { labelStyle.Draw(r, "•••", isHover, isHover, false, false); } if (isHover) { EditorGUIUtility.AddCursorRect(new Rect(0, 0, Size.x, Size.y), MouseCursor.Link); if (Input.ButtonReleased(EMouseButton.Left)) { GUIUtility.keyboardControl = -1; var p = EditorUtility.OpenFolderPanel("Automatron Path", automatronPath, ""); if (!string.IsNullOrEmpty(p)) { automatronPath = p; } } } GUILayout.EndArea(); }
protected override void OnGUI() { EditorGUI.LabelField(new Rect(0, 10, Size.x, Size.y), "AUTOMATRON", headerStyle); GUILayout.BeginArea(new Rect(50, 125, Size.x - 100, 16)); ExtendedGUI.HorizontalLine(); GUILayout.EndArea(); ListGUI(); if (anim > 0) { CreateGUI(); } if (Event.current.type == EventType.Repaint && AutomatronSettings.FirstRun) { AutomatronSettings.FirstRun.Value = false; if (configs.Count == 0) { var v = EditorUtility.DisplayDialog("", "It seems that this is your first time you here.\nDo you want to add some example projects?", "Yes", "No"); if (v) { if (!Directory.Exists(AutomatronSettings.ConfigFolder)) { Directory.CreateDirectory(AutomatronSettings.ConfigFolder); } AddExample("ForEach Example"); AddExample("For Example"); AddExample("Conditional Example"); AddExample("Advanced Example"); AddExample("Simple Example"); SaveRecents(); } } } switch (Event.current.type) { case EventType.DragUpdated: case EventType.DragPerform: { var paths = DragAndDrop.paths.Where(p => p.EndsWith(".acfg")).ToList(); if (paths.Count > 0) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; } if (Event.current.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); if (paths.Count == 1) { loadAutomatron = true; automatron = paths[0]; } else { addAutomatrons = true; automatrons = paths; } } } break; } if (Event.current.type == EventType.Repaint) { if (createAutomatron) { createAutomatron = false; try { var p = Path.Combine(automatronPath, automatronName).Replace("\\", "/") + ".acfg"; var i = -1; while ((i = configs.IndexOf(p)) != -1) { configs.RemoveAt(i); } configs.Insert(0, p); SaveRecents(); } catch (System.Exception) { EditorUtility.DisplayDialog("Oops", "Something went wrong trying to make this Automatron!", "OK"); return; } Remove(); var wnd = new AutomatronEditor(); AddWindow(wnd); wnd.NewAutomatron(automatronPath, automatronName); return; } else if (loadAutomatron) { loadAutomatron = false; var i = configs.IndexOf(automatron); if (i != -1) { configs.RemoveAt(i); } configs.Insert(0, automatron); SaveRecents(); Remove(); var wnd = new AutomatronEditor(); AddWindow(wnd); wnd.LoadAutomatron(automatron); return; } else if (deleteAutomatron) { deleteAutomatron = false; var i = configs.IndexOf(automatron); if (i != -1) { configs.RemoveAt(i); SaveRecents(); } return; } else if (addAutomatrons) { addAutomatrons = false; foreach (var item in automatrons) { if (configs.Contains(item)) { continue; } configs.Insert(0, item); } SaveRecents(); } } Repaint(); }
private void ListGUI() { var area = new Rect(50 + (Size.x * anim), 125, Size.x - 100, Size.y - 200); GUILayout.BeginArea(area); GUILayout.BeginArea(new Rect(area.width - 125, 35, 125, 16)); ExtendedGUI.HorizontalLine(); GUILayout.EndArea(); var cbr = new Rect(area.width - 115, 7.5f, 50, 20); var isHover = cbr.Contains(Input.MousePosition); if (Event.current.type == EventType.Repaint) { buttonStyle.Draw(cbr, "Create", isHover, isHover, false, false); } if (isHover) { EditorGUIUtility.AddCursorRect(new Rect(0, 0, Size.x, Size.y), MouseCursor.Link); if (Input.ButtonReleased(EMouseButton.Left)) { target = 1; } } var obr = new Rect(area.width - 60, 7.5f, 50, 20); isHover = obr.Contains(Input.MousePosition); if (Event.current.type == EventType.Repaint) { buttonStyle.Draw(obr, "Open", isHover, isHover, false, false); } if (isHover) { EditorGUIUtility.AddCursorRect(new Rect(0, 0, Size.x, Size.y), MouseCursor.Link); if (Input.ButtonReleased(EMouseButton.Left)) { var p = EditorUtility.OpenFilePanel("Select Automation", "", "acfg"); if (!string.IsNullOrEmpty(p)) { var a = AutomatronSerializer.Load(p); if (a != null) { loadAutomatron = true; automatron = p; } } } } GUILayout.Space(50); if (configs.Count == 0) { EditorGUILayout.LabelField("It seems pretty empty over here", noneStyle, GUILayout.ExpandHeight(true)); } else { scroll = EditorGUILayout.BeginScrollView(scroll); for (int i = 0; i < configs.Count; i++) { var p = configs[i]; var l = Path.GetFileNameWithoutExtension(p); var s = p.Replace("\\", "/"); GUILayout.Space(5); var r = EditorGUILayout.GetControlRect(false, 48); isHover = r.Contains(Input.MousePosition); if (Event.current.type == EventType.Repaint) { labelStyle.Draw(r, l, isHover, isHover, false, false); } EditorGUI.LabelField(new Rect(r.x + 12, r.y + 24, r.width, 20), s, subLabelStyle); if (isHover) { EditorGUIUtility.AddCursorRect(new Rect(0, 0, Size.x, Size.y), MouseCursor.Link); if (Input.ButtonReleased(EMouseButton.Left)) { automatron = p; if (File.Exists(p)) { loadAutomatron = true; } else { if (EditorUtility.DisplayDialog("Automatron", string.Format("\"{0}\" could not be opened. Do you want to remove the reference from the list?", l), "Yes", "No")) { deleteAutomatron = true; } } } } } EditorGUILayout.EndScrollView(); } GUILayout.EndArea(); }