|
|
|
@ -12,13 +12,17 @@ using Rotorz.ReorderableList;
|
|
|
|
|
namespace Fungus |
|
|
|
|
{ |
|
|
|
|
public class CommandListAdaptor : IReorderableListAdaptor { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected SerializedProperty _arrayProperty; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public float fixedItemHeight; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Rect nodeRect = new Rect(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static bool pinShiftToTop; |
|
|
|
|
public static int firstSelectedIndex = 0; |
|
|
|
|
public static int lastSelectedIndex = 0; |
|
|
|
|
|
|
|
|
|
public SerializedProperty this[int index] { |
|
|
|
|
get { return _arrayProperty.GetArrayElementAtIndex(index); } |
|
|
|
|
} |
|
|
|
@ -39,7 +43,7 @@ namespace Fungus
|
|
|
|
|
|
|
|
|
|
public CommandListAdaptor(SerializedProperty arrayProperty) : this(arrayProperty, 0f) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int Count { |
|
|
|
|
get { return _arrayProperty.arraySize; } |
|
|
|
|
} |
|
|
|
@ -47,7 +51,7 @@ namespace Fungus
|
|
|
|
|
public virtual bool CanDrag(int index) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual bool CanRemove(int index) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -58,23 +62,23 @@ namespace Fungus
|
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int newIndex = _arrayProperty.arraySize; |
|
|
|
|
++_arrayProperty.arraySize; |
|
|
|
|
_arrayProperty.GetArrayElementAtIndex(newIndex).objectReferenceValue = newCommand; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Insert(int index) { |
|
|
|
|
Command newCommand = AddNewCommand(); |
|
|
|
|
if (newCommand == null) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_arrayProperty.InsertArrayElementAtIndex(index); |
|
|
|
|
_arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue = newCommand; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Command AddNewCommand() |
|
|
|
|
{ |
|
|
|
|
FungusScript fungusScript = FungusScriptWindow.GetFungusScript(); |
|
|
|
@ -88,21 +92,21 @@ namespace Fungus
|
|
|
|
|
{ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Command newCommand = Undo.AddComponent<Comment>(sequence.gameObject) as Command; |
|
|
|
|
fungusScript.ClearSelectedCommands(); |
|
|
|
|
fungusScript.AddSelectedCommand(newCommand); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return newCommand; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Duplicate(int index) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Command command = _arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue as Command; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add the command as a new component |
|
|
|
|
Sequence parentSequence = command.GetComponent<Sequence>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.Type type = command.GetType(); |
|
|
|
|
Command newCommand = Undo.AddComponent(parentSequence.gameObject, type) as Command; |
|
|
|
|
System.Reflection.FieldInfo[] fields = type.GetFields(); |
|
|
|
@ -110,11 +114,11 @@ namespace Fungus
|
|
|
|
|
{ |
|
|
|
|
field.SetValue(newCommand, field.GetValue(command)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_arrayProperty.InsertArrayElementAtIndex(index); |
|
|
|
|
_arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue = newCommand; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Remove(int index) { |
|
|
|
|
// Remove the Fungus Command component |
|
|
|
|
Command command = _arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue as Command; |
|
|
|
@ -122,17 +126,17 @@ namespace Fungus
|
|
|
|
|
{ |
|
|
|
|
Undo.DestroyObjectImmediate(command); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue = null; |
|
|
|
|
_arrayProperty.DeleteArrayElementAtIndex(index); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Move(int sourceIndex, int destIndex) { |
|
|
|
|
if (destIndex > sourceIndex) |
|
|
|
|
--destIndex; |
|
|
|
|
_arrayProperty.MoveArrayElement(sourceIndex, destIndex); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Clear() { |
|
|
|
|
while (Count > 0) |
|
|
|
|
{ |
|
|
|
@ -148,22 +152,22 @@ namespace Fungus
|
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CommandInfoAttribute commandInfoAttr = CommandEditor.GetCommandInfo(command.GetType()); |
|
|
|
|
if (commandInfoAttr == null) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FungusScript fungusScript = command.GetFungusScript(); |
|
|
|
|
if (fungusScript == null) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool isComment = (command.GetType() == typeof(Comment)); |
|
|
|
|
|
|
|
|
|
bool isComment = command.GetType() == typeof(Comment); |
|
|
|
|
bool isLabel = (command.GetType() == typeof(Label)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool error = false; |
|
|
|
|
string summary = command.GetSummary(); |
|
|
|
|
if (summary == null) |
|
|
|
@ -197,20 +201,21 @@ namespace Fungus
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string commandName = commandInfoAttr.CommandName; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GUIStyle commandLabelStyle = new GUIStyle(GUI.skin.box); |
|
|
|
|
commandLabelStyle.normal.background = FungusEditorResources.texCommandBackground; |
|
|
|
|
commandLabelStyle.border.top = 1; |
|
|
|
|
commandLabelStyle.border.bottom = 1; |
|
|
|
|
commandLabelStyle.border.left = 1; |
|
|
|
|
commandLabelStyle.border.right = 1; |
|
|
|
|
int borderSize = 5; |
|
|
|
|
commandLabelStyle.border.top = borderSize; |
|
|
|
|
commandLabelStyle.border.bottom = borderSize; |
|
|
|
|
commandLabelStyle.border.left = borderSize; |
|
|
|
|
commandLabelStyle.border.right = borderSize; |
|
|
|
|
commandLabelStyle.alignment = TextAnchor.MiddleLeft; |
|
|
|
|
commandLabelStyle.richText = true; |
|
|
|
|
commandLabelStyle.fontSize = 11; |
|
|
|
|
commandLabelStyle.padding.top -= 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float indentSize = 20; |
|
|
|
|
for (int i = 0; i < command.indentLevel; ++i) |
|
|
|
|
{ |
|
|
|
@ -222,16 +227,16 @@ namespace Fungus
|
|
|
|
|
GUI.backgroundColor = new Color(0.5f, 0.5f, 0.5f, 1f); |
|
|
|
|
GUI.Box(indentRect, "", commandLabelStyle); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float commandNameWidth = Mathf.Max(commandLabelStyle.CalcSize(new GUIContent(commandName)).x, 90f); |
|
|
|
|
float indentWidth = command.indentLevel * indentSize; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rect commandLabelRect = position; |
|
|
|
|
commandLabelRect.x += indentWidth - 21; |
|
|
|
|
commandLabelRect.y -= 2; |
|
|
|
|
commandLabelRect.width -= (indentSize * command.indentLevel - 22); |
|
|
|
|
commandLabelRect.height += 5; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Select command via left click |
|
|
|
|
if (Event.current.type == EventType.MouseDown && |
|
|
|
|
Event.current.button == 0 && |
|
|
|
@ -239,28 +244,98 @@ namespace Fungus
|
|
|
|
|
{ |
|
|
|
|
if (fungusScript.selectedCommands.Contains(command) && Event.current.button == 0) |
|
|
|
|
{ |
|
|
|
|
// Left click on an already selected command |
|
|
|
|
fungusScript.selectedCommands.Remove(command); |
|
|
|
|
// Left click on already selected command |
|
|
|
|
// Command key and shift key is not pressed |
|
|
|
|
if (!EditorGUI.actionKey && !Event.current.shift) |
|
|
|
|
{ |
|
|
|
|
fungusScript.selectedCommands.Remove(command); |
|
|
|
|
fungusScript.ClearSelectedCommands(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Command key pressed |
|
|
|
|
if (EditorGUI.actionKey) |
|
|
|
|
{ |
|
|
|
|
fungusScript.selectedCommands.Remove(command); |
|
|
|
|
} |
|
|
|
|
// Shift key pressed |
|
|
|
|
if (Event.current.shift) |
|
|
|
|
{ |
|
|
|
|
fungusScript.ClearSelectedCommands(); |
|
|
|
|
if (pinShiftToTop) |
|
|
|
|
{ |
|
|
|
|
for (int i = firstSelectedIndex; i < index+1; ++i) |
|
|
|
|
{ |
|
|
|
|
fungusScript.AddSelectedCommand(fungusScript.selectedSequence.commandList[i]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
for (int i = index; i < lastSelectedIndex+1; ++i) |
|
|
|
|
{ |
|
|
|
|
fungusScript.AddSelectedCommand(fungusScript.selectedSequence.commandList[i]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
// Left click and no command key |
|
|
|
|
if (!EditorGUI.actionKey && Event.current.button == 0) |
|
|
|
|
if (!Event.current.shift && !EditorGUI.actionKey && Event.current.button == 0) |
|
|
|
|
{ |
|
|
|
|
fungusScript.ClearSelectedCommands(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fungusScript.AddSelectedCommand(command); |
|
|
|
|
|
|
|
|
|
bool firstSelectedCommandFound = false; |
|
|
|
|
if (fungusScript.selectedCommands.Count > 0) |
|
|
|
|
{ |
|
|
|
|
if ( fungusScript.selectedSequence != null) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < fungusScript.selectedSequence.commandList.Count; i++) |
|
|
|
|
{ |
|
|
|
|
Command commandInSequence = fungusScript.selectedSequence.commandList[i]; |
|
|
|
|
|
|
|
|
|
foreach (Command selectedCommand in fungusScript.selectedCommands) |
|
|
|
|
{ |
|
|
|
|
if (commandInSequence == selectedCommand) |
|
|
|
|
{ |
|
|
|
|
if (!firstSelectedCommandFound) |
|
|
|
|
{ |
|
|
|
|
firstSelectedIndex = i; |
|
|
|
|
firstSelectedCommandFound = true; |
|
|
|
|
} |
|
|
|
|
lastSelectedIndex = i; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (Event.current.shift) |
|
|
|
|
{ |
|
|
|
|
for (int i = firstSelectedIndex; i < lastSelectedIndex; ++i) |
|
|
|
|
{ |
|
|
|
|
fungusScript.AddSelectedCommand(fungusScript.selectedSequence.commandList[i]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (index == firstSelectedIndex) |
|
|
|
|
{ |
|
|
|
|
pinShiftToTop = false; |
|
|
|
|
} |
|
|
|
|
else if (index == lastSelectedIndex) |
|
|
|
|
{ |
|
|
|
|
pinShiftToTop = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Color commandLabelColor = Color.white; |
|
|
|
|
if (fungusScript.colorCommands) |
|
|
|
|
{ |
|
|
|
|
commandLabelColor = command.GetButtonColor(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (commandIsSelected) |
|
|
|
|
{ |
|
|
|
|
commandLabelColor = Color.green; |
|
|
|
@ -273,10 +348,10 @@ namespace Fungus
|
|
|
|
|
{ |
|
|
|
|
// TODO: Show warning icon |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GUI.backgroundColor = commandLabelColor; |
|
|
|
|
|
|
|
|
|
if (isComment || isLabel) |
|
|
|
|
|
|
|
|
|
if (isComment) |
|
|
|
|
{ |
|
|
|
|
GUI.Label(commandLabelRect, "", commandLabelStyle); |
|
|
|
|
} |
|
|
|
@ -284,7 +359,7 @@ namespace Fungus
|
|
|
|
|
{ |
|
|
|
|
GUI.Label(commandLabelRect, commandName, commandLabelStyle); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (command.IsExecuting()) |
|
|
|
|
{ |
|
|
|
|
Rect iconRect = new Rect(commandLabelRect); |
|
|
|
@ -293,23 +368,28 @@ namespace Fungus
|
|
|
|
|
iconRect.height = 20; |
|
|
|
|
GUI.Label(iconRect, FungusEditorResources.texPlaySmall, new GUIStyle()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rect summaryRect = new Rect(commandLabelRect); |
|
|
|
|
if (!isComment && !isLabel) |
|
|
|
|
if (isComment) |
|
|
|
|
{ |
|
|
|
|
summaryRect.x += 5; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
summaryRect.x += commandNameWidth; |
|
|
|
|
summaryRect.width -= commandNameWidth; |
|
|
|
|
summaryRect.width -= 5; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GUIStyle summaryStyle = new GUIStyle(); |
|
|
|
|
summaryStyle.fontSize = 10; |
|
|
|
|
summaryStyle.padding.top += 5; |
|
|
|
|
summaryStyle.richText = true; |
|
|
|
|
summaryStyle.wordWrap = false; |
|
|
|
|
summaryStyle.clipping = TextClipping.Clip; |
|
|
|
|
commandLabelStyle.alignment = TextAnchor.MiddleLeft; |
|
|
|
|
GUI.Label(summaryRect, summary, summaryStyle); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (error) |
|
|
|
|
{ |
|
|
|
|
GUISkin editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector); |
|
|
|
@ -320,10 +400,10 @@ namespace Fungus
|
|
|
|
|
GUI.Label(errorRect, editorSkin.GetStyle("CN EntryError").normal.background); |
|
|
|
|
summaryRect.width -= 20; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GUI.backgroundColor = Color.white; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual float GetItemHeight(int index) { |
|
|
|
|
return fixedItemHeight != 0f |
|
|
|
|
? fixedItemHeight |
|
|
|
@ -369,4 +449,3 @@ namespace Fungus
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|