From 113d6f8e650470ae883c13bf83a2e47f8fd007f1 Mon Sep 17 00:00:00 2001 From: Almas Baimagambetov Date: Sun, 14 Nov 2021 16:59:25 +0000 Subject: [PATCH] added MoveNode editor action, WIP RemoveNode action --- .../fxgl/tools/dialogues/MouseGestures.java | 3 ++ .../fxgl/tools/dialogues/DialoguePane.kt | 5 ++ .../fxgl/tools/dialogues/EditorActions.kt | 51 ++++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/fxgl-tools/src/main/java/com/almasb/fxgl/tools/dialogues/MouseGestures.java b/fxgl-tools/src/main/java/com/almasb/fxgl/tools/dialogues/MouseGestures.java index af425cc06b..8b5c6b1ae7 100644 --- a/fxgl-tools/src/main/java/com/almasb/fxgl/tools/dialogues/MouseGestures.java +++ b/fxgl-tools/src/main/java/com/almasb/fxgl/tools/dialogues/MouseGestures.java @@ -60,6 +60,9 @@ private class DragContext { x = event.getSceneX(); y = event.getSceneY(); + + node.getProperties().put("startLayoutX", node.getLayoutX()); + node.getProperties().put("startLayoutY", node.getLayoutY()); }; private EventHandler onMouseDraggedEventHandler = event -> { diff --git a/fxgl-tools/src/main/kotlin/com/almasb/fxgl/tools/dialogues/DialoguePane.kt b/fxgl-tools/src/main/kotlin/com/almasb/fxgl/tools/dialogues/DialoguePane.kt index 0172c683bc..46c9f60282 100644 --- a/fxgl-tools/src/main/kotlin/com/almasb/fxgl/tools/dialogues/DialoguePane.kt +++ b/fxgl-tools/src/main/kotlin/com/almasb/fxgl/tools/dialogues/DialoguePane.kt @@ -459,6 +459,11 @@ class DialoguePane(graph: DialogueGraph = DialogueGraph()) : Pane() { mouseGestures.makeDraggable(nodeView) { if (getb(IS_SNAP_TO_GRID)) snapToGrid(nodeView) + + val startLayoutX = nodeView.properties["startLayoutX"] as Double + val startLayoutY = nodeView.properties["startLayoutY"] as Double + + performUIAction(MoveNodeAction(nodeView, startLayoutX, startLayoutY, nodeView.layoutX, nodeView.layoutY)) } nodeView.cursor = Cursor.MOVE diff --git a/fxgl-tools/src/main/kotlin/com/almasb/fxgl/tools/dialogues/EditorActions.kt b/fxgl-tools/src/main/kotlin/com/almasb/fxgl/tools/dialogues/EditorActions.kt index b1a0ce1a3f..2c28bf6174 100644 --- a/fxgl-tools/src/main/kotlin/com/almasb/fxgl/tools/dialogues/EditorActions.kt +++ b/fxgl-tools/src/main/kotlin/com/almasb/fxgl/tools/dialogues/EditorActions.kt @@ -6,6 +6,7 @@ package com.almasb.fxgl.tools.dialogues +import com.almasb.fxgl.cutscene.dialogue.DialogueEdge import com.almasb.fxgl.cutscene.dialogue.DialogueGraph import com.almasb.fxgl.cutscene.dialogue.DialogueNode @@ -28,6 +29,25 @@ interface EditorAction { // * add edge // * remove edge +class MoveNodeAction( + private val nodeView: NodeView, + private val startX: Double, + private val startY: Double, + private val endX: Double, + private val endY: Double +) : EditorAction { + + override fun run() { + nodeView.layoutX = endX + nodeView.layoutY = endY + } + + override fun undo() { + nodeView.layoutX = startX + nodeView.layoutY = startY + } +} + class AddNodeAction( private val graph: DialogueGraph, private val node: DialogueNode @@ -44,4 +64,33 @@ class AddNodeAction( override fun toString(): String { return "AddNode(${node.type})" } -} \ No newline at end of file +} + + + +//class RemoveNodeAction( +// private val graph: DialogueGraph, +// private val node: DialogueNode +//) : EditorAction { +// +// private val edges = arrayListOf() +// +// override fun run() { +// graph.edges.filter { it.source === node || it.target === node } +// .forEach { edges += it } +// +// graph.removeNode(node) +// } +// +// override fun undo() { +// graph.addNode(node) +// +// edges.forEach { +// if (it.target === node) { +// graph.addEdge() +// +// graph.addChoiceEdge() +// } +// } +// } +//} \ No newline at end of file