using UnityEngine; using System; using System.Collections; using System.Collections.Generic; using System.Text.RegularExpressions; namespace Fungus { /** * Manages and draws a text box for rendering story text and multiple choice menus. */ [ExecuteInEditMode] public class PageController : MonoBehaviour, IDialog { /// Options for default Page position on screen public enum PagePosition { /// Page appears full-size and horizontally centered at top of screen. Top, /// Page appears centered in middle of screen, with height fitted to content. Middle, /// Page appears full-size and horizontally centered at bottom of screen. Bottom } /** * Defines a rect in normalized screen space coordinates. * e.g. x1 = 0 means left of screen, x2 = 1 means right of screen. */ public class ScreenRect { public float x1; public float y1; public float x2; public float y2; } /// Options for controlling page layout public enum Layout { /// Use the full rect to display the page. FullSize, /// Resize to fit displayed text and snap to top of rect. FitToTop, /// Resize to fit displayed text and snap to middle of rect. FitToMiddle, /// Resize to fit displayed text and snap to bottom of rect. FitToBottom } /// Controls layout of content within Page rect. public Layout layout = Layout.FullSize; /// Supported states for Page public enum Mode { /// No content to be displayed. Idle, /// Show a single line of text and wait for player input. Say, /// Show a multiple choice menu and wait for player to select an option. Choose }; /** * The style to apply when displaying Pages. */ public PageStyle activePageStyle; /// Current Page story telling state [HideInInspector] public Mode mode = Mode.Idle; /// Screen space rect for Page in pixels. [HideInInspector] public Rect pageRect; /** * Writing speed for page text. */ public int charactersPerSecond = 60; /** * Icon to display when waiting for player input to continue */ public Texture2D continueIcon; /** * Position of continue and swipe icons in normalized screen space coords. * (0,0) = top left, (1,1) = bottom right */ public Vector2 iconPosition = new Vector2(1,1); /** * Default screen position for Page when player enters a Room. */ public PageController.PagePosition defaultPagePosition; /** * Default width and height of Page as a fraction of screen height [0..1] */ public Vector2 defaultPageScale = new Vector2(0.75f, 0.25f); /** * Automatically center the Page when player is choosing from multiple options. */ public bool centerChooseMenu = true; /** * Width of Page as a fraction of screen width [0..1] when automatically centering a Choose menu. * This setting only has an effect when centerChooseMenu is enabled. */ public float chooseMenuWidth = 0.5f; /** * Sound effect to play when buttons are clicked. */ public AudioClip clickSound; string headerText = ""; string footerText = ""; string displayedStoryText = ""; string originalStoryText = ""; Action deferredAction; Action continueAction; class Option { public string optionText; public Action optionAction; public Option(string _optionText, Action _optionAction) { optionText = _optionText; optionAction = _optionAction; } } List