An easy to use Unity 3D library for creating illustrated Interactive Fiction games and more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
3.6 KiB

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
namespace Fungus
{
[CommandInfo("Narrative",
"Say",
"Writes text in a dialog box.")]
[AddComponentMenu("")]
public class Say : Command, ILocalizable
{
// Removed this tooltip as users's reported it obscures the text box
[TextArea(5,10)]
public string storyText = "";
[Tooltip("Notes about this story text for other authors, localization, etc.")]
public string description = "";
[Tooltip("Character that is speaking")]
public Character character;
[Tooltip("Portrait that represents speaking character")]
public Sprite portrait;
[Tooltip("Voiceover audio to play when writing the text")]
public AudioClip voiceOverClip;
[Tooltip("Always show this Say text when the command is executed multiple times")]
public bool showAlways = true;
[Tooltip("Number of times to show this Say text when the command is executed multiple times")]
public int showCount = 1;
[Tooltip("Type this text in the previous dialog box.")]
public bool extendPrevious = false;
[Tooltip("Fade out the dialog box when writing has finished and not waiting for input.")]
public bool fadeWhenDone = true;
[Tooltip("Wait for player to click before continuing.")]
public bool waitForClick = true;
[Tooltip("Sets the active Say dialog with a reference to a Say Dialog object in the scene. All story text will now display using this Say Dialog.")]
public SayDialog setSayDialog;
protected int executionCount;
public override void OnEnter()
{
if (!showAlways && executionCount >= showCount)
{
Continue();
return;
}
executionCount++;
// Override the active say dialog if needed
if (setSayDialog != null)
{
SayDialog.activeSayDialog = setSayDialog;
}
SayDialog sayDialog = SayDialog.GetSayDialog();
if (sayDialog == null)
{
Continue();
return;
}
Flowchart flowchart = GetFlowchart();
sayDialog.SetCharacter(character, flowchart);
sayDialog.SetCharacterImage(portrait);
sayDialog.gameObject.SetActive(true);
string displayText = storyText;
foreach (CustomTag ct in CustomTag.activeCustomTags)
{
displayText = displayText.Replace(ct.tagStartSymbol, ct.replaceTagStartWith);
if (ct.tagEndSymbol != "" && ct.replaceTagEndWith != "")
{
displayText = displayText.Replace(ct.tagEndSymbol, ct.replaceTagEndWith);
}
}
string subbedText = flowchart.SubstituteVariables(displayText);
sayDialog.Say(subbedText, !extendPrevious, waitForClick, fadeWhenDone, voiceOverClip, delegate {
Continue();
});
}
public override string GetSummary()
{
string namePrefix = "";
if (character != null)
{
namePrefix = character.nameText + ": ";
}
if (extendPrevious)
{
namePrefix = "EXTEND" + ": ";
}
return namePrefix + "\"" + storyText + "\"";
}
public override Color GetButtonColor()
{
return new Color32(184, 210, 235, 255);
}
public override void OnReset()
{
executionCount = 0;
}
//
// ILocalizable implementation
//
public virtual string GetStandardText()
{
return storyText;
}
public virtual void SetStandardText(string standardText)
{
storyText = standardText;
}
public virtual string GetDescription()
{
return description;
}
public virtual string GetStringId()
{
// String id for Say commands is SAY.<Localization Id>.<Command id>.[Character Name]
string stringId = "SAY." + GetFlowchartLocalizationId() + "." + itemId + ".";
if (character != null)
{
stringId += character.nameText;
}
return stringId;
}
}
}