improvement
This commit is contained in:
@@ -57,31 +57,25 @@ func add_node(node_type: String, position: Vector2) -> BaseGraphNode:
|
||||
|
||||
match node_type:
|
||||
"entry":
|
||||
new_node = preload("res://addons/cutscene_editor/editor/nodes/EntryNode.gd").new()
|
||||
new_node = preload("res://addons/cutscene_editor/editor/nodes/EntryNode.tscn").instantiate()
|
||||
"exit":
|
||||
new_node = preload("res://addons/cutscene_editor/editor/nodes/ExitNode.gd").new()
|
||||
new_node = preload("res://addons/cutscene_editor/editor/nodes/ExitNode.tscn").instantiate()
|
||||
"move":
|
||||
new_node = preload("res://addons/cutscene_editor/editor/nodes/MoveActionNode.gd").new()
|
||||
new_node = preload("res://addons/cutscene_editor/editor/nodes/MoveActionNode.tscn").instantiate()
|
||||
"turn":
|
||||
new_node = preload("res://addons/cutscene_editor/editor/nodes/TurnActionNode.gd").new()
|
||||
new_node = preload("res://addons/cutscene_editor/editor/nodes/TurnActionNode.tscn").instantiate()
|
||||
"dialogue":
|
||||
new_node = preload("res://addons/cutscene_editor/editor/nodes/DialogueActionNode.gd").new()
|
||||
new_node = preload("res://addons/cutscene_editor/editor/nodes/DialogueActionNode.tscn").instantiate()
|
||||
"animation":
|
||||
new_node = preload("res://addons/cutscene_editor/editor/nodes/AnimationActionNode.gd").new()
|
||||
new_node = preload("res://addons/cutscene_editor/editor/nodes/AnimationActionNode.tscn").instantiate()
|
||||
"wait":
|
||||
new_node = preload("res://addons/cutscene_editor/editor/nodes/WaitActionNode.gd").new()
|
||||
"parallel":
|
||||
new_node = preload("res://addons/cutscene_editor/editor/nodes/ParallelGroupNode.gd").new()
|
||||
new_node = preload("res://addons/cutscene_editor/editor/nodes/WaitActionNode.tscn").instantiate()
|
||||
_:
|
||||
return null
|
||||
|
||||
# Set node position
|
||||
new_node.position_offset = position
|
||||
|
||||
# Special handling for parallel groups
|
||||
if new_node is ParallelGroupNode:
|
||||
# Set a larger initial size for parallel groups
|
||||
new_node.custom_minimum_size = Vector2(200, 150)
|
||||
|
||||
# Add to GraphEdit
|
||||
add_child(new_node)
|
||||
@@ -105,21 +99,6 @@ func _on_connection_request(from_node: String, from_port: int, to_node: String,
|
||||
var from_node_instance = get_node_or_null(from_node)
|
||||
var to_node_instance = get_node_or_null(to_node)
|
||||
|
||||
# Special handling for parallel groups
|
||||
if to_node_instance is ParallelGroupNode:
|
||||
# Connecting to a parallel group
|
||||
if _is_valid_parallel_connection(from_node_instance, from_port, to_node_instance, to_port):
|
||||
# Add child node to parallel group
|
||||
if to_node_instance.can_add_child_node(from_node_instance):
|
||||
to_node_instance.add_child_node(from_node_instance)
|
||||
|
||||
# Create a logical connection (not visual)
|
||||
_create_logical_parallel_connection(from_node, from_port, to_node, to_port)
|
||||
|
||||
# Emit signal
|
||||
emit_signal("connection_created", from_node, from_port, to_node, to_port)
|
||||
emit_signal("graph_changed")
|
||||
return
|
||||
|
||||
# Create the connection
|
||||
connect_node(from_node, from_port, to_node, to_port)
|
||||
@@ -137,19 +116,6 @@ func _on_disconnection_request(from_node: String, from_port: int, to_node: Strin
|
||||
var from_node_instance = get_node_or_null(from_node)
|
||||
var to_node_instance = get_node_or_null(to_node)
|
||||
|
||||
# Special handling for parallel groups
|
||||
if to_node_instance is ParallelGroupNode:
|
||||
# Remove child node from parallel group
|
||||
if from_node_instance in to_node_instance.child_nodes:
|
||||
to_node_instance.remove_child_node(from_node_instance)
|
||||
|
||||
# Remove logical connection
|
||||
_remove_logical_parallel_connection(from_node, from_port, to_node, to_port)
|
||||
|
||||
# Emit signal
|
||||
emit_signal("connection_removed", from_node, from_port, to_node, to_port)
|
||||
emit_signal("graph_changed")
|
||||
return
|
||||
|
||||
# Remove the connection
|
||||
disconnect_node(from_node, from_port, to_node, to_port)
|
||||
@@ -187,12 +153,6 @@ func _is_connection_valid(from_node_name: String, from_port: int, to_node_name:
|
||||
"exit":
|
||||
# Exit cannot have outgoing connections
|
||||
return false
|
||||
"parallel":
|
||||
# Parallel group output can connect to any node except entry/parallel
|
||||
if from_port == from_node.input_connections: # Output port
|
||||
return to_node.node_type != "entry" and to_node.node_type != "parallel"
|
||||
else: # Input port
|
||||
return to_node.node_type != "exit" and to_node.node_type != "parallel"
|
||||
_:
|
||||
# Other nodes can connect to any node except entry
|
||||
return to_node.node_type != "entry"
|
||||
@@ -231,24 +191,6 @@ func _dfs_cycle_check(current_node_name: String, target_node_name: String, visit
|
||||
elif recursion_stack.has(next_node_name):
|
||||
return true
|
||||
|
||||
# Check parallel connections
|
||||
if has_meta("logical_connections"):
|
||||
var logical_connections = get_meta("logical_connections")
|
||||
for connection in logical_connections:
|
||||
if connection["from_node"] == current_node_name:
|
||||
var next_node_name = connection["to_node"]
|
||||
|
||||
# If we reached the target node, we found a cycle
|
||||
if next_node_name == target_node_name:
|
||||
return true
|
||||
|
||||
# If next node not visited, recursively check
|
||||
if not visited.has(next_node_name):
|
||||
if _dfs_cycle_check(next_node_name, target_node_name, visited, recursion_stack):
|
||||
return true
|
||||
# If next node is in recursion stack, we found a cycle
|
||||
elif recursion_stack.has(next_node_name):
|
||||
return true
|
||||
|
||||
# Remove from recursion stack
|
||||
recursion_stack[current_node_name] = false
|
||||
@@ -274,7 +216,6 @@ func _on_popup_request(position: Vector2) -> void:
|
||||
menu.add_item("Add Dialogue Action", 4)
|
||||
menu.add_item("Add Animation Action", 5)
|
||||
menu.add_item("Add Wait Action", 6)
|
||||
menu.add_item("Add Parallel Group", 7)
|
||||
|
||||
# Connect menu signals
|
||||
menu.connect("id_pressed", _on_context_menu_selected.bind(position))
|
||||
@@ -303,8 +244,6 @@ func _on_context_menu_selected(id: int, position: Vector2) -> void:
|
||||
node_type = "animation"
|
||||
6:
|
||||
node_type = "wait"
|
||||
7:
|
||||
node_type = "parallel"
|
||||
_:
|
||||
return
|
||||
|
||||
@@ -346,22 +285,6 @@ func _on_graph_node_selected(node: BaseGraphNode) -> void:
|
||||
|
||||
# Handle graph node deletion
|
||||
func _on_graph_node_deleted(node: BaseGraphNode) -> void:
|
||||
# Special handling for parallel groups
|
||||
if node is ParallelGroupNode:
|
||||
# Remove all child nodes first
|
||||
for child_node in node.child_nodes:
|
||||
# Remove child from scene tree
|
||||
if child_node.get_parent():
|
||||
child_node.get_parent().remove_child(child_node)
|
||||
|
||||
# Add child back to main graph
|
||||
add_child(child_node)
|
||||
|
||||
# Update child position to be near the parallel group
|
||||
child_node.position_offset = node.position_offset + Vector2(50, 50)
|
||||
|
||||
# Clear child nodes array
|
||||
node.child_nodes.clear()
|
||||
|
||||
# Remove all connections to/from this node
|
||||
var connections = get_connection_list()
|
||||
@@ -369,16 +292,6 @@ func _on_graph_node_deleted(node: BaseGraphNode) -> void:
|
||||
if connection["from_node"] == node.name or connection["to_node"] == node.name:
|
||||
disconnect_node(connection["from_node"], connection["from_port"], connection["to_node"], connection["to_port"])
|
||||
|
||||
# Remove logical connections for parallel groups
|
||||
if has_meta("logical_connections"):
|
||||
var logical_connections = get_meta("logical_connections")
|
||||
var i = 0
|
||||
while i < logical_connections.size():
|
||||
var conn = logical_connections[i]
|
||||
if conn["from_node"] == node.name or conn["to_node"] == node.name:
|
||||
logical_connections.remove_at(i)
|
||||
else:
|
||||
i += 1
|
||||
|
||||
# Remove node from GraphEdit
|
||||
remove_child(node)
|
||||
@@ -477,65 +390,6 @@ func save_to_cutscene() -> CutsceneResource:
|
||||
|
||||
return current_cutscene
|
||||
|
||||
# Special handling for parallel groups
|
||||
func _is_valid_parallel_connection(from_node: BaseGraphNode, from_port: int, to_node: ParallelGroupNode, to_port: int) -> bool:
|
||||
# Can only connect to input ports of parallel groups
|
||||
if to_port >= to_node.input_connections:
|
||||
return false
|
||||
|
||||
# Can't connect parallel group to itself
|
||||
if from_node == to_node:
|
||||
return false
|
||||
|
||||
# Can't connect entry or exit nodes to parallel groups
|
||||
if from_node.node_type == "entry" or from_node.node_type == "exit":
|
||||
return false
|
||||
|
||||
# Can't connect parallel groups to parallel groups
|
||||
if from_node.node_type == "parallel":
|
||||
return false
|
||||
|
||||
return true
|
||||
|
||||
# Create a logical connection for parallel groups (not visually represented)
|
||||
func _create_logical_parallel_connection(from_node: String, from_port: int, to_node: String, to_port: int) -> void:
|
||||
# Store the logical connection in our data structure
|
||||
# This connection won't be visually represented but will be used for generation
|
||||
var logical_connection = {
|
||||
"from_node": from_node,
|
||||
"from_port": from_port,
|
||||
"to_node": to_node,
|
||||
"to_port": to_port,
|
||||
"is_parallel": true
|
||||
}
|
||||
|
||||
# Add to a separate list of logical connections
|
||||
if not has_meta("logical_connections"):
|
||||
set_meta("logical_connections", [])
|
||||
|
||||
var logical_connections = get_meta("logical_connections")
|
||||
logical_connections.append(logical_connection)
|
||||
|
||||
# Remove a logical connection for parallel groups
|
||||
func _remove_logical_parallel_connection(from_node: String, from_port: int, to_node: String, to_port: int) -> void:
|
||||
if not has_meta("logical_connections"):
|
||||
return
|
||||
|
||||
var logical_connections = get_meta("logical_connections")
|
||||
var i = 0
|
||||
while i < logical_connections.size():
|
||||
var conn = logical_connections[i]
|
||||
if (conn["from_node"] == from_node and conn["from_port"] == from_port and
|
||||
conn["to_node"] == to_node and conn["to_port"] == to_port):
|
||||
logical_connections.remove_at(i)
|
||||
return
|
||||
i += 1
|
||||
|
||||
# Get all logical connections
|
||||
func get_logical_connections() -> Array:
|
||||
if has_meta("logical_connections"):
|
||||
return get_meta("logical_connections")
|
||||
return []
|
||||
|
||||
# Set up preview system
|
||||
func setup_preview() -> void:
|
||||
|
||||
Reference in New Issue
Block a user