Mostly working, double invocation of dialogue progression

This commit is contained in:
Michal Pikulski
2025-09-29 00:15:58 +02:00
parent 02031335e3
commit e6cb55975c
9 changed files with 717 additions and 16 deletions

View File

@@ -36,6 +36,7 @@ namespace Dialogue
{
ItemManager.Instance.OnItemPickedUp += OnAnyItemPickedUp;
ItemManager.Instance.OnCorrectItemSlotted += OnAnyItemSlotted;
ItemManager.Instance.OnItemsCombined += OnAnyItemsCombined;
}
speechBubble = GetComponentInChildren<SpeechBubble>();
@@ -86,6 +87,7 @@ namespace Dialogue
{
ItemManager.Instance.OnItemPickedUp -= OnAnyItemPickedUp;
ItemManager.Instance.OnCorrectItemSlotted -= OnAnyItemSlotted;
ItemManager.Instance.OnItemsCombined -= OnAnyItemsCombined;
}
}
@@ -140,7 +142,7 @@ namespace Dialogue
{
currentLine = currentNode.dialogueLines[currentLineIndex];
}
Debug.Log("Returning line: " + currentLine);
// Return the current line
return currentLine;
}
@@ -242,6 +244,15 @@ namespace Dialogue
}
break;
case RuntimeDialogueNodeType.WaitOnCombination:
// Check if the result item is already created through combination
if (IsResultItemCreated(currentNode.combinationResultItemID))
{
// If it's already created, move past this node automatically
MoveToNextNode();
}
break;
case RuntimeDialogueNodeType.End:
// End node, complete the dialogue
IsActive = false;
@@ -269,8 +280,8 @@ namespace Dialogue
MoveToNextNode();
// Notify any listeners about the dialogue change
string line = GetCurrentDialogueLine();
OnDialogueChanged?.Invoke(line);
// string line = GetCurrentDialogueLine();
// OnDialogueChanged?.Invoke(line);
// Update bubble visibility after state change
if (speechBubble != null)
@@ -294,8 +305,8 @@ namespace Dialogue
MoveToNextNode();
// Notify any listeners about the dialogue change
string line = GetCurrentDialogueLine();
OnDialogueChanged?.Invoke(line);
// string line = GetCurrentDialogueLine();
// OnDialogueChanged?.Invoke(line);
// Update bubble visibility after state change
if (speechBubble != null)
@@ -305,14 +316,16 @@ namespace Dialogue
}
// Always check if any dialogue was unblocked by this pickup
if (speechBubble != null)
{
speechBubble.UpdatePromptVisibility(HasAnyLines());
}
// if (speechBubble != null)
// {
// speechBubble.UpdatePromptVisibility(HasAnyLines());
// }
}
private void OnAnyItemSlotted(PickupItemData slotDefinition, PickupItemData slottedItem)
{
Debug.Log("[DialogueComponent] OnAnyItemSlotted");
// Only react if we're active and waiting on a slot
if (!IsActive || IsCompleted || currentNode == null ||
currentNode.nodeType != RuntimeDialogueNodeType.WaitOnSlot)
@@ -325,8 +338,8 @@ namespace Dialogue
MoveToNextNode();
// Notify any listeners about the dialogue change
string line = GetCurrentDialogueLine();
OnDialogueChanged?.Invoke(line);
// string line = GetCurrentDialogueLine();
// OnDialogueChanged?.Invoke(line);
// Update bubble visibility after state change
if (speechBubble != null)
@@ -336,10 +349,41 @@ namespace Dialogue
}
// Always check if any dialogue was unblocked by this slotting
if (speechBubble != null)
// if (speechBubble != null)
// {
// speechBubble.UpdatePromptVisibility(HasAnyLines());
// }
}
private void OnAnyItemsCombined(PickupItemData itemA, PickupItemData itemB, PickupItemData resultItem)
{
// Only react if we're active and waiting on a combination
if (!IsActive || IsCompleted || currentNode == null ||
currentNode.nodeType != RuntimeDialogueNodeType.WaitOnCombination)
return;
// Check if this is the result item we're waiting for
if (resultItem.itemId == currentNode.combinationResultItemID)
{
speechBubble.UpdatePromptVisibility(HasAnyLines());
// Move to next node automatically when condition is met
MoveToNextNode();
// Notify any listeners about the dialogue change
// string line = GetCurrentDialogueLine();
// OnDialogueChanged?.Invoke(line);
// Update bubble visibility after state change
if (speechBubble != null)
{
speechBubble.UpdatePromptVisibility(HasAnyLines());
}
}
// Always check if any dialogue was unblocked by this combination
// if (speechBubble != null)
// {
// speechBubble.UpdatePromptVisibility(HasAnyLines());
// }
}
// Helper methods
@@ -355,6 +399,8 @@ namespace Dialogue
return !IsItemPickedUp(currentNode.pickupItemID);
case RuntimeDialogueNodeType.WaitOnSlot:
return !IsItemSlotted(currentNode.slotItemID);
case RuntimeDialogueNodeType.WaitOnCombination:
return !IsResultItemCreated(currentNode.combinationResultItemID);
default:
return false;
}
@@ -398,6 +444,14 @@ namespace Dialogue
return false;
}
private bool IsResultItemCreated(string resultItemId)
{
if (ItemManager.Instance == null) return false;
// Use the ItemManager's tracking of items created through combination
return ItemManager.Instance.WasItemCreatedThroughCombination(resultItemId);
}
/// <summary>
/// Checks if the dialogue component has any lines available to serve
/// </summary>

View File

@@ -11,6 +11,7 @@ namespace Dialogue
WaitOnPuzzleStep,
WaitOnPickup,
WaitOnSlot,
WaitOnCombination,
End
}
@@ -43,6 +44,7 @@ namespace Dialogue
public string puzzleStepID; // For WaitOnPuzzleStep
public string pickupItemID; // For WaitOnPickup
public string slotItemID; // For WaitOnSlot
public string combinationResultItemID; // For WaitOnCombination
// For WaitOnSlot - different responses
public List<string> incorrectItemLines = new List<string>();