AUtoprogress dialogue
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Bootstrap;
|
||||
using Core;
|
||||
using Interactions;
|
||||
using UnityEngine;
|
||||
@@ -46,23 +47,6 @@ namespace Dialogue
|
||||
Debug.LogError("SpeechBubble component is missing on Dialogue Component");
|
||||
}
|
||||
|
||||
// Register for global events
|
||||
if (PuzzleManager.Instance != null)
|
||||
PuzzleManager.Instance.OnStepCompleted += OnAnyPuzzleStepCompleted;
|
||||
|
||||
if (ItemManager.Instance != null)
|
||||
{
|
||||
ItemManager.Instance.OnItemPickedUp += OnAnyItemPickedUp;
|
||||
ItemManager.Instance.OnCorrectItemSlotted += OnAnyItemSlotted;
|
||||
ItemManager.Instance.OnIncorrectItemSlotted += OnAnyIncorrectItemSlotted;
|
||||
ItemManager.Instance.OnForbiddenItemSlotted += OnAnyForbiddenItemSlotted;
|
||||
ItemManager.Instance.OnItemSlotCleared += OnAnyItemSlotCleared;
|
||||
ItemManager.Instance.OnItemsCombined += OnAnyItemsCombined;
|
||||
}
|
||||
|
||||
// Auto-start the dialogue
|
||||
// StartDialogue();
|
||||
|
||||
var interactable = GetComponent<Interactable>();
|
||||
if (interactable != null)
|
||||
{
|
||||
@@ -74,6 +58,20 @@ namespace Dialogue
|
||||
{
|
||||
speechBubble.UpdatePromptVisibility(HasAnyLines());
|
||||
}
|
||||
|
||||
BootCompletionService.RegisterInitAction(InitializePostBoot);
|
||||
}
|
||||
|
||||
private void InitializePostBoot()
|
||||
{
|
||||
// Register for global events
|
||||
PuzzleManager.Instance.OnStepCompleted += OnAnyPuzzleStepCompleted;
|
||||
ItemManager.Instance.OnItemPickedUp += OnAnyItemPickedUp;
|
||||
ItemManager.Instance.OnCorrectItemSlotted += OnAnyItemSlotted;
|
||||
ItemManager.Instance.OnIncorrectItemSlotted += OnAnyIncorrectItemSlotted;
|
||||
ItemManager.Instance.OnForbiddenItemSlotted += OnAnyForbiddenItemSlotted;
|
||||
ItemManager.Instance.OnItemSlotCleared += OnAnyItemSlotCleared;
|
||||
ItemManager.Instance.OnItemsCombined += OnAnyItemsCombined;
|
||||
}
|
||||
|
||||
private void OnCharacterArrived()
|
||||
@@ -457,6 +455,12 @@ namespace Dialogue
|
||||
// Global event handlers
|
||||
private void OnAnyPuzzleStepCompleted(PuzzleStepSO step)
|
||||
{
|
||||
// Initialize if needed
|
||||
if (!initialized)
|
||||
{
|
||||
StartDialogue();
|
||||
}
|
||||
|
||||
// Only react if we're active and waiting on a puzzle step
|
||||
if (!IsActive || IsCompleted || currentNode == null ||
|
||||
currentNode.nodeType != RuntimeDialogueNodeType.WaitOnPuzzleStep)
|
||||
@@ -465,19 +469,21 @@ namespace Dialogue
|
||||
// Check if this is the step we're waiting for
|
||||
if (step.stepId == currentNode.puzzleStepID)
|
||||
{
|
||||
// Instead of immediately moving to the next node, set the flag
|
||||
// Set the flag that condition is satisfied
|
||||
_conditionSatisfiedPendingAdvance = true;
|
||||
|
||||
// Update bubble visibility after state change to show interaction prompt
|
||||
if (speechBubble != null)
|
||||
{
|
||||
speechBubble.UpdatePromptVisibility(HasAnyLines());
|
||||
}
|
||||
UpdateDialogueVisibilityOnItemEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnyItemPickedUp(PickupItemData item)
|
||||
{
|
||||
// Initialize if needed
|
||||
if (!initialized)
|
||||
{
|
||||
StartDialogue();
|
||||
}
|
||||
|
||||
// Only react if we're active and waiting on an item pickup
|
||||
if (!IsActive || IsCompleted || currentNode == null ||
|
||||
currentNode.nodeType != RuntimeDialogueNodeType.WaitOnPickup)
|
||||
@@ -486,14 +492,10 @@ namespace Dialogue
|
||||
// Check if this is the item we're waiting for
|
||||
if (item.itemId == currentNode.pickupItemID)
|
||||
{
|
||||
// Instead of immediately moving to the next node, set the flag
|
||||
// Set the flag that condition is satisfied
|
||||
_conditionSatisfiedPendingAdvance = true;
|
||||
|
||||
// Update bubble visibility after state change to show interaction prompt
|
||||
if (speechBubble != null)
|
||||
{
|
||||
speechBubble.UpdatePromptVisibility(HasAnyLines());
|
||||
}
|
||||
UpdateDialogueVisibilityOnItemEvent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,6 +503,12 @@ namespace Dialogue
|
||||
{
|
||||
Logging.Debug("[DialogueComponent] OnAnyItemSlotted");
|
||||
|
||||
// Initialize if needed
|
||||
if (!initialized)
|
||||
{
|
||||
StartDialogue();
|
||||
}
|
||||
|
||||
// Only react if we're active and waiting on a slot
|
||||
if (!IsActive || IsCompleted || currentNode == null ||
|
||||
currentNode.nodeType != RuntimeDialogueNodeType.WaitOnSlot)
|
||||
@@ -509,19 +517,21 @@ namespace Dialogue
|
||||
// Check if this is the slot we're waiting for
|
||||
if (slotDefinition.itemId == currentNode.slotItemID)
|
||||
{
|
||||
// Instead of immediately moving to the next node, set the flag
|
||||
// Set the flag that condition is satisfied
|
||||
_conditionSatisfiedPendingAdvance = true;
|
||||
|
||||
// Update bubble visibility after state change to show interaction prompt
|
||||
if (speechBubble != null)
|
||||
{
|
||||
speechBubble.UpdatePromptVisibility(HasAnyLines());
|
||||
}
|
||||
UpdateDialogueVisibilityOnItemEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnyItemsCombined(PickupItemData itemA, PickupItemData itemB, PickupItemData resultItem)
|
||||
{
|
||||
// Initialize if needed
|
||||
if (!initialized)
|
||||
{
|
||||
StartDialogue();
|
||||
}
|
||||
|
||||
// Only react if we're active and waiting on a combination
|
||||
if (!IsActive || IsCompleted || currentNode == null ||
|
||||
currentNode.nodeType != RuntimeDialogueNodeType.WaitOnCombination)
|
||||
@@ -530,19 +540,21 @@ namespace Dialogue
|
||||
// Check if this is the result item we're waiting for
|
||||
if (resultItem.itemId == currentNode.combinationResultItemID)
|
||||
{
|
||||
// Instead of immediately moving to the next node, set the flag
|
||||
// Set the flag that condition is satisfied
|
||||
_conditionSatisfiedPendingAdvance = true;
|
||||
|
||||
// Update bubble visibility after state change to show interaction prompt
|
||||
if (speechBubble != null)
|
||||
{
|
||||
speechBubble.UpdatePromptVisibility(HasAnyLines());
|
||||
}
|
||||
UpdateDialogueVisibilityOnItemEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnyIncorrectItemSlotted(PickupItemData slotDefinition, PickupItemData slottedItem)
|
||||
{
|
||||
// Initialize if needed
|
||||
if (!initialized)
|
||||
{
|
||||
StartDialogue();
|
||||
}
|
||||
|
||||
// Update the slot state for displaying the correct dialogue lines
|
||||
if (!IsActive || IsCompleted || currentNode == null)
|
||||
return;
|
||||
@@ -554,16 +566,18 @@ namespace Dialogue
|
||||
_currentSlotState = ItemSlotState.Incorrect;
|
||||
_lastSlottedItem = slottedItem;
|
||||
|
||||
// Trigger dialogue update
|
||||
if (speechBubble != null)
|
||||
{
|
||||
speechBubble.UpdatePromptVisibility(HasAnyLines());
|
||||
}
|
||||
UpdateDialogueVisibilityOnItemEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnyForbiddenItemSlotted(PickupItemData slotDefinition, PickupItemData slottedItem)
|
||||
{
|
||||
// Initialize if needed
|
||||
if (!initialized)
|
||||
{
|
||||
StartDialogue();
|
||||
}
|
||||
|
||||
// Update the slot state for displaying the correct dialogue lines
|
||||
if (!IsActive || IsCompleted || currentNode == null)
|
||||
return;
|
||||
@@ -575,16 +589,18 @@ namespace Dialogue
|
||||
_currentSlotState = ItemSlotState.Forbidden;
|
||||
_lastSlottedItem = slottedItem;
|
||||
|
||||
// Trigger dialogue update
|
||||
if (speechBubble != null)
|
||||
{
|
||||
speechBubble.UpdatePromptVisibility(HasAnyLines());
|
||||
}
|
||||
UpdateDialogueVisibilityOnItemEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnyItemSlotCleared(PickupItemData removedItem)
|
||||
{
|
||||
// Initialize if needed
|
||||
if (!initialized)
|
||||
{
|
||||
StartDialogue();
|
||||
}
|
||||
|
||||
// Update the slot state when an item is removed
|
||||
if (!IsActive || IsCompleted || currentNode == null)
|
||||
return;
|
||||
@@ -594,8 +610,21 @@ namespace Dialogue
|
||||
{
|
||||
_currentSlotState = ItemSlotState.None;
|
||||
_lastSlottedItem = null;
|
||||
|
||||
// Trigger dialogue update
|
||||
|
||||
UpdateDialogueVisibilityOnItemEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDialogueVisibilityOnItemEvent()
|
||||
{
|
||||
// If auto-play is enabled, immediately display dialogue
|
||||
if (currentNode.shouldAutoPlay)
|
||||
{
|
||||
OnCharacterArrived();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Manual mode: just update bubble visibility to show interaction prompt
|
||||
if (speechBubble != null)
|
||||
{
|
||||
speechBubble.UpdatePromptVisibility(HasAnyLines());
|
||||
|
||||
Reference in New Issue
Block a user