Skip to content

Commit

Permalink
added MoveNode editor action, WIP RemoveNode action
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmasB committed Nov 14, 2021
1 parent 3b5bc48 commit 113d6f8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<MouseEvent> onMouseDraggedEventHandler = event -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -44,4 64,33 @@ class AddNodeAction(
override fun toString(): String {
return "AddNode(${node.type})"
}
}
}



//class RemoveNodeAction(
// private val graph: DialogueGraph,
// private val node: DialogueNode
//) : EditorAction {
//
// private val edges = arrayListOf<DialogueEdge>()
//
// 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()
// }
// }
// }
//}

0 comments on commit 113d6f8

Please sign in to comment.