From 92a1c696853ac11d7f6548696a4ef3862d626526 Mon Sep 17 00:00:00 2001 From: kabix09 Date: Sat, 24 Dec 2022 20:16:41 +0100 Subject: [PATCH] Dialogues - after fix --- Assets/Scripts/NPCs' Scripts/NPCFollowing.cs | 4 +--- .../Dialogue/Manager/DialogueManager.cs | 15 +++++++++++---- .../Application/NPC/NpcDialogueManager.cs | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/NPCs' Scripts/NPCFollowing.cs b/Assets/Scripts/NPCs' Scripts/NPCFollowing.cs index 1f593d7e..ba51980a 100644 --- a/Assets/Scripts/NPCs' Scripts/NPCFollowing.cs +++ b/Assets/Scripts/NPCs' Scripts/NPCFollowing.cs @@ -29,7 +29,7 @@ public class NPCFollowing : MonoBehaviour // Start is called before the first frame update void Start() { - //isAfterAction = System.Convert.ToBoolean(PlayerPrefs.GetInt(gameObject.GetComponent().name + ".FirstDialogue")); + isAfterAction = System.Convert.ToBoolean(PlayerPrefs.GetInt(gameObject.GetComponent().name + ".FirstDialogue")); myRigidbody = GetComponent(); anim = GetComponent(); @@ -84,8 +84,6 @@ public class NPCFollowing : MonoBehaviour //start dialogue here we want uga bunga gameObject.GetComponent().State = NPCStateEnum.Talking; - - gameObject.GetComponent().OpenDialoguePanel(); } } diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Manager/DialogueManager.cs b/Assets/Scripts/REFACTORING/Application/Dialogue/Manager/DialogueManager.cs index 8a808d5b..81a59a8b 100644 --- a/Assets/Scripts/REFACTORING/Application/Dialogue/Manager/DialogueManager.cs +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Manager/DialogueManager.cs @@ -38,8 +38,6 @@ public class DialogueManager : MonoBehaviour public virtual void Start() { Dialogue = Instantiate(languageDetector.DetectInstanceBasedOnLanguage()); - Dialogue.SetSpeakerName(SpeakerName); - Dialogue.Dialogues.ForEach(dial => dial.Value.SetActionAfterDialogueStep(dial.Key, dial.Value.ResetDialogue)); // reset dial } @@ -47,7 +45,9 @@ public class DialogueManager : MonoBehaviour public void Update() { if (OpenInDefaultWay && Input.GetKeyDown(keyToOpen) && OpenPanelCondition()) + { OpenDialoguePanel(); + } } @@ -76,7 +76,6 @@ public class DialogueManager : MonoBehaviour if (GetCurrentDialoguePanelStatus()) { - Debug.Log("Close dialog - defaulty way"); Dialogue.BreakDialogueStep(); } } @@ -85,7 +84,12 @@ public class DialogueManager : MonoBehaviour public void OpenDialoguePanel() { if(OpenPanelCondition()) + { + // Update speaker name before every opening + Dialogue.SetSpeakerName(SpeakerName); + gameObject.GetComponent().Dialogue.StartDialogue(); + } } public virtual bool OpenPanelCondition() { @@ -101,6 +105,7 @@ public class DialogueManager : MonoBehaviour { return CanBeOpened; } + protected virtual bool ComponentEnabledCondition() { return !gameObject.GetComponent().enabled; @@ -120,7 +125,9 @@ public class DialogueManager : MonoBehaviour .Where(dialogue => dialogue.Key == multiDialStatius.Item1) .First() .Value - .DialogueSteps[multiDialStatius.Item2].DialogueController.CurrentPanel != null; + .DialogueSteps + .ElementAtOrDefault(multiDialStatius.Item2) + ?.DialogueController.CurrentPanel != null; } } diff --git a/Assets/Scripts/REFACTORING/Application/NPC/NpcDialogueManager.cs b/Assets/Scripts/REFACTORING/Application/NPC/NpcDialogueManager.cs index 88aa9623..6fbf70ee 100644 --- a/Assets/Scripts/REFACTORING/Application/NPC/NpcDialogueManager.cs +++ b/Assets/Scripts/REFACTORING/Application/NPC/NpcDialogueManager.cs @@ -13,6 +13,7 @@ public class NpcDialogueManager : DialogueManager base.Start(); CanBeOpened = false; + OpenInDefaultWay = false; } public override bool OpenPanelCondition() {