From a562d2897adb6e2ab4b97c2ab11e5a1534db91ae Mon Sep 17 00:00:00 2001 From: lealeelu Date: Thu, 2 Mar 2017 00:00:32 -0500 Subject: [PATCH] Move addline to dosay --- .../Fungus/Scripts/Components/NarrativeLog.cs | 29 ++++++++++++++++++- .../Scripts/Components/NarrativeLogMenu.cs | 11 +++++-- Assets/Fungus/Scripts/Components/SayDialog.cs | 2 +- .../Conversation/Say History.unity | 10 +++++-- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/Assets/Fungus/Scripts/Components/NarrativeLog.cs b/Assets/Fungus/Scripts/Components/NarrativeLog.cs index 3c80ad0a..d2b6de6a 100644 --- a/Assets/Fungus/Scripts/Components/NarrativeLog.cs +++ b/Assets/Fungus/Scripts/Components/NarrativeLog.cs @@ -38,6 +38,13 @@ namespace Fungus public class NarrativeLog : MonoBehaviour { + /// + /// NarrativeAdded signal. Sent when a line is added. + /// + public static event NarrativeAddedHandler OnNarrativeAdded; + public delegate void NarrativeAddedHandler(); + public static void DoNarrativeAdded() { if (OnNarrativeAdded != null) OnNarrativeAdded(); } + NarrativeData history; protected virtual void Awake() @@ -45,8 +52,27 @@ namespace Fungus history = new NarrativeData(); } - #region Public Methods + protected virtual void OnEnable() + { + WriterSignals.OnWriterState += OnWriterState; + } + + protected virtual void OnDisable() + { + WriterSignals.OnWriterState -= OnWriterState; + } + + protected virtual void OnWriterState(Writer writer, WriterState writerState) + { + if (writerState == WriterState.End) + { + AddLine(SayDialog.GetSayDialog().NameText.text, + SayDialog.GetSayDialog().StoryText.text); + } + } + #region Public Methods + /// /// Add a line of dialog to the Narrative Log /// @@ -58,6 +84,7 @@ namespace Fungus line.name = name; line.text = text; history.lines.Add(line); + DoNarrativeAdded(); } /// diff --git a/Assets/Fungus/Scripts/Components/NarrativeLogMenu.cs b/Assets/Fungus/Scripts/Components/NarrativeLogMenu.cs index 97866bb6..e80fb6af 100644 --- a/Assets/Fungus/Scripts/Components/NarrativeLogMenu.cs +++ b/Assets/Fungus/Scripts/Components/NarrativeLogMenu.cs @@ -77,6 +77,7 @@ namespace Fungus SaveManagerSignals.OnSavePointLoaded += OnSavePointLoaded; SaveManagerSignals.OnSaveReset += OnSaveReset; BlockSignals.OnBlockEnd += OnBlockEnd; + NarrativeLog.OnNarrativeAdded += OnNarrativeAdded; } protected virtual void OnDisable() @@ -85,11 +86,17 @@ namespace Fungus SaveManagerSignals.OnSavePointLoaded -= OnSavePointLoaded; SaveManagerSignals.OnSaveReset -= OnSaveReset; BlockSignals.OnBlockEnd -= OnBlockEnd; + NarrativeLog.OnNarrativeAdded -= OnNarrativeAdded; + } + + protected virtual void OnNarrativeAdded() + { + UpdateNarrativeLogText(); } protected virtual void OnWriterState(Writer writer, WriterState writerState) { - if (writerState == WriterState.End || writerState == WriterState.Start) + if (writerState == WriterState.Start) { UpdateNarrativeLogText(); } @@ -123,7 +130,7 @@ namespace Fungus var historyText = narrativeLogView.GetComponentInChildren(); if (historyText != null) { - historyText.text = FungusManager.Instance.NarrativeLog.GetPrettyHistory(previousLines); + historyText.text = FungusManager.Instance.NarrativeLog.GetPrettyHistory(); } } } diff --git a/Assets/Fungus/Scripts/Components/SayDialog.cs b/Assets/Fungus/Scripts/Components/SayDialog.cs index 7b36996d..f9380580 100644 --- a/Assets/Fungus/Scripts/Components/SayDialog.cs +++ b/Assets/Fungus/Scripts/Components/SayDialog.cs @@ -25,6 +25,7 @@ namespace Fungus [Tooltip("The name text UI object")] [SerializeField] protected Text nameText; + public virtual Text NameText { get { return nameText; } } [Tooltip("The story text UI object")] [SerializeField] protected Text storyText; @@ -435,7 +436,6 @@ namespace Fungus /// Callback to execute when writing and player input have finished. public virtual void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, Action onComplete) { - FungusManager.Instance.NarrativeLog.AddLine(nameText.text, text); StartCoroutine(DoSay(text, clearPrevious, waitForInput, fadeWhenDone, stopVoiceover, voiceOverClip, onComplete)); } diff --git a/Assets/FungusExamples/Conversation/Say History.unity b/Assets/FungusExamples/Conversation/Say History.unity index 5683c4cb..4f5377cf 100644 --- a/Assets/FungusExamples/Conversation/Say History.unity +++ b/Assets/FungusExamples/Conversation/Say History.unity @@ -2033,7 +2033,7 @@ MonoBehaviour: selectedBlocks: - {fileID: 775007736} selectedCommands: - - {fileID: 775007749} + - {fileID: 775007735} variables: [] description: stepPause: 0 @@ -2058,7 +2058,11 @@ MonoBehaviour: m_EditorClassIdentifier: itemId: 1 indentLevel: 0 - storyText: After Save 1! + storyText: '{b}After Save 1!{/b}{w} + + {color=Blue}What do we do now?{/color} + + {flash=0.5}On to the next save!' description: character: {fileID: 1021439244} portrait: {fileID: 0} @@ -4365,7 +4369,7 @@ MonoBehaviour: m_HandleRect: {fileID: 282981322} m_Direction: 2 m_Value: 1 - m_Size: 0.98689735 + m_Size: 1 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: