From 75d9441fa5681819f65846b9e9479e9096ff1132 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Tue, 28 Oct 2014 14:21:29 +0000 Subject: [PATCH] Sort add command menu. Comments are now a top level item. --- .../Fungus/FungusScript/Commands/Comment.cs | 2 +- .../FungusScript/Editor/SequenceEditor.cs | 28 +++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Assets/Fungus/FungusScript/Commands/Comment.cs b/Assets/Fungus/FungusScript/Commands/Comment.cs index bd31315e..d309109d 100644 --- a/Assets/Fungus/FungusScript/Commands/Comment.cs +++ b/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 diff --git a/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs b/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs index e7f892c8..789e9a52 100644 --- a/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs +++ b/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 x, KeyValuePair 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 menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList(); List> 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();