Browse Source

Reverted IMenuDialog interface

master
Christopher 9 years ago
parent
commit
33d633b3a3
  1. 2
      Assets/Fungus/Scripts/Commands/Menu.cs
  2. 2
      Assets/Fungus/Scripts/Commands/MenuTimer.cs
  3. 61
      Assets/Fungus/Scripts/Components/MenuDialog.cs
  4. 81
      Assets/Fungus/Scripts/Interfaces/IMenuDialog.cs
  5. 12
      Assets/Fungus/Scripts/Interfaces/IMenuDialog.cs.meta

2
Assets/Fungus/Scripts/Commands/Menu.cs

@ -48,7 +48,7 @@ namespace Fungus.Commands
if (!hideOption)
{
IMenuDialog menuDialog = MenuDialog.GetMenuDialog();
var menuDialog = MenuDialog.GetMenuDialog();
if (menuDialog != null)
{
menuDialog.SetActive(true);

2
Assets/Fungus/Scripts/Commands/MenuTimer.cs

@ -27,7 +27,7 @@ namespace Fungus.Commands
public override void OnEnter()
{
IMenuDialog menuDialog = MenuDialog.GetMenuDialog();
var menuDialog = MenuDialog.GetMenuDialog();
if (menuDialog != null &&
targetBlock != null)

61
Assets/Fungus/Scripts/Components/MenuDialog.cs

@ -10,7 +10,10 @@ using MoonSharp.Interpreter;
namespace Fungus
{
public class MenuDialog : MonoBehaviour, IMenuDialog
/// <summary>
/// Presents multiple choice buttons to the players.
/// </summary>
public class MenuDialog : MonoBehaviour
{
[Tooltip("Automatically select the first interactable button when the menu is shown.")]
[SerializeField] protected bool autoSelectFirstButton = false;
@ -20,14 +23,14 @@ namespace Fungus
protected Slider cachedSlider;
// Currently active Menu Dialog used to display Menu options
public static IMenuDialog activeMenuDialog;
public static MenuDialog activeMenuDialog;
public static IMenuDialog GetMenuDialog()
public static MenuDialog GetMenuDialog()
{
if (activeMenuDialog == null)
{
// Use first Menu Dialog found in the scene (if any)
IMenuDialog md = GameObject.FindObjectOfType<MenuDialog>();
var md = GameObject.FindObjectOfType<MenuDialog>();
if (md != null)
{
activeMenuDialog = md;
@ -42,7 +45,7 @@ namespace Fungus
GameObject go = Instantiate(prefab) as GameObject;
go.SetActive(false);
go.name = "MenuDialog";
activeMenuDialog = go.GetComponent<IMenuDialog>();
activeMenuDialog = go.GetComponent<MenuDialog>();
}
}
}
@ -102,17 +105,31 @@ namespace Fungus
}
}
#region IMenuDialog implementation
#region Public methods
/// <summary>
/// A cached list of button objects in the menu dialog.
/// </summary>
/// <value>The cached buttons.</value>
public virtual Button[] CachedButtons { get { return cachedButtons; } }
/// <summary>
/// A cached slider object used for the timer in the menu dialog.
/// </summary>
/// <value>The cached slider.</value>
public virtual Slider CachedSlider { get { return cachedSlider; } }
/// <summary>
/// Sets the active state of the Menu Dialog gameobject.
/// </summary>
public virtual void SetActive(bool state)
{
gameObject.SetActive(state);
}
/// <summary>
/// Clear all displayed options in the Menu Dialog.
/// </summary>
public virtual void Clear()
{
StopAllCoroutines();
@ -138,6 +155,9 @@ namespace Fungus
}
}
/// <summary>
/// Hides any currently displayed Say Dialog.
/// </summary>
public virtual void HideSayDialog()
{
var sayDialog = SayDialog.GetSayDialog();
@ -146,7 +166,15 @@ namespace Fungus
sayDialog.FadeWhenDone = true;
}
}
/// <summary>
/// Adds the option to the list of displayed options. Calls a Block when selected.
/// Will cause the Menu dialog to become visible if it is not already visible.
/// </summary>
/// <returns><c>true</c>, if the option was added successfully.</returns>
/// <param name="text">The option text to display on the button.</param>
/// <param name="interactable">If false, the option is displayed but is not selectable.</param>
/// <param name="targetBlock">Block to execute when the option is selected.</param>
public virtual bool AddOption(string text, bool interactable, Block targetBlock)
{
bool addedOption = false;
@ -202,6 +230,11 @@ namespace Fungus
return addedOption;
}
/// <summary>
/// Adds the option to the list of displayed options, calls a Lua function when selected.
/// Will cause the Menu dialog to become visible if it is not already visible.
/// </summary>
/// <returns><c>true</c>, if the option was added successfully.</returns>
public bool AddOption(string text, bool interactable, ILuaEnvironment luaEnv, Closure callBack)
{
if (!gameObject.activeSelf)
@ -244,6 +277,11 @@ namespace Fungus
return addedOption;
}
/// <summary>
/// Show a timer during which the player can select an option. Calls a Block when the timer expires.
/// </summary>
/// <param name="duration">The duration during which the player can select an option.</param>
/// <param name="targetBlock">Block to execute if the player does not select an option in time.</param>
public virtual void ShowTimer(float duration, Block targetBlock)
{
if (cachedSlider != null)
@ -255,6 +293,9 @@ namespace Fungus
}
}
/// <summary>
/// Show a timer during which the player can select an option. Calls a Lua function when the timer expires.
/// </summary>
public IEnumerator ShowTimer(float duration, ILuaEnvironment luaEnv, Closure callBack)
{
if (CachedSlider == null ||
@ -292,11 +333,17 @@ namespace Fungus
}
}
/// <summary>
/// Returns true if the Menu Dialog is currently displayed.
/// </summary>
public virtual bool IsActive()
{
return gameObject.activeInHierarchy;
}
/// <summary>
/// Returns the number of currently displayed options.
/// </summary>
public virtual int DisplayedOptionsCount
{
get {

81
Assets/Fungus/Scripts/Interfaces/IMenuDialog.cs

@ -1,81 +0,0 @@
// 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)
using UnityEngine.UI;
using MoonSharp.Interpreter;
using System.Collections;
namespace Fungus
{
/// <summary>
/// Presents multiple choice buttons to the players.
/// </summary>
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>
/// Sets the active state of the Menu Dialog gameobject.
/// </summary>
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>
/// Adds the option to the list of displayed options. Calls a Block when selected.
/// Will cause the Menu dialog to become visible if it is not already visible.
/// </summary>
/// <returns><c>true</c>, if the option was added successfully.</returns>
/// <param name="text">The option text to display on the button.</param>
/// <param name="interactable">If false, the option is displayed but is not selectable.</param>
/// <param name="targetBlock">Block to execute when the option is selected.</param>
bool AddOption(string text, bool interactable, Block targetBlock);
/// <summary>
/// Adds the option to the list of displayed options, calls a Lua function when selected.
/// Will cause the Menu dialog to become visible if it is not already visible.
/// </summary>
/// <returns><c>true</c>, if the option was added successfully.</returns>
bool AddOption(string text, bool interactable, ILuaEnvironment luaEnv, Closure callBack);
/// <summary>
/// Show a timer during which the player can select an option. Calls a Block when the timer expires.
/// </summary>
/// <param name="duration">The duration during which the player can select an option.</param>
/// <param name="targetBlock">Block to execute if the player does not select an option in time.</param>
void ShowTimer(float duration, Block targetBlock);
/// <summary>
/// Show a timer during which the player can select an option. Calls a Lua function when the timer expires.
/// </summary>
IEnumerator ShowTimer(float duration, ILuaEnvironment luaEnv, Closure callBack);
/// <summary>
/// Returns true if the Menu Dialog is currently displayed.
/// </summary>
bool IsActive();
/// <summary>
/// Returns the number of currently displayed options.
/// </summary>
int DisplayedOptionsCount { get; }
}
}

12
Assets/Fungus/Scripts/Interfaces/IMenuDialog.cs.meta

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 88b3741e7161f40d3b6166170b69c55e
timeCreated: 1473425656
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save