Browse Source

bold, italic, color, speed tags. Fixed text area refresh.

master
chrisgregan 11 years ago
parent
commit
9aea6a99c8
  1. 103
      Assets/Fungus/Dialog/Scripts/Dialog.cs
  2. 1
      Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs
  3. 1
      Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs
  4. BIN
      Assets/Shuttle/ShuttleGame.unity

103
Assets/Fungus/Dialog/Scripts/Dialog.cs

@ -27,6 +27,12 @@ namespace Fungus.Script
public Image leftImage; public Image leftImage;
public Image rightImage; public Image rightImage;
float speed;
bool boldActive;
bool italicActive;
bool colorActive;
string colorText;
protected enum GlyphType protected enum GlyphType
{ {
Character, // Text character Character, // Text character
@ -120,6 +126,11 @@ namespace Fungus.Script
protected IEnumerator WriteText(string text, Action onWritingComplete, Action onExitTag) protected IEnumerator WriteText(string text, Action onWritingComplete, Action onExitTag)
{ {
storyText.text = ""; storyText.text = "";
boldActive = false;
italicActive = false;
colorActive = false;
colorText = "";
speed = writingSpeed;
List<Glyph> glyphs = MakeGlyphList(text); List<Glyph> glyphs = MakeGlyphList(text);
@ -128,9 +139,9 @@ namespace Fungus.Script
yield break; yield break;
} }
// Zero writingSpeed means write instantly // Zero speed means write instantly
// Also write instantly if text contains rich text markup tags // Also write instantly if text contains rich text markup tags
if (writingSpeed == 0 || if (speed == 0 ||
text.Contains("<")) text.Contains("<"))
{ {
foreach (Glyph glyph in glyphs) foreach (Glyph glyph in glyphs)
@ -160,9 +171,9 @@ namespace Fungus.Script
} }
float writeDelay = 0f; float writeDelay = 0f;
if (writingSpeed > 0) if (speed > 0)
{ {
writeDelay = (1f / (float)writingSpeed); writeDelay = (1f / (float)speed);
} }
float timeAccumulator = 0f; float timeAccumulator = 0f;
@ -188,10 +199,55 @@ namespace Fungus.Script
} }
else 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 += "<b>";
end += "</b>";
}
if (italicActive)
{
start += "<i>";
end += "</i>";
}
if (colorActive)
{
start += "<color=" + colorText + ">";
end += "</color>";
}
storyText.text += start + glyph.param + end;
} }
break; 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: case GlyphType.Wait:
float duration = 1f; float duration = 1f;
if (!Single.TryParse(glyph.param, out duration)) if (!Single.TryParse(glyph.param, out duration))
@ -220,14 +276,14 @@ namespace Fungus.Script
break; break;
case GlyphType.Speed: case GlyphType.Speed:
if (!Single.TryParse(glyph.param, out writingSpeed)) if (!Single.TryParse(glyph.param, out speed))
{ {
writingSpeed = 0f; speed = 0f;
} }
writeDelay = 0; writeDelay = 0;
if (writingSpeed > 0) if (speed > 0)
{ {
writeDelay = (1f / (float)writingSpeed); writeDelay = (1f / (float)speed);
} }
break; break;
@ -349,7 +405,32 @@ namespace Fungus.Script
GlyphType type = GlyphType.Character; GlyphType type = GlyphType.Character;
string paramText = ""; 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; type = GlyphType.WaitForInputNoClear;
} }
@ -360,7 +441,7 @@ namespace Fungus.Script
else if (tag.StartsWith("wp=")) else if (tag.StartsWith("wp="))
{ {
type = GlyphType.WaitOnPunctuation; type = GlyphType.WaitOnPunctuation;
paramText = tag.Substring(2, tag.Length - 2); paramText = tag.Substring(3, tag.Length - 3);
} }
else if (tag == "wp") else if (tag == "wp")
{ {

1
Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs

@ -63,6 +63,7 @@ namespace Fungus.Script
{ {
Undo.RecordObject(t, "Toggle Expanded"); Undo.RecordObject(t, "Toggle Expanded");
t.expanded = !t.expanded; t.expanded = !t.expanded;
GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus)
} }
GUI.backgroundColor = Color.white; GUI.backgroundColor = Color.white;

1
Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs

@ -272,6 +272,7 @@ namespace Fungus.Script
fungusScript.selectedSequence = s; fungusScript.selectedSequence = s;
Selection.activeGameObject = fungusScript.gameObject; Selection.activeGameObject = fungusScript.gameObject;
GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus)
} }
} }
} }

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save