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
{
[CommandInfo("Scripting",
[CommandInfo("",
"Comment",
"Use comments to record design notes and reminders about your game.")]
public class Comment : Command

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

@ -230,6 +230,17 @@ namespace Fungus
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()
{
Sequence sequence = target as Sequence;
@ -241,6 +252,8 @@ namespace Fungus
List<System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList();
List<KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = GetFilteredCommandInfoAttribute(menuTypes);
filteredAttributes.Sort( CompareCommandAttributes );
foreach(var keyPair in filteredAttributes)
{
AddCommandOperation commandOperation = new AddCommandOperation();
@ -248,9 +261,18 @@ namespace Fungus
commandOperation.sequence = sequence;
commandOperation.commandType = keyPair.Key;
commandOperation.index = index;
commandMenu.AddItem (new GUIContent (keyPair.Value.Category + "/" + keyPair.Value.CommandName),
false, AddCommandCallback, commandOperation);
GUIContent menuItem;
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();

Loading…
Cancel
Save