From af3dbcbb118b8605cd02ebc80bd9848efdbd4da0 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Tue, 26 Aug 2014 23:06:31 +0100 Subject: [PATCH] Renamed DialogController to Dialog --- Assets/Fungus/Dialog/Commands/Say.cs | 6 +- Assets/Fungus/Dialog/Commands/SetDialog.cs | 2 +- Assets/Fungus/Dialog/Editor/SetDialog.cs | 2 +- Assets/Fungus/Dialog/Scripts/Character.cs | 4 +- Assets/Fungus/Dialog/Scripts/Dialog.cs | 907 +++--------------- Assets/Fungus/Dialog/Scripts/Dialog.cs.meta | 2 +- .../Fungus/Dialog/Scripts/DialogController.cs | 235 ----- .../{Sprite => Legacy}/Scripts/Button.cs | 0 .../{Sprite => Legacy}/Scripts/Button.cs.meta | 0 .../{Sprite => Legacy}/Scripts/GUIButton.cs | 0 .../Scripts/GUIButton.cs.meta | 0 Assets/Fungus/Legacy/Scripts/Game.cs | 4 +- Assets/Fungus/Legacy/Scripts/LegacyDialog.cs | 878 +++++++++++++++++ .../Scripts/LegacyDialog.cs.meta} | 2 +- Assets/Shuttle/NewDialog.unity | Bin 59292 -> 59292 bytes 15 files changed, 1021 insertions(+), 1021 deletions(-) delete mode 100644 Assets/Fungus/Dialog/Scripts/DialogController.cs rename Assets/Fungus/{Sprite => Legacy}/Scripts/Button.cs (100%) rename Assets/Fungus/{Sprite => Legacy}/Scripts/Button.cs.meta (100%) rename Assets/Fungus/{Sprite => Legacy}/Scripts/GUIButton.cs (100%) rename Assets/Fungus/{Sprite => Legacy}/Scripts/GUIButton.cs.meta (100%) create mode 100644 Assets/Fungus/Legacy/Scripts/LegacyDialog.cs rename Assets/Fungus/{Dialog/Scripts/DialogController.cs.meta => Legacy/Scripts/LegacyDialog.cs.meta} (78%) diff --git a/Assets/Fungus/Dialog/Commands/Say.cs b/Assets/Fungus/Dialog/Commands/Say.cs index dd8743ee..8df464e2 100644 --- a/Assets/Fungus/Dialog/Commands/Say.cs +++ b/Assets/Fungus/Dialog/Commands/Say.cs @@ -9,7 +9,7 @@ namespace Fungus.Script [HelpText("Writes a line of story text to the dialog. A list of options can be specified for the player to choose from. Use a non-zero timeout to give the player a limited time to choose.")] public class Say : FungusCommand { - static public DialogController dialogController; + static public Dialog dialogController; public Character character; public string storyText; @@ -50,10 +50,10 @@ namespace Fungus.Script if (options.Count > 0) { - List dialogOptions = new List(); + List dialogOptions = new List(); foreach (SayOption sayOption in options) { - DialogController.Option dialogOption = new DialogController.Option(); + Dialog.Option dialogOption = new Dialog.Option(); dialogOption.text = sayOption.optionText; Sequence onSelectSequence = sayOption.targetSequence; diff --git a/Assets/Fungus/Dialog/Commands/SetDialog.cs b/Assets/Fungus/Dialog/Commands/SetDialog.cs index 606f3b5a..2c039ff5 100644 --- a/Assets/Fungus/Dialog/Commands/SetDialog.cs +++ b/Assets/Fungus/Dialog/Commands/SetDialog.cs @@ -10,7 +10,7 @@ namespace Fungus.Script [HelpText("Sets the active dialog for displaying story text with the Say command.")] public class SetDialog : FungusCommand { - public DialogController dialogController; + public Dialog dialogController; public override void OnEnter() { diff --git a/Assets/Fungus/Dialog/Editor/SetDialog.cs b/Assets/Fungus/Dialog/Editor/SetDialog.cs index 57da91c7..0db31e9e 100644 --- a/Assets/Fungus/Dialog/Editor/SetDialog.cs +++ b/Assets/Fungus/Dialog/Editor/SetDialog.cs @@ -17,7 +17,7 @@ namespace Fungus.Script EditorGUI.BeginChangeCheck(); - DialogController dialogController = FungusCommandEditor.ObjectField(new GUIContent("Active Dialog", "Dialog to use when displaying Say command story text"), + Dialog dialogController = FungusCommandEditor.ObjectField(new GUIContent("Active Dialog", "Dialog to use when displaying Say command story text"), new GUIContent(""), t.dialogController); if (EditorGUI.EndChangeCheck()) diff --git a/Assets/Fungus/Dialog/Scripts/Character.cs b/Assets/Fungus/Dialog/Scripts/Character.cs index e6cf2de8..73ca0ec8 100644 --- a/Assets/Fungus/Dialog/Scripts/Character.cs +++ b/Assets/Fungus/Dialog/Scripts/Character.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; using System.Collections; namespace Fungus.Script @@ -8,7 +8,7 @@ namespace Fungus.Script { public string characterName; public Sprite characterImage; - public DialogController.DialogSide dialogSide; + public Dialog.DialogSide dialogSide; public Color characterColor; } diff --git a/Assets/Fungus/Dialog/Scripts/Dialog.cs b/Assets/Fungus/Dialog/Scripts/Dialog.cs index 2cfd24a3..ab094e14 100644 --- a/Assets/Fungus/Dialog/Scripts/Dialog.cs +++ b/Assets/Fungus/Dialog/Scripts/Dialog.cs @@ -1,878 +1,235 @@ using UnityEngine; +using UnityEngine.UI; +using UnityEngine.Events; using System; using System.Collections; using System.Collections.Generic; -namespace Fungus +namespace Fungus.Script { - /** - * Permitted states for Dialogs. - */ - public enum DialogMode - { - /// Dialog has no pending content to display so is not shown. - Idle, - /// Dialog is currently writing out content. - Writing, - /// Dialog has finished writing out content and is waiting for player input. - Waiting - } - - /** - * Interface for Dialog implementations. - * This allows us to introduce new types of Dialog in future. - */ - public interface IDialog - { - /** - * Returns the current state of the Dialog. - */ - DialogMode GetDialogMode(); - - /** - * Display a line of story text. - * If any options have previously been added using AddOption(), these will be displayed and the - * user must choose an option to continue. The sayAction parameter is ignored - * @param sayText The line of story text to be displayed. - * @param sayAction Delegate method to call when the player taps to continue. - */ - void Say(string sayText, Action sayAction); - - /** - * Clear the current list of options previously added using AddOption(). - */ - void ClearOptions(); - - /** - * Add an option to the list of options to be displayed on the next call to Say(). - * @param optionText Text to display on the button for the option. - * @param optionAction Delegate method to call when the option button is pressed. - */ - void AddOption(string optionText, Action optionAction); - - /** - * Sets a time limit for the player to choose between multiple options. - * If the player fails to make a choice in time then the timeoutAction delegate method is called. - * This setting only applies to the next Say() command and will be reset afterwards. - * @timeoutDuration Length of time for the player to choose an option. - * @timeoutAction Delegate method to call when player fails to choose an option. - */ - void SetTimeout(float timeoutDuration, Action timeoutAction); - } - [ExecuteInEditMode] - public class Dialog : MonoBehaviour, IDialog + public class Dialog : MonoBehaviour { - /** - * Padding values for each side of the dialog. - * Values are in normalized screen coords [0..1] - */ - [Serializable] - public class Layout - { - /** - * Push the left dialog edge away from the left side of the screen. - */ - [Tooltip("Push the left dialog edge away from the left side of the screen.")] - public bool leftSpace = false; - - /** - * Push the top dialog edge away from the top side of the screen. - */ - [Tooltip("Push the top dialog edge away from the top side of the screen.")] - public bool topSpace = true; - - /** - * Push the right dialog edge away from the right side of the screen. - */ - [Tooltip("Push the right dialog edge away from the right side of the screen.")] - public bool rightSpace = false; - - /** - * Push the bottom dialog edge away from the bottom side of the screen. - */ - [Tooltip("Push the bottom dialog edge away from the bottom side of the screen.")] - public bool bottomSpace = false; - - /** - * Minimum dimensions of the dialog in normalized screen coordinates [0..1]. - * The dialog may expand beyond these dimensions to fit content. - */ - [Tooltip("Minimum dimensions of the dialog in normalized screen coordinates [0..1].")] - public Vector2 size = new Vector2(1f, 0.25f); - - /** - * Offset the dialog relative to the top left corner of the screen. - * Coordinates are in normalized screen coordinates [0..1] - */ - [Tooltip("Offset the dialog relative to the top left corner of the screen.")] - public Vector2 offset; - } - - /** - * Layout values used to control size and position of the dialog. - */ - [Tooltip("Layout values used to control size and position of the dialog.")] - public Layout layout; - - /** - * Defines the dialog display properties of a game character. - */ - [System.Serializable] - public class Character - { - /** - * Side of screen to display character image. - */ - public enum ImageSide - { - /// Display image on the left side of the dialog. - Left, - /// Display image on the right side of the dialog. - Right - } - - /** - * Identifier for this character for use with the SetCharacter() command. - */ - [Tooltip("Identifier for this character for use with the SetCharacter() command.")] - public string characterID; - - /** - * Name text to display for the character on the dialog. - * If empty then the name field is not displayed. - */ - [Tooltip("Name text to display for the character on the dialog.")] - public string name; - - /** - * The color of the name text label. - * This always overrides any color value specified in the NameStyle property. - */ - [Tooltip("The color of the name text label.")] - public Color nameColor; - - /** - * Image to display for the character. - * If no image is specified then no character image will be displayed. - */ - [Tooltip("Image to display for the character.")] - public Texture2D image; - - /** - * Side of dialog where character image will be displayed. - */ - [Tooltip("Side of dialog where character image will be displayed.")] - public ImageSide imageSide; - } - - /** - * List of game characters that can be displayed using this dialog. - */ - [Tooltip("List of game characters that can be displayed using this dialog.")] - public Character[] characters; - - /** - * Active character to use when displaying dialog (set using the SetCharacter() command). - */ - [Tooltip("Active character to use when displaying dialog.")] - public int activeCharacter; - - /** - * Writing speed for say text in characters per second. - */ - [Range(0, 1000)] - [Tooltip("Writing speed for say text in characters per second.")] - public int writingSpeed = 100; - - /** - * Sound to play while text is being written in the dialog. - */ - [Tooltip("Sound to play while text is being written in the dialog.")] - public AudioClip writingSound; - - /** - * Loop the writing sound as long as text is being written. - */ - [Tooltip("Loop the writing sound while text is being written.")] - public bool loopWritingSound = true; - - /** - * Sound effect to play when the player taps to continue. - */ - [Tooltip("Sound effect to play when the player taps to continue.")] - public AudioClip continueSound; - - /** - * Icon to display under the story text when waiting for player to tap to continue. - */ - [Tooltip("Icon to display under the story text when waiting for player to tap to continue.")] - public Texture2D continueIcon; - - /** - * Number of buttons to display in the same row when showing multiple options. - */ - [Range(0, 10)] - [Tooltip("Number of buttons to display in the same row when showing multiple options.")] - public int buttonsPerRow = 2; - - /** - * Minimum width of each button as a fraction of the screen width [0..1]. - * This is useful to create a column of buttons with matching width. - */ - [Range(0, 1)] - [Tooltip("Minimum width of each button as a fraction of the screen width [0..1].")] - public float minButtonWidth = 0; - - /** - * Padding values for each side of the character image. - */ - [System.Serializable] - public class ImagePadding - { - /** - * Padding to apply to left side of image as a fraction of screen height [-2..2]. - */ - [Range(-2,2)] - [Tooltip("Padding to apply to left side of image as a fraction of screen height [-2..2].")] - public float left; - - /** - * Padding to apply to right side of image as a fraction of screen height [-2..2]. - */ - [Range(-2,2)] - [Tooltip("Padding to apply to right side of image as a fraction of screen height [-2..2].")] - public float right; - - /** - * Padding to apply to top side of image as a fraction of screen height [-1..1]. - */ - [Range(-1,1)] - [Tooltip("Padding to apply to top side of image as a fraction of screen height [-1..1].")] - public float top; - - /** - * Padding to apply to bottom side of image as a fraction of screen height [-1..1]. - */ - [Range(-1,1)] - [Tooltip("Padding to apply to bottom side of image as a fraction of screen height [-1..1].")] - public float bottom; - } - - /** - * Padding offset to apply around the character image. - */ - [Tooltip("Padding offset to apply around the character image.")] - public ImagePadding imagePadding; - - /** - * Scale of character image, specified as a fraction of current screen height [0..1]. - */ - [Range(0, 1)] - [Tooltip("Scale of character image, specified as a fraction of current screen height [0..1].")] - public float imageScale = 0.25f; - - /** - * Animation frames for multiple choice time indicator. - */ - [Tooltip("Animation frames for multiple choice time indicator.")] - public Texture2D[] timerAnimation; - - /** - * Scale of timer image, specified as a fraction of current screen height [0..1]. - */ - [Range(0, 1)] - [Tooltip("Scale of timer image, specified as a fraction of current screen height [0..1].")] - public float timerScale = 0.2f; - - /** - * Sound effect to play when time indicator advances. - */ - [Tooltip("Sound effect to play when time indicator advances.")] - public AudioClip timerSound; - - /** - * Style for dialog box background. - */ - [Tooltip("Style for dialog box background.")] - public GUIStyle boxStyle; - - /** - * Style for name text. - */ - [Tooltip("Style for name text.")] - public GUIStyle nameTextStyle; - - /** - * Style for say text. - */ - [Tooltip("Style for say text.")] - public GUIStyle sayTextStyle; - - /** - * Style for option buttons - */ - [Tooltip("Style for option buttons.")] - public GUIStyle buttonStyle; - - DialogMode dialogMode; - - public DialogMode GetDialogMode() + public enum DialogSide { - return dialogMode; - } + Left, + Right + }; - class Option + public class Option { - public string optionText; - public Action optionAction; - - public Option(string _optionText, Action _optionAction) - { - optionText = _optionText; - optionAction = _optionAction; - } + public string text; + public Action onSelect; } - List