From 63e597492ce8539fc825b2d67661e945ce0deb5d Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Sun, 9 Nov 2014 21:23:00 +0000 Subject: [PATCH] Moved variables list over the Fungus Script window --- .../FungusScript/Editor/FungusScriptEditor.cs | 68 ++++++--- .../FungusScript/Editor/FungusScriptWindow.cs | 131 +++++------------- .../FungusScript/Scripts/FungusScript.cs | 9 ++ 3 files changed, 90 insertions(+), 118 deletions(-) diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs index 9ed38125..f3e5bfee 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs @@ -97,35 +97,65 @@ namespace Fungus EditorGUILayout.Separator(); - DrawVariablesGUI(); - serializedObject.ApplyModifiedProperties(); } public virtual void DrawVariablesGUI() { + serializedObject.Update(); + FungusScript t = target as FungusScript; - - ReorderableListGUI.Title("Variables"); - VariableListAdaptor adaptor = new VariableListAdaptor(variablesProp, 0); - ReorderableListControl.DrawControlFromState(adaptor, null, ReorderableListFlags.DisableContextMenu | ReorderableListFlags.HideAddButton); - - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - - if (!Application.isPlaying && GUILayout.Button("Add Variable")) + if (!t.variablesExpanded) { - GenericMenu menu = new GenericMenu (); - - menu.AddItem(new GUIContent ("Boolean"), false, AddVariable, t); - menu.AddItem (new GUIContent ("Integer"), false, AddVariable, t); - menu.AddItem (new GUIContent ("Float"), false, AddVariable, t); - menu.AddItem (new GUIContent ("String"), false, AddVariable, t); + if (GUILayout.Button ("Variables", GUILayout.Height(24))) + { + t.variablesExpanded = true; + } + } + else + { + ReorderableListGUI.Title("Variables"); + VariableListAdaptor adaptor = new VariableListAdaptor(variablesProp, 0); + ReorderableListControl.DrawControlFromState(adaptor, null, ReorderableListFlags.DisableContextMenu | ReorderableListFlags.HideAddButton); + + float plusWidth = 32; + float plusHeight = 24; + + Rect listRect = GUILayoutUtility.GetLastRect(); + + Rect buttonRect = listRect; + float buttonHeight = 24; + buttonRect.x = 4; + buttonRect.y -= buttonHeight - 1; + buttonRect.width -= 30; + buttonRect.height = buttonHeight; - menu.ShowAsContext (); + if (GUI.Button (buttonRect, "Variables")) + { + t.variablesExpanded = false; + } + + Rect plusRect = listRect; + plusRect.x += plusRect.width - plusWidth; + plusRect.y -= plusHeight - 1; + plusRect.width = plusWidth; + plusRect.height = plusHeight; + + if (!Application.isPlaying && GUI.Button(plusRect, FungusEditorResources.texAddButton)) + { + GenericMenu menu = new GenericMenu (); + + menu.AddItem(new GUIContent ("Boolean"), false, AddVariable, t); + menu.AddItem (new GUIContent ("Integer"), false, AddVariable, t); + menu.AddItem (new GUIContent ("Float"), false, AddVariable, t); + menu.AddItem (new GUIContent ("String"), false, AddVariable, t); + + menu.ShowAsContext (); + } } - GUILayout.EndHorizontal(); + + serializedObject.ApplyModifiedProperties(); } protected virtual void AddVariable(object obj) where T : Variable diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs index d337f98f..8412ad97 100755 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs @@ -92,7 +92,7 @@ namespace Fungus deleteList.Clear(); DrawScriptView(fungusScript); - DrawControls(fungusScript); + DrawOverlay(fungusScript); if (Event.current.type == EventType.Repaint && showContextMenu) @@ -102,7 +102,7 @@ namespace Fungus } } - protected virtual void DrawControls(FungusScript fungusScript) + protected virtual void DrawOverlay(FungusScript fungusScript) { GUILayout.Space(8); @@ -116,11 +116,39 @@ namespace Fungus 50 - fungusScript.scrollPos.y); CreateSequence(fungusScript, newNodePosition); } - - GUILayout.FlexibleSpace(); + + GUILayout.Space(8); fungusScript.zoom = GUILayout.HorizontalSlider(fungusScript.zoom, minZoomValue, maxZoomValue, GUILayout.Width(100)); + GUILayout.FlexibleSpace(); + + GUILayout.EndHorizontal(); + + GUILayout.FlexibleSpace(); + + GUILayout.BeginHorizontal(); + + GUILayout.BeginVertical(GUILayout.Width(300)); + + GUILayout.FlexibleSpace(); + + fungusScript.variablesScrollPos = GUILayout.BeginScrollView(fungusScript.variablesScrollPos, GUILayout.MaxHeight(position.height * 0.75f)); + + GUILayout.FlexibleSpace(); + + GUILayout.Space(8); + + FungusScriptEditor fungusScriptEditor = Editor.CreateEditor (fungusScript) as FungusScriptEditor; + fungusScriptEditor.DrawVariablesGUI(); + DestroyImmediate(fungusScriptEditor); + + GUILayout.EndScrollView(); + + GUILayout.EndVertical(); + + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); } @@ -271,101 +299,6 @@ namespace Fungus } } - /* - protected virtual void ResizeViews(FungusScript fungusScript) - { - cursorChangeRect = new Rect(this.position.width - fungusScript.commandViewWidth, 0, 4f, 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) - { - fungusScript.commandViewWidth = this.position.width - Event.current.mousePosition.x; - fungusScript.commandViewWidth = Mathf.Max(minViewWidth, fungusScript.commandViewWidth); - fungusScript.commandViewWidth = Mathf.Min(this.position.width - minViewWidth, fungusScript.commandViewWidth); - } - if(Event.current.type == EventType.MouseUp) - { - resize = false; - } - } - - protected virtual void DrawSequenceView(FungusScript fungusScript) - { - GUILayout.Space(5); - - fungusScript.commandScrollPos = GUILayout.BeginScrollView(fungusScript.commandScrollPos); - - EditorGUILayout.BeginVertical(); - - GUILayout.Box("Sequence", GUILayout.ExpandWidth(true)); - - GUILayout.BeginHorizontal(); - - if (fungusScript.selectedSequence == null) - { - GUILayout.FlexibleSpace(); - } - - if (GUILayout.Button(fungusScript.selectedSequence == null ? "Create Sequence" : "Create", - fungusScript.selectedSequence == null ? EditorStyles.miniButton : EditorStyles.miniButtonLeft)) - { - Vector2 newPosition; - if (fungusScript.selectedSequence == null) - { - newPosition = newNodePosition; - } - else - { - Rect selectedRect = fungusScript.selectedSequence.nodeRect; - newPosition = new Vector2(selectedRect.position.x + selectedRect.width + 20, selectedRect.y); - } - - CreateSequence(fungusScript, newPosition); - } - - if (fungusScript.selectedSequence == null) - { - GUILayout.FlexibleSpace(); - } - else - { - if (GUILayout.Button("Delete", EditorStyles.miniButtonMid)) - { - DeleteSequence(fungusScript, fungusScript.selectedSequence); - } - if (GUILayout.Button("Duplicate", EditorStyles.miniButtonRight)) - { - DuplicateSequence(fungusScript, fungusScript.selectedSequence); - } - } - - GUILayout.EndHorizontal(); - - if (fungusScript.selectedSequence != null) - { - EditorGUILayout.Separator(); - - SequenceEditor sequenceEditor = Editor.CreateEditor(fungusScript.selectedSequence) as SequenceEditor; - sequenceEditor.DrawSequenceGUI(fungusScript); - DestroyImmediate(sequenceEditor); - - GUILayout.FlexibleSpace(); - } - - EditorGUILayout.EndVertical(); - - GUILayout.EndScrollView(); - } - */ - public static Sequence CreateSequence(FungusScript fungusScript, Vector2 position) { Sequence newSequence = fungusScript.CreateSequence(position); diff --git a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs index 139d0cce..ed409a24 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs +++ b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs @@ -25,6 +25,15 @@ namespace Fungus [HideInInspector] public Vector2 scrollPos; + /** + * Scroll position of Fungus Script variables window. + */ + [HideInInspector] + public Vector2 variablesScrollPos; + + [HideInInspector] + public bool variablesExpanded = true; + /** * Zoom level of Fungus Script editor window */