From abb953647e730d3cacb6d72aa9aac634dd52f87e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Mon, 26 Feb 2024 00:34:25 +0100 Subject: [PATCH] FINISHED PORTING 10 gotta still finalize dialogues 98% completed dialogue system! BUT ALL THE PORTING COMPLEDD --- .../data/dialogue/boxes/hating-simulator.hx | 14 +++---- .../data/dialogue/boxes/spirit-creepy-box.hx | 33 +++++++++++---- assets/data/stages/school-evil.xml | 2 +- assets/songs/roses/dialogue.hx | 8 ++++ assets/songs/thorns/cutscene.hx | 4 +- .../events/DialogueStructureEvent.hx | 11 +++++ source/funkin/game/PlayState.hx | 29 +++++++------ .../funkin/game/cutscenes/DialogueCutscene.hx | 41 ++++++++++++++++--- .../game/cutscenes/dialogue/DialogueBox.hx | 2 +- .../cutscenes/dialogue/DialogueCharacter.hx | 2 +- 10 files changed, 108 insertions(+), 38 deletions(-) create mode 100644 assets/songs/roses/dialogue.hx create mode 100644 source/funkin/backend/scripting/events/DialogueStructureEvent.hx diff --git a/assets/data/dialogue/boxes/hating-simulator.hx b/assets/data/dialogue/boxes/hating-simulator.hx index 791bc411..b3584aee 100644 --- a/assets/data/dialogue/boxes/hating-simulator.hx +++ b/assets/data/dialogue/boxes/hating-simulator.hx @@ -1,3 +1,4 @@ +var loopedTimah:FlxTimer; // Hey! a man has fallen into the river in lego city! and if youre asking why this is here, you shall disappear! - Nex var bgFade:FlxSprite; var hand:FlxSprite; @@ -8,7 +9,7 @@ function postCreate() { bgFade.alpha = 0; cutscene.insert(0, bgFade); - new FlxTimer().start(0.83, function(tmr:FlxTimer) + loopedTimah = new FlxTimer().start(0.83, function(tmr:FlxTimer) { bgFade.alpha += (1 / 5) * 0.7; if (bgFade.alpha > 0.7) @@ -26,14 +27,11 @@ function close(event) { else event.cancelled = true; cutscene.canProceed = false; - if(cutscene.curMusic != null) { - cutscene.curMusic.persist = true; - cutscene.curMusic.fadeOut(2.2, 0); - cutscene.curMusic.fadeTween.onComplete = (_) -> cutscene.curMusic.destroy(); - } - + cutscene.curMusic?.fadeOut(1, 0); for(c in cutscene.charMap) c.visible = false; - new FlxTimer().start(0.2, function(tmr:FlxTimer) + + loopedTimah.cancel(); + loopedTimah = new FlxTimer().start(0.2, function(tmr:FlxTimer) { if (tmr.elapsedLoops <= 5) { cutscene.dialogueBox.alpha -= 1 / 5; diff --git a/assets/data/dialogue/boxes/spirit-creepy-box.hx b/assets/data/dialogue/boxes/spirit-creepy-box.hx index 63efe4f8..ddb0b6ff 100644 --- a/assets/data/dialogue/boxes/spirit-creepy-box.hx +++ b/assets/data/dialogue/boxes/spirit-creepy-box.hx @@ -1,4 +1,3 @@ -// TO FINISH!!! - Nex import flixel.tweens.FlxTweenType; var aberration:CustomShader = null; @@ -8,17 +7,37 @@ function postCreate() { spirit.setGraphicSize(Std.int(spirit.width * 6)); if(Options.gameplayShaders) { spirit.shader = aberration = new CustomShader('chromaticAberration'); - FlxTween.num(-0.003, 0.003, 3, {ease: FlxEase.sineInOut, type: FlxTweenType.PINGPONG}, function(num) { aberration.redOff = [0, -num]; aberration.blueOff = [0, num]; }); + FlxTween.num(-0.003, 0.003, 3, {ease: FlxEase.sineInOut, type: FlxTweenType.PINGPONG}, function(num) { if(aberration == null) return; aberration.redOff = [0, -num]; aberration.blueOff = [0, num]; }); } - //spirit.alpha = 0; cutscene.add(spirit); + + FlxG.camera._fxFadeAlpha = 0; + cutscene.dialogueCamera.bgColor = FlxColor.fromRGBFloat(1, 1, 1, 0.3); +} + +var finished:Bool = false; +function close(event) { + if(finished) return; + else event.cancelled = true; + cutscene.canProceed = false; + + cutscene.curMusic?.fadeOut(1, 0); + for(c in cutscene.charMap) c.visible = false; + + spirit.destroy(); + spirit.shader = aberration = null; + new FlxTimer().start(0.4, function(swagTimer:FlxTimer) { + cutscene.dialogueCamera.alpha -= 0.15; + + if(cutscene.dialogueCamera.alpha > 0) swagTimer.reset(); + else { + finished = true; + cutscene.close(); + } + }); } function popupChar(event) { if(!active || event.char.positionName != "left") return; event.char.color = FlxColor.BLACK; - var pos = positions["left"]; - if (pos == null) return; // It shouldnt but whatever - Nex - - //spirit.setPosition((FlxG.width / 2) + pos.x - event.char.offset.x, FlxG.height - pos.y - event.char.offset.y); } \ No newline at end of file diff --git a/assets/data/stages/school-evil.xml b/assets/data/stages/school-evil.xml index 297e98bd..568b3aad 100644 --- a/assets/data/stages/school-evil.xml +++ b/assets/data/stages/school-evil.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/assets/songs/roses/dialogue.hx b/assets/songs/roses/dialogue.hx new file mode 100644 index 00000000..c4329664 --- /dev/null +++ b/assets/songs/roses/dialogue.hx @@ -0,0 +1,8 @@ +function next(first:Bool) { + if(first && canProceed) { + canProceed = false; + dialogueLines[0].playSound.play(); + new FlxTimer().start(1, (_) -> this.next(true)); + } + else if(this.lastLine == null) canProceed = true; // If its not null means the dialogue is not at the first one! - Nex +} \ No newline at end of file diff --git a/assets/songs/thorns/cutscene.hx b/assets/songs/thorns/cutscene.hx index 13ceed85..ee84365e 100644 --- a/assets/songs/thorns/cutscene.hx +++ b/assets/songs/thorns/cutscene.hx @@ -41,10 +41,10 @@ function create() { }); scream = FlxG.sound.play(Paths.sound('cutscenes/weeb/Senpai_Dies'), 1, false, null, true, function() { - new FlxTimer().start(0.2, function(swagTimer:FlxTimer) { + new FlxTimer().start(0.4, function(swagTimer:FlxTimer) { FlxG.camera._fxFadeAlpha -= 0.15; - if(FlxG.camera._fxFadeAlpha > 0) swagTimer.reset(); + if(FlxG.camera._fxFadeAlpha > 0.3) swagTimer.reset(); else { camHUD.visible = true; self.startDialogue("songs/" + PlayState.instance.SONG.meta.name.toLowerCase() + "/creepyDialogue.xml", self.close); diff --git a/source/funkin/backend/scripting/events/DialogueStructureEvent.hx b/source/funkin/backend/scripting/events/DialogueStructureEvent.hx new file mode 100644 index 00000000..da4d5da4 --- /dev/null +++ b/source/funkin/backend/scripting/events/DialogueStructureEvent.hx @@ -0,0 +1,11 @@ +package funkin.backend.scripting.events; + +import haxe.xml.Access; + +/** + * CANCEL this event to customize from 0 the xml structure part! + */ +final class DialogueStructureEvent extends CancellableEvent +{ + public var dialogueData:Access; +} \ No newline at end of file diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index 72cb008c..6a9a0a30 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -726,7 +726,7 @@ class PlayState extends MusicBeatState scoreTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Score:0", 16); missesTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Misses:0", 16); - accuracyTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Acc:-% (N/A)", 16); + accuracyTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Accuracy:-% (N/A)", 16); accuracyTxt.addFormat(accFormat, 0, 1); for(text in [scoreTxt, missesTxt, accuracyTxt]) { @@ -736,6 +736,7 @@ class PlayState extends MusicBeatState scoreTxt.alignment = RIGHT; missesTxt.alignment = CENTER; accuracyTxt.alignment = LEFT; + updateRatingStuff(); for(e in [healthBar, healthBarBG, iconP1, iconP2, scoreTxt, missesTxt, accuracyTxt]) e.cameras = [camHUD]; @@ -1191,17 +1192,7 @@ class PlayState extends MusicBeatState iconP2.health = 1 - (healthBar.percent / 100); } - @:dox(hide) - override public function update(elapsed:Float) - { - scripts.call("update", [elapsed]); - - if (inCutscene) { - super.update(elapsed); - scripts.call("postUpdate", [elapsed]); - return; - } - + function updateRatingStuff() { scoreTxt.text = 'Score:$songScore'; missesTxt.text = '${comboBreaks ? "Combo Breaks" : "Misses"}:$misses'; @@ -1215,6 +1206,20 @@ class PlayState extends MusicBeatState accuracyTxt._formatRanges[0].range.start = accuracyTxt.text.length - curRating.rating.length; accuracyTxt._formatRanges[0].range.end = accuracyTxt.text.length; } + } + + @:dox(hide) + override public function update(elapsed:Float) + { + scripts.call("update", [elapsed]); + + if (inCutscene) { + super.update(elapsed); + scripts.call("postUpdate", [elapsed]); + return; + } + + updateRatingStuff(); if (controls.PAUSE && startedCountdown && canPause) pauseGame(); diff --git a/source/funkin/game/cutscenes/DialogueCutscene.hx b/source/funkin/game/cutscenes/DialogueCutscene.hx index 518c0a05..d4c706e3 100644 --- a/source/funkin/game/cutscenes/DialogueCutscene.hx +++ b/source/funkin/game/cutscenes/DialogueCutscene.hx @@ -1,10 +1,12 @@ package funkin.game.cutscenes; -import funkin.backend.scripting.events.CancellableEvent; +import funkin.backend.utils.FunkinParentDisabler; +import funkin.backend.scripting.events.*; import funkin.backend.scripting.Script; import flixel.sound.FlxSound; import funkin.game.cutscenes.dialogue.*; import haxe.xml.Access; +import haxe.io.Path; /** * Substate made for dialogue cutscenes. To use it in a scripted cutscene, call `startDialogue`. @@ -24,7 +26,7 @@ class DialogueCutscene extends Cutscene { public var curMusic:FlxSound = null; public static var cutscene:DialogueCutscene; - //public var dialogueScript:Script; + public var dialogueScript:Script; public function set_curLine(val:DialogueLine) { lastLine = curLine; @@ -37,14 +39,23 @@ class DialogueCutscene extends Cutscene { camera = dialogueCamera = new FlxCamera(); dialogueCamera.bgColor = 0; FlxG.cameras.add(dialogueCamera, false); + + dialogueScript = Script.create(Paths.script(Path.withoutExtension(dialoguePath), null, dialoguePath.startsWith('assets'))); + dialogueScript.setParent(cutscene = this); + dialogueScript.load(); } + var parentDisabler:FunkinParentDisabler; public override function create() { - cutscene = this; super.create(); + add(parentDisabler = new FunkinParentDisabler()); try { - dialogueData = new Access(Xml.parse(Assets.getText(dialoguePath)).firstElement()); + var event = EventManager.get(DialogueStructureEvent).recycle(dialogueData); + event.dialogueData = new Access(Xml.parse(Assets.getText(dialoguePath)).firstElement()); + dialogueScript.call('structureLoaded', [event]); + if(event.cancelled) return; + dialogueData = event.dialogueData; // Add characters for(char in dialogueData.nodes.char) { @@ -98,10 +109,18 @@ class DialogueCutscene extends Cutscene { Logs.trace('Error while loading dialogue at ${dialoguePath}: ${e.toString()}', ERROR); close(); } + dialogueScript.call("postCreate"); + } + + public override function beatHit(curBeat:Int) { + super.beatHit(curBeat); + dialogueScript.call("beatHit", [curBeat]); } public override function update(elapsed:Float) { super.update(elapsed); + dialogueScript.call("update", [elapsed]); + if(controls.ACCEPT) { @:privateAccess if(dialogueBox.dialogueEnded) next(); @@ -109,8 +128,13 @@ class DialogueCutscene extends Cutscene { } } + /** + * Use this to cancel `next`! + */ public var canProceed:Bool = true; + public function next(playFirst:Bool = false) { + dialogueScript.call("next", [playFirst]); if(!canProceed) return; if ((curLine = dialogueLines.shift()) == null) { @@ -145,20 +169,25 @@ class DialogueCutscene extends Cutscene { curMusic.play(); curMusic.fadeIn(1, 0, curMusic.volume); } else if(curLine.musicVolume != null && curMusic != null) curMusic.volume = curLine.musicVolume; + + dialogueScript.call("postNext", [playFirst]); } public override function close() { var event = new CancellableEvent(); for(c in charMap) c.dialogueCharScript.call("close", [event]); dialogueBox.dialogueBoxScript.call("close", [event]); - if(event.cancelled) - return; + dialogueScript.call("close", [event]); + if(event.cancelled) return; super.close(); } public override function destroy() { if(curMusic != null && !curMusic.persist) curMusic.destroy(); + dialogueScript.call("destroy"); + dialogueScript.destroy(); + super.destroy(); cutscene = null; FlxG.cameras.remove(dialogueCamera); diff --git a/source/funkin/game/cutscenes/dialogue/DialogueBox.hx b/source/funkin/game/cutscenes/dialogue/DialogueBox.hx index 28f3b090..68cc5157 100644 --- a/source/funkin/game/cutscenes/dialogue/DialogueBox.hx +++ b/source/funkin/game/cutscenes/dialogue/DialogueBox.hx @@ -36,7 +36,7 @@ class DialogueBox extends FunkinSprite { if(event.cancelled) return; // No idea the pyscho that would do this but hey, it can happen - Nex try { - event.dialogueBoxData = dialogueBoxData = new Access(Xml.parse(Assets.getText(Paths.xml(defPath + event.name))).firstElement()); + event.dialogueBoxData = new Access(Xml.parse(Assets.getText(Paths.xml(defPath + event.name))).firstElement()); dialogueBoxScript.call('structureLoaded', [event]); if(event.cancelled) return; name = event.name; diff --git a/source/funkin/game/cutscenes/dialogue/DialogueCharacter.hx b/source/funkin/game/cutscenes/dialogue/DialogueCharacter.hx index 223d2111..73088192 100644 --- a/source/funkin/game/cutscenes/dialogue/DialogueCharacter.hx +++ b/source/funkin/game/cutscenes/dialogue/DialogueCharacter.hx @@ -32,7 +32,7 @@ class DialogueCharacter extends FunkinSprite { if(event.cancelled) return; try { - event.charData = charData = new Access(Xml.parse(Assets.getText(Paths.xml(defPath + event.name))).firstElement()); + event.charData = new Access(Xml.parse(Assets.getText(Paths.xml(defPath + event.name))).firstElement()); dialogueCharScript.call('structureLoaded', [event]); if(event.cancelled) return; name = event.name;