From ba8d7f430db345e9813c382ba01705667e142a8e Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Fri, 12 Dec 2014 17:03:16 +0000 Subject: [PATCH] Integrated Say & Choose dialog pull request from lynxelia [Tweaked the image sizes to avoid horizontal scroll bar appearing in insepctor] [Reverted changes to .gitignore file] --- .../Fungus/Dialog/Editor/AddOptionEditor.cs | 20 ++--- .../Fungus/Dialog/Editor/CharacterEditor.cs | 8 +- Assets/Fungus/Dialog/Editor/ChooseEditor.cs | 55 ++++++------- Assets/Fungus/Dialog/Editor/SayEditor.cs | 81 ++++++++++--------- Assets/Fungus/Dialog/Scripts/Character.cs | 2 + .../Fungus/Dialog/Scripts/Commands/Choose.cs | 13 ++- Assets/Fungus/Dialog/Scripts/Commands/Say.cs | 20 ++++- 7 files changed, 118 insertions(+), 81 deletions(-) diff --git a/Assets/Fungus/Dialog/Editor/AddOptionEditor.cs b/Assets/Fungus/Dialog/Editor/AddOptionEditor.cs index 69f1aa88..bb76713d 100644 --- a/Assets/Fungus/Dialog/Editor/AddOptionEditor.cs +++ b/Assets/Fungus/Dialog/Editor/AddOptionEditor.cs @@ -7,14 +7,14 @@ using Rotorz.ReorderableList; namespace Fungus { - + [CustomEditor (typeof(AddOption))] public class AddOptionEditor : SetVariableEditor { protected SerializedProperty optionTextProp; protected SerializedProperty hideOnSelectedProp; protected SerializedProperty targetSequenceProp; - + protected override void OnEnable() { base.OnEnable(); @@ -22,26 +22,28 @@ namespace Fungus hideOnSelectedProp = serializedObject.FindProperty("hideOnSelected"); targetSequenceProp = serializedObject.FindProperty("targetSequence"); } - + public override void DrawCommandGUI() { serializedObject.Update(); - + AddOption t = target as AddOption; - + EditorGUILayout.PropertyField(optionTextProp, new GUIContent("Option Text", "Text to display on the option button.")); - + SequenceEditor.SequenceField(targetSequenceProp, new GUIContent("Target Sequence", "Sequence to execute when this option is selected by the player."), new GUIContent(""), t.GetFungusScript()); - EditorGUILayout.PropertyField(hideOnSelectedProp, new GUIContent("Hide On Selected", "Hide this option forever once the player has selected it.")); - serializedObject.ApplyModifiedProperties(); base.DrawCommandGUI(); + + serializedObject.Update(); + EditorGUILayout.PropertyField(hideOnSelectedProp, new GUIContent("Hide On Selected", "Hide this option forever once the player has selected it.")); + serializedObject.ApplyModifiedProperties(); } } - + } \ No newline at end of file diff --git a/Assets/Fungus/Dialog/Editor/CharacterEditor.cs b/Assets/Fungus/Dialog/Editor/CharacterEditor.cs index 7f9d8381..d6bb7a62 100644 --- a/Assets/Fungus/Dialog/Editor/CharacterEditor.cs +++ b/Assets/Fungus/Dialog/Editor/CharacterEditor.cs @@ -12,6 +12,8 @@ namespace Fungus protected SerializedProperty nameTextProp; protected SerializedProperty nameColorProp; + protected SerializedProperty sayDialogBoxProp; + protected SerializedProperty chooseDialogBoxProp; protected SerializedProperty profileSpriteProp; protected SerializedProperty soundEffectProp; protected SerializedProperty notesProp; @@ -20,6 +22,8 @@ namespace Fungus { nameTextProp = serializedObject.FindProperty ("nameText"); nameColorProp = serializedObject.FindProperty ("nameColor"); + sayDialogBoxProp = serializedObject.FindProperty ("sayDialogBox"); + chooseDialogBoxProp = serializedObject.FindProperty ("chooseDialogBox"); profileSpriteProp = serializedObject.FindProperty ("profileSprite"); soundEffectProp = serializedObject.FindProperty ("soundEffect"); notesProp = serializedObject.FindProperty ("notes"); @@ -43,6 +47,8 @@ namespace Fungus EditorGUILayout.PropertyField(nameTextProp, new GUIContent("Name Text", "Name of the character display in the dialog")); EditorGUILayout.PropertyField(nameColorProp, new GUIContent("Name Color", "Color of name text display in the dialog")); + EditorGUILayout.PropertyField(sayDialogBoxProp, new GUIContent("Say Dialog", "Say dialog box this character should use")); + EditorGUILayout.PropertyField(chooseDialogBoxProp, new GUIContent("Choose Dialog", "Choose dialog box this character should use")); EditorGUILayout.PropertyField(profileSpriteProp, new GUIContent("Image", "Character image sprite to display in the dialog")); EditorGUILayout.PropertyField(soundEffectProp, new GUIContent("Sound Effect", "Sound to play when the character is talking. Overrides the setting in the Dialog.")); EditorGUILayout.PropertyField(notesProp, new GUIContent("Notes", "Notes about this story character (personality, attibutes, etc.)")); @@ -56,7 +62,7 @@ namespace Fungus EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); float aspect = (float)t.profileSprite.texture.width / (float)t.profileSprite.texture.height; - Rect imagePreviewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(150), GUILayout.ExpandWidth(false)); + Rect imagePreviewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(250), GUILayout.ExpandWidth(true)); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); diff --git a/Assets/Fungus/Dialog/Editor/ChooseEditor.cs b/Assets/Fungus/Dialog/Editor/ChooseEditor.cs index bd565f7b..390cfe86 100644 --- a/Assets/Fungus/Dialog/Editor/ChooseEditor.cs +++ b/Assets/Fungus/Dialog/Editor/ChooseEditor.cs @@ -7,18 +7,18 @@ using Rotorz.ReorderableList; namespace Fungus { - + [CustomEditor (typeof(Choose))] public class ChooseEditor : CommandEditor { static public bool showTagHelp; - + protected SerializedProperty chooseTextProp; protected SerializedProperty characterProp; protected SerializedProperty chooseDialogProp; protected SerializedProperty voiceOverClipProp; protected SerializedProperty timeoutDurationProp; - + protected virtual void OnEnable() { chooseTextProp = serializedObject.FindProperty("chooseText"); @@ -27,27 +27,46 @@ namespace Fungus voiceOverClipProp = serializedObject.FindProperty("voiceOverClip"); timeoutDurationProp = serializedObject.FindProperty("timeoutDuration"); } - + public override void DrawCommandGUI() { serializedObject.Update(); + CommandEditor.ObjectField(characterProp, + new GUIContent("Character", "Character to display in dialog"), + new GUIContent(""), + Character.activeCharacters); + + CommandEditor.ObjectField(chooseDialogProp, + new GUIContent("Choose Dialog", "Choose Dialog object to use to display the multiple player choices"), + new GUIContent(""), + ChooseDialog.activeDialogs); + EditorGUILayout.BeginHorizontal(); + + EditorGUILayout.PropertyField(chooseTextProp); + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton))) { showTagHelp = !showTagHelp; } EditorGUILayout.EndHorizontal(); - + if (showTagHelp) { SayEditor.DrawTagHelpLabel(); } - - EditorGUILayout.BeginHorizontal(); - EditorGUILayout.PropertyField(chooseTextProp); + EditorGUILayout.Separator(); + + EditorGUILayout.PropertyField(voiceOverClipProp, new GUIContent("Voice Over Clip", "Voice over audio to play when the choose text is displayed")); + + EditorGUILayout.PropertyField(timeoutDurationProp, new GUIContent("Timeout Duration", "Time limit for player to make a choice. Set to 0 for no limit.")); Choose t = target as Choose; @@ -58,30 +77,12 @@ namespace Fungus Texture2D characterTexture = t.character.profileSprite.texture; float aspect = (float)characterTexture.width / (float)characterTexture.height; - Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(50), GUILayout.ExpandWidth(false)); + Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true)); CharacterEditor characterEditor = Editor.CreateEditor(t.character) as CharacterEditor; characterEditor.DrawPreview(previewRect, characterTexture); DestroyImmediate(characterEditor); } - EditorGUILayout.EndHorizontal(); - - EditorGUILayout.Separator(); - - CommandEditor.ObjectField(characterProp, - new GUIContent("Character", "Character to display in dialog"), - new GUIContent(""), - Character.activeCharacters); - - CommandEditor.ObjectField(chooseDialogProp, - new GUIContent("Choose Dialog", "Choose Dialog object to use to display the multiple player choices"), - new GUIContent(""), - ChooseDialog.activeDialogs); - - EditorGUILayout.PropertyField(voiceOverClipProp, new GUIContent("Voice Over Clip", "Voice over audio to play when the choose text is displayed")); - - EditorGUILayout.PropertyField(timeoutDurationProp, new GUIContent("Timeout Duration", "Time limit for player to make a choice. Set to 0 for no limit.")); - serializedObject.ApplyModifiedProperties(); } } diff --git a/Assets/Fungus/Dialog/Editor/SayEditor.cs b/Assets/Fungus/Dialog/Editor/SayEditor.cs index 4045d5d9..f39258de 100644 --- a/Assets/Fungus/Dialog/Editor/SayEditor.cs +++ b/Assets/Fungus/Dialog/Editor/SayEditor.cs @@ -7,12 +7,12 @@ using Rotorz.ReorderableList; namespace Fungus { - + [CustomEditor (typeof(Say))] public class SayEditor : CommandEditor { static public bool showTagHelp; - + static public void DrawTagHelpLabel() { string tagsText = "\t{b} Bold Text {/b}\n" + @@ -31,14 +31,14 @@ namespace Fungus float pixelHeight = EditorStyles.miniLabel.CalcHeight(new GUIContent(tagsText), EditorGUIUtility.currentViewWidth); EditorGUILayout.SelectableLabel(tagsText, EditorStyles.miniLabel, GUILayout.MinHeight(pixelHeight)); } - + protected SerializedProperty storyTextProp; protected SerializedProperty characterProp; protected SerializedProperty sayDialogProp; protected SerializedProperty voiceOverClipProp; protected SerializedProperty showAlwaysProp; protected SerializedProperty showCountProp; - + protected virtual void OnEnable() { storyTextProp = serializedObject.FindProperty("storyText"); @@ -48,66 +48,69 @@ namespace Fungus showAlwaysProp = serializedObject.FindProperty("showAlways"); showCountProp = serializedObject.FindProperty("showCount"); } - + public override void DrawCommandGUI() { serializedObject.Update(); - + + CommandEditor.ObjectField(characterProp, + new GUIContent("Character", "Character to display in dialog"), + new GUIContent(""), + Character.activeCharacters); + + CommandEditor.ObjectField(sayDialogProp, + new GUIContent("Say Dialog", "Say Dialog object to use to display the story text"), + new GUIContent(""), + SayDialog.activeDialogs); + + EditorGUILayout.BeginHorizontal(); + + EditorGUILayout.PropertyField(storyTextProp); + + EditorGUILayout.EndHorizontal(); + EditorGUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton))) { showTagHelp = !showTagHelp; } EditorGUILayout.EndHorizontal(); - + if (showTagHelp) { DrawTagHelpLabel(); } - - EditorGUILayout.BeginHorizontal(); - - EditorGUILayout.PropertyField(storyTextProp); - + + EditorGUILayout.Separator(); + + EditorGUILayout.PropertyField(voiceOverClipProp, + new GUIContent("Voice Over Clip", "Voice over audio to play when the say text is displayed")); + + EditorGUILayout.PropertyField(showAlwaysProp); + + if (showAlwaysProp.boolValue == false) + { + EditorGUILayout.PropertyField(showCountProp); + } + Say t = target as Say; - + if (t.character != null && t.character.profileSprite != null && t.character.profileSprite.texture != null) { Texture2D characterTexture = t.character.profileSprite.texture; - + float aspect = (float)characterTexture.width / (float)characterTexture.height; - Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(50), GUILayout.ExpandWidth(false)); + Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true)); CharacterEditor characterEditor = Editor.CreateEditor(t.character) as CharacterEditor; characterEditor.DrawPreview(previewRect, characterTexture); DestroyImmediate(characterEditor); } - - EditorGUILayout.EndHorizontal(); - - EditorGUILayout.Separator(); - - CommandEditor.ObjectField(characterProp, - new GUIContent("Character", "Character to display in dialog"), - new GUIContent(""), - Character.activeCharacters); - - CommandEditor.ObjectField(sayDialogProp, - new GUIContent("Say Dialog", "Say Dialog object to use to display the story text"), - new GUIContent(""), - SayDialog.activeDialogs); - - EditorGUILayout.PropertyField(voiceOverClipProp); - - EditorGUILayout.PropertyField(showAlwaysProp); - - if (showAlwaysProp.boolValue == false) - { - EditorGUILayout.PropertyField(showCountProp); - } - + serializedObject.ApplyModifiedProperties(); } } diff --git a/Assets/Fungus/Dialog/Scripts/Character.cs b/Assets/Fungus/Dialog/Scripts/Character.cs index 40367a60..2d8a5abf 100644 --- a/Assets/Fungus/Dialog/Scripts/Character.cs +++ b/Assets/Fungus/Dialog/Scripts/Character.cs @@ -10,6 +10,8 @@ namespace Fungus { public string nameText; // We need a separate name as the object name is used for character variations (e.g. "Smurf Happy", "Smurf Sad") public Color nameColor = Color.white; + public SayDialog sayDialogBox; + public ChooseDialog chooseDialogBox; public Sprite profileSprite; public AudioClip soundEffect; diff --git a/Assets/Fungus/Dialog/Scripts/Commands/Choose.cs b/Assets/Fungus/Dialog/Scripts/Commands/Choose.cs index cf7ac093..94e187b6 100644 --- a/Assets/Fungus/Dialog/Scripts/Commands/Choose.cs +++ b/Assets/Fungus/Dialog/Scripts/Commands/Choose.cs @@ -44,8 +44,17 @@ namespace Fungus showBasicGUI = false; if (chooseDialog == null) { - // Try to get any SayDialog in the scene - chooseDialog = GameObject.FindObjectOfType(); + if ( character != null ) { + // Try to get character's choose box + chooseDialog = character.chooseDialogBox; + } + + if (chooseDialog == null) + { + // Try to get any SayDialog in the scene + chooseDialog = GameObject.FindObjectOfType(); + } + if (chooseDialog == null) { showBasicGUI = true; diff --git a/Assets/Fungus/Dialog/Scripts/Commands/Say.cs b/Assets/Fungus/Dialog/Scripts/Commands/Say.cs index 79e39f47..9681b131 100644 --- a/Assets/Fungus/Dialog/Scripts/Commands/Say.cs +++ b/Assets/Fungus/Dialog/Scripts/Commands/Say.cs @@ -48,10 +48,19 @@ namespace Fungus showBasicGUI = false; if (sayDialog == null) { - // Try to get any SayDialog in the scene - sayDialog = GameObject.FindObjectOfType(); + if ( character != null ) { + // Try to get character's dialog box + sayDialog = character.sayDialogBox; + } + if (sayDialog == null) { + // Try to get any SayDialog in the scene + sayDialog = GameObject.FindObjectOfType(); + } + if (sayDialog == null) + { + // No custom dialog box exists, just use basic gui showBasicGUI = true; return; } @@ -77,7 +86,12 @@ namespace Fungus public override string GetSummary() { - return "\"" + storyText + "\""; + string namePrefix = ""; + if (character != null) + { + namePrefix = character.nameText + ": "; + } + return namePrefix + "\"" + storyText + "\""; } protected virtual void OnGUI()