From 585efc25264b96a339d85186eb2c3463d51688e2 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Mon, 25 Aug 2014 22:44:45 +0100 Subject: [PATCH] Added command categories --- Assets/Fungus/Audio/Commands/PlayMusic.cs | 1 + Assets/Fungus/Audio/Commands/PlaySound.cs | 1 + .../Fungus/Audio/Commands/SetMusicVolume.cs | 1 + Assets/Fungus/Audio/Commands/StopMusic.cs | 1 + Assets/Fungus/Camera/Commands/FadeToView.cs | 1 + Assets/Fungus/Camera/Commands/MoveToView.cs | 1 + Assets/Fungus/Dialog/Commands/AddOption.cs | 1 + Assets/Fungus/Dialog/Commands/Say.cs | 1 + Assets/Fungus/FungusScript/Commands/Call.cs | 1 + Assets/Fungus/FungusScript/Commands/If.cs | 1 + .../FungusScript/Commands/LoadGlobals.cs | 1 + .../Fungus/FungusScript/Commands/LoadScene.cs | 1 + .../FungusScript/Commands/SaveGlobals.cs | 1 + Assets/Fungus/FungusScript/Commands/Set.cs | 1 + Assets/Fungus/FungusScript/Commands/Wait.cs | 1 + .../Fungus/FungusScript/Editor/CallEditor.cs | 1 - .../FungusScript/Editor/FungusScriptEditor.cs | 86 +++++++++++++----- .../FungusScript/Editor/FungusScriptWindow.cs | 5 +- .../FungusScript/Scripts/FungusCommand.cs | 10 ++ .../FungusScript/Scripts/FungusScript.cs | 3 + Assets/Fungus/Sprite/Commands/FadeSprite.cs | 1 + Assets/Shuttle/ShuttleGame.unity | Bin 123540 -> 123468 bytes 22 files changed, 92 insertions(+), 29 deletions(-) diff --git a/Assets/Fungus/Audio/Commands/PlayMusic.cs b/Assets/Fungus/Audio/Commands/PlayMusic.cs index e22dfee0..dee22250 100644 --- a/Assets/Fungus/Audio/Commands/PlayMusic.cs +++ b/Assets/Fungus/Audio/Commands/PlayMusic.cs @@ -3,6 +3,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Audio")] [CommandName("Play Music")] [HelpText("Plays game music. If any game music is already playing, it is stopped. Music continues playing across scene loads.")] public class PlayMusic : FungusCommand diff --git a/Assets/Fungus/Audio/Commands/PlaySound.cs b/Assets/Fungus/Audio/Commands/PlaySound.cs index 4c0d9400..8ac91ac5 100644 --- a/Assets/Fungus/Audio/Commands/PlaySound.cs +++ b/Assets/Fungus/Audio/Commands/PlaySound.cs @@ -3,6 +3,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Audio")] [CommandName("Play Sound")] [HelpText("Plays a sound effect. Multiple sound effects can play at the same time.")] public class PlaySound : FungusCommand diff --git a/Assets/Fungus/Audio/Commands/SetMusicVolume.cs b/Assets/Fungus/Audio/Commands/SetMusicVolume.cs index b02e85d9..5d0e31c9 100644 --- a/Assets/Fungus/Audio/Commands/SetMusicVolume.cs +++ b/Assets/Fungus/Audio/Commands/SetMusicVolume.cs @@ -3,6 +3,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Audio")] [CommandName("Set Music Volume")] [HelpText("Sets the game music volume level.")] public class SetMusicVolume : FungusCommand diff --git a/Assets/Fungus/Audio/Commands/StopMusic.cs b/Assets/Fungus/Audio/Commands/StopMusic.cs index 062c25cf..ceb92e20 100644 --- a/Assets/Fungus/Audio/Commands/StopMusic.cs +++ b/Assets/Fungus/Audio/Commands/StopMusic.cs @@ -3,6 +3,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Audio")] [CommandName("Stop Music")] [HelpText("Stops the currently playing game music.")] public class StopMusic : FungusCommand diff --git a/Assets/Fungus/Camera/Commands/FadeToView.cs b/Assets/Fungus/Camera/Commands/FadeToView.cs index 5e62899a..a6ee8b3f 100644 --- a/Assets/Fungus/Camera/Commands/FadeToView.cs +++ b/Assets/Fungus/Camera/Commands/FadeToView.cs @@ -4,6 +4,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Camera")] [CommandName("Fade To View")] [HelpText("Fades the camera out and in again at a location specified by a View object.")] public class FadeToView : FungusCommand diff --git a/Assets/Fungus/Camera/Commands/MoveToView.cs b/Assets/Fungus/Camera/Commands/MoveToView.cs index 97dbb3d1..101be2eb 100644 --- a/Assets/Fungus/Camera/Commands/MoveToView.cs +++ b/Assets/Fungus/Camera/Commands/MoveToView.cs @@ -4,6 +4,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Camera")] [CommandName("Move To View")] [HelpText("Moves the camera to a location specified by a View object.")] public class MoveToView : FungusCommand diff --git a/Assets/Fungus/Dialog/Commands/AddOption.cs b/Assets/Fungus/Dialog/Commands/AddOption.cs index 8e590487..ec80688f 100644 --- a/Assets/Fungus/Dialog/Commands/AddOption.cs +++ b/Assets/Fungus/Dialog/Commands/AddOption.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; namespace Fungus.Script { + [CommandCategory("Dialog")] [CommandName("Add Option")] [HelpText("Adds an option button to be displayed by the next Say command. The target sequence is run when the player selects the option. A condition can be specified for when the option should be shown.")] public class AddOption : FungusCommand diff --git a/Assets/Fungus/Dialog/Commands/Say.cs b/Assets/Fungus/Dialog/Commands/Say.cs index 067278f4..da1fe1bc 100644 --- a/Assets/Fungus/Dialog/Commands/Say.cs +++ b/Assets/Fungus/Dialog/Commands/Say.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; namespace Fungus.Script { + [CommandCategory("Dialog")] [HelpText("Writes a line of story text to the dialog. A condition can be specified for when the story text should be shown.")] public class Say : FungusCommand { diff --git a/Assets/Fungus/FungusScript/Commands/Call.cs b/Assets/Fungus/FungusScript/Commands/Call.cs index 12fae471..87db0705 100644 --- a/Assets/Fungus/FungusScript/Commands/Call.cs +++ b/Assets/Fungus/FungusScript/Commands/Call.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; namespace Fungus.Script { + [CommandCategory("Scripting")] [HelpText("Execute another sequence.")] public class Call : FungusCommand { diff --git a/Assets/Fungus/FungusScript/Commands/If.cs b/Assets/Fungus/FungusScript/Commands/If.cs index 5492eda4..ca48c70b 100644 --- a/Assets/Fungus/FungusScript/Commands/If.cs +++ b/Assets/Fungus/FungusScript/Commands/If.cs @@ -14,6 +14,7 @@ namespace Fungus.Script GreaterThanOrEquals // >= } + [CommandCategory("Scripting")] [HelpText("Execute another sequence IF a condition is true. Sequences can be specified for both true (THEN) and false (ELSE) conditions.")] public class If : FungusCommand { diff --git a/Assets/Fungus/FungusScript/Commands/LoadGlobals.cs b/Assets/Fungus/FungusScript/Commands/LoadGlobals.cs index a3bb2547..2b27d6d5 100644 --- a/Assets/Fungus/FungusScript/Commands/LoadGlobals.cs +++ b/Assets/Fungus/FungusScript/Commands/LoadGlobals.cs @@ -4,6 +4,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Scripting")] [CommandName("Load Globals")] [HelpText("Loads a set of global variables previously saved using the SaveGlobals command.")] public class LoadGlobals : FungusCommand diff --git a/Assets/Fungus/FungusScript/Commands/LoadScene.cs b/Assets/Fungus/FungusScript/Commands/LoadScene.cs index 78422551..0a1f6099 100644 --- a/Assets/Fungus/FungusScript/Commands/LoadScene.cs +++ b/Assets/Fungus/FungusScript/Commands/LoadScene.cs @@ -4,6 +4,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Scripting")] [CommandName("Load Scene")] [HelpText("Loads a new scene and displays an optional loading image. This is useful " + "for splitting a large game across multiple scene files to reduce peak memory " + diff --git a/Assets/Fungus/FungusScript/Commands/SaveGlobals.cs b/Assets/Fungus/FungusScript/Commands/SaveGlobals.cs index 7a8c544f..4a9c5365 100644 --- a/Assets/Fungus/FungusScript/Commands/SaveGlobals.cs +++ b/Assets/Fungus/FungusScript/Commands/SaveGlobals.cs @@ -4,6 +4,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Scripting")] [CommandName("Save Globals")] [HelpText("Saves all current global variables to be loaded again later using the LoadGlobals command. This provides a basic save game system.")] public class SaveGlobals : FungusCommand diff --git a/Assets/Fungus/FungusScript/Commands/Set.cs b/Assets/Fungus/FungusScript/Commands/Set.cs index 652718a3..10611e8a 100644 --- a/Assets/Fungus/FungusScript/Commands/Set.cs +++ b/Assets/Fungus/FungusScript/Commands/Set.cs @@ -3,6 +3,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Scripting")] [HelpText("Sets a variable to a new value using simple arithmetic operations. The value can be a constant or another variable.")] public class Set : FungusCommand { diff --git a/Assets/Fungus/FungusScript/Commands/Wait.cs b/Assets/Fungus/FungusScript/Commands/Wait.cs index abb29b8e..dca69418 100644 --- a/Assets/Fungus/FungusScript/Commands/Wait.cs +++ b/Assets/Fungus/FungusScript/Commands/Wait.cs @@ -4,6 +4,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Scripting")] [HelpText("Waits for period of time before executing the next command in the sequence.")] public class Wait : FungusCommand { diff --git a/Assets/Fungus/FungusScript/Editor/CallEditor.cs b/Assets/Fungus/FungusScript/Editor/CallEditor.cs index 9c9ee618..99ed0495 100644 --- a/Assets/Fungus/FungusScript/Editor/CallEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/CallEditor.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; namespace Fungus.Script { - [CustomEditor (typeof(Call))] public class CallEditor : FungusCommandEditor { diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs index 752c983c..6e0a0610 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs @@ -95,9 +95,7 @@ namespace Fungus.Script sequence.description = desc; } - GUI.backgroundColor = Color.yellow; GUILayout.Box("Commands", GUILayout.ExpandWidth(true)); - GUI.backgroundColor = Color.white; FungusCommand[] commands = sequence.GetComponents(); int index = 1; @@ -113,52 +111,90 @@ namespace Fungus.Script } EditorGUILayout.Separator(); - - GUI.backgroundColor = Color.yellow; + GUILayout.Box("New Command", GUILayout.ExpandWidth(true)); - GUI.backgroundColor = Color.white; + List categories = new List(); + // Build list of categories - List commandTypes = EditorExtensions.FindDerivedTypes(typeof(FungusCommand)).ToList(); - if (commandTypes.Count == 0) + List subTypes = EditorExtensions.FindDerivedTypes(typeof(FungusCommand)).ToList(); + foreach(System.Type type in subTypes) { - return; + object[] attributes = type.GetCustomAttributes(false); + foreach (object obj in attributes) + { + CommandCategoryAttribute categoryAttr = obj as CommandCategoryAttribute; + if (categoryAttr != null) + { + if (!categories.Contains(categoryAttr.Category)) + { + categories.Add(categoryAttr.Category); + } + } + } } - List commandNames = new List(); - foreach(System.Type type in commandTypes) - { - commandNames.Add(GetCommandName(type)); - } + categories.Sort(); EditorGUI.BeginChangeCheck(); - int selectedCommandIndex = EditorGUILayout.Popup("Command", fungusScript.selectedCommandIndex, commandNames.ToArray()); + EditorGUILayout.BeginHorizontal(); + int selectedCategoryIndex = EditorGUILayout.Popup(fungusScript.selectedCategoryIndex, categories.ToArray()); + + List commandNames = new List(); + List commandTypes = new List(); + + string categoryName = categories[selectedCategoryIndex]; + foreach (System.Type type in subTypes) + { + object[] attributes = type.GetCustomAttributes(false); + foreach (object obj in attributes) + { + CommandCategoryAttribute categoryAttr = obj as CommandCategoryAttribute; + if (categoryAttr != null) + { + if (categoryAttr.Category == categoryName) + { + commandNames.Add(type.Name); + commandTypes.Add(type); + } + } + } + } + + int selectedCommandIndex = EditorGUILayout.Popup(fungusScript.selectedCommandIndex, commandNames.ToArray()); + + if (selectedCategoryIndex != fungusScript.selectedCategoryIndex) + { + // Default to first item in list if category has changed + selectedCommandIndex = 0; + } + if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(fungusScript, "Select Command"); + fungusScript.selectedCategoryIndex = selectedCategoryIndex; fungusScript.selectedCommandIndex = selectedCommandIndex; } System.Type selectedType = commandTypes[selectedCommandIndex]; - if (selectedType == null) + if (fungusScript.selectedSequence == null || + selectedType == null) { + EditorGUILayout.EndHorizontal(); return; } - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - if (GUILayout.Button(new GUIContent("Add Command", "Add the selected command to the sequence"))) + if (GUILayout.Button(new GUIContent("Add", "Add the selected command to the sequence"), EditorStyles.miniButton)) { - Undo.AddComponent(sequence.gameObject, selectedType); + Undo.AddComponent(fungusScript.selectedSequence.gameObject, selectedType); } - GUILayout.EndHorizontal(); + + EditorGUILayout.EndHorizontal(); - EditorGUILayout.Separator(); - - object[] attributes = selectedType.GetCustomAttributes(typeof(HelpTextAttribute), false); - foreach (object obj in attributes) + object[] helpAttributes = selectedType.GetCustomAttributes(typeof(HelpTextAttribute), false); + foreach (object obj in helpAttributes) { HelpTextAttribute helpTextAttr = obj as HelpTextAttribute; if (helpTextAttr != null) @@ -169,6 +205,8 @@ namespace Fungus.Script break; } } + + EditorGUILayout.Separator(); } public void DrawVariablesGUI() diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs index 59e64430..fe3a6dac 100755 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs @@ -190,11 +190,8 @@ namespace Fungus.Script EditorGUILayout.BeginVertical(); - EditorGUILayout.Separator(); - GUI.backgroundColor = Color.yellow; GUILayout.Box("Sequence", GUILayout.ExpandWidth(true)); - GUI.backgroundColor = Color.white; - + GUILayout.BeginHorizontal(); if (fungusScript.selectedSequence == null) diff --git a/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs b/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs index c3e73774..eef19df5 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs +++ b/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs @@ -28,6 +28,16 @@ namespace Fungus.Script public string HelpText { get; set; } } + public class CommandCategoryAttribute : Attribute + { + public CommandCategoryAttribute(string categoryText) + { + this.Category = categoryText; + } + + public string Category { get; set; } + } + [RequireComponent(typeof(Sequence))] public class FungusCommand : MonoBehaviour { diff --git a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs index 383243e7..e01d7861 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs +++ b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs @@ -15,6 +15,9 @@ namespace Fungus.Script [System.NonSerialized] public FungusCommand copyCommand; + [HideInInspector] + public int selectedCategoryIndex; + [HideInInspector] public int selectedCommandIndex; diff --git a/Assets/Fungus/Sprite/Commands/FadeSprite.cs b/Assets/Fungus/Sprite/Commands/FadeSprite.cs index 1c898356..e9c2f8de 100644 --- a/Assets/Fungus/Sprite/Commands/FadeSprite.cs +++ b/Assets/Fungus/Sprite/Commands/FadeSprite.cs @@ -4,6 +4,7 @@ using System.Collections; namespace Fungus.Script { + [CommandCategory("Sprite")] [CommandName("Fade Sprite")] [HelpText("Fades a sprite to a target color over a period of time.")] public class FadeSprite : FungusCommand diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index a2879f9e71b487c09f958d11732317bbc9f7ef45..54f03d44a34222396efa10354c548d43ab4f054d 100644 GIT binary patch delta 2941 zcmZ|RZ)}rA90%|_7_i~k25ic(8$|{TCQyZq8qpPo(m^2w$J`%Tx3NDR+gQOl1`-}b zkS5MpJ)uP~%oipz5$M89(HPhZb&D~sFGPtivpsLm#2THbO`e?t{H)hfQZ6U-i{^*1u#zYJE%n*7o|kqMG*l z#FnsTEIO0T%b&#xOeySqX)<%AO z<;;d;_DN|aujEgmMs|5kCcBj}nfddl(b;TjRt`IFC}c`-GBXuqu(YfyX3Chz z-Ye9x~E}vHsTOnKUof_sac`y?kML;KFh`m`af2Nb)djP-lx^iFiJIz}R?;VRo2B=(_~w(V3}JDX|BE zVvyMmr~ zIj#aa5v7*;H*Q6+OE3fMd)^8Q4sVLWdhuOLY=QYV64C!`uKLA5b07s*bmrkUHGo<8j4m98B$- zz}uSRT}nv^D3;KAysN}nDwnVr7J*^WVW;v=~{`+7wfb`1TrM=}g^SIXtT0wd4Gs}QRU z@{_B;GLBkleuVj9_>d7^!fUX!EpqvERgRQOQxze2MaCxR zfGKX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