Skip to content

Commit

Permalink
feat: dialogue editor now supports node duplication, shortcut CTRL+D,…
Browse files Browse the repository at this point in the history
… related to #1322
  • Loading branch information
AlmasB committed Dec 2, 2023
1 parent 4b9214b commit 91d763d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ class DialoguePane(graph: DialogueGraph = DialogueGraph()) : Pane() {
}

private fun onSelectedNodeViewChanged(newNodeView: NodeView?) {

}

/**
Expand Down Expand Up @@ -635,6 +635,17 @@ class DialoguePane(graph: DialogueGraph = DialogueGraph()) : Pane() {
showMessage("TODO: Sorry, not implemented yet.")
}

fun duplicate() {
selectedNodeView.value?.let { nodeView ->
// currently we do not allow multiple start nodes
if (nodeView.node.type != START) {
val node = nodeView.node.copy()

performUIAction(AddNodeAction(graph, node))
}
}
}

fun save(): SerializableGraph {
isDirtyProperty.value = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ class MainUI : BorderPane() {
val contextMenuEdit = FXGLContextMenu()
contextMenuEdit.addItem("Undo (CTRL+Z)") { undo() }
//contextMenuEdit.addItem("Redo") { redo() }
//contextMenuEdit.addItem("Copy (CTRL+C)") { }
//contextMenuEdit.addItem("Paste (CTRL+V)") { }
contextMenuEdit.addItem("Duplicate Node (CTRL+D)") { duplicate() }
contextMenuEdit.addItem("Preferences") { openPreferencesDialog() }

val contextMenuAdd = FXGLContextMenu()
Expand Down Expand Up @@ -152,6 +151,12 @@ class MainUI : BorderPane() {
undo()
}
}, KeyCode.Z, InputModifier.CTRL)

getInput().addAction(object : UserAction("Duplicate") {
override fun onActionBegin() {
duplicate()
}
}, KeyCode.D, InputModifier.CTRL)
}

private fun makeRunButton(): Node {
Expand Down Expand Up @@ -270,6 +275,10 @@ class MainUI : BorderPane() {
currentTab?.pane?.redo()
}

private fun duplicate() {
currentTab?.pane?.duplicate()
}

private fun openAboutDialog() {
showMessage(
"${getSettings().title}: v.${getSettings().version}\n\n"
Expand Down

0 comments on commit 91d763d

Please sign in to comment.