Skip to content

Commit f113387

Browse files
committed
feat: Dialogue Editor can now exit the dialogue from any node, related to #1322
1 parent a7a00e3 commit f113387

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

fxgl-gameplay/src/main/kotlin/com/almasb/fxgl/cutscene/CutsceneService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class CutsceneService : EngineService() {
3232
private var gameVars: PropertyMap? = null
3333

3434
private val scene by lazy { CutsceneScene(sceneService) }
35-
private val dialogueScene by lazy { DialogueScene(sceneService) }
35+
val dialogueScene by lazy { DialogueScene(sceneService) }
3636
private val videoScene by lazy { VideoScene(sceneService) }
3737

3838
@JvmOverloads fun startCutscene(cutscene: Cutscene, onFinished: Runnable = EmptyRunnable) {

fxgl-gameplay/src/main/kotlin/com/almasb/fxgl/cutscene/dialogue/DialogueScene.kt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,6 @@ class DialogueScene(private val sceneService: SceneService) : SubScene() {
187187
}
188188
}
189189

190-
private fun endCutscene() {
191-
boxPlayerLines.opacity = 0.0
192-
animation2.onFinished = Runnable {
193-
sceneService.popSubScene()
194-
onClose()
195-
}
196-
animation1.startReverse()
197-
animation2.startReverse()
198-
}
199-
200190
fun start(dialogueGraph: DialogueGraph, context: DialogueContext, functionHandler: FunctionCallHandler, onFinished: Runnable) {
201191
graph = dialogueGraph.copy()
202192
this.functionHandler = functionHandler
@@ -230,6 +220,20 @@ class DialogueScene(private val sceneService: SceneService) : SubScene() {
230220
sceneService.pushSubScene(this)
231221
}
232222

223+
/**
224+
* Terminates currently active dialogue and closes the dialogue scene.
225+
*/
226+
fun endDialogue() {
227+
topText.text = ""
228+
boxPlayerLines.opacity = 0.0
229+
animation2.onFinished = Runnable {
230+
sceneService.popSubScene()
231+
onClose()
232+
}
233+
animation1.startReverse()
234+
animation2.startReverse()
235+
}
236+
233237
private fun loadSubDialogue(subDialogueNode: SubDialogueNode): DialogueGraph {
234238
return assetLoader.load(AssetType.DIALOGUE, subDialogueNode.text)
235239
}
@@ -253,8 +257,7 @@ class DialogueScene(private val sceneService: SceneService) : SubScene() {
253257

254258
// no next node available, the dialogue is complete
255259
if (nextNode == null) {
256-
topText.text = ""
257-
endCutscene()
260+
endDialogue()
258261
return
259262
}
260263

fxgl-tools/src/main/kotlin/com/almasb/fxgl/tools/dialogues/MainUI.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,12 @@ class MainUI : BorderPane() {
138138
tabPane.prefWidthProperty().bind(FXGL.getSettings().actualWidthProperty())
139139
tabPane.prefHeightProperty().bind(FXGL.getSettings().actualHeightProperty())
140140

141-
//nodeInspectorPane.prefWidth = 200.0
142-
//nodeInspectorPane.prefHeightProperty().bind(FXGL.getSettings().actualHeightProperty())
141+
val exitButton = Button("Exit")
142+
exitButton.translateXProperty().bind(FXGL.getSettings().actualWidthProperty().subtract(45))
143+
exitButton.translateY = 15.0
144+
exitButton.setOnAction { FXGL.getCutsceneService().dialogueScene.endDialogue() }
145+
146+
FXGL.getCutsceneService().dialogueScene.contentRoot.children += exitButton
143147

144148
center = pane
145149

0 commit comments

Comments
 (0)