|
|
@ -6,10 +6,7 @@ using System.Text; |
|
|
|
|
|
|
|
|
|
|
|
namespace Fungus |
|
|
|
namespace Fungus |
|
|
|
{ |
|
|
|
{ |
|
|
|
/// <summary> |
|
|
|
public class ConversationManager : IConversationManager |
|
|
|
/// Helper class to manage parsing and executing the conversation format. |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
public class ConversationManager |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
protected struct ConversationItem |
|
|
|
protected struct ConversationItem |
|
|
|
{ |
|
|
|
{ |
|
|
@ -26,12 +23,6 @@ namespace Fungus |
|
|
|
|
|
|
|
|
|
|
|
protected bool exitSayWait; |
|
|
|
protected bool exitSayWait; |
|
|
|
|
|
|
|
|
|
|
|
public void PopulateCharacterCache() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// cache characters for faster lookup |
|
|
|
|
|
|
|
characters = UnityEngine.Object.FindObjectsOfType<Character>(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected ISayDialog GetSayDialog(Character character) |
|
|
|
protected ISayDialog GetSayDialog(Character character) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ISayDialog sayDialog = null; |
|
|
|
ISayDialog sayDialog = null; |
|
|
@ -51,115 +42,6 @@ namespace Fungus |
|
|
|
return sayDialog; |
|
|
|
return sayDialog; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Parse and execute a conversation string |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="conv"></param> |
|
|
|
|
|
|
|
public IEnumerator DoConversation(string conv) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(conv)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
yield break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var conversationItems = Parse(conv); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (conversationItems.Count == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
yield break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Track the current and previous parameter values |
|
|
|
|
|
|
|
Character currentCharacter = null; |
|
|
|
|
|
|
|
Sprite currentPortrait = null; |
|
|
|
|
|
|
|
RectTransform currentPosition = null; |
|
|
|
|
|
|
|
Character previousCharacter = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Play the conversation |
|
|
|
|
|
|
|
for (int i = 0; i < conversationItems.Count; ++i) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ConversationItem item = conversationItems[i]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (item.Character != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
currentCharacter = item.Character; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
currentPortrait = item.Portrait; |
|
|
|
|
|
|
|
currentPosition = item.Position; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ISayDialog sayDialog = GetSayDialog(currentCharacter); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sayDialog == null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Should never happen |
|
|
|
|
|
|
|
yield break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sayDialog.SetActive(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentCharacter != null && |
|
|
|
|
|
|
|
currentCharacter != previousCharacter) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
sayDialog.SetCharacter(currentCharacter); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var stage = Stage.GetActiveStage(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stage != null && currentCharacter != null && |
|
|
|
|
|
|
|
(currentPortrait != currentCharacter.State.portrait || |
|
|
|
|
|
|
|
currentPosition != currentCharacter.State.position)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var portraitOptions = new PortraitOptions(true); |
|
|
|
|
|
|
|
portraitOptions.display = item.Hide ? DisplayType.Hide : DisplayType.Show; |
|
|
|
|
|
|
|
portraitOptions.character = currentCharacter; |
|
|
|
|
|
|
|
portraitOptions.fromPosition = currentCharacter.State.position; |
|
|
|
|
|
|
|
portraitOptions.toPosition = currentPosition; |
|
|
|
|
|
|
|
portraitOptions.portrait = currentPortrait; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Flip option - Flip the opposite direction the character is currently facing |
|
|
|
|
|
|
|
if (item.Flip) portraitOptions.facing = item.FacingDirection; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Do a move tween if the character is already on screen and not yet at the specified position |
|
|
|
|
|
|
|
if (currentCharacter.State.onScreen && |
|
|
|
|
|
|
|
currentPosition != currentCharacter.State.position) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
portraitOptions.move = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (item.Hide) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
stage.Hide(portraitOptions); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
stage.Show(portraitOptions); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stage == null && |
|
|
|
|
|
|
|
currentPortrait != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
sayDialog.SetCharacterImage(currentPortrait); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
previousCharacter = currentCharacter; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(item.Text)) { |
|
|
|
|
|
|
|
exitSayWait = false; |
|
|
|
|
|
|
|
sayDialog.Say(item.Text, true, true, true, false, null, () => { |
|
|
|
|
|
|
|
exitSayWait = true; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (!exitSayWait) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
yield return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
exitSayWait = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual List<ConversationItem> Parse(string conv) |
|
|
|
protected virtual List<ConversationItem> Parse(string conv) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//find SimpleScript say strings with portrait options |
|
|
|
//find SimpleScript say strings with portrait options |
|
|
@ -372,5 +254,120 @@ namespace Fungus |
|
|
|
|
|
|
|
|
|
|
|
return results.ToArray(); |
|
|
|
return results.ToArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region IConversationManager |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void PopulateCharacterCache() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// cache characters for faster lookup |
|
|
|
|
|
|
|
characters = UnityEngine.Object.FindObjectsOfType<Character>(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerator DoConversation(string conv) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(conv)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
yield break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var conversationItems = Parse(conv); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (conversationItems.Count == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
yield break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Track the current and previous parameter values |
|
|
|
|
|
|
|
Character currentCharacter = null; |
|
|
|
|
|
|
|
Sprite currentPortrait = null; |
|
|
|
|
|
|
|
RectTransform currentPosition = null; |
|
|
|
|
|
|
|
Character previousCharacter = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Play the conversation |
|
|
|
|
|
|
|
for (int i = 0; i < conversationItems.Count; ++i) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ConversationItem item = conversationItems[i]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (item.Character != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
currentCharacter = item.Character; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
currentPortrait = item.Portrait; |
|
|
|
|
|
|
|
currentPosition = item.Position; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ISayDialog sayDialog = GetSayDialog(currentCharacter); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sayDialog == null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Should never happen |
|
|
|
|
|
|
|
yield break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sayDialog.SetActive(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentCharacter != null && |
|
|
|
|
|
|
|
currentCharacter != previousCharacter) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
sayDialog.SetCharacter(currentCharacter); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var stage = Stage.GetActiveStage(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stage != null && currentCharacter != null && |
|
|
|
|
|
|
|
(currentPortrait != currentCharacter.State.portrait || |
|
|
|
|
|
|
|
currentPosition != currentCharacter.State.position)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var portraitOptions = new PortraitOptions(true); |
|
|
|
|
|
|
|
portraitOptions.display = item.Hide ? DisplayType.Hide : DisplayType.Show; |
|
|
|
|
|
|
|
portraitOptions.character = currentCharacter; |
|
|
|
|
|
|
|
portraitOptions.fromPosition = currentCharacter.State.position; |
|
|
|
|
|
|
|
portraitOptions.toPosition = currentPosition; |
|
|
|
|
|
|
|
portraitOptions.portrait = currentPortrait; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Flip option - Flip the opposite direction the character is currently facing |
|
|
|
|
|
|
|
if (item.Flip) portraitOptions.facing = item.FacingDirection; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Do a move tween if the character is already on screen and not yet at the specified position |
|
|
|
|
|
|
|
if (currentCharacter.State.onScreen && |
|
|
|
|
|
|
|
currentPosition != currentCharacter.State.position) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
portraitOptions.move = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (item.Hide) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
stage.Hide(portraitOptions); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
stage.Show(portraitOptions); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stage == null && |
|
|
|
|
|
|
|
currentPortrait != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
sayDialog.SetCharacterImage(currentPortrait); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
previousCharacter = currentCharacter; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(item.Text)) { |
|
|
|
|
|
|
|
exitSayWait = false; |
|
|
|
|
|
|
|
sayDialog.Say(item.Text, true, true, true, false, null, () => { |
|
|
|
|
|
|
|
exitSayWait = true; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (!exitSayWait) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
yield return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
exitSayWait = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|