A different approach
Let's just override the original implementation with our own!
This commit is contained in:
@@ -4,9 +4,9 @@ import flixel.addons.text.FlxTypeText;
|
||||
import flixel.input.keyboard.FlxKey;
|
||||
|
||||
/**
|
||||
* An FlxTypeText that accounts for text-wrapping in advance,
|
||||
* by overriding the functions of resetText() to check the finished state.
|
||||
* Avoids words starting on one line and continuing in the next.
|
||||
* An FlxTypeText that better accounts for text-wrapping,
|
||||
* by overriding the functions of insertBreakLines() to check the finished state.
|
||||
* Also fixes a bug where empty strings would make the typing never 'finish'.
|
||||
*/
|
||||
class FunkinTypeText extends FlxTypeText
|
||||
{
|
||||
@@ -19,54 +19,86 @@ class FunkinTypeText extends FlxTypeText
|
||||
preWrapping = CheckWrapping;
|
||||
}
|
||||
|
||||
override public function resetText(Text:String):Void
|
||||
override public function start(?Delay:Float, ForceRestart:Bool = false, AutoErase:Bool = false, ?SkipKeys:Array<FlxKey>, ?Callback:Void->Void):Void
|
||||
{
|
||||
_finalText = Text;
|
||||
|
||||
if (preWrapping)
|
||||
if (Delay != null)
|
||||
{
|
||||
text = prefix + Text;
|
||||
var prefixLength:Null<Int> = prefix.length;
|
||||
var split:String = '';
|
||||
|
||||
// trace('Breaking apart text lines...');
|
||||
|
||||
for (i in 0...textField.numLines)
|
||||
{
|
||||
var curLine = textField.getLineText(i);
|
||||
// trace('now at line $i, curLine: $curLine');
|
||||
if (prefixLength >= curLine.length)
|
||||
{
|
||||
prefixLength -= curLine.length;
|
||||
}
|
||||
else if (prefixLength != null)
|
||||
{
|
||||
split += curLine.substr(prefixLength);
|
||||
prefixLength = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
split += '\n' + curLine;
|
||||
}
|
||||
// trace('now at line $i, split: $split');
|
||||
}
|
||||
|
||||
_finalText = split;
|
||||
delay = Delay;
|
||||
}
|
||||
|
||||
text = prefix;
|
||||
_typing = false;
|
||||
_typing = true;
|
||||
_erasing = false;
|
||||
paused = false;
|
||||
_waiting = false;
|
||||
_length = 0;
|
||||
|
||||
if (ForceRestart)
|
||||
{
|
||||
text = "";
|
||||
_length = 0;
|
||||
}
|
||||
|
||||
autoErase = AutoErase;
|
||||
|
||||
if (SkipKeys != null)
|
||||
{
|
||||
skipKeys = SkipKeys;
|
||||
}
|
||||
|
||||
if (Callback != null)
|
||||
{
|
||||
completeCallback = Callback;
|
||||
}
|
||||
|
||||
if (useDefaultSound)
|
||||
{
|
||||
loadDefaultSound();
|
||||
}
|
||||
|
||||
// Autocomplete if the text is empty anyway. Why bother?
|
||||
if (_finalText.length == 0)
|
||||
{
|
||||
onComplete();
|
||||
return;
|
||||
}
|
||||
|
||||
if (preWrapping)
|
||||
{
|
||||
insertBreakLines();
|
||||
}
|
||||
}
|
||||
|
||||
override public function start(?Delay:Float, ForceRestart:Bool = false, AutoErase:Bool = false, ?SkipKeys:Array<FlxKey>, ?Callback:Void->Void):Void
|
||||
override function insertBreakLines()
|
||||
{
|
||||
super.start(Delay, ForceRestart, AutoErase, SkipKeys, Callback);
|
||||
var saveText = text;
|
||||
|
||||
// Autocomplete if the text is empty anyway.
|
||||
if (_finalText.length == 0) onComplete();
|
||||
// See what it looks like when it's finished typing.
|
||||
text = prefix + _finalText;
|
||||
var prefixLength:Null<Int> = prefix.length;
|
||||
var split:String = '';
|
||||
|
||||
// trace('Breaking apart text lines...');
|
||||
|
||||
for (i in 0...textField.numLines)
|
||||
{
|
||||
var curLine = textField.getLineText(i);
|
||||
// trace('now at line $i, curLine: $curLine');
|
||||
if (prefixLength >= curLine.length)
|
||||
{
|
||||
prefixLength -= curLine.length;
|
||||
}
|
||||
else if (prefixLength != null)
|
||||
{
|
||||
split += curLine.substr(prefixLength);
|
||||
prefixLength = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
split += '\n' + curLine;
|
||||
}
|
||||
// trace('now at line $i, split: $split');
|
||||
}
|
||||
|
||||
_finalText = split;
|
||||
text = saveText;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user