Browse Source

Command editor now scrolls independently of command list #84

Also changed add command to insert new commands after last selected
command in the list.
master
chrisgregan 10 years ago
parent
commit
9820dc403c
  1. 191
      Assets/Fungus/FungusScript/Editor/SequenceEditor.cs
  2. 65
      Assets/Fungus/FungusScript/Editor/SequenceInspector.cs
  3. 9
      Assets/Fungus/FungusScript/Scripts/FungusScript.cs

191
Assets/Fungus/FungusScript/Editor/SequenceEditor.cs

@ -26,6 +26,27 @@ namespace Fungus
public int index; public int index;
} }
public virtual void DrawSequenceName(FungusScript fungusScript)
{
serializedObject.Update();
SerializedProperty sequenceNameProperty = serializedObject.FindProperty("sequenceName");
Rect sequenceLabelRect = new Rect(45, 5, 120, 16);
EditorGUI.LabelField(sequenceLabelRect, new GUIContent("Sequence Name"));
Rect sequenceNameRect = new Rect(45, 21, 180, 16);
EditorGUI.PropertyField(sequenceNameRect, sequenceNameProperty, new GUIContent(""));
// Ensure sequence name is unique for this Fungus Script
Sequence sequence = target as Sequence;
string uniqueName = fungusScript.GetUniqueSequenceKey(sequenceNameProperty.stringValue, sequence);
if (uniqueName != sequence.sequenceName)
{
sequenceNameProperty.stringValue = uniqueName;
}
serializedObject.ApplyModifiedProperties();
}
public virtual void DrawSequenceGUI(FungusScript fungusScript) public virtual void DrawSequenceGUI(FungusScript fungusScript)
{ {
serializedObject.Update(); serializedObject.Update();
@ -45,20 +66,7 @@ namespace Fungus
DrawEventHandlerGUI(fungusScript); DrawEventHandlerGUI(fungusScript);
UpdateIndentLevels(sequence); UpdateIndentLevels(sequence);
SerializedProperty sequenceNameProperty = serializedObject.FindProperty("sequenceName");
Rect sequenceLabelRect = new Rect(45, 5, 120, 16);
EditorGUI.LabelField(sequenceLabelRect, new GUIContent("Sequence Name"));
Rect sequenceNameRect = new Rect(45, 21, 180, 16);
EditorGUI.PropertyField(sequenceNameRect, sequenceNameProperty, new GUIContent(""));
// Ensure sequence name is unique for this Fungus Script
string uniqueName = fungusScript.GetUniqueSequenceKey(sequenceNameProperty.stringValue, sequence);
if (uniqueName != sequence.sequenceName)
{
sequenceNameProperty.stringValue = uniqueName;
}
// Make sure each command has a reference to its parent sequence // Make sure each command has a reference to its parent sequence
foreach (Command command in sequence.commandList) foreach (Command command in sequence.commandList)
{ {
@ -82,27 +90,10 @@ namespace Fungus
ShowContextMenu(); ShowContextMenu();
} }
GUILayout.BeginHorizontal();
// Previous Command
if ((Event.current.type == EventType.keyDown) && (Event.current.keyCode == KeyCode.PageUp))
{
SelectPrevious();
GUI.FocusControl("dummycontrol");
Event.current.Use();
}
// Next Command
if ((Event.current.type == EventType.keyDown) && (Event.current.keyCode == KeyCode.PageDown))
{
SelectNext();
GUI.FocusControl("dummycontrol");
Event.current.Use();
}
if (GUIUtility.keyboardControl == 0) //Only call keyboard shortcuts when not typing in a text field if (GUIUtility.keyboardControl == 0) //Only call keyboard shortcuts when not typing in a text field
{ {
Event e = Event.current; Event e = Event.current;
// Copy keyboard shortcut // Copy keyboard shortcut
if (e.type == EventType.ValidateCommand && e.commandName == "Copy") if (e.type == EventType.ValidateCommand && e.commandName == "Copy")
{ {
@ -111,12 +102,13 @@ namespace Fungus
e.Use(); e.Use();
} }
} }
if (e.type == EventType.ExecuteCommand && e.commandName == "Copy") if (e.type == EventType.ExecuteCommand && e.commandName == "Copy")
{ {
Copy(); Copy();
e.Use(); e.Use();
} }
// Cut keyboard shortcut // Cut keyboard shortcut
if (e.type == EventType.ValidateCommand && e.commandName == "Cut") if (e.type == EventType.ValidateCommand && e.commandName == "Cut")
{ {
@ -125,12 +117,13 @@ namespace Fungus
e.Use(); e.Use();
} }
} }
if (e.type == EventType.ExecuteCommand && e.commandName == "Cut") if (e.type == EventType.ExecuteCommand && e.commandName == "Cut")
{ {
Cut(); Cut();
e.Use(); e.Use();
} }
// Paste keyboard shortcut // Paste keyboard shortcut
if (e.type == EventType.ValidateCommand && e.commandName == "Paste") if (e.type == EventType.ValidateCommand && e.commandName == "Paste")
{ {
@ -140,12 +133,13 @@ namespace Fungus
e.Use(); e.Use();
} }
} }
if (e.type == EventType.ExecuteCommand && e.commandName == "Paste") if (e.type == EventType.ExecuteCommand && e.commandName == "Paste")
{ {
Paste(); Paste();
e.Use(); e.Use();
} }
// Duplicate keyboard shortcut // Duplicate keyboard shortcut
if (e.type == EventType.ValidateCommand && e.commandName == "Duplicate") if (e.type == EventType.ValidateCommand && e.commandName == "Duplicate")
{ {
@ -154,13 +148,14 @@ namespace Fungus
e.Use(); e.Use();
} }
} }
if (e.type == EventType.ExecuteCommand && e.commandName == "Duplicate") if (e.type == EventType.ExecuteCommand && e.commandName == "Duplicate")
{ {
Copy(); Copy();
Paste(); Paste();
e.Use(); e.Use();
} }
// Delete keyboard shortcut // Delete keyboard shortcut
if (e.type == EventType.ValidateCommand && e.commandName == "Delete") if (e.type == EventType.ValidateCommand && e.commandName == "Delete")
{ {
@ -169,17 +164,19 @@ namespace Fungus
e.Use(); e.Use();
} }
} }
if (e.type == EventType.ExecuteCommand && e.commandName == "Delete") if (e.type == EventType.ExecuteCommand && e.commandName == "Delete")
{ {
Delete(); Delete();
e.Use(); e.Use();
} }
// SelectAll keyboard shortcut // SelectAll keyboard shortcut
if (e.type == EventType.ValidateCommand && e.commandName == "SelectAll") if (e.type == EventType.ValidateCommand && e.commandName == "SelectAll")
{ {
e.Use(); e.Use();
} }
if (e.type == EventType.ExecuteCommand && e.commandName == "SelectAll") if (e.type == EventType.ExecuteCommand && e.commandName == "SelectAll")
{ {
SelectAll(); SelectAll();
@ -187,47 +184,6 @@ namespace Fungus
} }
} }
// Up Button
Texture2D upIcon = Resources.Load("Icons/up") as Texture2D;
if (GUILayout.Button(upIcon))
{
SelectPrevious();
}
// Down Button
Texture2D downIcon = Resources.Load("Icons/down") as Texture2D;
if (GUILayout.Button(downIcon))
{
SelectNext();
}
GUILayout.FlexibleSpace();
GUILayout.FlexibleSpace();
// Add Button
Texture2D addIcon = Resources.Load("Icons/add") as Texture2D;
if (GUILayout.Button(addIcon))
{
ShowCommandMenu();
}
// Duplicate Button
Texture2D duplicateIcon = Resources.Load("Icons/duplicate") as Texture2D;
if (GUILayout.Button(duplicateIcon))
{
Copy();
Paste();
}
// Delete Button
Texture2D deleteIcon = Resources.Load("Icons/delete") as Texture2D;
if (GUILayout.Button(deleteIcon))
{
Delete();
}
GUILayout.EndHorizontal();
} }
// Remove any null entries in the command list. // Remove any null entries in the command list.
@ -244,6 +200,66 @@ namespace Fungus
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();
} }
public virtual void DrawButtonToolbar()
{
GUILayout.BeginHorizontal();
// Previous Command
if ((Event.current.type == EventType.keyDown) && (Event.current.keyCode == KeyCode.PageUp))
{
SelectPrevious();
GUI.FocusControl("dummycontrol");
Event.current.Use();
}
// Next Command
if ((Event.current.type == EventType.keyDown) && (Event.current.keyCode == KeyCode.PageDown))
{
SelectNext();
GUI.FocusControl("dummycontrol");
Event.current.Use();
}
// Up Button
Texture2D upIcon = Resources.Load("Icons/up") as Texture2D;
if (GUILayout.Button(upIcon))
{
SelectPrevious();
}
// Down Button
Texture2D downIcon = Resources.Load("Icons/down") as Texture2D;
if (GUILayout.Button(downIcon))
{
SelectNext();
}
GUILayout.FlexibleSpace();
// Add Button
Texture2D addIcon = Resources.Load("Icons/add") as Texture2D;
if (GUILayout.Button(addIcon))
{
ShowCommandMenu();
}
// Duplicate Button
Texture2D duplicateIcon = Resources.Load("Icons/duplicate") as Texture2D;
if (GUILayout.Button(duplicateIcon))
{
Copy();
Paste();
}
// Delete Button
Texture2D deleteIcon = Resources.Load("Icons/delete") as Texture2D;
if (GUILayout.Button(deleteIcon))
{
Delete();
}
GUILayout.EndHorizontal();
}
protected void DrawEventHandlerGUI(FungusScript fungusScript) protected void DrawEventHandlerGUI(FungusScript fungusScript)
{ {
// Show available Event Handlers in a drop down list with type of current // Show available Event Handlers in a drop down list with type of current
@ -454,7 +470,22 @@ namespace Fungus
void ShowCommandMenu() void ShowCommandMenu()
{ {
Sequence sequence = target as Sequence; Sequence sequence = target as Sequence;
int index = sequence.commandList.Count;
FungusScript fungusScript = sequence.GetFungusScript();
// Use index of last selected command in list, or end of list if nothing selected.
int index = -1;
foreach (Command command in fungusScript.selectedCommands)
{
if (command.commandIndex + 1 > index)
{
index = command.commandIndex + 1;
}
}
if (index == -1)
{
index = sequence.commandList.Count;
}
GenericMenu commandMenu = new GenericMenu(); GenericMenu commandMenu = new GenericMenu();
@ -544,7 +575,7 @@ namespace Fungus
Undo.RecordObject(sequence, "Set command type"); Undo.RecordObject(sequence, "Set command type");
if (commandOperation.index < sequence.commandList.Count - 1) if (commandOperation.index < sequence.commandList.Count - 1)
{ {
sequence.commandList[commandOperation.index] = newCommand; sequence.commandList.Insert(commandOperation.index, newCommand);
} }
else else
{ {

65
Assets/Fungus/FungusScript/Editor/SequenceInspector.cs

@ -19,6 +19,11 @@ namespace Fungus
[CustomEditor (typeof(SequenceInspector), true)] [CustomEditor (typeof(SequenceInspector), true)]
public class SequenceInspectorEditor : Editor public class SequenceInspectorEditor : Editor
{ {
protected Vector2 sequenceScrollPos;
protected Vector2 commandScrollPos;
protected bool resize = false;
protected float topPanelHeight = 50;
public override void OnInspectorGUI () public override void OnInspectorGUI ()
{ {
SequenceInspector sequenceInspector = target as SequenceInspector; SequenceInspector sequenceInspector = target as SequenceInspector;
@ -32,8 +37,11 @@ namespace Fungus
FungusScript fungusScript = sequence.GetFungusScript(); FungusScript fungusScript = sequence.GetFungusScript();
SequenceEditor sequenceEditor = Editor.CreateEditor(sequence) as SequenceEditor; SequenceEditor sequenceEditor = Editor.CreateEditor(sequence) as SequenceEditor;
sequenceEditor.DrawSequenceName(fungusScript);
sequenceScrollPos = GUILayout.BeginScrollView(sequenceScrollPos, GUILayout.Height(fungusScript.sequenceViewHeight));
sequenceEditor.DrawSequenceGUI(fungusScript); sequenceEditor.DrawSequenceGUI(fungusScript);
DestroyImmediate(sequenceEditor); GUILayout.EndScrollView();
Command inspectCommand = null; Command inspectCommand = null;
if (fungusScript.selectedCommands.Count == 1) if (fungusScript.selectedCommands.Count == 1)
@ -46,9 +54,18 @@ namespace Fungus
inspectCommand.parentSequence != sequence) inspectCommand.parentSequence != sequence)
{ {
Repaint(); Repaint();
DestroyImmediate(sequenceEditor);
return; return;
} }
ResizeScrollView(fungusScript);
GUILayout.Space(7);
sequenceEditor.DrawButtonToolbar();
commandScrollPos = GUILayout.BeginScrollView(commandScrollPos);
if (inspectCommand != null) if (inspectCommand != null)
{ {
CommandEditor commandEditor = Editor.CreateEditor(inspectCommand) as CommandEditor; CommandEditor commandEditor = Editor.CreateEditor(inspectCommand) as CommandEditor;
@ -56,7 +73,53 @@ namespace Fungus
DestroyImmediate(commandEditor); DestroyImmediate(commandEditor);
} }
GUILayout.EndScrollView();
Repaint(); Repaint();
DestroyImmediate(sequenceEditor);
}
private void ResizeScrollView(FungusScript fungusScript)
{
Rect cursorChangeRect = new Rect(0, fungusScript.sequenceViewHeight + topPanelHeight, Screen.width, 4f);
GUI.color = Color.grey;
GUI.DrawTexture(cursorChangeRect, EditorGUIUtility.whiteTexture);
GUI.color = Color.white;
EditorGUIUtility.AddCursorRect(cursorChangeRect, MouseCursor.ResizeVertical);
if (Event.current.type == EventType.mouseDown && cursorChangeRect.Contains(Event.current.mousePosition))
{
resize = true;
}
if (resize)
{
float height = Event.current.mousePosition.y - topPanelHeight;
height = Mathf.Max(200, height);
height = Mathf.Min(Screen.height - 200,height);
Undo.RecordObject(fungusScript, "Resize view");
fungusScript.sequenceViewHeight = height;
}
// Stop resizing if mouse is outside inspector window.
// This isn't standard Unity UI behavior but it is robust and safe.
if (resize && Event.current.type == EventType.mouseDrag)
{
Rect windowRect = new Rect(0, 0, Screen.width, Screen.height);
if (!windowRect.Contains(Event.current.mousePosition))
{
resize = false;
}
}
if (Event.current.type == EventType.MouseUp)
{
resize = false;
}
} }
} }

9
Assets/Fungus/FungusScript/Scripts/FungusScript.cs

@ -28,9 +28,18 @@ namespace Fungus
[HideInInspector] [HideInInspector]
public Vector2 variablesScrollPos; public Vector2 variablesScrollPos;
/**
* Show the variables pane.
*/
[HideInInspector] [HideInInspector]
public bool variablesExpanded = true; public bool variablesExpanded = true;
/**
* Height of command sequence view in inspector.
*/
[HideInInspector]
public float sequenceViewHeight = 400;
/** /**
* Zoom level of Fungus Script editor window * Zoom level of Fungus Script editor window
*/ */

Loading…
Cancel
Save