From 05a5dc92687b87ad9eb1e371bdb0aabe65574f94 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Tue, 26 Aug 2014 16:04:00 +0100 Subject: [PATCH] New dialog option buttons --- Assets/Fungus/Dialog/Commands/Say.cs | 110 ++++---- Assets/Fungus/Dialog/Editor.meta | 5 + .../Editor/OptionEditor.cs | 0 .../Editor/OptionEditor.cs.meta | 0 Assets/Fungus/Dialog/Editor/SayEditor.cs | 86 ++++++ .../Editor/SayEditor.cs.meta | 0 Assets/Fungus/Dialog/Scripts/Character.cs | 15 + .../Fungus/Dialog/Scripts/Character.cs.meta | 8 + .../Fungus/Dialog/Scripts/DialogController.cs | 263 +++++++++++------- .../Fungus/FungusScript/Editor/SayEditor.cs | 51 ---- .../FungusScript/Editor/SequenceEditor.cs | 38 +++ Assets/Shuttle/NewDialog.prefab | Bin 0 -> 34784 bytes Assets/Shuttle/NewDialog.prefab.meta | 4 + Assets/Shuttle/NewDialog.unity | Bin 0 -> 57012 bytes Assets/Shuttle/NewDialog.unity.meta | 4 + Assets/Shuttle/ShuttleGame.unity | Bin 123468 -> 123652 bytes 16 files changed, 384 insertions(+), 200 deletions(-) create mode 100644 Assets/Fungus/Dialog/Editor.meta rename Assets/Fungus/{FungusScript => Dialog}/Editor/OptionEditor.cs (100%) rename Assets/Fungus/{FungusScript => Dialog}/Editor/OptionEditor.cs.meta (100%) create mode 100644 Assets/Fungus/Dialog/Editor/SayEditor.cs rename Assets/Fungus/{FungusScript => Dialog}/Editor/SayEditor.cs.meta (100%) create mode 100644 Assets/Fungus/Dialog/Scripts/Character.cs create mode 100644 Assets/Fungus/Dialog/Scripts/Character.cs.meta delete mode 100644 Assets/Fungus/FungusScript/Editor/SayEditor.cs create mode 100644 Assets/Shuttle/NewDialog.prefab create mode 100644 Assets/Shuttle/NewDialog.prefab.meta create mode 100644 Assets/Shuttle/NewDialog.unity create mode 100644 Assets/Shuttle/NewDialog.unity.meta diff --git a/Assets/Fungus/Dialog/Commands/Say.cs b/Assets/Fungus/Dialog/Commands/Say.cs index da1fe1bc..81522cda 100644 --- a/Assets/Fungus/Dialog/Commands/Say.cs +++ b/Assets/Fungus/Dialog/Commands/Say.cs @@ -9,65 +9,33 @@ namespace Fungus.Script [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 { - public enum ShowCondition + public DialogController dialogController; + public Character character; + public string storyText; + public bool displayOnce; + + [Serializable] + public class SayOption { - Always, - Once, - BooleanIsTrue, - BooleanIsFalse + public string optionText; + public Sequence targetSequence; } - - public string character; - public string text; - public ShowCondition showCondition; - public BooleanVariable booleanVariable; + + public List options = new List(); + + public float timeoutDuration; int executionCount; public override void OnEnter() { - Dialog dialog = Game.GetInstance().dialog; - if (dialog == null) + if (dialogController == null) { Continue(); return; } - bool showSayText = true; - - if (showCondition == ShowCondition.Always) - { - // Always show option - } - else if (showCondition == ShowCondition.Once) - { - if (executionCount > 0) - { - showSayText = false; - } - } - else - { - if (booleanVariable == null) - { - showSayText = false; - } - else - { - if (showCondition == ShowCondition.BooleanIsTrue && - booleanVariable.Value != true) - { - showSayText = false; - } - else if (showCondition == ShowCondition.BooleanIsFalse && - booleanVariable.Value != false) - { - showSayText = false; - } - } - } - - if (!showSayText) + if (displayOnce && executionCount > 0) { Continue(); return; @@ -75,19 +43,55 @@ namespace Fungus.Script executionCount++; - if (character.Length > 0) + if (character != null) { - dialog.SetCharacter(character); + dialogController.SetCharacter(character); } - dialog.Say (text, delegate { - Continue(); - }); + if (options.Count > 0) + { + List dialogOptions = new List(); + foreach (SayOption sayOption in options) + { + DialogController.Option dialogOption = new DialogController.Option(); + dialogOption.text = sayOption.optionText; + Sequence onSelectSequence = sayOption.targetSequence; + + dialogOption.onSelect = delegate { + if (onSelectSequence == null) + { + Continue (); + } + else + { + ExecuteSequence(onSelectSequence); + } + }; + + dialogOptions.Add(dialogOption); + } + + dialogController.Say(storyText, dialogOptions); + } + else + { + dialogController.Say(storyText, delegate { + Continue(); + }); + } } public override string GetSummary() { - return "\"" + text + "\""; + return "\"" + storyText + "\""; + } + + public override void GetConnectedSequences (ref List connectedSequences) + { + foreach (SayOption option in options) + { + connectedSequences.Add(option.targetSequence); + } } } diff --git a/Assets/Fungus/Dialog/Editor.meta b/Assets/Fungus/Dialog/Editor.meta new file mode 100644 index 00000000..d054a054 --- /dev/null +++ b/Assets/Fungus/Dialog/Editor.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 805471f08101f4ad8a705fc863435758 +folderAsset: yes +DefaultImporter: + userData: diff --git a/Assets/Fungus/FungusScript/Editor/OptionEditor.cs b/Assets/Fungus/Dialog/Editor/OptionEditor.cs similarity index 100% rename from Assets/Fungus/FungusScript/Editor/OptionEditor.cs rename to Assets/Fungus/Dialog/Editor/OptionEditor.cs diff --git a/Assets/Fungus/FungusScript/Editor/OptionEditor.cs.meta b/Assets/Fungus/Dialog/Editor/OptionEditor.cs.meta similarity index 100% rename from Assets/Fungus/FungusScript/Editor/OptionEditor.cs.meta rename to Assets/Fungus/Dialog/Editor/OptionEditor.cs.meta diff --git a/Assets/Fungus/Dialog/Editor/SayEditor.cs b/Assets/Fungus/Dialog/Editor/SayEditor.cs new file mode 100644 index 00000000..6b8d44c9 --- /dev/null +++ b/Assets/Fungus/Dialog/Editor/SayEditor.cs @@ -0,0 +1,86 @@ +using UnityEditor; +using UnityEditorInternal; +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using Rotorz.ReorderableList; + +namespace Fungus.Script +{ + + [CustomEditor (typeof(Say))] + public class SayEditor : FungusCommandEditor + { + public override void DrawCommandGUI() + { + serializedObject.Update(); + + SerializedProperty optionListProperty = serializedObject.FindProperty("options"); + + Say t = target as Say; + + EditorGUI.BeginChangeCheck(); + + EditorGUILayout.PrefixLabel(new GUIContent("Say Text", "Text to display in dialog")); + GUIStyle sayStyle = new GUIStyle(EditorStyles.textArea); + sayStyle.wordWrap = true; + string text = EditorGUILayout.TextArea(t.storyText, sayStyle, GUILayout.MinHeight(30)); + + DialogController dialogController = EditorGUILayout.ObjectField(new GUIContent("Dialog", "Dialog to display story text with"), + t.dialogController, + typeof(DialogController), true) as DialogController; + + Character character = EditorGUILayout.ObjectField(new GUIContent("Character", "Character to display in dialog"), + t.character, + typeof(Character), true) as Character; + + bool displayOnce = EditorGUILayout.Toggle(new GUIContent("Display Once", "Display this text once and never show it again."), t.displayOnce); + + if (EditorGUI.EndChangeCheck()) + { + Undo.RecordObject(t, "Set Say"); + t.dialogController = dialogController; + t.character = character; + t.storyText = text; + t.displayOnce = displayOnce; + } + + ReorderableListGUI.Title("Options"); + ReorderableListGUI.ListField(optionListProperty); + + serializedObject.ApplyModifiedProperties(); + } + } + + [CustomPropertyDrawer (typeof(Say.SayOption))] + public class SayOptionDrawer : PropertyDrawer + { + public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) + { + EditorGUI.BeginProperty(position, label, property); + + SerializedProperty optionTextProp = property.FindPropertyRelative("optionText"); + SerializedProperty targetSequenceProp = property.FindPropertyRelative("targetSequence"); + + Rect optionTextRect = position; + optionTextRect.width *= 0.5f; + Rect targetSequenceRect = position; + targetSequenceRect.width *= 0.5f; + targetSequenceRect.x += optionTextRect.width; + + FungusScript fungusScript = FungusScriptWindow.GetFungusScript(); + + optionTextProp.stringValue = EditorGUI.TextField(optionTextRect, optionTextProp.stringValue); + if (fungusScript != null) + { + targetSequenceProp.objectReferenceValue = SequenceEditor.SequenceField(targetSequenceRect, + new GUIContent(""), + fungusScript, + targetSequenceProp.objectReferenceValue as Sequence); + } + + EditorGUI.EndProperty(); + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/FungusScript/Editor/SayEditor.cs.meta b/Assets/Fungus/Dialog/Editor/SayEditor.cs.meta similarity index 100% rename from Assets/Fungus/FungusScript/Editor/SayEditor.cs.meta rename to Assets/Fungus/Dialog/Editor/SayEditor.cs.meta diff --git a/Assets/Fungus/Dialog/Scripts/Character.cs b/Assets/Fungus/Dialog/Scripts/Character.cs new file mode 100644 index 00000000..e6cf2de8 --- /dev/null +++ b/Assets/Fungus/Dialog/Scripts/Character.cs @@ -0,0 +1,15 @@ +using UnityEngine; +using System.Collections; + +namespace Fungus.Script +{ + + public class Character : MonoBehaviour + { + public string characterName; + public Sprite characterImage; + public DialogController.DialogSide dialogSide; + public Color characterColor; + } + +} \ No newline at end of file diff --git a/Assets/Fungus/Dialog/Scripts/Character.cs.meta b/Assets/Fungus/Dialog/Scripts/Character.cs.meta new file mode 100644 index 00000000..b3029dac --- /dev/null +++ b/Assets/Fungus/Dialog/Scripts/Character.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 25fb867d2049d41f597aefdd6b19f598 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/Dialog/Scripts/DialogController.cs b/Assets/Fungus/Dialog/Scripts/DialogController.cs index 90697292..051dff1b 100644 --- a/Assets/Fungus/Dialog/Scripts/DialogController.cs +++ b/Assets/Fungus/Dialog/Scripts/DialogController.cs @@ -5,145 +5,216 @@ using System; using System.Collections; using System.Collections.Generic; -public class DialogController : MonoBehaviour +namespace Fungus.Script { - public Sprite testCharacter; - public Canvas dialogCanvas; - public List