From 4e0c596d7792d4e3e97f70fbb5726508b61aa760 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Mon, 25 Aug 2014 15:36:21 +0100 Subject: [PATCH] Commands are now in same window as sequence nodes --- .../Editor/FungusCommandEditor.cs | 2 - .../FungusScript/Editor/FungusScriptEditor.cs | 118 +++-------- .../FungusScript/Editor/FungusScriptWindow.cs | 183 ++++++++++++++---- .../FungusScript/Scripts/FungusScript.cs | 5 +- Assets/Shuttle/ShuttleGame.unity | Bin 118996 -> 119260 bytes 5 files changed, 168 insertions(+), 140 deletions(-) diff --git a/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs index 94d13f3f..d9739e8a 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs @@ -148,8 +148,6 @@ namespace Fungus.Script t.IsExecuting()) { Rect rect = GUILayoutUtility.GetLastRect(); - rect.x -= 10; - rect.width += 10; GLDraw.DrawBox(rect, Color.green, 1.5f); } } diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs index 98f5379a..728256bf 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs @@ -22,25 +22,7 @@ namespace Fungus.Script if (t != null) { - // Hide the transform component if FungusScript & Variables are the only components on the game object - // Gives a bit more room in inspector for editing commands. The transform will become visible if any non-Fungus - // components are attached to the game object. - Component[] components = t.GetComponents(typeof(Component)); - int count = 0; - foreach (Component component in components) - { - System.Type type = component.GetType(); - if (type == typeof(Transform) || - type == typeof(FungusScript) || - type == typeof(BooleanVariable) || - type == typeof(IntegerVariable) || - type == typeof(FloatVariable) || - type == typeof(StringVariable)) - { - count++; - } - } - t.transform.hideFlags = (count == components.Length) ? HideFlags.HideInInspector : HideFlags.None; + t.transform.hideFlags = HideFlags.None; } EditorGUI.BeginChangeCheck(); @@ -78,80 +60,22 @@ namespace Fungus.Script } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); + } - EditorGUILayout.Separator(); - GUI.backgroundColor = Color.yellow; - GUILayout.Box("Sequence Editor", GUILayout.ExpandWidth(true)); - GUI.backgroundColor = Color.white; - - GUILayout.BeginHorizontal(); - - if (t.selectedSequence == null) - { - GUILayout.FlexibleSpace(); - } - - if (GUILayout.Button(t.selectedSequence == null ? "Create Sequence" : "Create", - t.selectedSequence == null ? EditorStyles.miniButton : EditorStyles.miniButtonLeft)) - { - Sequence newSequence = t.CreateSequence(t.scrollPos); - Undo.RegisterCreatedObjectUndo(newSequence, "New Sequence"); - t.selectedSequence = newSequence; - } - - if (t.selectedSequence == null) - { - GUILayout.FlexibleSpace(); - } - - if (t.selectedSequence != null) - { - if (GUILayout.Button("Delete", EditorStyles.miniButtonMid)) - { - Undo.DestroyObjectImmediate(t.selectedSequence.gameObject); - t.selectedSequence = null; - } - if (GUILayout.Button("Duplicate", EditorStyles.miniButtonRight)) - { - GameObject copy = GameObject.Instantiate(t.selectedSequence.gameObject) as GameObject; - copy.transform.parent = t.transform; - copy.transform.hideFlags = HideFlags.HideInHierarchy; - copy.name = t.selectedSequence.name; - - Sequence sequenceCopy = copy.GetComponent(); - sequenceCopy.nodeRect.x += sequenceCopy.nodeRect.width + 10; - - Undo.RegisterCreatedObjectUndo(copy, "Duplicate Sequence"); - t.selectedSequence = sequenceCopy; - } - } - - GUILayout.EndHorizontal(); - - EditorGUILayout.Separator(); - - if (t.selectedSequence != null) + public void DrawSequenceGUI(FungusScript fungusScript) + { + if (fungusScript.selectedSequence == null) { - DrawSequenceGUI(t.selectedSequence); - - if (!Application.isPlaying) - { - EditorGUILayout.Separator(); - DrawAddCommandGUI(t.selectedSequence); - } + return; } - } + + Sequence sequence = fungusScript.selectedSequence; - public void DrawSequenceGUI(Sequence sequence) - { EditorGUI.BeginChangeCheck(); string name = EditorGUILayout.TextField(new GUIContent("Sequence Name", "Name of sequence displayed in editor window"), sequence.name); - EditorGUILayout.PrefixLabel(new GUIContent("Description", "Sequence description displayed in editor window")); - GUIStyle descriptionStyle = new GUIStyle(EditorStyles.textArea); - descriptionStyle.wordWrap = true; - string desc = EditorGUILayout.TextArea(sequence.description, descriptionStyle); - + string desc = EditorGUILayout.TextField(new GUIContent("Description", "Sequence description displayed in editor window"), sequence.description); + EditorGUILayout.Separator(); if (name != sequence.name) @@ -167,7 +91,9 @@ namespace Fungus.Script sequence.description = desc; } - EditorGUILayout.PrefixLabel("Commands"); + GUI.backgroundColor = Color.yellow; + GUILayout.Box("Commands", GUILayout.ExpandWidth(true)); + GUI.backgroundColor = Color.white; FungusCommand[] commands = sequence.GetComponents(); int index = 1; @@ -176,14 +102,16 @@ namespace Fungus.Script FungusCommandEditor commandEditor = Editor.CreateEditor(command) as FungusCommandEditor; commandEditor.DrawInspectorGUI(index++); } - } - public void DrawAddCommandGUI(Sequence sequence) - { - FungusScript t = target as FungusScript; + if (Application.isPlaying) + { + return; + } + + EditorGUILayout.Separator(); GUI.backgroundColor = Color.yellow; - GUILayout.Box("Add Command", GUILayout.ExpandWidth(true)); + GUILayout.Box("New Command", GUILayout.ExpandWidth(true)); GUI.backgroundColor = Color.white; // Build list of categories @@ -201,12 +129,12 @@ namespace Fungus.Script EditorGUI.BeginChangeCheck(); - int selectedCommandIndex = EditorGUILayout.Popup("Command", t.selectedCommandIndex, commandNames.ToArray()); + int selectedCommandIndex = EditorGUILayout.Popup("Command", fungusScript.selectedCommandIndex, commandNames.ToArray()); if (EditorGUI.EndChangeCheck()) { - Undo.RecordObject(t, "Select Command"); - t.selectedCommandIndex = selectedCommandIndex; + Undo.RecordObject(fungusScript, "Select Command"); + fungusScript.selectedCommandIndex = selectedCommandIndex; } System.Type selectedType = commandTypes[selectedCommandIndex]; diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs index f27acb7e..59e64430 100755 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs @@ -6,9 +6,13 @@ using System.Collections.Generic; namespace Fungus.Script { - public class FungusScriptWindow : EditorWindow { + float commandViewWidth; + bool resize = false; + Rect cursorChangeRect; + public const float minViewWidth = 300; + private List windowSequenceMap = new List(); [MenuItem("Window/Fungus Script")] @@ -17,6 +21,12 @@ namespace Fungus.Script GetWindow(typeof(FungusScriptWindow), false, "Fungus Script"); } + void OnEnable() + { + commandViewWidth = minViewWidth; + cursorChangeRect = new Rect(this.position.width - commandViewWidth, 0, 4f, this.position.height); + } + public void OnInspectorUpdate() { Repaint(); @@ -32,8 +42,8 @@ namespace Fungus.Script return null; } - void OnGUI() - { + void OnGUI() + { FungusScript fungusScript = GetFungusScript(); if (fungusScript == null) { @@ -41,12 +51,21 @@ namespace Fungus.Script return; } + GUILayout.BeginHorizontal(); + DrawScriptView(fungusScript); + ResizeViews(); + DrawCommandView(fungusScript); + GUILayout.EndHorizontal(); + } + + void DrawScriptView(FungusScript fungusScript) + { EditorUtility.SetDirty(fungusScript); - + Sequence[] sequences = fungusScript.GetComponentsInChildren(); - + Rect scrollViewRect = new Rect(); - + foreach (Sequence s in sequences) { scrollViewRect.xMin = Mathf.Min(scrollViewRect.xMin, s.nodeRect.xMin); @@ -54,52 +73,55 @@ namespace Fungus.Script scrollViewRect.yMin = Mathf.Min(scrollViewRect.yMin, s.nodeRect.yMin); scrollViewRect.yMax = Mathf.Max(scrollViewRect.yMax, s.nodeRect.yMax); } - + // Empty buffer area around edges of scroll rect float bufferScale = 0.25f; scrollViewRect.xMin -= position.width * bufferScale; scrollViewRect.yMin -= position.height * bufferScale; scrollViewRect.xMax += position.width * bufferScale; scrollViewRect.yMax += position.height * bufferScale; - - Rect windowRect = new Rect(0, 0, position.width, position.height); + + // Calc rect for left hand script view + Rect scriptViewRect = new Rect(0, 0, this.position.width - commandViewWidth, this.position.height); // Clip GL drawing so not to overlap scrollbars - Rect clipRect = new Rect(fungusScript.scrollPos.x + scrollViewRect.x, - fungusScript.scrollPos.y + scrollViewRect.y, - windowRect.width - 15, - windowRect.height - 15); - - fungusScript.scrollPos = GLDraw.BeginScrollView(windowRect, fungusScript.scrollPos, scrollViewRect, clipRect); + Rect clipRect = new Rect(fungusScript.scriptScrollPos.x + scrollViewRect.x, + fungusScript.scriptScrollPos.y + scrollViewRect.y, + scriptViewRect.width - 15, + scriptViewRect.height - 15); + GUILayoutUtility.GetRect(scriptViewRect.width, scriptViewRect.height); + + fungusScript.scriptScrollPos = GLDraw.BeginScrollView(scriptViewRect, fungusScript.scriptScrollPos, scrollViewRect, clipRect); + if (Event.current.type == EventType.ContextClick) { GenericMenu menu = new GenericMenu(); Vector2 mousePos = Event.current.mousePosition; - mousePos += fungusScript.scrollPos; + mousePos += fungusScript.scriptScrollPos; menu.AddItem (new GUIContent ("Create Sequence"), false, CreateSequenceCallback, mousePos); menu.ShowAsContext (); Event.current.Use(); } - - BeginWindows(); - + + BeginWindows(); + GUIStyle windowStyle = new GUIStyle(GUI.skin.window); - + windowSequenceMap.Clear(); for (int i = 0; i < sequences.Length; ++i) { Sequence sequence = sequences[i]; - + float titleWidth = windowStyle.CalcSize(new GUIContent(sequence.name)).x; float windowWidth = Mathf.Max (titleWidth + 10, 100); - + sequence.nodeRect = GUILayout.Window(i, sequence.nodeRect, DrawWindow, sequence.name, GUILayout.Width(windowWidth), GUILayout.Height(20), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); - + windowSequenceMap.Add(sequence); } - + // Draw connections foreach (Sequence s in windowSequenceMap) { @@ -109,9 +131,9 @@ namespace Fungus.Script { DrawConnections(fungusScript, s, true); } - - EndWindows(); - + + EndWindows(); + if (fungusScript.selectedSequence != null || fungusScript.executingSequence != null) { @@ -130,26 +152,103 @@ namespace Fungus.Script outlineRect.y -= 5; GLDraw.DrawBox(outlineRect, Color.green, 2); } - + GLDraw.EndScrollView(); + } + + void ResizeViews() + { + cursorChangeRect.x = this.position.width - commandViewWidth; + cursorChangeRect.height = this.position.height; + + GUI.color = Color.grey; + GUI.DrawTexture(cursorChangeRect, EditorGUIUtility.whiteTexture); + GUI.color = Color.white; + EditorGUIUtility.AddCursorRect(cursorChangeRect, MouseCursor.ResizeHorizontal); + + if (Event.current.type == EventType.mouseDown && cursorChangeRect.Contains(Event.current.mousePosition)) + { + resize = true; + } + if (resize) + { + commandViewWidth = this.position.width - Event.current.mousePosition.x; + commandViewWidth = Mathf.Max(minViewWidth, commandViewWidth); + commandViewWidth = Mathf.Min(this.position.width - minViewWidth, commandViewWidth); + } + if(Event.current.type == EventType.MouseUp) + { + resize = false; + } + } + + void DrawCommandView(FungusScript fungusScript) + { + GUILayout.Space(5); - GUILayout.BeginVertical(); - GUILayout.FlexibleSpace(); - GUILayout.BeginHorizontal(); - GUILayout.Space(10); - GUILayout.Label(fungusScript.name, EditorStyles.miniLabel); - GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(); - GUILayout.Space(10); + fungusScript.commandScrollPos = GUILayout.BeginScrollView(fungusScript.commandScrollPos); + + EditorGUILayout.BeginVertical(); + + EditorGUILayout.Separator(); + GUI.backgroundColor = Color.yellow; + GUILayout.Box("Sequence", GUILayout.ExpandWidth(true)); GUI.backgroundColor = Color.white; - if (GUILayout.Button("Show Variables")) + + GUILayout.BeginHorizontal(); + + if (fungusScript.selectedSequence == null) { - EditorWindow.GetWindow("Fungus Variables"); + GUILayout.FlexibleSpace(); } - GUILayout.FlexibleSpace(); + + if (GUILayout.Button(fungusScript.selectedSequence == null ? "Create Sequence" : "Create", + fungusScript.selectedSequence == null ? EditorStyles.miniButton : EditorStyles.miniButtonLeft)) + { + Sequence newSequence = fungusScript.CreateSequence(fungusScript.scriptScrollPos); + Undo.RegisterCreatedObjectUndo(newSequence, "New Sequence"); + fungusScript.selectedSequence = newSequence; + } + + if (fungusScript.selectedSequence == null) + { + GUILayout.FlexibleSpace(); + } + + if (fungusScript.selectedSequence != null) + { + if (GUILayout.Button("Delete", EditorStyles.miniButtonMid)) + { + Undo.DestroyObjectImmediate(fungusScript.selectedSequence.gameObject); + fungusScript.selectedSequence = null; + } + if (GUILayout.Button("Duplicate", EditorStyles.miniButtonRight)) + { + GameObject copy = GameObject.Instantiate(fungusScript.selectedSequence.gameObject) as GameObject; + copy.transform.parent = fungusScript.transform; + copy.transform.hideFlags = HideFlags.HideInHierarchy; + copy.name = fungusScript.selectedSequence.name; + + Sequence sequenceCopy = copy.GetComponent(); + sequenceCopy.nodeRect.x += sequenceCopy.nodeRect.width + 10; + + Undo.RegisterCreatedObjectUndo(copy, "Duplicate Sequence"); + fungusScript.selectedSequence = sequenceCopy; + } + } + GUILayout.EndHorizontal(); - GUILayout.Space(20); - GUILayout.EndVertical(); + + EditorGUILayout.Separator(); + + FungusScriptEditor editor = Editor.CreateEditor(fungusScript) as FungusScriptEditor; + editor.DrawSequenceGUI(fungusScript); + + GUILayout.FlexibleSpace(); + + EditorGUILayout.EndVertical(); + + GUILayout.EndScrollView(); } void CreateSequenceCallback(object item) @@ -158,7 +257,7 @@ namespace Fungus.Script if (fungusScript != null) { Vector2 position = (Vector2)item; - position -= fungusScript.scrollPos; + position -= fungusScript.scriptScrollPos; Sequence newSequence = fungusScript.CreateSequence(position); Undo.RegisterCreatedObjectUndo(newSequence, "New Sequence"); fungusScript.selectedSequence = newSequence; diff --git a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs index 3e46189e..383243e7 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs +++ b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs @@ -19,7 +19,10 @@ namespace Fungus.Script public int selectedCommandIndex; [HideInInspector] - public Vector2 scrollPos; + public Vector2 scriptScrollPos; + + [HideInInspector] + public Vector2 commandScrollPos; public float stepTime; diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/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