OnClick version of sockets
This commit is contained in:
@ -8,6 +8,7 @@
|
|||||||
[node name="Station" type="Node2D"]
|
[node name="Station" type="Node2D"]
|
||||||
physics_interpolation_mode = 2
|
physics_interpolation_mode = 2
|
||||||
script = ExtResource("1_8usqu")
|
script = ExtResource("1_8usqu")
|
||||||
|
databank_installations = null
|
||||||
mass = 1.0
|
mass = 1.0
|
||||||
|
|
||||||
[node name="InteractionArea" type="Area2D" parent="."]
|
[node name="InteractionArea" type="Area2D" parent="."]
|
||||||
|
|||||||
@ -36,7 +36,9 @@ func _init() -> void:
|
|||||||
# It tells the layout system the smallest size this container can be.
|
# It tells the layout system the smallest size this container can be.
|
||||||
func _get_minimum_size() -> Vector2:
|
func _get_minimum_size() -> Vector2:
|
||||||
# The minimum size is simply the grid dimensions multiplied by the pixel size.
|
# 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:
|
func _notification(what: int) -> void:
|
||||||
if what == NOTIFICATION_SORT_CHILDREN:
|
if what == NOTIFICATION_SORT_CHILDREN:
|
||||||
@ -116,6 +118,8 @@ func toggle_wiring_mode():
|
|||||||
|
|
||||||
for panel in installed_panels:
|
for panel in installed_panels:
|
||||||
panel.set_wiring_mode(wiring_mode)
|
panel.set_wiring_mode(wiring_mode)
|
||||||
|
for socket in panel.all_sockets:
|
||||||
|
socket.socket_selected.connect(on_socket_pressed)
|
||||||
|
|
||||||
if wiring_mode:
|
if wiring_mode:
|
||||||
_build_databanks(databanks)
|
_build_databanks(databanks)
|
||||||
@ -150,6 +154,7 @@ class InstalledDatabank:
|
|||||||
var socket = SocketScene.instantiate()
|
var socket = SocketScene.instantiate()
|
||||||
inputs_container.add_child(socket)
|
inputs_container.add_child(socket)
|
||||||
socket.initialize(socket_name, Socket.SocketType.INPUT)
|
socket.initialize(socket_name, Socket.SocketType.INPUT)
|
||||||
|
|
||||||
all_sockets.append(socket)
|
all_sockets.append(socket)
|
||||||
|
|
||||||
# Populate Output Sockets
|
# Populate Output Sockets
|
||||||
@ -159,11 +164,28 @@ class InstalledDatabank:
|
|||||||
socket.initialize(socket_name, Socket.SocketType.OUTPUT)
|
socket.initialize(socket_name, Socket.SocketType.OUTPUT)
|
||||||
all_sockets.append(socket)
|
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]):
|
func _build_databanks(dbs_to_install: Array[Databank]):
|
||||||
if not is_instance_valid(databanks_container):
|
if not is_instance_valid(databanks_container):
|
||||||
databanks_container = GridContainer.new()
|
databanks_container = GridContainer.new()
|
||||||
databanks_container.columns = columns
|
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)
|
databanks_container.add_theme_constant_override("v_separation", Constants.UI_GRID_SIZE + 16)
|
||||||
add_child(databanks_container)
|
add_child(databanks_container)
|
||||||
|
|
||||||
@ -177,30 +199,18 @@ func _build_databanks(dbs_to_install: Array[Databank]):
|
|||||||
installed_databank.databank_ref = to_install
|
installed_databank.databank_ref = to_install
|
||||||
databanks_container.add_child(installed_databank)
|
databanks_container.add_child(installed_databank)
|
||||||
installed_databank._populate_sockets()
|
installed_databank._populate_sockets()
|
||||||
|
for socket: Socket in installed_databank.all_sockets:
|
||||||
|
socket.socket_selected.connect(on_socket_pressed)
|
||||||
|
|
||||||
func _gui_input(event: InputEvent):
|
func _gui_input(event: InputEvent):
|
||||||
if event is InputEventMouseButton:
|
if event is InputEventMouseButton:
|
||||||
# --- Start or End a Wire ---
|
# --- Add wire point to grid ---
|
||||||
if event.button_index == MOUSE_BUTTON_LEFT:
|
if event.button_index == MOUSE_BUTTON_LEFT and current_state == WiringState.DRAGGING_WIRE:
|
||||||
if event.is_pressed():
|
# Add intermediate point
|
||||||
|
active_wire_points.append(get_local_mouse_position())
|
||||||
var socket = _get_socket_at_pos(event.position)
|
|
||||||
if socket:
|
# --- Remove last placed wire node ---
|
||||||
current_state = WiringState.DRAGGING_WIRE
|
if event.button_index == MOUSE_BUTTON_RIGHT:
|
||||||
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:
|
|
||||||
# Pop Last Point
|
# Pop Last Point
|
||||||
active_wire_points.remove_at(active_wire_points.size() - 1)
|
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
|
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)
|
active_wire_points.append(end_pos)
|
||||||
new_connection.path_points = active_wire_points
|
new_connection.path_points = active_wire_points
|
||||||
|
|
||||||
@ -265,10 +275,3 @@ func _reset_wiring_state():
|
|||||||
end_socket = null
|
end_socket = null
|
||||||
active_wire_points.clear()
|
active_wire_points.clear()
|
||||||
queue_redraw()
|
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
|
|
||||||
|
|||||||
@ -1,16 +1,15 @@
|
|||||||
# Socket.gd
|
# Socket.gd
|
||||||
extends Control
|
extends TextureButton
|
||||||
class_name Socket
|
class_name Socket
|
||||||
|
|
||||||
|
signal socket_selected(socket: Socket)
|
||||||
|
|
||||||
enum SocketType { INPUT, OUTPUT }
|
enum SocketType { INPUT, OUTPUT }
|
||||||
|
|
||||||
enum SocketDataTypes {
|
enum SocketDataTypes {
|
||||||
FLOAT, INT, STRING, EXEC
|
FLOAT, INT, STRING, EXEC
|
||||||
}
|
}
|
||||||
|
|
||||||
@onready var icon: ColorRect = $Icon
|
|
||||||
@onready var label: Label = $Label
|
|
||||||
|
|
||||||
var socket_name: String
|
var socket_name: String
|
||||||
var socket_type: SocketType
|
var socket_type: SocketType
|
||||||
|
|
||||||
@ -19,12 +18,7 @@ func initialize(s_name: String, s_type: SocketType):
|
|||||||
socket_name = s_name
|
socket_name = s_name
|
||||||
socket_type = s_type
|
socket_type = s_type
|
||||||
|
|
||||||
icon.tooltip_text = socket_name
|
tooltip_text = socket_name
|
||||||
|
|
||||||
if socket_type == SocketType.INPUT:
|
func _pressed() -> void:
|
||||||
icon.color = Color.DODGER_BLUE
|
socket_selected.emit(self)
|
||||||
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
|
||||||
else: # OUTPUT
|
|
||||||
icon.color = Color.ORANGE
|
|
||||||
# For output sockets, we can right-align the text to make it look neat.
|
|
||||||
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
|
|
||||||
|
|||||||
@ -1,17 +1,12 @@
|
|||||||
[gd_scene load_steps=2 format=3 uid="uid://8glctqud5ioq"]
|
[gd_scene load_steps=3 format=3 uid="uid://8glctqud5ioq"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://d3d6tgy757f43" path="res://scenes/ship/computer/wiring/socket.gd" id="1_ubhg7"]
|
[ext_resource type="Script" uid="uid://d3d6tgy757f43" path="res://scenes/ship/computer/wiring/socket.gd" id="1_ubhg7"]
|
||||||
|
|
||||||
[node name="Socket" type="HBoxContainer"]
|
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_ubhg7"]
|
||||||
offset_right = 5.0
|
size = Vector2(24, 24)
|
||||||
offset_bottom = 23.0
|
|
||||||
|
[node name="Socket" type="TextureButton"]
|
||||||
|
offset_right = 53.0
|
||||||
|
offset_bottom = 48.0
|
||||||
|
texture_normal = SubResource("PlaceholderTexture2D_ubhg7")
|
||||||
script = ExtResource("1_ubhg7")
|
script = ExtResource("1_ubhg7")
|
||||||
|
|
||||||
[node name="Icon" type="ColorRect" parent="."]
|
|
||||||
custom_minimum_size = Vector2(48, 48)
|
|
||||||
layout_mode = 2
|
|
||||||
mouse_filter = 1
|
|
||||||
color = Color(0.2, 0.235294, 0.796078, 1)
|
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="."]
|
|
||||||
layout_mode = 2
|
|
||||||
|
|||||||
Reference in New Issue
Block a user