diff --git a/Assets/Fungus/Scripts/Commands/Menu.cs b/Assets/Fungus/Scripts/Commands/Menu.cs index 377faaa4..b40e96c4 100644 --- a/Assets/Fungus/Scripts/Commands/Menu.cs +++ b/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); diff --git a/Assets/Fungus/Scripts/Commands/MenuTimer.cs b/Assets/Fungus/Scripts/Commands/MenuTimer.cs index bdca678f..32d83a83 100644 --- a/Assets/Fungus/Scripts/Commands/MenuTimer.cs +++ b/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) diff --git a/Assets/Fungus/Scripts/Components/MenuDialog.cs b/Assets/Fungus/Scripts/Components/MenuDialog.cs index 6fa6c7b2..9c3db6ef 100644 --- a/Assets/Fungus/Scripts/Components/MenuDialog.cs +++ b/Assets/Fungus/Scripts/Components/MenuDialog.cs @@ -10,7 +10,10 @@ using MoonSharp.Interpreter; namespace Fungus { - public class MenuDialog : MonoBehaviour, IMenuDialog + /// + /// Presents multiple choice buttons to the players. + /// + 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(); + var md = GameObject.FindObjectOfType(); 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(); + activeMenuDialog = go.GetComponent(); } } } @@ -102,17 +105,31 @@ namespace Fungus } } - #region IMenuDialog implementation + #region Public methods + /// + /// A cached list of button objects in the menu dialog. + /// + /// The cached buttons. public virtual Button[] CachedButtons { get { return cachedButtons; } } + /// + /// A cached slider object used for the timer in the menu dialog. + /// + /// The cached slider. public virtual Slider CachedSlider { get { return cachedSlider; } } + /// + /// Sets the active state of the Menu Dialog gameobject. + /// public virtual void SetActive(bool state) { gameObject.SetActive(state); } + /// + /// Clear all displayed options in the Menu Dialog. + /// public virtual void Clear() { StopAllCoroutines(); @@ -138,6 +155,9 @@ namespace Fungus } } + /// + /// Hides any currently displayed Say Dialog. + /// public virtual void HideSayDialog() { var sayDialog = SayDialog.GetSayDialog(); @@ -146,7 +166,15 @@ namespace Fungus sayDialog.FadeWhenDone = true; } } - + + /// + /// 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. + /// + /// true, if the option was added successfully. + /// The option text to display on the button. + /// If false, the option is displayed but is not selectable. + /// Block to execute when the option is selected. public virtual bool AddOption(string text, bool interactable, Block targetBlock) { bool addedOption = false; @@ -202,6 +230,11 @@ namespace Fungus return addedOption; } + /// + /// 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. + /// + /// true, if the option was added successfully. public bool AddOption(string text, bool interactable, ILuaEnvironment luaEnv, Closure callBack) { if (!gameObject.activeSelf) @@ -244,6 +277,11 @@ namespace Fungus return addedOption; } + /// + /// Show a timer during which the player can select an option. Calls a Block when the timer expires. + /// + /// The duration during which the player can select an option. + /// Block to execute if the player does not select an option in time. public virtual void ShowTimer(float duration, Block targetBlock) { if (cachedSlider != null) @@ -255,6 +293,9 @@ namespace Fungus } } + /// + /// Show a timer during which the player can select an option. Calls a Lua function when the timer expires. + /// public IEnumerator ShowTimer(float duration, ILuaEnvironment luaEnv, Closure callBack) { if (CachedSlider == null || @@ -292,11 +333,17 @@ namespace Fungus } } + /// + /// Returns true if the Menu Dialog is currently displayed. + /// public virtual bool IsActive() { return gameObject.activeInHierarchy; } + /// + /// Returns the number of currently displayed options. + /// public virtual int DisplayedOptionsCount { get { diff --git a/Assets/Fungus/Scripts/Interfaces/IMenuDialog.cs b/Assets/Fungus/Scripts/Interfaces/IMenuDialog.cs deleted file mode 100644 index 9d000f89..00000000 --- a/Assets/Fungus/Scripts/Interfaces/IMenuDialog.cs +++ /dev/null @@ -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 -{ - /// - /// Presents multiple choice buttons to the players. - /// - public interface IMenuDialog - { - /// - /// A cached list of button objects in the menu dialog. - /// - /// The cached buttons. - Button[] CachedButtons { get; } - - /// - /// A cached slider object used for the timer in the menu dialog. - /// - /// The cached slider. - Slider CachedSlider { get; } - - /// - /// Sets the active state of the Menu Dialog gameobject. - /// - void SetActive(bool state); - - /// - /// Clear all displayed options in the Menu Dialog. - /// - void Clear(); - - /// - /// Hides any currently displayed Say Dialog. - /// - void HideSayDialog(); - - /// - /// 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. - /// - /// true, if the option was added successfully. - /// The option text to display on the button. - /// If false, the option is displayed but is not selectable. - /// Block to execute when the option is selected. - bool AddOption(string text, bool interactable, Block targetBlock); - - /// - /// 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. - /// - /// true, if the option was added successfully. - bool AddOption(string text, bool interactable, ILuaEnvironment luaEnv, Closure callBack); - - /// - /// Show a timer during which the player can select an option. Calls a Block when the timer expires. - /// - /// The duration during which the player can select an option. - /// Block to execute if the player does not select an option in time. - void ShowTimer(float duration, Block targetBlock); - - /// - /// Show a timer during which the player can select an option. Calls a Lua function when the timer expires. - /// - IEnumerator ShowTimer(float duration, ILuaEnvironment luaEnv, Closure callBack); - - /// - /// Returns true if the Menu Dialog is currently displayed. - /// - bool IsActive(); - - /// - /// Returns the number of currently displayed options. - /// - int DisplayedOptionsCount { get; } - } -} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Interfaces/IMenuDialog.cs.meta b/Assets/Fungus/Scripts/Interfaces/IMenuDialog.cs.meta deleted file mode 100644 index 56a427eb..00000000 --- a/Assets/Fungus/Scripts/Interfaces/IMenuDialog.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 88b3741e7161f40d3b6166170b69c55e -timeCreated: 1473425656 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: