Browse Source

Moved all public methods to IMenuDialog

master
Christopher 9 years ago
parent
commit
02d0d74982
  1. 23
      Assets/Fungus/Narrative/Scripts/IMenuDialog.cs
  2. 78
      Assets/Fungus/Narrative/Scripts/MenuDialog.cs

23
Assets/Fungus/Narrative/Scripts/IMenuDialog.cs

@ -1,4 +1,5 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI;
namespace Fungus namespace Fungus
{ {
@ -7,11 +8,33 @@ namespace Fungus
/// </summary> /// </summary>
public interface IMenuDialog public interface IMenuDialog
{ {
/// <summary>
/// A cached list of button objects in the menu dialog.
/// </summary>
/// <value>The cached buttons.</value>
Button[] CachedButtons { get; }
/// <summary>
/// A cached slider object used for the timer in the menu dialog.
/// </summary>
/// <value>The cached slider.</value>
Slider CachedSlider { get; }
/// <summary> /// <summary>
/// Sets the active state of the Menu Dialog gameobject. /// Sets the active state of the Menu Dialog gameobject.
/// </summary> /// </summary>
void SetActive(bool state); void SetActive(bool state);
/// <summary>
/// Clear all displayed options in the Menu Dialog.
/// </summary>
void Clear();
/// <summary>
/// Hides any currently displayed Say Dialog.
/// </summary>
void HideSayDialog();
/// <summary> /// <summary>
/// Adds the option to the list of displayed options. /// Adds the option to the list of displayed options.
/// Will cause the Menu dialog to become visible if it is not already visible. /// Will cause the Menu dialog to become visible if it is not already visible.

78
Assets/Fungus/Narrative/Scripts/MenuDialog.cs

@ -18,10 +18,8 @@ namespace Fungus
[SerializeField] protected bool autoSelectFirstButton = false; [SerializeField] protected bool autoSelectFirstButton = false;
protected Button[] cachedButtons; protected Button[] cachedButtons;
public virtual Button[] CachedButtons { get { return cachedButtons; } }
protected Slider cachedSlider; protected Slider cachedSlider;
public virtual Slider CachedSlider { get { return cachedSlider; } }
public static IMenuDialog GetMenuDialog() public static IMenuDialog GetMenuDialog()
{ {
@ -51,7 +49,7 @@ namespace Fungus
return activeMenuDialog; return activeMenuDialog;
} }
public virtual void Awake() protected virtual void Awake()
{ {
Button[] optionButtons = GetComponentsInChildren<Button>(); Button[] optionButtons = GetComponentsInChildren<Button>();
cachedButtons = optionButtons; cachedButtons = optionButtons;
@ -66,47 +64,13 @@ namespace Fungus
} }
} }
public virtual void OnEnable() protected virtual void OnEnable()
{ {
// The canvas may fail to update if the menu dialog is enabled in the first game frame. // The canvas may fail to update if the menu dialog is enabled in the first game frame.
// To fix this we just need to force a canvas update when the object is enabled. // To fix this we just need to force a canvas update when the object is enabled.
Canvas.ForceUpdateCanvases(); Canvas.ForceUpdateCanvases();
} }
public virtual void Clear()
{
StopAllCoroutines();
Button[] optionButtons = GetComponentsInChildren<Button>();
foreach (UnityEngine.UI.Button button in optionButtons)
{
button.onClick.RemoveAllListeners();
}
foreach (UnityEngine.UI.Button button in optionButtons)
{
if (button != null)
{
button.gameObject.SetActive(false);
}
}
Slider timeoutSlider = GetComponentInChildren<Slider>();
if (timeoutSlider != null)
{
timeoutSlider.gameObject.SetActive(false);
}
}
public virtual void HideSayDialog()
{
ISayDialog sayDialog = SayDialog.GetSayDialog();
if (sayDialog != null)
{
sayDialog.FadeWhenDone = true;
}
}
protected virtual IEnumerator WaitForTimeout(float timeoutDuration, Block targetBlock) protected virtual IEnumerator WaitForTimeout(float timeoutDuration, Block targetBlock)
{ {
float elapsedTime = 0; float elapsedTime = 0;
@ -139,11 +103,49 @@ namespace Fungus
#region IMenuDialog implementation #region IMenuDialog implementation
public virtual Button[] CachedButtons { get { return cachedButtons; } }
public virtual Slider CachedSlider { get { return cachedSlider; } }
public virtual void SetActive(bool state) public virtual void SetActive(bool state)
{ {
gameObject.SetActive(state); gameObject.SetActive(state);
} }
public virtual void Clear()
{
StopAllCoroutines();
Button[] optionButtons = GetComponentsInChildren<Button>();
foreach (UnityEngine.UI.Button button in optionButtons)
{
button.onClick.RemoveAllListeners();
}
foreach (UnityEngine.UI.Button button in optionButtons)
{
if (button != null)
{
button.gameObject.SetActive(false);
}
}
Slider timeoutSlider = GetComponentInChildren<Slider>();
if (timeoutSlider != null)
{
timeoutSlider.gameObject.SetActive(false);
}
}
public virtual void HideSayDialog()
{
ISayDialog sayDialog = SayDialog.GetSayDialog();
if (sayDialog != null)
{
sayDialog.FadeWhenDone = true;
}
}
public virtual bool AddOption(string text, bool interactable, Block targetBlock) public virtual bool AddOption(string text, bool interactable, Block targetBlock)
{ {
bool addedOption = false; bool addedOption = false;

Loading…
Cancel
Save