|
|
@ -15,7 +15,7 @@ using System.Reflection; |
|
|
|
|
|
|
|
|
|
|
|
namespace Fungus.EditorUtils |
|
|
|
namespace Fungus.EditorUtils |
|
|
|
{ |
|
|
|
{ |
|
|
|
[CustomEditor (typeof(Block))] |
|
|
|
[CustomEditor(typeof(Block))] |
|
|
|
public class BlockEditor : Editor |
|
|
|
public class BlockEditor : Editor |
|
|
|
{ |
|
|
|
{ |
|
|
|
protected class SetEventHandlerOperation |
|
|
|
protected class SetEventHandlerOperation |
|
|
@ -38,6 +38,7 @@ namespace Fungus.EditorUtils |
|
|
|
protected Texture2D addIcon; |
|
|
|
protected Texture2D addIcon; |
|
|
|
protected Texture2D duplicateIcon; |
|
|
|
protected Texture2D duplicateIcon; |
|
|
|
protected Texture2D deleteIcon; |
|
|
|
protected Texture2D deleteIcon; |
|
|
|
|
|
|
|
protected string commandTextFieldContents = string.Empty; |
|
|
|
|
|
|
|
|
|
|
|
static List<System.Type> commandTypes; |
|
|
|
static List<System.Type> commandTypes; |
|
|
|
static List<System.Type> eventHandlerTypes; |
|
|
|
static List<System.Type> eventHandlerTypes; |
|
|
@ -308,6 +309,8 @@ namespace Fungus.EditorUtils |
|
|
|
|
|
|
|
|
|
|
|
GUILayout.FlexibleSpace(); |
|
|
|
GUILayout.FlexibleSpace(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commandTextFieldContents = GUILayout.TextField(commandTextFieldContents, GUILayout.MinWidth(20), GUILayout.MaxWidth(200)); |
|
|
|
|
|
|
|
|
|
|
|
// Add Button |
|
|
|
// Add Button |
|
|
|
if (GUILayout.Button(addIcon)) |
|
|
|
if (GUILayout.Button(addIcon)) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -539,17 +542,17 @@ namespace Fungus.EditorUtils |
|
|
|
// Dump command info |
|
|
|
// Dump command info |
|
|
|
List<System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList(); |
|
|
|
List<System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList(); |
|
|
|
List<KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = GetFilteredCommandInfoAttribute(menuTypes); |
|
|
|
List<KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = GetFilteredCommandInfoAttribute(menuTypes); |
|
|
|
filteredAttributes.Sort( CompareCommandAttributes ); |
|
|
|
filteredAttributes.Sort(CompareCommandAttributes); |
|
|
|
|
|
|
|
|
|
|
|
// Build list of command categories |
|
|
|
// Build list of command categories |
|
|
|
List<string> commandCategories = new List<string>(); |
|
|
|
List<string> commandCategories = new List<string>(); |
|
|
|
foreach(var keyPair in filteredAttributes) |
|
|
|
foreach (var keyPair in filteredAttributes) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CommandInfoAttribute info = keyPair.Value; |
|
|
|
CommandInfoAttribute info = keyPair.Value; |
|
|
|
if (info.Category != "" && |
|
|
|
if (info.Category != "" && |
|
|
|
!commandCategories.Contains(info.Category)) |
|
|
|
!commandCategories.Contains(info.Category)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
commandCategories.Add (info.Category); |
|
|
|
commandCategories.Add(info.Category); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
commandCategories.Sort(); |
|
|
|
commandCategories.Sort(); |
|
|
@ -560,7 +563,7 @@ namespace Fungus.EditorUtils |
|
|
|
string markdown = "# " + category + " commands # {#" + category.ToLower() + "_commands}\n\n"; |
|
|
|
string markdown = "# " + category + " commands # {#" + category.ToLower() + "_commands}\n\n"; |
|
|
|
markdown += "[TOC]\n"; |
|
|
|
markdown += "[TOC]\n"; |
|
|
|
|
|
|
|
|
|
|
|
foreach(var keyPair in filteredAttributes) |
|
|
|
foreach (var keyPair in filteredAttributes) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CommandInfoAttribute info = keyPair.Value; |
|
|
|
CommandInfoAttribute info = keyPair.Value; |
|
|
|
|
|
|
|
|
|
|
@ -629,10 +632,10 @@ namespace Fungus.EditorUtils |
|
|
|
protected static string GetPropertyInfo(System.Type type) |
|
|
|
protected static string GetPropertyInfo(System.Type type) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string markdown = ""; |
|
|
|
string markdown = ""; |
|
|
|
foreach(FieldInfo field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) |
|
|
|
foreach (FieldInfo field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
TooltipAttribute attribute = (TooltipAttribute)Attribute.GetCustomAttribute(field, typeof(TooltipAttribute)); |
|
|
|
TooltipAttribute attribute = (TooltipAttribute)Attribute.GetCustomAttribute(field, typeof(TooltipAttribute)); |
|
|
|
if (attribute == null ) |
|
|
|
if (attribute == null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
@ -641,7 +644,7 @@ namespace Fungus.EditorUtils |
|
|
|
string propertyName = Regex.Replace(field.Name, "(\\B[A-Z])", " $1"); |
|
|
|
string propertyName = Regex.Replace(field.Name, "(\\B[A-Z])", " $1"); |
|
|
|
if (propertyName.Length > 1) |
|
|
|
if (propertyName.Length > 1) |
|
|
|
{ |
|
|
|
{ |
|
|
|
propertyName = propertyName.Substring(0,1).ToUpper() + propertyName.Substring(1); |
|
|
|
propertyName = propertyName.Substring(0, 1).ToUpper() + propertyName.Substring(1); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
@ -684,9 +687,9 @@ namespace Fungus.EditorUtils |
|
|
|
// Build menu list |
|
|
|
// Build menu list |
|
|
|
List<KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = GetFilteredCommandInfoAttribute(commandTypes); |
|
|
|
List<KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = GetFilteredCommandInfoAttribute(commandTypes); |
|
|
|
|
|
|
|
|
|
|
|
filteredAttributes.Sort( CompareCommandAttributes ); |
|
|
|
filteredAttributes.Sort(CompareCommandAttributes); |
|
|
|
|
|
|
|
|
|
|
|
foreach(var keyPair in filteredAttributes) |
|
|
|
foreach (var keyPair in filteredAttributes) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Skip command type if the Flowchart doesn't support it |
|
|
|
// Skip command type if the Flowchart doesn't support it |
|
|
|
if (!flowchart.IsCommandSupported(keyPair.Value)) |
|
|
|
if (!flowchart.IsCommandSupported(keyPair.Value)) |
|
|
@ -707,7 +710,7 @@ namespace Fungus.EditorUtils |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
menuItem = new GUIContent (keyPair.Value.Category + "/" + keyPair.Value.CommandName); |
|
|
|
menuItem = new GUIContent(keyPair.Value.Category + "/" + keyPair.Value.CommandName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
commandMenu.AddItem(menuItem, false, AddCommandCallback, commandOperation); |
|
|
|
commandMenu.AddItem(menuItem, false, AddCommandCallback, commandOperation); |
|
|
@ -716,7 +719,7 @@ namespace Fungus.EditorUtils |
|
|
|
commandMenu.ShowAsContext(); |
|
|
|
commandMenu.ShowAsContext(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected static List<KeyValuePair<System.Type,CommandInfoAttribute>> GetFilteredCommandInfoAttribute(List<System.Type> menuTypes) |
|
|
|
protected static List<KeyValuePair<System.Type, CommandInfoAttribute>> GetFilteredCommandInfoAttribute(List<System.Type> menuTypes) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Dictionary<string, KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = new Dictionary<string, KeyValuePair<System.Type, CommandInfoAttribute>>(); |
|
|
|
Dictionary<string, KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = new Dictionary<string, KeyValuePair<System.Type, CommandInfoAttribute>>(); |
|
|
|
|
|
|
|
|
|
|
@ -744,13 +747,21 @@ namespace Fungus.EditorUtils |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return filteredAttributes.Values.ToList<KeyValuePair<System.Type,CommandInfoAttribute>>(); |
|
|
|
return filteredAttributes.Values.ToList<KeyValuePair<System.Type, CommandInfoAttribute>>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Used by GenericMenu Delegate |
|
|
|
protected static void AddCommandCallback(object obj) |
|
|
|
protected static void AddCommandCallback(object obj) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AddCommandOperation commandOperation = obj as AddCommandOperation; |
|
|
|
AddCommandOperation commandOperation = obj as AddCommandOperation; |
|
|
|
|
|
|
|
if (commandOperation != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
AddCommandCallback(commandOperation); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected static void AddCommandCallback(AddCommandOperation commandOperation) |
|
|
|
|
|
|
|
{ |
|
|
|
var block = commandOperation.block; |
|
|
|
var block = commandOperation.block; |
|
|
|
if (block == null) |
|
|
|
if (block == null) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -823,38 +834,38 @@ namespace Fungus.EditorUtils |
|
|
|
|
|
|
|
|
|
|
|
if (showCut) |
|
|
|
if (showCut) |
|
|
|
{ |
|
|
|
{ |
|
|
|
commandMenu.AddItem (new GUIContent ("Cut"), false, Cut); |
|
|
|
commandMenu.AddItem(new GUIContent("Cut"), false, Cut); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
commandMenu.AddDisabledItem(new GUIContent ("Cut")); |
|
|
|
commandMenu.AddDisabledItem(new GUIContent("Cut")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (showCopy) |
|
|
|
if (showCopy) |
|
|
|
{ |
|
|
|
{ |
|
|
|
commandMenu.AddItem (new GUIContent ("Copy"), false, Copy); |
|
|
|
commandMenu.AddItem(new GUIContent("Copy"), false, Copy); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
commandMenu.AddDisabledItem(new GUIContent ("Copy")); |
|
|
|
commandMenu.AddDisabledItem(new GUIContent("Copy")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (showPaste) |
|
|
|
if (showPaste) |
|
|
|
{ |
|
|
|
{ |
|
|
|
commandMenu.AddItem (new GUIContent ("Paste"), false, Paste); |
|
|
|
commandMenu.AddItem(new GUIContent("Paste"), false, Paste); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
commandMenu.AddDisabledItem(new GUIContent ("Paste")); |
|
|
|
commandMenu.AddDisabledItem(new GUIContent("Paste")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (showDelete) |
|
|
|
if (showDelete) |
|
|
|
{ |
|
|
|
{ |
|
|
|
commandMenu.AddItem (new GUIContent ("Delete"), false, Delete); |
|
|
|
commandMenu.AddItem(new GUIContent("Delete"), false, Delete); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
commandMenu.AddDisabledItem(new GUIContent ("Delete")); |
|
|
|
commandMenu.AddDisabledItem(new GUIContent("Delete")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (showPlay) |
|
|
|
if (showPlay) |
|
|
@ -865,8 +876,8 @@ namespace Fungus.EditorUtils |
|
|
|
|
|
|
|
|
|
|
|
commandMenu.AddSeparator(""); |
|
|
|
commandMenu.AddSeparator(""); |
|
|
|
|
|
|
|
|
|
|
|
commandMenu.AddItem (new GUIContent ("Select All"), false, SelectAll); |
|
|
|
commandMenu.AddItem(new GUIContent("Select All"), false, SelectAll); |
|
|
|
commandMenu.AddItem (new GUIContent ("Select None"), false, SelectNone); |
|
|
|
commandMenu.AddItem(new GUIContent("Select None"), false, SelectNone); |
|
|
|
|
|
|
|
|
|
|
|
commandMenu.ShowAsContext(); |
|
|
|
commandMenu.ShowAsContext(); |
|
|
|
} |
|
|
|
} |
|
|
@ -1133,7 +1144,7 @@ namespace Fungus.EditorUtils |
|
|
|
if (firstSelectedIndex > 0) |
|
|
|
if (firstSelectedIndex > 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
flowchart.ClearSelectedCommands(); |
|
|
|
flowchart.ClearSelectedCommands(); |
|
|
|
flowchart.AddSelectedCommand(flowchart.SelectedBlock.CommandList[firstSelectedIndex-1]); |
|
|
|
flowchart.AddSelectedCommand(flowchart.SelectedBlock.CommandList[firstSelectedIndex - 1]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Repaint(); |
|
|
|
Repaint(); |
|
|
@ -1160,10 +1171,10 @@ namespace Fungus.EditorUtils |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (lastSelectedIndex < flowchart.SelectedBlock.CommandList.Count-1) |
|
|
|
if (lastSelectedIndex < flowchart.SelectedBlock.CommandList.Count - 1) |
|
|
|
{ |
|
|
|
{ |
|
|
|
flowchart.ClearSelectedCommands(); |
|
|
|
flowchart.ClearSelectedCommands(); |
|
|
|
flowchart.AddSelectedCommand(flowchart.SelectedBlock.CommandList[lastSelectedIndex+1]); |
|
|
|
flowchart.AddSelectedCommand(flowchart.SelectedBlock.CommandList[lastSelectedIndex + 1]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Repaint(); |
|
|
|
Repaint(); |
|
|
|