Skip to content

Commit b1b1663

Browse files
Event based dialogue handling (#443)
* Event based dialogue handling * better imo * typo * Small script example new script by NexIsDumb --------- Co-authored-by: ⍚~Nex <87421482+NexIsDumb@users.noreply.github.com>
1 parent f8a19b1 commit b1b1663

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

assets/songs/test/dialogue.hx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function next(event)
2+
if (!event.playFirst) trace("-");
3+
4+
function postNext(event)
5+
trace(curLine.char + " says: " + curLine.text);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package funkin.backend.scripting.events.dialogue;
2+
3+
/**
4+
* CANCEL this event to prevent continuing with the next dialogue.
5+
*
6+
* **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)!
7+
*/
8+
final class DialogueNextLineEvent extends CancellableEvent
9+
{
10+
/**
11+
* If the dialogue has just been opened.
12+
*/
13+
public var playFirst:Bool = false;
14+
}

source/funkin/game/cutscenes/DialogueCutscene.hx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package funkin.game.cutscenes;
33
import funkin.backend.utils.FunkinParentDisabler;
44
import funkin.backend.scripting.events.dialogue.*;
55
import funkin.backend.scripting.events.CancellableEvent;
6-
import funkin.backend.scripting.events.DynamicEvent;
6+
import funkin.backend.scripting.events.dialogue.DialogueNextLineEvent;
77
import funkin.backend.scripting.Script;
88
import flixel.sound.FlxSound;
99
import funkin.game.cutscenes.dialogue.*;
@@ -138,8 +138,8 @@ class DialogueCutscene extends Cutscene {
138138
public var canProceed:Bool = true;
139139

140140
public function next(playFirst:Bool = false) {
141-
var event = EventManager.get(DynamicEvent).recycle(playFirst);
142-
dialogueScript.call("next", [playFirst]);
141+
var event = EventManager.get(DialogueNextLineEvent).recycle(playFirst);
142+
dialogueScript.call("next", [event]);
143143
if(event.cancelled || !canProceed) return;
144144

145145
if ((curLine = dialogueLines.shift()) == null) {
@@ -154,7 +154,7 @@ class DialogueCutscene extends Cutscene {
154154
}
155155

156156
if (curLine.callback != null)
157-
dialogueScript.call(curLine.callback, [playFirst]);
157+
dialogueScript.call(curLine.callback, [event.playFirst]);
158158

159159
for (k=>c in charMap)
160160
if (k != curLine.char)
@@ -167,8 +167,8 @@ class DialogueCutscene extends Cutscene {
167167
dialogueBox.popupChar(char, force);
168168
}
169169

170-
var finalSuffix:String = playFirst && dialogueBox.hasAnimation(curLine.bubble + "-firstOpen") ? "-firstOpen" : dialogueBox.hasAnimation(curLine.bubble + "-open") ? "-open" : "";
171-
dialogueBox.playBubbleAnim(curLine.bubble, finalSuffix, curLine.text, curLine.format, curLine.speed, curLine.nextSound, curLine.textSound != null ? [curLine.textSound] : null, finalSuffix == "-firstOpen" || finalSuffix == "-open", !playFirst);
170+
var finalSuffix:String = event.playFirst && dialogueBox.hasAnimation(curLine.bubble + "-firstOpen") ? "-firstOpen" : dialogueBox.hasAnimation(curLine.bubble + "-open") ? "-open" : "";
171+
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);
172172

173173
if(curLine.playSound != null) curLine.playSound.play();
174174
if(curLine.changeMusic != null) {
@@ -178,7 +178,7 @@ class DialogueCutscene extends Cutscene {
178178
curMusic.fadeIn(1, 0, curMusic.volume);
179179
} else if(curLine.musicVolume != null && curMusic != null) curMusic.volume = curLine.musicVolume;
180180

181-
dialogueScript.call("postNext", [playFirst]);
181+
dialogueScript.call("postNext", [event]);
182182
}
183183

184184
public override function close() {

0 commit comments

Comments
 (0)