diff --git a/assets/songs/test/dialogue.hx b/assets/songs/test/dialogue.hx new file mode 100644 index 00000000..5d3e7fa0 --- /dev/null +++ b/assets/songs/test/dialogue.hx @@ -0,0 +1,5 @@ +function next(event) + if (!event.playFirst) trace("-"); + +function postNext(event) + trace(curLine.char + " says: " + curLine.text); \ No newline at end of file diff --git a/source/funkin/backend/scripting/events/dialogue/DialogueNextLineEvent.hx b/source/funkin/backend/scripting/events/dialogue/DialogueNextLineEvent.hx new file mode 100644 index 00000000..7a5e3eac --- /dev/null +++ b/source/funkin/backend/scripting/events/dialogue/DialogueNextLineEvent.hx @@ -0,0 +1,14 @@ +package funkin.backend.scripting.events.dialogue; + +/** + * CANCEL this event to prevent continuing with the next dialogue. + * + * **NOTE**: To access the current, past or next lines, use `curLine`, `lastLine` or also `dialogueLines` in the `DialogueCutscene` class (they're globals and can be accessed at any time as long as the Dialogue Cutscene is active)! + */ +final class DialogueNextLineEvent extends CancellableEvent +{ + /** + * If the dialogue has just been opened. + */ + public var playFirst:Bool = false; +} \ No newline at end of file diff --git a/source/funkin/game/cutscenes/DialogueCutscene.hx b/source/funkin/game/cutscenes/DialogueCutscene.hx index cc4032f7..99ba142b 100644 --- a/source/funkin/game/cutscenes/DialogueCutscene.hx +++ b/source/funkin/game/cutscenes/DialogueCutscene.hx @@ -3,7 +3,7 @@ package funkin.game.cutscenes; import funkin.backend.utils.FunkinParentDisabler; import funkin.backend.scripting.events.dialogue.*; import funkin.backend.scripting.events.CancellableEvent; -import funkin.backend.scripting.events.DynamicEvent; +import funkin.backend.scripting.events.dialogue.DialogueNextLineEvent; import funkin.backend.scripting.Script; import flixel.sound.FlxSound; import funkin.game.cutscenes.dialogue.*; @@ -138,8 +138,8 @@ class DialogueCutscene extends Cutscene { public var canProceed:Bool = true; public function next(playFirst:Bool = false) { - var event = EventManager.get(DynamicEvent).recycle(playFirst); - dialogueScript.call("next", [playFirst]); + var event = EventManager.get(DialogueNextLineEvent).recycle(playFirst); + dialogueScript.call("next", [event]); if(event.cancelled || !canProceed) return; if ((curLine = dialogueLines.shift()) == null) { @@ -154,7 +154,7 @@ class DialogueCutscene extends Cutscene { } if (curLine.callback != null) - dialogueScript.call(curLine.callback, [playFirst]); + dialogueScript.call(curLine.callback, [event.playFirst]); for (k=>c in charMap) if (k != curLine.char) @@ -167,8 +167,8 @@ class DialogueCutscene extends Cutscene { dialogueBox.popupChar(char, force); } - var finalSuffix:String = playFirst && dialogueBox.hasAnimation(curLine.bubble + "-firstOpen") ? "-firstOpen" : dialogueBox.hasAnimation(curLine.bubble + "-open") ? "-open" : ""; - dialogueBox.playBubbleAnim(curLine.bubble, finalSuffix, curLine.text, curLine.format, curLine.speed, curLine.nextSound, curLine.textSound != null ? [curLine.textSound] : null, finalSuffix == "-firstOpen" || finalSuffix == "-open", !playFirst); + var finalSuffix:String = event.playFirst && dialogueBox.hasAnimation(curLine.bubble + "-firstOpen") ? "-firstOpen" : dialogueBox.hasAnimation(curLine.bubble + "-open") ? "-open" : ""; + dialogueBox.playBubbleAnim(curLine.bubble, finalSuffix, curLine.text, curLine.format, curLine.speed, curLine.nextSound, curLine.textSound != null ? [curLine.textSound] : null, finalSuffix == "-firstOpen" || finalSuffix == "-open", !event.playFirst); if(curLine.playSound != null) curLine.playSound.play(); if(curLine.changeMusic != null) { @@ -178,7 +178,7 @@ class DialogueCutscene extends Cutscene { curMusic.fadeIn(1, 0, curMusic.volume); } else if(curLine.musicVolume != null && curMusic != null) curMusic.volume = curLine.musicVolume; - dialogueScript.call("postNext", [playFirst]); + dialogueScript.call("postNext", [event]); } public override function close() {