Browse Source

Added Stop() method to Say Dialog and Writer

Can now stop writing mid sentence
master
chrisgregan 10 years ago
parent
commit
716ee5bf2b
  1. 12
      Assets/Fungus/Narrative/Scripts/SayDialog.cs
  2. 21
      Assets/Fungus/UI/Scripts/Writer.cs
  3. 1521
      Assets/Tests/Narrative/NarrativeTests.unity

12
Assets/Fungus/Narrative/Scripts/SayDialog.cs

@ -138,11 +138,23 @@ namespace Fungus
} }
} }
/**
* Tell dialog to fade out if it's finished writing.
*/
public virtual void FadeOut() public virtual void FadeOut()
{ {
fadeWhenDone = true; fadeWhenDone = true;
} }
/**
* Stop a Say Dialog while its writing text.
*/
public virtual void Stop()
{
fadeWhenDone = true;
GetWriter().Stop();
}
protected virtual void UpdateAlpha() protected virtual void UpdateAlpha()
{ {
if (GetWriter().isWriting) if (GetWriter().isWriting)

21
Assets/Fungus/UI/Scripts/Writer.cs

@ -64,6 +64,7 @@ namespace Fungus
protected bool colorActive = false; protected bool colorActive = false;
protected string colorText = ""; protected string colorText = "";
protected bool inputFlag; protected bool inputFlag;
protected bool exitFlag;
protected List<IWriterListener> writerListeners = new List<IWriterListener>(); protected List<IWriterListener> writerListeners = new List<IWriterListener>();
@ -237,7 +238,12 @@ namespace Fungus
textMesh.color = tempColor; textMesh.color = tempColor;
} }
} }
public virtual void Stop()
{
exitFlag = true;
}
public virtual void Write(string content, bool clear, bool waitForInput, AudioClip audioClip, Action onComplete) public virtual void Write(string content, bool clear, bool waitForInput, AudioClip audioClip, Action onComplete)
{ {
if (clear) if (clear)
@ -275,11 +281,11 @@ namespace Fungus
currentPunctuationPause = punctuationPause; currentPunctuationPause = punctuationPause;
currentWritingSpeed = writingSpeed; currentWritingSpeed = writingSpeed;
exitFlag = false;
isWriting = true; isWriting = true;
foreach (TextTagParser.Token token in tokens) foreach (TextTagParser.Token token in tokens)
{ {
bool exit = false;
switch (token.type) switch (token.type)
{ {
@ -351,7 +357,7 @@ namespace Fungus
break; break;
case TextTagParser.TokenType.Exit: case TextTagParser.TokenType.Exit:
exit = true; exitFlag = true;
break; break;
case TextTagParser.TokenType.Message: case TextTagParser.TokenType.Message:
@ -436,13 +442,14 @@ namespace Fungus
break; break;
} }
if (exit) if (exitFlag)
{ {
break; break;
} }
} }
inputFlag = false; inputFlag = false;
exitFlag = false;
isWriting = false; isWriting = false;
NotifyEnd(); NotifyEnd();
@ -463,6 +470,12 @@ namespace Fungus
for (int i = 0; i < param.Length; ++i) for (int i = 0; i < param.Length; ++i)
{ {
// Exit immediately if the exit flag has been set
if (exitFlag)
{
break;
}
string left = ""; string left = "";
string right = ""; string right = "";

1521
Assets/Tests/Narrative/NarrativeTests.unity

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save