First pass on the image drawing

This commit is contained in:
Michal Pikulski
2025-10-08 10:51:14 +02:00
parent d6ed35969d
commit 1a05f89226
12 changed files with 645 additions and 104 deletions

View File

@@ -74,19 +74,86 @@ namespace Dialogue
private void OnCharacterArrived()
{
if (speechBubble == null || ! HasAnyLines()) return;
if (speechBubble == null || !HasAnyLines()) return;
AdvanceDialogueState();
// Get the current dialogue line
string line = GetCurrentDialogueLine();
// Display the line with the new method that handles timed updates
speechBubble.DisplayDialogueLine(line, HasAnyLines());
// Advance dialogue state for next interaction
// Check if we have DialogueContent available
DialogueContent content = GetCurrentDialogueContent();
if (content != null)
{
// Display the content with the new method that handles both text and images
speechBubble.DisplayDialogueContent(content, HasAnyLines());
}
else
{
// Fall back to legacy text-only method
string line = GetCurrentDialogueLine();
speechBubble.DisplayDialogueLine(line, HasAnyLines());
}
}
/// <summary>
/// Get the current dialogue content (text or image)
/// </summary>
/// <returns>DialogueContent or null if only legacy text content is available</returns>
private DialogueContent GetCurrentDialogueContent()
{
// Initialize if needed
if (!initialized)
{
StartDialogue();
}
if (!IsActive || IsCompleted || currentNode == null)
return null;
// Check if we have DialogueContent available
if (currentNode.dialogueContent != null && currentNode.dialogueContent.Count > 0)
{
// For WaitOnSlot nodes, use the appropriate content based on slot state
if (currentNode.nodeType == RuntimeDialogueNodeType.WaitOnSlot)
{
// Choose the appropriate content collection based on the current slot state
List<DialogueContent> contentForState = currentNode.dialogueContent; // Default content
switch (_currentSlotState)
{
case ItemSlotState.Incorrect:
// Use incorrect item content if available
if (currentNode.incorrectItemContent != null && currentNode.incorrectItemContent.Count > 0)
contentForState = currentNode.incorrectItemContent;
break;
case ItemSlotState.Forbidden:
// Use forbidden item content if available
if (currentNode.forbiddenItemContent != null && currentNode.forbiddenItemContent.Count > 0)
contentForState = currentNode.forbiddenItemContent;
break;
}
// If we have content for this state, return the current one
if (contentForState != null && contentForState.Count > 0)
{
// Make sure index is within bounds
int index = Mathf.Clamp(currentLineIndex, 0, contentForState.Count - 1);
return contentForState[index];
}
}
else
{
// For other node types, use the default dialogueContent
if (currentLineIndex >= 0 && currentLineIndex < currentNode.dialogueContent.Count)
{
return currentNode.dialogueContent[currentLineIndex];
}
}
}
// No DialogueContent available, will fall back to legacy text handling
return null;
}
private void OnDestroy()
{
// Unregister from events
@@ -205,7 +272,7 @@ namespace Dialogue
{
if (!IsActive || IsCompleted || currentNode == null)
return;
// If the condition was satisfied earlier, move to the next node immediately
if (_conditionSatisfiedPendingAdvance)
{
@@ -213,21 +280,21 @@ namespace Dialogue
MoveToNextNode();
return;
}
// If we have more lines in the current node, advance to the next line
if (currentLineIndex < currentNode.dialogueLines.Count - 1)
{
currentLineIndex++;
return;
}
// If we should loop through lines, reset the index
if (currentNode.loopThroughLines && currentNode.dialogueLines.Count > 0)
{
currentLineIndex = 0;
return;
}
// If we're at a node that doesn't have a next node, we're done
if (string.IsNullOrEmpty(currentNode.nextNodeID))
{
@@ -235,7 +302,7 @@ namespace Dialogue
IsCompleted = true;
return;
}
// Move to the next node only if no conditions to wait for
if (!IsWaitingForCondition())
{
@@ -560,60 +627,110 @@ namespace Dialogue
// Special case: if condition has been satisfied but not yet advanced, we should show lines
if (_conditionSatisfiedPendingAdvance && !string.IsNullOrEmpty(currentNode.nextNodeID))
{
// Check if the next node would have lines
// Check if the next node would have lines or content
RuntimeDialogueNode nextNode = dialogueGraph.GetNodeByID(currentNode.nextNodeID);
return nextNode != null && (nextNode.dialogueLines.Count > 0 || nextNode.nodeType != RuntimeDialogueNodeType.End);
return nextNode != null &&
((nextNode.dialogueLines != null && nextNode.dialogueLines.Count > 0) ||
(nextNode.dialogueContent != null && nextNode.dialogueContent.Count > 0) ||
nextNode.nodeType != RuntimeDialogueNodeType.End);
}
// For WaitOnSlot nodes, check for lines based on current slot state
// For WaitOnSlot nodes, check for lines or content based on current slot state
if (currentNode.nodeType == RuntimeDialogueNodeType.WaitOnSlot)
{
// Choose the appropriate line collection based on the current slot state
List<string> linesForState = currentNode.dialogueLines; // Default lines
// First check for DialogueContent
if (currentNode.dialogueContent != null && currentNode.dialogueContent.Count > 0)
{
// Choose the appropriate content collection based on the current slot state
List<DialogueContent> contentForState = currentNode.dialogueContent;
switch (_currentSlotState)
{
case ItemSlotState.Incorrect:
if (currentNode.incorrectItemContent != null && currentNode.incorrectItemContent.Count > 0)
contentForState = currentNode.incorrectItemContent;
break;
case ItemSlotState.Forbidden:
if (currentNode.forbiddenItemContent != null && currentNode.forbiddenItemContent.Count > 0)
contentForState = currentNode.forbiddenItemContent;
break;
}
if (contentForState.Count > 0)
{
if (currentLineIndex < contentForState.Count - 1 || currentNode.loopThroughLines)
{
return true;
}
}
}
// Fall back to legacy text lines
List<string> linesForState = currentNode.dialogueLines;
switch (_currentSlotState)
{
case ItemSlotState.Incorrect:
// Use incorrect item lines if available, otherwise fall back to default lines
if (currentNode.incorrectItemLines != null && currentNode.incorrectItemLines.Count > 0)
linesForState = currentNode.incorrectItemLines;
break;
case ItemSlotState.Forbidden:
// Use forbidden item lines if available, otherwise fall back to default lines
if (currentNode.forbiddenItemLines != null && currentNode.forbiddenItemLines.Count > 0)
linesForState = currentNode.forbiddenItemLines;
break;
}
// Check if we have any lines for the current state
if (linesForState != null && linesForState.Count > 0)
{
// If we're not at the end of the lines or we loop through them
if (currentLineIndex < linesForState.Count - 1 || currentNode.loopThroughLines)
{
return true;
}
}
}
// For other node types, use the standard check
else if (currentNode.dialogueLines.Count > 0)
// For other node types, check for DialogueContent first, then fall back to legacy text
else
{
// If we're not at the end of the lines or we loop through them
if (currentLineIndex < currentNode.dialogueLines.Count - 1 || currentNode.loopThroughLines)
// Check for DialogueContent
if (currentNode.dialogueContent != null && currentNode.dialogueContent.Count > 0)
{
return true;
if (currentLineIndex < currentNode.dialogueContent.Count - 1 || currentNode.loopThroughLines)
{
return true;
}
// If we're at the end of content but not waiting for a condition and have a next node
if (!IsWaitingForCondition() && !string.IsNullOrEmpty(currentNode.nextNodeID))
{
RuntimeDialogueNode nextNode = dialogueGraph.GetNodeByID(currentNode.nextNodeID);
return nextNode != null &&
((nextNode.dialogueContent != null && nextNode.dialogueContent.Count > 0) ||
(nextNode.dialogueLines != null && nextNode.dialogueLines.Count > 0) ||
nextNode.nodeType != RuntimeDialogueNodeType.End);
}
}
// If we're at the end of lines but not waiting for a condition and have a next node
if (!IsWaitingForCondition() && !string.IsNullOrEmpty(currentNode.nextNodeID))
// Fall back to legacy text lines
if (currentNode.dialogueLines != null && currentNode.dialogueLines.Count > 0)
{
// We need to check if the next node would have lines
RuntimeDialogueNode nextNode = dialogueGraph.GetNodeByID(currentNode.nextNodeID);
return nextNode != null && (nextNode.dialogueLines.Count > 0 || nextNode.nodeType != RuntimeDialogueNodeType.End);
if (currentLineIndex < currentNode.dialogueLines.Count - 1 || currentNode.loopThroughLines)
{
return true;
}
// If we're at the end of lines but not waiting for a condition and have a next node
if (!IsWaitingForCondition() && !string.IsNullOrEmpty(currentNode.nextNodeID))
{
RuntimeDialogueNode nextNode = dialogueGraph.GetNodeByID(currentNode.nextNodeID);
return nextNode != null &&
((nextNode.dialogueContent != null && nextNode.dialogueContent.Count > 0) ||
(nextNode.dialogueLines != null && nextNode.dialogueLines.Count > 0) ||
nextNode.nodeType != RuntimeDialogueNodeType.End);
}
}
}
return false;
}