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>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
function next(event)
|
||||
if (!event.playFirst) trace("-");
|
||||
|
||||
function postNext(event)
|
||||
trace(curLine.char + " says: " + curLine.text);
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user