From 08110d64d19bd7a6e8b06223f35a8e25f1cbe7e0 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 23 Sep 2016 20:57:38 +0100 Subject: [PATCH] Reverted ISayDialog interface --- Assets/Fungus/Scripts/Commands/Say.cs | 5 +- Assets/Fungus/Scripts/Components/Character.cs | 2 +- .../Fungus/Scripts/Components/MenuDialog.cs | 2 +- Assets/Fungus/Scripts/Components/SayDialog.cs | 55 ++++++++++++-- .../Fungus/Scripts/Interfaces/ISayDialog.cs | 75 ------------------- .../Scripts/Interfaces/ISayDialog.cs.meta | 12 --- .../Scripts/Utils/ConversationManager.cs | 6 +- .../FungusLua/Scripts/Components/LuaUtils.cs | 2 +- .../FungusLua/Scripts/Interfaces/ILuaUtils.cs | 2 +- 9 files changed, 58 insertions(+), 103 deletions(-) delete mode 100644 Assets/Fungus/Scripts/Interfaces/ISayDialog.cs delete mode 100644 Assets/Fungus/Scripts/Interfaces/ISayDialog.cs.meta diff --git a/Assets/Fungus/Scripts/Commands/Say.cs b/Assets/Fungus/Scripts/Commands/Say.cs index 2e660900..f322d648 100644 --- a/Assets/Fungus/Scripts/Commands/Say.cs +++ b/Assets/Fungus/Scripts/Commands/Say.cs @@ -77,8 +77,7 @@ namespace Fungus.Commands SayDialog.activeSayDialog = setSayDialog; } - ISayDialog sayDialog = SayDialog.GetSayDialog(); - + var sayDialog = SayDialog.GetSayDialog(); if (sayDialog == null) { Continue(); @@ -136,7 +135,7 @@ namespace Fungus.Commands public override void OnStopExecuting() { - ISayDialog sayDialog = SayDialog.GetSayDialog(); + var sayDialog = SayDialog.GetSayDialog(); if (sayDialog == null) { return; diff --git a/Assets/Fungus/Scripts/Components/Character.cs b/Assets/Fungus/Scripts/Components/Character.cs index c606ff05..45d1125b 100644 --- a/Assets/Fungus/Scripts/Components/Character.cs +++ b/Assets/Fungus/Scripts/Components/Character.cs @@ -97,7 +97,7 @@ namespace Fungus /// /// Sets the active Say dialog with a reference to a Say Dialog object in the scene. This Say Dialog will be used whenever the character speaks. /// - public virtual ISayDialog SetSayDialog { get { return setSayDialog; } } + public virtual SayDialog SetSayDialog { get { return setSayDialog; } } /// /// Returns the name of the game object. diff --git a/Assets/Fungus/Scripts/Components/MenuDialog.cs b/Assets/Fungus/Scripts/Components/MenuDialog.cs index 3a081fd0..6fa6c7b2 100644 --- a/Assets/Fungus/Scripts/Components/MenuDialog.cs +++ b/Assets/Fungus/Scripts/Components/MenuDialog.cs @@ -140,7 +140,7 @@ namespace Fungus public virtual void HideSayDialog() { - ISayDialog sayDialog = SayDialog.GetSayDialog(); + var sayDialog = SayDialog.GetSayDialog(); if (sayDialog != null) { sayDialog.FadeWhenDone = true; diff --git a/Assets/Fungus/Scripts/Components/SayDialog.cs b/Assets/Fungus/Scripts/Components/SayDialog.cs index 6b18ccf0..fcd5b491 100644 --- a/Assets/Fungus/Scripts/Components/SayDialog.cs +++ b/Assets/Fungus/Scripts/Components/SayDialog.cs @@ -9,9 +9,9 @@ using System.Collections; namespace Fungus { /// - /// Presents story text to the player in a dialogue box. + /// Display story text in a visual novel style dialog box. /// - public class SayDialog : MonoBehaviour, ISayDialog + public class SayDialog : MonoBehaviour { [Tooltip("Duration to fade dialogue in/out")] [SerializeField] protected float fadeDuration = 0.25f; @@ -50,12 +50,12 @@ namespace Fungus protected Sprite currentCharacterImage; // Currently active Say Dialog used to display Say text - public static ISayDialog activeSayDialog; + public static SayDialog activeSayDialog; // Most recent speaking character public static Character speakingCharacter; - public static ISayDialog GetSayDialog() + public static SayDialog GetSayDialog() { if (activeSayDialog == null) { @@ -75,7 +75,7 @@ namespace Fungus GameObject go = Instantiate(prefab) as GameObject; go.SetActive(false); go.name = "SayDialog"; - activeSayDialog = go.GetComponent(); + activeSayDialog = go.GetComponent(); } } } @@ -238,13 +238,21 @@ namespace Fungus } } - #region ISayDialog implementation + #region Public methods + /// + /// Sets the active state of the Say Dialog gameobject. + /// public virtual void SetActive(bool state) { gameObject.SetActive(state); } + /// + /// Sets the active speaking character. + /// + /// The active speaking character. + /// An optional Flowchart to use for variable substitution in the character name string. public virtual void SetCharacter(Character character, IFlowchart flowchart = null) { if (character == null) @@ -304,6 +312,9 @@ namespace Fungus } } + /// + /// Sets the character image to display on the Say Dialog. + /// public virtual void SetCharacterImage(Sprite image) { if (characterImage == null) @@ -356,6 +367,9 @@ namespace Fungus } } + /// + /// Sets the character name to display on the Say Dialog. + /// public virtual void SetCharacterName(string name, Color color) { if (nameText != null) @@ -365,11 +379,31 @@ namespace Fungus } } + /// + /// Write a line of story text to the Say Dialog. Starts coroutine automatically. + /// + /// The text to display. + /// Clear any previous text in the Say Dialog. + /// Wait for player input before continuing once text is written. + /// Fade out the Say Dialog when writing and player input has finished. + /// Stop any existing voiceover audio before writing starts. + /// Voice over audio clip to play. + /// Callback to execute when writing and player input have finished. public virtual void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, Action onComplete) { StartCoroutine(DoSay(text, clearPrevious, waitForInput, fadeWhenDone, stopVoiceover, voiceOverClip, onComplete)); } + /// + /// Write a line of story text to the Say Dialog. Must be started as a coroutine. + /// + /// The text to display. + /// Clear any previous text in the Say Dialog. + /// Wait for player input before continuing once text is written. + /// Fade out the Say Dialog when writing and player input has finished. + /// Stop any existing voiceover audio before writing starts. + /// Voice over audio clip to play. + /// Callback to execute when writing and player input have finished. public virtual IEnumerator DoSay(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, Action onComplete) { IWriter writer = GetWriter(); @@ -403,14 +437,23 @@ namespace Fungus yield return StartCoroutine(writer.Write(text, clearPrevious, waitForInput, stopVoiceover, soundEffectClip, onComplete)); } + /// + /// Tell the Say Dialog to fade out once writing and player input have finished. + /// public virtual bool FadeWhenDone { set { fadeWhenDone = value; } } + /// + /// Stop the Say Dialog while its writing text. + /// public virtual void Stop() { fadeWhenDone = true; GetWriter().Stop(); } + /// + /// Stops writing text and clears the Say Dialog. + /// public virtual void Clear() { ClearStoryText(); diff --git a/Assets/Fungus/Scripts/Interfaces/ISayDialog.cs b/Assets/Fungus/Scripts/Interfaces/ISayDialog.cs deleted file mode 100644 index b5b060ad..00000000 --- a/Assets/Fungus/Scripts/Interfaces/ISayDialog.cs +++ /dev/null @@ -1,75 +0,0 @@ -// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus). -// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) - -using UnityEngine; -using System.Collections; - -namespace Fungus -{ - /// - /// Display story text in a visual novel style dialog box. - /// - public interface ISayDialog - { - /// - /// Sets the active state of the Say Dialog gameobject. - /// - void SetActive(bool state); - - /// - /// Sets the active speaking character. - /// - /// The active speaking character. - /// An optional Flowchart to use for variable substitution in the character name string. - void SetCharacter(Character character, IFlowchart flowchart = null); - - /// - /// Sets the character image to display on the Say Dialog. - /// - void SetCharacterImage(Sprite image); - - /// - /// Sets the character name to display on the Say Dialog. - /// - void SetCharacterName(string name, Color color); - - /// - /// Write a line of story text to the Say Dialog. Starts coroutine automatically. - /// - /// The text to display. - /// Clear any previous text in the Say Dialog. - /// Wait for player input before continuing once text is written. - /// Fade out the Say Dialog when writing and player input has finished. - /// Stop any existing voiceover audio before writing starts. - /// Voice over audio clip to play. - /// Callback to execute when writing and player input have finished. - void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, System.Action onComplete); - - /// - /// Write a line of story text to the Say Dialog. Must be started as a coroutine. - /// - /// The text to display. - /// Clear any previous text in the Say Dialog. - /// Wait for player input before continuing once text is written. - /// Fade out the Say Dialog when writing and player input has finished. - /// Stop any existing voiceover audio before writing starts. - /// Voice over audio clip to play. - /// Callback to execute when writing and player input have finished. - IEnumerator DoSay(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, System.Action onComplete); - - /// - /// Tell the Say Dialog to fade out once writing and player input have finished. - /// - bool FadeWhenDone { set; } - - /// - /// Stop the Say Dialog while its writing text. - /// - void Stop(); - - /// - /// Stops writing text and clears the Say Dialog. - /// - void Clear(); - } -} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Interfaces/ISayDialog.cs.meta b/Assets/Fungus/Scripts/Interfaces/ISayDialog.cs.meta deleted file mode 100644 index ce474358..00000000 --- a/Assets/Fungus/Scripts/Interfaces/ISayDialog.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: a1a9184c86a4048d5973b766e9fd6803 -timeCreated: 1473421269 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Utils/ConversationManager.cs b/Assets/Fungus/Scripts/Utils/ConversationManager.cs index 759c95ec..99f27993 100644 --- a/Assets/Fungus/Scripts/Utils/ConversationManager.cs +++ b/Assets/Fungus/Scripts/Utils/ConversationManager.cs @@ -73,9 +73,9 @@ namespace Fungus.Utils return results.ToArray(); } - protected ISayDialog GetSayDialog(Character character) + protected SayDialog GetSayDialog(Character character) { - ISayDialog sayDialog = null; + SayDialog sayDialog = null; if (character != null) { if (character.SetSayDialog != null) @@ -302,7 +302,7 @@ namespace Fungus.Utils currentPortrait = item.Portrait; currentPosition = item.Position; - ISayDialog sayDialog = GetSayDialog(currentCharacter); + var sayDialog = GetSayDialog(currentCharacter); if (sayDialog == null) { diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaUtils.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaUtils.cs index 553d6d22..8c25d9ad 100644 --- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaUtils.cs +++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaUtils.cs @@ -430,7 +430,7 @@ namespace Fungus return conversationManager.DoConversation(conv); } - public void SetSayDialog(ISayDialog sayDialog) + public void SetSayDialog(SayDialog sayDialog) { SayDialog.activeSayDialog = sayDialog; } diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaUtils.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaUtils.cs index 0908842c..73e9ddaa 100644 --- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaUtils.cs +++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaUtils.cs @@ -85,6 +85,6 @@ namespace Fungus /// Sync the active say dialog with what Lua thinks the SayDialog should be /// /// - void SetSayDialog(ISayDialog sayDialog); + void SetSayDialog(SayDialog sayDialog); } } \ No newline at end of file