dialogues stuff & porting WIP 4

This commit is contained in:
⍚~Nex
2024-02-19 02:34:58 +01:00
parent 471f7de4a1
commit 541e371b7e
11 changed files with 56 additions and 21 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
<!DOCTYPE codename-engine-dialogue-character>
<character sprite="pixel/boyfriend" x="570" y="-599" graphicSizex="1334" antialiasing="false" >
<character sprite="pixel/boyfriend" x="570" y="-599" graphicSizex="1334" antialiasing="false" textSound="pixel/pixelText">
<anim name="show" anim="Boyfriend portrait enter instance 10" fps="24" />
</character>
+1 -1
View File
@@ -1,4 +1,4 @@
<!DOCTYPE codename-engine-dialogue-character>
<character sprite="pixel/senpai" x="-392" y="-599" graphicSizex="1334" antialiasing="false" >
<character sprite="pixel/senpai" x="-392" y="-599" graphicSizex="1334" antialiasing="false" textSound="pixel/pixelText">
<anim name="show" anim="Senpai Portrait Enter instance 10" fps="24" />
</character>
+1 -1
View File
@@ -5,7 +5,7 @@
<char name="pixelBf" char="pixelBf" position="right" />
<!-- Lines -->
<line char="senpai">
<line char="senpai" playSound="pixel/ANGRY_TEXT_BOX" speed="0.08" textSound="pixel/ANGRY">
Not bad for an ugly worm.
</line>
<line char="senpai">
+1 -1
View File
@@ -5,7 +5,7 @@
<char name="pixelBf" char="pixelBf" position="right" />
<!-- Lines -->
<line char="senpai">
<line char="senpai" changeMusic="pixel/Lunchbox">
Ah, a new fair maiden has come in search of true love!
</line>
<line char="senpai">
+1 -1
View File
@@ -4,7 +4,7 @@
<char name="senpai" char="senpai" position="left" />
<!-- Lines -->
<line char="senpai">
<line char="senpai" changeMusic="pixel/LunchboxScary">
Direct contact with real humans, after being trapped in here for so long...
</line>
<line char="senpai">
Binary file not shown.
Binary file not shown.
@@ -17,8 +17,8 @@ class DialogueCutscene extends Cutscene {
public var curLine:DialogueLine = null;
public var dialogueBox:DialogueBox;
public var nextSFX:FlxSound;
public var dialogueCamera:FlxCamera;
public var curMusic:FlxSound = null;
public function new(dialoguePath:String, callback:Void->Void) {
super(callback);
@@ -42,22 +42,38 @@ class DialogueCutscene extends Cutscene {
add(charMap[char.att.name] = new DialogueCharacter(char.att.name, char.getAtt('position').getDefault('default')));
}
var useDef:Bool = false;
if(dialogueData.has.forceBoxDefaultTxtSound && dialogueData.att.forceBoxDefaultTxtSound == "true")
useDef = true;
// Add lines
for(node in dialogueData.nodes.line) {
dialogueLines.push({
var line:DialogueLine = {
text: XMLUtil.fixXMLText(node.innerHTML),
char: node.getAtt('char').getDefault('boyfriend'),
bubble: node.getAtt('bubble').getDefault('normal'),
callback: node.getAtt('callback'),
speed: node.has.speed ? Std.parseFloat(node.att.speed).getDefault(0.05) : 0.05
});
speed: node.has.speed ? Std.parseFloat(node.att.speed).getDefault(0.05) : 0.05,
changeMusic: node.has.changeMusic ? FlxG.sound.load(Paths.music(node.getAtt('changeMusic')), 0.8, true) : null,
playSound: node.has.playSound ? FlxG.sound.load(Paths.sound(node.getAtt('playSound'))) : null,
nextSound: node.has.nextSound ? FlxG.sound.load(Paths.music(node.getAtt('nextSound'))) : null,
textSound: null
};
if(node.has.textSound) line.textSound = FlxG.sound.load(Paths.sound(node.getAtt('textSound')));
else if(!useDef) {
var char:DialogueCharacter = charMap[line.char];
if(char != null && char.charData != null && char.charData.has.textSound)
line.textSound = FlxG.sound.load(Paths.sound(char.charData.getAtt("textSound")));
}
dialogueLines.push(line);
}
// Add dialogue box
dialogueBox = new DialogueBox(dialogueData.getAtt("box").getDefault("default"));
add(dialogueBox);
add(dialogueBox.text);
next();
} catch(e) {
@@ -84,10 +100,19 @@ class DialogueCutscene extends Cutscene {
if (charMap[curLine.char] != null)
dialogueBox.popupChar(charMap[curLine.char]);
dialogueBox.playBubbleAnim(curLine.bubble, curLine.text, curLine.speed);
dialogueBox.playBubbleAnim(curLine.bubble, curLine.text, curLine.speed, curLine.nextSound, curLine.textSound != null ? [curLine.textSound] : null);
if(curLine.playSound != null) curLine.playSound.play();
if(curLine.changeMusic != null) {
if(curMusic != null) curMusic.destroy();
curMusic = curLine.changeMusic;
curMusic.play();
curMusic.fadeIn(1, 0, curMusic.volume);
}
}
public override function destroy() {
if(curMusic != null) curMusic.destroy();
super.destroy();
FlxG.cameras.remove(dialogueCamera);
}
@@ -99,4 +124,8 @@ typedef DialogueLine = {
var bubble:String;
var callback:String;
var speed:Float;
var changeMusic:FlxSound;
var playSound:FlxSound;
var nextSound:FlxSound;
var textSound:FlxSound;
}
@@ -1,5 +1,6 @@
package funkin.game.cutscenes.dialogue;
import flixel.sound.FlxSound;
import flixel.addons.text.FlxTypeText;
import flixel.text.FlxText;
import flixel.math.FlxPoint;
@@ -10,13 +11,15 @@ class DialogueBox extends FunkinSprite {
public var positions:Map<String, CharPosDef> = [];
public var everPlayedAny:Bool = false;
public var textTypeSFX:String = Paths.sound('dialogue/text');
public var nextSFX:String = Paths.sound('dialogue/next');
public var defaultTextTypeSFX:Array<FlxSound>;
public var text:FlxTypeText;
public function new(name:String) {
super();
var textTypeSFX:String = Paths.sound('dialogue/text');
try {
dialogueBoxData = new Access(Xml.parse(Assets.getText(Paths.xml('dialogue/boxes/$name'))).firstElement());
if(!dialogueBoxData.has.sprite) dialogueBoxData.x.set("sprite", name);
@@ -31,9 +34,10 @@ class DialogueBox extends FunkinSprite {
if(dialogueBoxData.has.nextSound) nextSFX = Paths.sound(dialogueBoxData.att.nextSound);
animation.finishCallback = (name:String) -> {
if(name.endsWith("-open") || name.endsWith("-firstOpen")) {
playAnim(name.substr(0, name.length - 5));
setText(__nextText, __speed);
var finalPt:String;
if(name.endsWith(finalPt = "-open") || name.endsWith(finalPt = "-firstOpen")) {
playAnim(name.substr(0, name.length - finalPt.length));
setText(__nextText, __speed, __customTypeSFX);
}
}
@@ -57,7 +61,6 @@ class DialogueBox extends FunkinSprite {
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";
text.sounds = [FlxG.sound.load(textTypeSFX)];
if(textNode.has.borderStyle) {
text.borderStyle = switch(textNode.att.borderStyle.trim().toLowerCase()) {
case "none": NONE;
@@ -72,8 +75,8 @@ class DialogueBox extends FunkinSprite {
active = false;
Logs.trace('Couldn\'t load dialogue box "$name": ${e.toString()}', ERROR);
}
defaultTextTypeSFX = [FlxG.sound.load(textTypeSFX)];
FlxG.sound.cache(nextSFX);
FlxG.sound.cache(textTypeSFX);
}
public function popupChar(char:DialogueCharacter) {
@@ -86,22 +89,25 @@ class DialogueBox extends FunkinSprite {
private var __nextText:String;
private var __speed:Float;
public function playBubbleAnim(bubble:String, text:String, speed:Float = 0.05) {
private var __customTypeSFX:Array<FlxSound>;
public function playBubbleAnim(bubble:String, text:String, speed:Float = 0.05, ?customSFX:FlxSound, ?customTypeSFX:Array<FlxSound>, ?playNext:Bool) {
this.__nextText = text;
this.__speed = speed;
this.__customTypeSFX = customTypeSFX;
this.text.resetText(text);
FlxG.sound.play(nextSFX);
if(playNext || (playNext == null && everPlayedAny)) customSFX != null ? customSFX.play() : FlxG.sound.play(nextSFX);
if(hasAnimation('$bubble-open')) playAnim('$bubble-open', true);
else if(hasAnimation('$bubble-firstOpen') && !everPlayedAny) playAnim('$bubble-firstOpen', true);
else {
playAnim(bubble);
setText(__nextText, __speed);
setText(__nextText, __speed, __customTypeSFX);
}
visible = true;
everPlayedAny = true;
}
public function setText(text:String, speed:Float = 0.02) {
public function setText(text:String, speed:Float = 0.02, ?customTypeSFX:Array<FlxSound>) {
this.text.sounds = customTypeSFX != null ? customTypeSFX : defaultTextTypeSFX;
this.text.delay = speed;
this.text.start(speed, true);
}