Browse Source

Sort add command menu. Comments are now a top level item.

master
chrisgregan 10 years ago
parent
commit
75d9441fa5
  1. 2
      Assets/Fungus/FungusScript/Commands/Comment.cs
  2. 28
      Assets/Fungus/FungusScript/Editor/SequenceEditor.cs

2
Assets/Fungus/FungusScript/Commands/Comment.cs

@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace Fungus namespace Fungus
{ {
[CommandInfo("Scripting", [CommandInfo("",
"Comment", "Comment",
"Use comments to record design notes and reminders about your game.")] "Use comments to record design notes and reminders about your game.")]
public class Comment : Command public class Comment : Command

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

@ -230,6 +230,17 @@ namespace Fungus
return result; return result;
} }
// Compare delegate for sorting the list of command attributes
static int CompareCommandAttributes(KeyValuePair<System.Type, CommandInfoAttribute> x, KeyValuePair<System.Type, CommandInfoAttribute> y)
{
int compare = (x.Value.Category.CompareTo(y.Value.Category));
if (compare == 0)
{
compare = (x.Value.CommandName.CompareTo(y.Value.CommandName));
}
return compare;
}
void ShowCommandMenu() void ShowCommandMenu()
{ {
Sequence sequence = target as Sequence; Sequence sequence = target as Sequence;
@ -241,6 +252,8 @@ namespace Fungus
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 );
foreach(var keyPair in filteredAttributes) foreach(var keyPair in filteredAttributes)
{ {
AddCommandOperation commandOperation = new AddCommandOperation(); AddCommandOperation commandOperation = new AddCommandOperation();
@ -248,9 +261,18 @@ namespace Fungus
commandOperation.sequence = sequence; commandOperation.sequence = sequence;
commandOperation.commandType = keyPair.Key; commandOperation.commandType = keyPair.Key;
commandOperation.index = index; commandOperation.index = index;
commandMenu.AddItem (new GUIContent (keyPair.Value.Category + "/" + keyPair.Value.CommandName), GUIContent menuItem;
false, AddCommandCallback, commandOperation); if (keyPair.Value.Category == "")
{
menuItem = new GUIContent(keyPair.Value.CommandName);
}
else
{
menuItem = new GUIContent (keyPair.Value.Category + "/" + keyPair.Value.CommandName);
}
commandMenu.AddItem(menuItem, false, AddCommandCallback, commandOperation);
} }
commandMenu.ShowAsContext(); commandMenu.ShowAsContext();

Loading…
Cancel
Save