From 36558c1bf6efd63427d148c8e764952d9c3a0bf0 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Fri, 11 Apr 2014 13:51:50 +0100 Subject: [PATCH] Continue button can now be placed either on the page or on the screen. --- Assets/Fungus/Prefabs/ContinueStyle.prefab | Bin 10816 -> 10848 bytes Assets/Fungus/Scripts/ContinueStyle.cs | 28 +++-------- Assets/Fungus/Scripts/Page.cs | 54 ++++++++++++++++++++- 3 files changed, 59 insertions(+), 23 deletions(-) diff --git a/Assets/Fungus/Prefabs/ContinueStyle.prefab b/Assets/Fungus/Prefabs/ContinueStyle.prefab index 13f3d451e6ee4932ecccbc3151310ab840fede3d..691242ff96cac1e27e4cbd85e32b24caea70eff2 100644 GIT binary patch delta 151 zcmX>Q@*qTjfkFKi1A|rq0|Nsmko{qzfITDs#(-0z@}Zu2B^C_%c>#&(sSJ!j`FsWE4V%T8m_;Vri^(wdPmU3j zXPhwkgPc6$#K{Kol9RWJ@iR^WiB3KuCNTNGoWSHKVj`O*#PbChdnR|NS4=k0WZk53 nfsvO5Xf_;AR@4-p{6W)XvWAwxWJWD{kSdM^ZHx?zj0_9_Lp~)h diff --git a/Assets/Fungus/Scripts/ContinueStyle.cs b/Assets/Fungus/Scripts/ContinueStyle.cs index 1bb84632..af4f3625 100644 --- a/Assets/Fungus/Scripts/ContinueStyle.cs +++ b/Assets/Fungus/Scripts/ContinueStyle.cs @@ -14,8 +14,15 @@ public class ContinueStyle : MonoBehaviour /// Style for continue button public GUIStyle style; + /** + * If true, places the continue button on the active page. + * If false, places the continue button on the screen. + */ + public bool onPage; + /** * Specifies continue button position in normalized screen coordinates. + * This setting is ignored if onPage == true * (0,0) is top left of screen. * (1,1) is bottom right of screen */ @@ -38,25 +45,4 @@ public class ContinueStyle : MonoBehaviour guiStyle.fontSize = Mathf.RoundToInt((float)Screen.height * continueFontScale); return guiStyle; } - - public Rect CalcContinueRect() - { - GUIStyle continueStyle = GetScaledContinueStyle(); - - GUIContent content = new GUIContent(continueText); - Vector2 size = continueStyle.CalcSize(content); - - float x = Screen.width * screenPosition.x; - float y = Screen.height * screenPosition.y; - float width = size.x; - float height = size.y; - - x = Mathf.Max(x, padding.x); - x = Mathf.Min(x, Screen.width - width - padding.x); - - y = Mathf.Max(y, padding.y); - y = Mathf.Min(y, Screen.height - height - padding.y); - - return new Rect(x, y, width, height); - } } diff --git a/Assets/Fungus/Scripts/Page.cs b/Assets/Fungus/Scripts/Page.cs index bb29cb5a..e5104067 100644 --- a/Assets/Fungus/Scripts/Page.cs +++ b/Assets/Fungus/Scripts/Page.cs @@ -272,8 +272,7 @@ namespace Fungus ContinueStyle continueStyle = Game.GetInstance().continueStyle; if (continueStyle != null) { - Rect continueRect = continueStyle.CalcContinueRect(); - GUI.Label(continueRect, new GUIContent(continueStyle.continueText), continueStyle.GetScaledContinueStyle()); + DrawContinueButton(outerRect); } // Player can continue by clicking anywhere @@ -494,5 +493,56 @@ namespace Fungus return FitRectToScreen(pageRect); } + + void DrawContinueButton(Rect containerRect) + { + PageStyle pageStyle = Game.GetInstance().activePageStyle; + ContinueStyle continueStyle = Game.GetInstance().continueStyle; + + if (pageStyle == null || + continueStyle == null) + { + return; + } + + GUIStyle style = continueStyle.style; + if (style == null) + { + return; + } + + GUIContent content = new GUIContent(continueStyle.continueText); + GUIStyle scaledContinueStyle = continueStyle.GetScaledContinueStyle(); + + Rect continueRect; + + if (continueStyle.onPage) + { + float width = scaledContinueStyle.CalcSize(content).x; + float height = scaledContinueStyle.lineHeight; + float x = containerRect.xMin + (containerRect.width) - (width) - pageStyle.boxStyle.padding.right; + float y = containerRect.yMax - height / 2f; + continueRect = new Rect(x, y, width, height); + } + else + { + Vector2 size = scaledContinueStyle.CalcSize(content); + + float x = Screen.width * continueStyle.screenPosition.x; + float y = Screen.height * continueStyle.screenPosition.y; + float width = size.x; + float height = size.y; + + x = Mathf.Max(x, continueStyle.padding.x); + x = Mathf.Min(x, Screen.width - width - continueStyle.padding.x); + + y = Mathf.Max(y, continueStyle.padding.y); + y = Mathf.Min(y, Screen.height - height - continueStyle.padding.y); + + continueRect = new Rect(x, y, width, height); + } + + GUI.Label(continueRect, content, scaledContinueStyle); + } } } \ No newline at end of file