This commit is contained in:
Yoshman29
2023-01-21 00:05:29 +01:00
parent d9a779151c
commit 7b5f0595c7
4 changed files with 44 additions and 7 deletions
+8 -1
View File
@@ -1,6 +1,13 @@
<!DOCTYPE codename-engine-dialogue-box>
<dialoguebox scale="0.9" y="75">
<!-- All positions for the dialogue box -->
<!--
Node containing all text settings
-->
<text font="vcr" x="107" y="206" width="1053" color="#000000" size="40"/>
<!--
All positions for characters
-->
<charpos name="left" x="-500" y="184" />
<charpos name="middle" x="0" y="184" />
<charpos name="right" x="500" y="184" flipBubble="true" />
+1 -1
View File
@@ -1 +1 @@
2122
2129
+2 -2
View File
@@ -56,7 +56,7 @@ class DialogueCutscene extends Cutscene {
// Add dialogue box
dialogueBox = new DialogueBox(dialogueData.getAtt("box").getDefault("default"));
add(dialogueBox);
add(dialogueBox.text);
next();
@@ -84,7 +84,7 @@ class DialogueCutscene extends Cutscene {
if (charMap[curLine.char] != null)
dialogueBox.popupChar(charMap[curLine.char]);
dialogueBox.playBubbleAnim(curLine.bubble);
dialogueBox.playBubbleAnim(curLine.bubble, curLine.text, curLine.speed);
}
public override function destroy() {
@@ -1,5 +1,7 @@
package funkin.cutscenes.dialogue;
import flixel.addons.text.FlxTypeText;
import flixel.text.FlxText;
import openfl.utils.Assets;
import flixel.FlxG;
import flixel.math.FlxPoint;
@@ -12,6 +14,8 @@ class DialogueBox extends FunkinSprite {
public var textTypeSFX:String = Paths.sound('dialogue/text');
public var nextSFX:String = Paths.sound('dialogue/next');
public var text:FlxTypeText;
public function new(name:String) {
super();
try {
@@ -42,6 +46,18 @@ class DialogueBox extends FunkinSprite {
if (dialogueBoxData.has.x) x += Std.parseFloat(dialogueBoxData.att.x).getDefault(0);
if (dialogueBoxData.has.y) y += Std.parseFloat(dialogueBoxData.att.y).getDefault(0);
visible = false;
var textNode = dialogueBoxData.node.text;
if (textNode == null)
throw "The dialog box XML requires one text element.";
text = new FlxTypeText(
textNode.has.x ? Std.parseFloat(textNode.att.x).getDefault(0) : 0,
FlxG.height - (textNode.has.y ? Std.parseFloat(textNode.att.y).getDefault(0) : 0),
textNode.has.width ? Std.parseInt(textNode.att.width).getDefault(FlxG.width) : FlxG.width, "");
text.color = textNode.getAtt("color").getColorFromDynamic().getDefault(0xFF000000);
text.size = Std.parseInt(textNode.att.size).getDefault(20);
text.font = Paths.font('${textNode.getAtt("font").getDefault("vcr")}.ttf');
text.antialiasing = textNode.getAtt("antialiasing").getDefault("false") == "true";
} catch(e) {
active = false;
Logs.trace('Couldn\'t load dialogue box "$name": ${e.toString()}', ERROR);
@@ -58,21 +74,35 @@ class DialogueBox extends FunkinSprite {
char.show((FlxG.width / 2) + pos.x, FlxG.height - pos.y);
}
public function playBubbleAnim(bubble:String) {
private var __nextText:String;
private var __speed:Float;
public function playBubbleAnim(bubble:String, text:String, speed:Float = 0.02) {
this.__nextText = text;
this.__speed = speed;
this.text.resetText(text);
FlxG.sound.play(nextSFX);
if (hasAnimation('$bubble-open'))
playAnim('$bubble-open', true);
else
else {
playAnim(bubble);
setText(__nextText, __speed);
}
visible = true;
}
public function setText(text:String, speed:Float = 0.02) {
this.text.delay = speed;
this.text.start(speed, true);
}
public override function update(elapsed:Float) {
super.update(elapsed);
if (isAnimFinished()) {
var animName = getAnimName();
if (animName.endsWith("-open"))
if (animName.endsWith("-open")) {
playAnim(animName.substr(0, animName.length - 5));
setText(__nextText, __speed);
}
}
}