Browse Source

Reverted ISayDialog interface

master
Christopher 8 years ago
parent
commit
08110d64d1
  1. 5
      Assets/Fungus/Scripts/Commands/Say.cs
  2. 2
      Assets/Fungus/Scripts/Components/Character.cs
  3. 2
      Assets/Fungus/Scripts/Components/MenuDialog.cs
  4. 55
      Assets/Fungus/Scripts/Components/SayDialog.cs
  5. 75
      Assets/Fungus/Scripts/Interfaces/ISayDialog.cs
  6. 12
      Assets/Fungus/Scripts/Interfaces/ISayDialog.cs.meta
  7. 6
      Assets/Fungus/Scripts/Utils/ConversationManager.cs
  8. 2
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaUtils.cs
  9. 2
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaUtils.cs

5
Assets/Fungus/Scripts/Commands/Say.cs

@ -77,8 +77,7 @@ namespace Fungus.Commands
SayDialog.activeSayDialog = setSayDialog; SayDialog.activeSayDialog = setSayDialog;
} }
ISayDialog sayDialog = SayDialog.GetSayDialog(); var sayDialog = SayDialog.GetSayDialog();
if (sayDialog == null) if (sayDialog == null)
{ {
Continue(); Continue();
@ -136,7 +135,7 @@ namespace Fungus.Commands
public override void OnStopExecuting() public override void OnStopExecuting()
{ {
ISayDialog sayDialog = SayDialog.GetSayDialog(); var sayDialog = SayDialog.GetSayDialog();
if (sayDialog == null) if (sayDialog == null)
{ {
return; return;

2
Assets/Fungus/Scripts/Components/Character.cs

@ -97,7 +97,7 @@ namespace Fungus
/// <summary> /// <summary>
/// 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. /// 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.
/// </summary> /// </summary>
public virtual ISayDialog SetSayDialog { get { return setSayDialog; } } public virtual SayDialog SetSayDialog { get { return setSayDialog; } }
/// <summary> /// <summary>
/// Returns the name of the game object. /// Returns the name of the game object.

2
Assets/Fungus/Scripts/Components/MenuDialog.cs

@ -140,7 +140,7 @@ namespace Fungus
public virtual void HideSayDialog() public virtual void HideSayDialog()
{ {
ISayDialog sayDialog = SayDialog.GetSayDialog(); var sayDialog = SayDialog.GetSayDialog();
if (sayDialog != null) if (sayDialog != null)
{ {
sayDialog.FadeWhenDone = true; sayDialog.FadeWhenDone = true;

55
Assets/Fungus/Scripts/Components/SayDialog.cs

@ -9,9 +9,9 @@ using System.Collections;
namespace Fungus namespace Fungus
{ {
/// <summary> /// <summary>
/// Presents story text to the player in a dialogue box. /// Display story text in a visual novel style dialog box.
/// </summary> /// </summary>
public class SayDialog : MonoBehaviour, ISayDialog public class SayDialog : MonoBehaviour
{ {
[Tooltip("Duration to fade dialogue in/out")] [Tooltip("Duration to fade dialogue in/out")]
[SerializeField] protected float fadeDuration = 0.25f; [SerializeField] protected float fadeDuration = 0.25f;
@ -50,12 +50,12 @@ namespace Fungus
protected Sprite currentCharacterImage; protected Sprite currentCharacterImage;
// Currently active Say Dialog used to display Say text // Currently active Say Dialog used to display Say text
public static ISayDialog activeSayDialog; public static SayDialog activeSayDialog;
// Most recent speaking character // Most recent speaking character
public static Character speakingCharacter; public static Character speakingCharacter;
public static ISayDialog GetSayDialog() public static SayDialog GetSayDialog()
{ {
if (activeSayDialog == null) if (activeSayDialog == null)
{ {
@ -75,7 +75,7 @@ namespace Fungus
GameObject go = Instantiate(prefab) as GameObject; GameObject go = Instantiate(prefab) as GameObject;
go.SetActive(false); go.SetActive(false);
go.name = "SayDialog"; go.name = "SayDialog";
activeSayDialog = go.GetComponent<ISayDialog>(); activeSayDialog = go.GetComponent<SayDialog>();
} }
} }
} }
@ -238,13 +238,21 @@ namespace Fungus
} }
} }
#region ISayDialog implementation #region Public methods
/// <summary>
/// Sets the active state of the Say Dialog gameobject.
/// </summary>
public virtual void SetActive(bool state) public virtual void SetActive(bool state)
{ {
gameObject.SetActive(state); gameObject.SetActive(state);
} }
/// <summary>
/// Sets the active speaking character.
/// </summary>
/// <param name="character">The active speaking character.</param>
/// <param name="flowchart">An optional Flowchart to use for variable substitution in the character name string.</param>
public virtual void SetCharacter(Character character, IFlowchart flowchart = null) public virtual void SetCharacter(Character character, IFlowchart flowchart = null)
{ {
if (character == null) if (character == null)
@ -304,6 +312,9 @@ namespace Fungus
} }
} }
/// <summary>
/// Sets the character image to display on the Say Dialog.
/// </summary>
public virtual void SetCharacterImage(Sprite image) public virtual void SetCharacterImage(Sprite image)
{ {
if (characterImage == null) if (characterImage == null)
@ -356,6 +367,9 @@ namespace Fungus
} }
} }
/// <summary>
/// Sets the character name to display on the Say Dialog.
/// </summary>
public virtual void SetCharacterName(string name, Color color) public virtual void SetCharacterName(string name, Color color)
{ {
if (nameText != null) if (nameText != null)
@ -365,11 +379,31 @@ namespace Fungus
} }
} }
/// <summary>
/// Write a line of story text to the Say Dialog. Starts coroutine automatically.
/// </summary>
/// <param name="text">The text to display.</param>
/// <param name="clearPrevious">Clear any previous text in the Say Dialog.</param>
/// <param name="waitForInput">Wait for player input before continuing once text is written.</param>
/// <param name="fadeWhenDone">Fade out the Say Dialog when writing and player input has finished.</param>
/// <param name="stopVoiceover">Stop any existing voiceover audio before writing starts.</param>
/// <param name="voiceOverClip">Voice over audio clip to play.</param>
/// <param name="onComplete">Callback to execute when writing and player input have finished.</param>
public virtual void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, Action onComplete) 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)); StartCoroutine(DoSay(text, clearPrevious, waitForInput, fadeWhenDone, stopVoiceover, voiceOverClip, onComplete));
} }
/// <summary>
/// Write a line of story text to the Say Dialog. Must be started as a coroutine.
/// </summary>
/// <param name="text">The text to display.</param>
/// <param name="clearPrevious">Clear any previous text in the Say Dialog.</param>
/// <param name="waitForInput">Wait for player input before continuing once text is written.</param>
/// <param name="fadeWhenDone">Fade out the Say Dialog when writing and player input has finished.</param>
/// <param name="stopVoiceover">Stop any existing voiceover audio before writing starts.</param>
/// <param name="voiceOverClip">Voice over audio clip to play.</param>
/// <param name="onComplete">Callback to execute when writing and player input have finished.</param>
public virtual IEnumerator DoSay(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, Action onComplete) public virtual IEnumerator DoSay(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, Action onComplete)
{ {
IWriter writer = GetWriter(); IWriter writer = GetWriter();
@ -403,14 +437,23 @@ namespace Fungus
yield return StartCoroutine(writer.Write(text, clearPrevious, waitForInput, stopVoiceover, soundEffectClip, onComplete)); yield return StartCoroutine(writer.Write(text, clearPrevious, waitForInput, stopVoiceover, soundEffectClip, onComplete));
} }
/// <summary>
/// Tell the Say Dialog to fade out once writing and player input have finished.
/// </summary>
public virtual bool FadeWhenDone { set { fadeWhenDone = value; } } public virtual bool FadeWhenDone { set { fadeWhenDone = value; } }
/// <summary>
/// Stop the Say Dialog while its writing text.
/// </summary>
public virtual void Stop() public virtual void Stop()
{ {
fadeWhenDone = true; fadeWhenDone = true;
GetWriter().Stop(); GetWriter().Stop();
} }
/// <summary>
/// Stops writing text and clears the Say Dialog.
/// </summary>
public virtual void Clear() public virtual void Clear()
{ {
ClearStoryText(); ClearStoryText();

75
Assets/Fungus/Scripts/Interfaces/ISayDialog.cs

@ -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
{
/// <summary>
/// Display story text in a visual novel style dialog box.
/// </summary>
public interface ISayDialog
{
/// <summary>
/// Sets the active state of the Say Dialog gameobject.
/// </summary>
void SetActive(bool state);
/// <summary>
/// Sets the active speaking character.
/// </summary>
/// <param name="character">The active speaking character.</param>
/// <param name="flowchart">An optional Flowchart to use for variable substitution in the character name string.</param>
void SetCharacter(Character character, IFlowchart flowchart = null);
/// <summary>
/// Sets the character image to display on the Say Dialog.
/// </summary>
void SetCharacterImage(Sprite image);
/// <summary>
/// Sets the character name to display on the Say Dialog.
/// </summary>
void SetCharacterName(string name, Color color);
/// <summary>
/// Write a line of story text to the Say Dialog. Starts coroutine automatically.
/// </summary>
/// <param name="text">The text to display.</param>
/// <param name="clearPrevious">Clear any previous text in the Say Dialog.</param>
/// <param name="waitForInput">Wait for player input before continuing once text is written.</param>
/// <param name="fadeWhenDone">Fade out the Say Dialog when writing and player input has finished.</param>
/// <param name="stopVoiceover">Stop any existing voiceover audio before writing starts.</param>
/// <param name="voiceOverClip">Voice over audio clip to play.</param>
/// <param name="onComplete">Callback to execute when writing and player input have finished.</param>
void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, System.Action onComplete);
/// <summary>
/// Write a line of story text to the Say Dialog. Must be started as a coroutine.
/// </summary>
/// <param name="text">The text to display.</param>
/// <param name="clearPrevious">Clear any previous text in the Say Dialog.</param>
/// <param name="waitForInput">Wait for player input before continuing once text is written.</param>
/// <param name="fadeWhenDone">Fade out the Say Dialog when writing and player input has finished.</param>
/// <param name="stopVoiceover">Stop any existing voiceover audio before writing starts.</param>
/// <param name="voiceOverClip">Voice over audio clip to play.</param>
/// <param name="onComplete">Callback to execute when writing and player input have finished.</param>
IEnumerator DoSay(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, System.Action onComplete);
/// <summary>
/// Tell the Say Dialog to fade out once writing and player input have finished.
/// </summary>
bool FadeWhenDone { set; }
/// <summary>
/// Stop the Say Dialog while its writing text.
/// </summary>
void Stop();
/// <summary>
/// Stops writing text and clears the Say Dialog.
/// </summary>
void Clear();
}
}

12
Assets/Fungus/Scripts/Interfaces/ISayDialog.cs.meta

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: a1a9184c86a4048d5973b766e9fd6803
timeCreated: 1473421269
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

6
Assets/Fungus/Scripts/Utils/ConversationManager.cs

@ -73,9 +73,9 @@ namespace Fungus.Utils
return results.ToArray(); return results.ToArray();
} }
protected ISayDialog GetSayDialog(Character character) protected SayDialog GetSayDialog(Character character)
{ {
ISayDialog sayDialog = null; SayDialog sayDialog = null;
if (character != null) if (character != null)
{ {
if (character.SetSayDialog != null) if (character.SetSayDialog != null)
@ -302,7 +302,7 @@ namespace Fungus.Utils
currentPortrait = item.Portrait; currentPortrait = item.Portrait;
currentPosition = item.Position; currentPosition = item.Position;
ISayDialog sayDialog = GetSayDialog(currentCharacter); var sayDialog = GetSayDialog(currentCharacter);
if (sayDialog == null) if (sayDialog == null)
{ {

2
Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaUtils.cs vendored

@ -430,7 +430,7 @@ namespace Fungus
return conversationManager.DoConversation(conv); return conversationManager.DoConversation(conv);
} }
public void SetSayDialog(ISayDialog sayDialog) public void SetSayDialog(SayDialog sayDialog)
{ {
SayDialog.activeSayDialog = sayDialog; SayDialog.activeSayDialog = sayDialog;
} }

2
Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaUtils.cs vendored

@ -85,6 +85,6 @@ namespace Fungus
/// Sync the active say dialog with what Lua thinks the SayDialog should be /// Sync the active say dialog with what Lua thinks the SayDialog should be
/// </summary> /// </summary>
/// <param name="sayDialog"></param> /// <param name="sayDialog"></param>
void SetSayDialog(ISayDialog sayDialog); void SetSayDialog(SayDialog sayDialog);
} }
} }
Loading…
Cancel
Save