Add prompt when dialogue
This commit is contained in:
@@ -19,14 +19,15 @@ namespace Dialogue
|
||||
public class SpeechBubble : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TextMeshProUGUI textDisplay;
|
||||
[SerializeField] private Image imageDisplay; // New field for displaying images
|
||||
[SerializeField] private Image imageDisplay; // For displaying images in dialogue
|
||||
[SerializeField] private Image dialoguePromptImage; // NEW: Reference to the dialogue prompt image
|
||||
[SerializeField] private GameObject dialogueBubble; // NEW: Reference to the dialogue bubble container
|
||||
[SerializeField] private TextDisplayMode displayMode = TextDisplayMode.Typewriter;
|
||||
[SerializeField] private float typewriterSpeed = 0.05f; // Time between characters in seconds
|
||||
[SerializeField] private AudioSource typingSoundSource;
|
||||
[SerializeField] private float typingSoundFrequency = 3; // Play sound every X characters
|
||||
[SerializeField] private bool useRichText = true; // Whether to respect rich text tags
|
||||
[SerializeField] private float dialogueDisplayTime = 1.5f; // Time in seconds to display dialogue before showing prompt
|
||||
[SerializeField] private string dialoguePromptText = ". . ."; // Text to show as a prompt for available dialogue
|
||||
|
||||
private Coroutine typewriterCoroutine;
|
||||
private Coroutine promptUpdateCoroutine;
|
||||
@@ -34,15 +35,22 @@ namespace Dialogue
|
||||
private Sprite currentImage = null;
|
||||
private bool isVisible = false;
|
||||
private DialogueContentType currentContentType = DialogueContentType.Text;
|
||||
private bool isPromptVisible = false; // Track if we're showing the prompt or dialogue
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Ensure we have both components
|
||||
// Ensure we have the required components
|
||||
if (textDisplay == null)
|
||||
Debug.LogError("SpeechBubble: TextMeshProUGUI component is not assigned!");
|
||||
|
||||
if (imageDisplay == null)
|
||||
Debug.LogError("SpeechBubble: Image component is not assigned!");
|
||||
Debug.LogError("SpeechBubble: Image component for dialogue is not assigned!");
|
||||
|
||||
if (dialoguePromptImage == null)
|
||||
Debug.LogError("SpeechBubble: Dialogue prompt image is not assigned!");
|
||||
|
||||
if (dialogueBubble == null)
|
||||
Debug.LogError("SpeechBubble: Dialogue bubble container is not assigned!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -50,16 +58,28 @@ namespace Dialogue
|
||||
/// </summary>
|
||||
public void Show()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
// If we're showing the prompt, we only activate the prompt image
|
||||
if (isPromptVisible)
|
||||
{
|
||||
dialogueBubble.SetActive(false);
|
||||
dialoguePromptImage.gameObject.SetActive(true);
|
||||
}
|
||||
else // Otherwise, show the dialogue bubble
|
||||
{
|
||||
dialogueBubble.SetActive(true);
|
||||
dialoguePromptImage.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
isVisible = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hide the speech bubble
|
||||
/// Hide the speech bubble and prompt
|
||||
/// </summary>
|
||||
public void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
dialogueBubble.SetActive(false);
|
||||
dialoguePromptImage.gameObject.SetActive(false);
|
||||
isVisible = false;
|
||||
|
||||
// Stop any ongoing typewriter effect
|
||||
@@ -102,6 +122,7 @@ namespace Dialogue
|
||||
|
||||
currentFullText = text;
|
||||
currentContentType = DialogueContentType.Text;
|
||||
isPromptVisible = false; // We're showing dialogue, not a prompt
|
||||
|
||||
// Stop any existing typewriter effect
|
||||
if (typewriterCoroutine != null)
|
||||
@@ -110,7 +131,7 @@ namespace Dialogue
|
||||
typewriterCoroutine = null;
|
||||
}
|
||||
|
||||
// Activate text display, deactivate image display
|
||||
// Activate text display, deactivate image display within the dialogue bubble
|
||||
textDisplay.gameObject.SetActive(true);
|
||||
if (imageDisplay != null)
|
||||
{
|
||||
@@ -150,6 +171,7 @@ namespace Dialogue
|
||||
// Display the dialogue line
|
||||
if (!string.IsNullOrEmpty(line))
|
||||
{
|
||||
isPromptVisible = false; // We're showing dialogue content
|
||||
SetText(line);
|
||||
|
||||
// After a delay, update the prompt visibility
|
||||
@@ -163,19 +185,24 @@ namespace Dialogue
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the speech bubble to either show a prompt or hide based on dialogue availability
|
||||
/// Update to either show the dialogue prompt image or hide based on dialogue availability
|
||||
/// </summary>
|
||||
/// <param name="hasDialogueAvailable">Whether dialogue is available</param>
|
||||
public void UpdatePromptVisibility(bool hasDialogueAvailable)
|
||||
{
|
||||
if (hasDialogueAvailable)
|
||||
{
|
||||
Show();
|
||||
SetText(dialoguePromptText);
|
||||
isPromptVisible = true; // We're showing the prompt, not dialogue
|
||||
|
||||
// Hide dialogue bubble, show prompt image
|
||||
dialogueBubble.SetActive(false);
|
||||
dialoguePromptImage.gameObject.SetActive(true);
|
||||
|
||||
isVisible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Hide();
|
||||
Hide(); // Hide both bubble and prompt
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,6 +318,7 @@ namespace Dialogue
|
||||
|
||||
currentImage = sprite;
|
||||
currentContentType = DialogueContentType.Image;
|
||||
isPromptVisible = false; // We're showing dialogue content, not a prompt
|
||||
|
||||
// Activate image display, set the sprite
|
||||
imageDisplay.gameObject.SetActive(true);
|
||||
@@ -364,6 +392,7 @@ namespace Dialogue
|
||||
}
|
||||
|
||||
// Display the content based on its type
|
||||
isPromptVisible = false; // We're showing dialogue content
|
||||
currentContentType = content.ContentType;
|
||||
|
||||
if (content.ContentType == DialogueContentType.Text)
|
||||
@@ -372,6 +401,10 @@ namespace Dialogue
|
||||
textDisplay.gameObject.SetActive(true);
|
||||
if (imageDisplay != null) imageDisplay.gameObject.SetActive(false);
|
||||
|
||||
// Show dialogue bubble, hide prompt
|
||||
dialogueBubble.SetActive(true);
|
||||
dialoguePromptImage.gameObject.SetActive(false);
|
||||
|
||||
// Display the text
|
||||
DisplayDialogueLine(content.Text, hasMoreDialogue);
|
||||
}
|
||||
@@ -381,6 +414,10 @@ namespace Dialogue
|
||||
textDisplay.gameObject.SetActive(false);
|
||||
if (imageDisplay != null) imageDisplay.gameObject.SetActive(true);
|
||||
|
||||
// Show dialogue bubble, hide prompt
|
||||
dialogueBubble.SetActive(true);
|
||||
dialoguePromptImage.gameObject.SetActive(false);
|
||||
|
||||
// Set the image
|
||||
SetImage(content.Image);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user