goofy ahh dialog

This commit is contained in:
Yoshman29
2023-01-20 23:12:59 +01:00
parent b7d01c2a08
commit d9a779151c
8 changed files with 69 additions and 32 deletions
+10 -9
View File
@@ -18,13 +18,14 @@ class DialogueCutscene extends Cutscene {
public var dialogueBox:DialogueBox;
public var nextSFX:FlxSound;
public var dialogueCamera:FlxCamera;
public function new(dialoguePath:String, callback:Void->Void) {
super(callback);
this.dialoguePath = dialoguePath;
camera = new FlxCamera();
camera.bgColor = 0;
FlxG.cameras.add(camera, false);
camera = dialogueCamera = new FlxCamera();
dialogueCamera.bgColor = 0;
FlxG.cameras.add(dialogueCamera, false);
}
public override function create() {
@@ -56,6 +57,8 @@ class DialogueCutscene extends Cutscene {
dialogueBox = new DialogueBox(dialogueData.getAtt("box").getDefault("default"));
add(dialogueBox);
next();
} catch(e) {
Logs.trace('Error while loading dialogue at ${dialoguePath}', ERROR);
@@ -75,11 +78,9 @@ class DialogueCutscene extends Cutscene {
return;
}
for(c in charMap) {
if (c.visible) {
// TODO: remove character smoothly
}
}
for(k=>c in charMap)
if (k != curLine.char)
c.hide();
if (charMap[curLine.char] != null)
dialogueBox.popupChar(charMap[curLine.char]);
@@ -88,7 +89,7 @@ class DialogueCutscene extends Cutscene {
public override function destroy() {
super.destroy();
FlxG.cameras.remove(camera);
FlxG.cameras.remove(dialogueCamera);
}
}
@@ -9,6 +9,9 @@ class DialogueBox extends FunkinSprite {
public var dialogueBoxData:Access;
public var positions:Map<String, CharPosDef> = [];
public var textTypeSFX:String = Paths.sound('dialogue/text');
public var nextSFX:String = Paths.sound('dialogue/next');
public function new(name:String) {
super();
try {
@@ -30,6 +33,9 @@ class DialogueBox extends FunkinSprite {
};
}
if (dialogueBoxData.has.textSound) textTypeSFX = Paths.sound(dialogueBoxData.att.textSound);
if (dialogueBoxData.has.nextSound) nextSFX = Paths.sound(dialogueBoxData.att.nextSound);
antialiasing = dialogueBoxData.getAtt("antialiasing").getDefault("true") == "true";
screenCenter(X);
y = FlxG.height - height;
@@ -40,6 +46,8 @@ class DialogueBox extends FunkinSprite {
active = false;
Logs.trace('Couldn\'t load dialogue box "$name": ${e.toString()}', ERROR);
}
FlxG.sound.cache(nextSFX);
FlxG.sound.cache(textTypeSFX);
}
public function popupChar(char:DialogueCharacter) {
@@ -47,15 +55,11 @@ class DialogueBox extends FunkinSprite {
var pos = positions[char.positionName];
if (pos == null) return;
if (!char.visible) {
char.alpha = 0;
char.visible = true;
char.setPosition(pos.x, pos.y + 100);
char.show(pos.y);
}
char.show((FlxG.width / 2) + pos.x, FlxG.height - pos.y);
}
public function playBubbleAnim(bubble:String) {
FlxG.sound.play(nextSFX);
if (hasAnimation('$bubble-open'))
playAnim('$bubble-open', true);
else
@@ -63,6 +67,15 @@ class DialogueBox extends FunkinSprite {
visible = true;
}
public override function update(elapsed:Float) {
super.update(elapsed);
if (isAnimFinished()) {
var animName = getAnimName();
if (animName.endsWith("-open"))
playAnim(animName.substr(0, animName.length - 5));
}
}
public override function destroy() {
super.destroy();
positions = null;
@@ -8,6 +8,7 @@ import haxe.xml.Access;
class DialogueCharacter extends FunkinSprite {
public var charData:Access;
public var curTween:FlxTween;
public var curTweenContext:DialogueCharTweenContext = NONE;
public var positionName:String;
public function new(name:String, position:String) {
@@ -17,10 +18,11 @@ class DialogueCharacter extends FunkinSprite {
charData = new Access(Xml.parse(Assets.getText(Paths.xml('dialogue/characters/$name'))).firstElement());
loadSprite(Paths.image('dialogue/characters/${charData.getAtt('sprite').getDefault(name)}'));
antialiasing = charData.getAtt('antialiasing').getDefault('true') == 'true';
scale.scale(charData.has.scale ? Std.parseFloat(charData.att.scale).getDefault(1) : 1);
updateHitbox();
offset.set(
charData.has.x ? Std.parseFloat(charData.att.x).getDefault(0) : 0,
charData.has.y ? Std.parseFloat(charData.att.y).getDefault(0) : 0);
scale.scale(charData.has.scale ? Std.parseFloat(charData.att.scale).getDefault(1) : 1);
(charData.has.y ? Std.parseFloat(charData.att.y).getDefault(0) : 0) + this.height);
for(anim in charData.nodes.anim)
XMLUtil.addXMLAnimation(this, anim, true);
} catch(e) {
@@ -29,10 +31,31 @@ class DialogueCharacter extends FunkinSprite {
visible = false;
}
public function show(y:Float) {
if (curTween != null)
curTween.cancel();
public function show(x:Float, y:Float) {
if (curTweenContext != (curTweenContext = POPIN)) {
setPosition(x, y + 100);
if (curTween != null)
curTween.cancel();
curTween = FlxTween.tween(this, {alpha: 1, y: y}, 0.5, {ease: FlxEase.cubeOut});
alpha = 0;
visible = true;
curTween = FlxTween.tween(this, {alpha: 1, y: y}, 0.2, {ease: FlxEase.quintOut});
}
}
public function hide() {
if (curTweenContext != (curTweenContext = POPOUT)) {
if (curTween != null)
curTween.cancel();
curTween = FlxTween.tween(this, {alpha: 0, y: y + 100}, 0.2, {ease: FlxEase.quintIn});
}
}
}
enum abstract DialogueCharTweenContext(Int) {
var NONE = -1;
var POPIN = 0;
var POPOUT = 1;
}