From 9aea6a99c8303502efb96fc2c56bfcd7bb21e67f Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Mon, 1 Sep 2014 10:32:54 +0100 Subject: [PATCH] bold, italic, color, speed tags. Fixed text area refresh. --- Assets/Fungus/Dialog/Scripts/Dialog.cs | 103 ++++++++++++++++-- .../Editor/FungusCommandEditor.cs | 1 + .../FungusScript/Editor/FungusScriptWindow.cs | 1 + Assets/Shuttle/ShuttleGame.unity | Bin 116636 -> 116668 bytes 4 files changed, 94 insertions(+), 11 deletions(-) diff --git a/Assets/Fungus/Dialog/Scripts/Dialog.cs b/Assets/Fungus/Dialog/Scripts/Dialog.cs index 5b9d54b8..f9c8046d 100644 --- a/Assets/Fungus/Dialog/Scripts/Dialog.cs +++ b/Assets/Fungus/Dialog/Scripts/Dialog.cs @@ -27,6 +27,12 @@ namespace Fungus.Script public Image leftImage; public Image rightImage; + float speed; + bool boldActive; + bool italicActive; + bool colorActive; + string colorText; + protected enum GlyphType { Character, // Text character @@ -120,6 +126,11 @@ namespace Fungus.Script protected IEnumerator WriteText(string text, Action onWritingComplete, Action onExitTag) { storyText.text = ""; + boldActive = false; + italicActive = false; + colorActive = false; + colorText = ""; + speed = writingSpeed; List glyphs = MakeGlyphList(text); @@ -128,9 +139,9 @@ namespace Fungus.Script yield break; } - // Zero writingSpeed means write instantly + // Zero speed means write instantly // Also write instantly if text contains rich text markup tags - if (writingSpeed == 0 || + if (speed == 0 || text.Contains("<")) { foreach (Glyph glyph in glyphs) @@ -160,9 +171,9 @@ namespace Fungus.Script } float writeDelay = 0f; - if (writingSpeed > 0) + if (speed > 0) { - writeDelay = (1f / (float)writingSpeed); + writeDelay = (1f / (float)speed); } float timeAccumulator = 0f; @@ -188,10 +199,55 @@ namespace Fungus.Script } else { - storyText.text += glyph.param; + // Wrap each individual character in rich text markup tags if required + // This must be done at the character level to support writing out the story text over time. + string start = ""; + string end = ""; + if (boldActive) + { + start += ""; + end += ""; + } + if (italicActive) + { + start += ""; + end += ""; + } + if (colorActive) + { + start += ""; + end += ""; + } + + storyText.text += start + glyph.param + end; } break; + case GlyphType.BoldStart: + boldActive = true; + break; + + case GlyphType.BoldEnd: + boldActive = false; + break; + + case GlyphType.ItalicStart: + italicActive = true; + break; + + case GlyphType.ItalicEnd: + italicActive = false; + break; + + case GlyphType.ColorStart: + colorActive = true; + colorText = glyph.param; + break; + + case GlyphType.ColorEnd: + colorActive = false; + break; + case GlyphType.Wait: float duration = 1f; if (!Single.TryParse(glyph.param, out duration)) @@ -220,14 +276,14 @@ namespace Fungus.Script break; case GlyphType.Speed: - if (!Single.TryParse(glyph.param, out writingSpeed)) + if (!Single.TryParse(glyph.param, out speed)) { - writingSpeed = 0f; + speed = 0f; } writeDelay = 0; - if (writingSpeed > 0) + if (speed > 0) { - writeDelay = (1f / (float)writingSpeed); + writeDelay = (1f / (float)speed); } break; @@ -349,7 +405,32 @@ namespace Fungus.Script GlyphType type = GlyphType.Character; string paramText = ""; - if (tag == "wi") + if (tag == "b") + { + type = GlyphType.BoldStart; + } + else if (tag == "/b") + { + type = GlyphType.BoldEnd; + } + else if (tag == "i") + { + type = GlyphType.ItalicStart; + } + else if (tag == "/i") + { + type = GlyphType.ItalicEnd; + } + else if (tag.StartsWith("color=")) + { + type = GlyphType.ColorStart; + paramText = tag.Substring(6, tag.Length - 6); + } + else if (tag == "/color") + { + type = GlyphType.ColorEnd; + } + else if (tag == "wi") { type = GlyphType.WaitForInputNoClear; } @@ -360,7 +441,7 @@ namespace Fungus.Script else if (tag.StartsWith("wp=")) { type = GlyphType.WaitOnPunctuation; - paramText = tag.Substring(2, tag.Length - 2); + paramText = tag.Substring(3, tag.Length - 3); } else if (tag == "wp") { diff --git a/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs index cce7aaec..fe41a8a6 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs @@ -63,6 +63,7 @@ namespace Fungus.Script { Undo.RecordObject(t, "Toggle Expanded"); t.expanded = !t.expanded; + GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus) } GUI.backgroundColor = Color.white; diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs index 75bf4e45..f3bf2b28 100755 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs @@ -272,6 +272,7 @@ namespace Fungus.Script fungusScript.selectedSequence = s; Selection.activeGameObject = fungusScript.gameObject; + GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus) } } } diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index 2f0a9d2056f737dcded9b2f76e934602c9982a41..10d1bb1f14f5717a1f1ddd0b39d993e9fbfc8be6 100644 GIT binary patch delta 2287 zcmZA2eM}o=90%~{L6UXLWVrc)I@l4jY`O@HXl&>fo9MF6L@dZQ7;&X9NAI@wu3V3n zQpz!OirW;DWtJ&#Ga=!R8Jjp$Ocqn)AM8Kt%qIS`Rp%TS&G3&cO`PKQ;EKNIyR`vA$o=KzWd-jG)pw4}cnN92=id!mgb^Ph z518ChS6MsZ32A~+<8i@SVS3wA<0-#yZBM~OCie)8>m+0hmLo*dU&v-)2H1elH;rct zjQ9z872p3g26MV)6rIML>BBi9T|!PvoM|FZeAFr34+j=zUlBl<+N|7UU)I19wU z*Jk_!Y-iM5aPH=u;DE8qdIdHGW4Gz~w%qZ2QLYB&>|t`~pG-O~1ZIG2!6_JtF+t>- zCSMD-!q{9hELD{IF106Q={4uFunrhIz_%WbhP2tD;89?C+#Kw$D(ezpY{wcbQ|GT&9N#cYeGHa^u^k_WSrdee>i2)q*t-BQ3&b{)1;c_cN59!5SO%sS%o{lwR)M9| zx317O1RH_{V0VmM7c6fwd{KbHz-qyJMlcM^z(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