Browse Source

Separate NarrativeLogMenu from SaveMenu

master
lealeelu 8 years ago
parent
commit
12fc2081f5
  1. 15
      Assets/Fungus/Scripts/Components/NarrativeLog.cs
  2. 152
      Assets/Fungus/Scripts/Components/NarrativeLogMenu.cs
  3. 12
      Assets/Fungus/Scripts/Components/NarrativeLogMenu.cs.meta
  4. 6
      Assets/Fungus/Scripts/Components/SaveData.cs
  5. 80
      Assets/Fungus/Scripts/Components/SaveMenu.cs
  6. 2
      Assets/Fungus/Scripts/Signals/WriterSignals.cs
  7. 2
      Assets/Fungus/Scripts/Utils/SaveHistory.cs
  8. 20
      Assets/FungusExamples/Conversation/Say History.unity

15
Assets/Fungus/Scripts/Components/NarrativeLog.cs

@ -45,21 +45,6 @@ namespace Fungus
history = new NarrativeData();
}
protected virtual void OnEnable()
{
SaveManagerSignals.OnSaveReset += OnSaveReset;
}
protected virtual void OnDisable()
{
SaveManagerSignals.OnSaveReset -= OnSaveReset;
}
protected virtual void OnSaveReset()
{
Clear();
}
#region Public Methods
/// <summary>

152
Assets/Fungus/Scripts/Components/NarrativeLogMenu.cs

@ -0,0 +1,152 @@
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
#if UNITY_5_3_OR_NEWER
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
namespace Fungus
{
/// <summary>
/// A singleton game object which displays a simple UI for the Narrative Log.
/// </summary>
public class NarrativeLogMenu : MonoBehaviour
{
[Tooltip("The button that shows conversation history.")]
[SerializeField] protected Button narrativeLogButton;
[Tooltip("A scrollable text field used for displaying conversation history.")]
[SerializeField] protected ScrollRect narrativeLogView;
[Tooltip("The CanvasGroup containing the save menu buttons")]
[SerializeField] protected CanvasGroup narrativeLogMenuGroup;
protected static bool narrativeLogActive = false;
protected AudioSource clickAudioSource;
protected LTDescr fadeTween;
protected static NarrativeLogMenu instance;
protected virtual void Awake()
{
// Only one instance of NarrativeLogMenu may exist
if (instance != null)
{
Destroy(gameObject);
return;
}
instance = this;
GameObject.DontDestroyOnLoad(this);
clickAudioSource = GetComponent<AudioSource>();
}
protected virtual void Start()
{
if (!narrativeLogActive)
{
narrativeLogMenuGroup.alpha = 0f;
}
//Clear up the lorem ipsum
UpdateNarrativeLogText();
}
protected virtual void OnEnable()
{
WriterSignals.OnWriterState += OnWriterState;
SaveManagerSignals.OnSavePointLoaded += OnSavePointLoaded;
SaveManagerSignals.OnSaveReset += OnSaveReset;
}
protected virtual void OnDisable()
{
WriterSignals.OnWriterState -= OnWriterState;
SaveManagerSignals.OnSavePointLoaded -= OnSavePointLoaded;
SaveManagerSignals.OnSaveReset -= OnSaveReset;
}
protected virtual void OnWriterState(Writer writer, WriterState writerState)
{
if (writerState == WriterState.End || writerState == WriterState.Start)
{
UpdateNarrativeLogText();
}
}
protected virtual void OnSavePointLoaded(string savePointKey)
{
UpdateNarrativeLogText();
}
protected virtual void OnSaveReset()
{
FungusManager.Instance.NarrativeLog.Clear();
UpdateNarrativeLogText();
}
protected void UpdateNarrativeLogText()
{
if (narrativeLogView.enabled)
{
Debug.Log("Update NarrativeLog");
var historyText = narrativeLogView.GetComponentInChildren<Text>();
if (historyText != null)
{
historyText.text = FungusManager.Instance.NarrativeLog.GetPrettyHistory();
}
}
}
protected void PlayClickSound()
{
if (clickAudioSource != null)
{
clickAudioSource.Play();
}
}
#region Public methods
public virtual void ToggleNarrativeLogView()
{
if (fadeTween != null)
{
LeanTween.cancel(fadeTween.id, true);
fadeTween = null;
}
if (narrativeLogActive)
{
// Switch menu off
LeanTween.value(narrativeLogMenuGroup.gameObject, narrativeLogMenuGroup.alpha, 0f, 0.2f).setOnUpdate((t) => {
narrativeLogMenuGroup.alpha = t;
}).setOnComplete(() => {
narrativeLogMenuGroup.alpha = 0f;
});
}
else
{
// Switch menu on
LeanTween.value(narrativeLogMenuGroup.gameObject, narrativeLogMenuGroup.alpha, 1f, 0.2f).setOnUpdate((t) => {
narrativeLogMenuGroup.alpha = t;
}).setOnComplete(() => {
narrativeLogMenuGroup.alpha = 1f;
});
}
narrativeLogActive = !narrativeLogActive;
}
#endregion
}
}
#endif

12
Assets/Fungus/Scripts/Components/NarrativeLogMenu.cs.meta

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 76befdada4ed8754db75aeb0b0d42976
timeCreated: 1487446345
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

6
Assets/Fungus/Scripts/Components/SaveData.cs

@ -17,7 +17,7 @@ namespace Fungus
{
protected const string FlowchartDataKey = "FlowchartData";
protected const string NarrativeLogKey = "HistoryData";
protected const string NarrativeLogKey = "NarrativeLogData";
[Tooltip("A list of Flowchart objects whose variables will be encoded in the save data. Boolean, Integer, Float and String variables are supported.")]
[SerializeField] protected List<Flowchart> flowcharts = new List<Flowchart>();
@ -37,8 +37,8 @@ namespace Fungus
var saveDataItem = SaveDataItem.Create(FlowchartDataKey, JsonUtility.ToJson(flowchartData));
saveDataItems.Add(saveDataItem);
var historyDataItem = SaveDataItem.Create(NarrativeLogKey, FungusManager.Instance.NarrativeLog.GetJsonHistory());
saveDataItems.Add(historyDataItem);
var narrativeLogItem = SaveDataItem.Create(NarrativeLogKey, FungusManager.Instance.NarrativeLog.GetJsonHistory());
saveDataItems.Add(narrativeLogItem);
}
}

80
Assets/Fungus/Scripts/Components/SaveMenu.cs

@ -47,22 +47,11 @@ namespace Fungus
[Tooltip("The button which restarts the game.")]
[SerializeField] protected Button restartButton;
[Tooltip("The button that shows conversation history.")]
[SerializeField] protected Button narrativeLogButton;
[Tooltip("A scrollable text field used for displaying conversation history.")]
[SerializeField] protected ScrollRect narrativeLogView;
[Tooltip("The CanvasGroup containing the save menu buttons")]
[SerializeField] protected CanvasGroup narrativeLogMenuGroup;
[Tooltip("A scrollable text field used for debugging the save data. The text field should be disabled in normal use.")]
[SerializeField] protected ScrollRect debugView;
protected static bool saveMenuActive = false;
protected static bool narrativeLogActive = false;
protected AudioSource clickAudioSource;
protected LTDescr fadeTween;
@ -92,14 +81,6 @@ namespace Fungus
saveMenuGroup.alpha = 0f;
}
if (!narrativeLogActive)
{
narrativeLogMenuGroup.alpha = 0f;
}
//Clear up the lorem ipsum
UpdateNarrativeLogText();
var saveManager = FungusManager.Instance.SaveManager;
// Make a note of the current scene. This will be used when restarting the game.
@ -167,13 +148,11 @@ namespace Fungus
protected virtual void OnEnable()
{
SaveManagerSignals.OnSavePointAdded += OnSavePointAdded;
WriterSignals.OnWriterState += OnWriterState;
}
protected virtual void OnDisable()
{
SaveManagerSignals.OnSavePointAdded -= OnSavePointAdded;
WriterSignals.OnWriterState -= OnWriterState;
}
protected virtual void OnSavePointAdded(string savePointKey, string savePointDescription)
@ -187,27 +166,6 @@ namespace Fungus
}
}
protected virtual void OnWriterState(Writer writer, WriterState writerState)
{
if (writerState == WriterState.End || writerState == WriterState.Start)
{
UpdateNarrativeLogText();
}
}
protected void UpdateNarrativeLogText()
{
if (narrativeLogView.enabled)
{
Debug.Log("Update NarrativeLog");
var historyText = narrativeLogView.GetComponentInChildren<Text>();
if (historyText != null)
{
historyText.text = FungusManager.Instance.NarrativeLog.GetPrettyHistory();
}
}
}
protected void PlayClickSound()
{
if (clickAudioSource != null)
@ -284,7 +242,6 @@ namespace Fungus
saveManager.Load(saveDataKey);
}
UpdateNarrativeLogText();
}
/// <summary>
@ -300,7 +257,6 @@ namespace Fungus
saveManager.Rewind();
}
UpdateNarrativeLogText();
}
/// <summary>
@ -334,48 +290,14 @@ namespace Fungus
// Reset the Save History for a new game
saveManager.ClearHistory();
// Update and clear narrative log
SaveManagerSignals.DoSaveReset();
UpdateNarrativeLogText();
if (restartDeletesSave)
{
saveManager.Delete(saveDataKey);
}
SaveManagerSignals.DoSaveReset();
SceneManager.LoadScene(saveManager.StartScene);
}
public virtual void ToggleNarrativeLogView()
{
if (fadeTween != null)
{
LeanTween.cancel(fadeTween.id, true);
fadeTween = null;
}
if (narrativeLogActive)
{
// Switch menu off
LeanTween.value(narrativeLogMenuGroup.gameObject, narrativeLogMenuGroup.alpha, 0f, 0.2f).setOnUpdate((t) => {
narrativeLogMenuGroup.alpha = t;
}).setOnComplete(() => {
narrativeLogMenuGroup.alpha = 0f;
});
}
else
{
// Switch menu on
LeanTween.value(narrativeLogMenuGroup.gameObject, narrativeLogMenuGroup.alpha, 1f, 0.2f).setOnUpdate((t) => {
narrativeLogMenuGroup.alpha = t;
}).setOnComplete(() => {
narrativeLogMenuGroup.alpha = 1f;
});
}
narrativeLogActive = !narrativeLogActive;
}
#endregion
}
}

2
Assets/Fungus/Scripts/Signals/WriterSignals.cs

@ -4,7 +4,7 @@
namespace Fungus
{
/// <summary>
/// Writer event signalling system.
/// Writer event signaling system.
/// You can use this to be notified about various events in the writing process.
/// </summary>
public static class WriterSignals

2
Assets/Fungus/Scripts/Utils/SaveHistory.cs

@ -53,7 +53,7 @@ namespace Fungus
/// <summary>
/// Rewinds to the previous Save Point in the Save History.
/// The latest Save Point is moved to a seperate list of rewound save points.
/// The latest Save Point is moved to a separate list of rewound save points.
/// </summary>
public void Rewind()
{

20
Assets/FungusExamples/Conversation/Say History.unity

@ -2984,6 +2984,7 @@ GameObject:
- component: {fileID: 1155851441}
- component: {fileID: 1155851440}
- component: {fileID: 1155851446}
- component: {fileID: 1155851447}
m_Layer: 5
m_Name: SaveMenu
m_TagString: Untagged
@ -3154,9 +3155,6 @@ MonoBehaviour:
rewindButton: {fileID: 1752978368}
forwardButton: {fileID: 1747792014}
restartButton: {fileID: 854933977}
narrativeLogButton: {fileID: 1334503914}
narrativeLogView: {fileID: 236109459}
narrativeLogMenuGroup: {fileID: 236109455}
debugView: {fileID: 1797755878}
--- !u!224 &1155851445
RectTransform:
@ -3202,6 +3200,20 @@ MonoBehaviour:
m_ChildForceExpandHeight: 0
m_ChildControlWidth: 0
m_ChildControlHeight: 0
--- !u!114 &1155851447
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1155851439}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 76befdada4ed8754db75aeb0b0d42976, type: 3}
m_Name:
m_EditorClassIdentifier:
narrativeLogButton: {fileID: 1334503914}
narrativeLogView: {fileID: 236109459}
narrativeLogMenuGroup: {fileID: 236109455}
--- !u!1 &1173948434
GameObject:
m_ObjectHideFlags: 0
@ -3594,7 +3606,7 @@ MonoBehaviour:
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1155851444}
- m_Target: {fileID: 1155851447}
m_MethodName: ToggleNarrativeLogView
m_Mode: 1
m_Arguments:

Loading…
Cancel
Save