|
|
|
|
@ -36,7 +36,9 @@ func _init() -> void:
|
|
|
|
|
# It tells the layout system the smallest size this container can be.
|
|
|
|
|
func _get_minimum_size() -> Vector2:
|
|
|
|
|
# The minimum size is simply the grid dimensions multiplied by the pixel size.
|
|
|
|
|
return Vector2(columns * Constants.UI_GRID_SIZE, rows * Constants.UI_GRID_SIZE)
|
|
|
|
|
var front_size = Vector2(columns * Constants.UI_GRID_SIZE, rows * Constants.UI_GRID_SIZE)
|
|
|
|
|
var back_size = Vector2(front_size.x, front_size.y + databanks_container.size.y) if is_instance_valid(databanks_container) else front_size
|
|
|
|
|
return front_size if not wiring_mode else Vector2.ZERO
|
|
|
|
|
|
|
|
|
|
func _notification(what: int) -> void:
|
|
|
|
|
if what == NOTIFICATION_SORT_CHILDREN:
|
|
|
|
|
@ -116,6 +118,8 @@ func toggle_wiring_mode():
|
|
|
|
|
|
|
|
|
|
for panel in installed_panels:
|
|
|
|
|
panel.set_wiring_mode(wiring_mode)
|
|
|
|
|
for socket in panel.all_sockets:
|
|
|
|
|
socket.socket_selected.connect(on_socket_pressed)
|
|
|
|
|
|
|
|
|
|
if wiring_mode:
|
|
|
|
|
_build_databanks(databanks)
|
|
|
|
|
@ -150,6 +154,7 @@ class InstalledDatabank:
|
|
|
|
|
var socket = SocketScene.instantiate()
|
|
|
|
|
inputs_container.add_child(socket)
|
|
|
|
|
socket.initialize(socket_name, Socket.SocketType.INPUT)
|
|
|
|
|
|
|
|
|
|
all_sockets.append(socket)
|
|
|
|
|
|
|
|
|
|
# Populate Output Sockets
|
|
|
|
|
@ -159,11 +164,28 @@ class InstalledDatabank:
|
|
|
|
|
socket.initialize(socket_name, Socket.SocketType.OUTPUT)
|
|
|
|
|
all_sockets.append(socket)
|
|
|
|
|
|
|
|
|
|
func on_socket_pressed(socket):
|
|
|
|
|
print(socket)
|
|
|
|
|
|
|
|
|
|
if socket:
|
|
|
|
|
current_state = WiringState.DRAGGING_WIRE
|
|
|
|
|
|
|
|
|
|
if not start_socket:
|
|
|
|
|
# start new wire
|
|
|
|
|
start_socket = socket
|
|
|
|
|
|
|
|
|
|
# Add start point to wire points
|
|
|
|
|
active_wire_points.append(start_socket.get_global_rect().get_center() - get_global_position())
|
|
|
|
|
elif start_socket and socket.socket_type != start_socket.socket_type:
|
|
|
|
|
end_socket = socket
|
|
|
|
|
_save_new_connection()
|
|
|
|
|
_reset_wiring_state()
|
|
|
|
|
|
|
|
|
|
func _build_databanks(dbs_to_install: Array[Databank]):
|
|
|
|
|
if not is_instance_valid(databanks_container):
|
|
|
|
|
databanks_container = GridContainer.new()
|
|
|
|
|
databanks_container.columns = columns
|
|
|
|
|
databanks_container.add_theme_constant_override("h_separation", Constants.UI_GRID_SIZE * 3)
|
|
|
|
|
databanks_container.add_theme_constant_override("h_separation", Constants.UI_GRID_SIZE * 1)
|
|
|
|
|
databanks_container.add_theme_constant_override("v_separation", Constants.UI_GRID_SIZE + 16)
|
|
|
|
|
add_child(databanks_container)
|
|
|
|
|
|
|
|
|
|
@ -177,30 +199,18 @@ func _build_databanks(dbs_to_install: Array[Databank]):
|
|
|
|
|
installed_databank.databank_ref = to_install
|
|
|
|
|
databanks_container.add_child(installed_databank)
|
|
|
|
|
installed_databank._populate_sockets()
|
|
|
|
|
for socket: Socket in installed_databank.all_sockets:
|
|
|
|
|
socket.socket_selected.connect(on_socket_pressed)
|
|
|
|
|
|
|
|
|
|
func _gui_input(event: InputEvent):
|
|
|
|
|
if event is InputEventMouseButton:
|
|
|
|
|
# --- Start or End a Wire ---
|
|
|
|
|
if event.button_index == MOUSE_BUTTON_LEFT:
|
|
|
|
|
if event.is_pressed():
|
|
|
|
|
|
|
|
|
|
var socket = _get_socket_at_pos(event.position)
|
|
|
|
|
if socket:
|
|
|
|
|
current_state = WiringState.DRAGGING_WIRE
|
|
|
|
|
if not start_socket:
|
|
|
|
|
# start new wire
|
|
|
|
|
start_socket = socket
|
|
|
|
|
# Add start point to wire points
|
|
|
|
|
active_wire_points.append(start_socket.icon.get_global_rect().get_center() - get_global_position())
|
|
|
|
|
elif start_socket and socket.socket_type != start_socket.socket_type:
|
|
|
|
|
end_socket = socket
|
|
|
|
|
_save_new_connection()
|
|
|
|
|
_reset_wiring_state()
|
|
|
|
|
elif current_state == WiringState.DRAGGING_WIRE:
|
|
|
|
|
# Add intermediate point
|
|
|
|
|
active_wire_points.append(get_local_mouse_position())
|
|
|
|
|
|
|
|
|
|
elif event.button_index == MOUSE_BUTTON_RIGHT:
|
|
|
|
|
# --- Add wire point to grid ---
|
|
|
|
|
if event.button_index == MOUSE_BUTTON_LEFT and current_state == WiringState.DRAGGING_WIRE:
|
|
|
|
|
# Add intermediate point
|
|
|
|
|
active_wire_points.append(get_local_mouse_position())
|
|
|
|
|
|
|
|
|
|
# --- Remove last placed wire node ---
|
|
|
|
|
if event.button_index == MOUSE_BUTTON_RIGHT:
|
|
|
|
|
# Pop Last Point
|
|
|
|
|
active_wire_points.remove_at(active_wire_points.size() - 1)
|
|
|
|
|
|
|
|
|
|
@ -250,7 +260,7 @@ func _save_new_connection():
|
|
|
|
|
new_connection.output_socket_name = end_socket.socket_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var end_pos = end_socket.icon.get_global_rect().get_center() - get_global_position()
|
|
|
|
|
var end_pos = end_socket.get_global_rect().get_center() - get_global_position()
|
|
|
|
|
active_wire_points.append(end_pos)
|
|
|
|
|
new_connection.path_points = active_wire_points
|
|
|
|
|
|
|
|
|
|
@ -265,10 +275,3 @@ func _reset_wiring_state():
|
|
|
|
|
end_socket = null
|
|
|
|
|
active_wire_points.clear()
|
|
|
|
|
queue_redraw()
|
|
|
|
|
|
|
|
|
|
func _get_socket_at_pos(global_pos: Vector2) -> Socket:
|
|
|
|
|
for panel in installed_panels:
|
|
|
|
|
for socket in panel.all_sockets:
|
|
|
|
|
if is_instance_valid(socket) and socket.icon.get_global_rect().has_point(global_pos):
|
|
|
|
|
return socket
|
|
|
|
|
return null
|
|
|
|
|
|