Less bookkeeping for select & deselect

This commit is contained in:
Rob Kelly 2025-07-04 16:30:11 -06:00
parent 73afb696a2
commit d8406bba9c
9 changed files with 58 additions and 71 deletions

View File

@ -241,6 +241,7 @@ skeleton = NodePath("../..")
[node name="StaticTrashCan" parent="Props" instance=ExtResource("21_wgtci")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 42, 0.5, -12)
skeleton = NodePath("../..")
surface_material_override/0 = null
[node name="PhysTrashCan" parent="Props" instance=ExtResource("25_8eukv")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 42.9, 0.5, -10.8)

File diff suppressed because one or more lines are too long

View File

@ -3,14 +3,23 @@ extends RayCast3D
@onready var parent := owner as Player
var _selected: Object
func _process(_delta: float) -> void:
var collider := self.get_collider()
if not collider:
if _selected and is_instance_valid(_selected):
_selected.emit_signal(Interactive.DESELECT_SIGNAL)
_selected = null
return
if collider.has_user_signal(Interactive.SELECT_SIGNAL):
collider.emit_signal(Interactive.SELECT_SIGNAL)
if collider != _selected:
if not _selected and is_instance_valid(_selected):
_selected.emit_signal(Interactive.DESELECT_SIGNAL)
_selected = collider
collider.emit_signal(Interactive.SELECT_SIGNAL)
if (
parent.activity_enabled

View File

@ -4,6 +4,7 @@ class_name Interactive extends Node
signal activated
const SELECT_SIGNAL := "selected"
const DESELECT_SIGNAL := "deselected"
const ACTIVATE_SIGNAL := "activated"
@export var enabled := false
@ -18,6 +19,8 @@ func _ready() -> void:
controller = get_parent()
controller.add_user_signal(SELECT_SIGNAL)
controller.connect(SELECT_SIGNAL, select)
controller.add_user_signal(DESELECT_SIGNAL)
controller.connect(DESELECT_SIGNAL, deselect)
controller.add_user_signal(ACTIVATE_SIGNAL)
controller.connect(ACTIVATE_SIGNAL, activate)
@ -26,6 +29,10 @@ func select() -> void:
Player.instance.hud.interact_hud.set_interactive(self)
func deselect() -> void:
Player.instance.hud.interact_hud.set_interactive(null)
func activate() -> void:
if enabled:
activated.emit()

View File

@ -7,19 +7,29 @@ class_name Holdable extends Node
func _ready() -> void:
if not controller:
controller = get_parent() as RigidBody3D
assert(controller, "Holdable %s must be a child of a RigidBody3D" % str(self))
controller = _default_controller()
assert(controller, "Holdable %s has no valid controller!" % str(self))
controller.add_user_signal(Interactive.SELECT_SIGNAL)
controller.connect(Interactive.SELECT_SIGNAL, select)
controller.add_user_signal(Interactive.DESELECT_SIGNAL)
controller.connect(Interactive.DESELECT_SIGNAL, deselect)
controller.add_user_signal(Interactive.ACTIVATE_SIGNAL)
controller.connect(Interactive.ACTIVATE_SIGNAL, activate)
func _default_controller() -> RigidBody3D:
return get_parent() as RigidBody3D
func select() -> void:
Player.instance.hud.hold_hud.select_prop()
func deselect() -> void:
Player.instance.hud.hold_hud.deselect()
func activate() -> void:
if not Player.instance.hold_component.holding_object():
Player.instance.hold_component.attach(controller, hold_distance)

View File

@ -7,7 +7,6 @@ enum State {
}
var state := State.NONE
var _selected_this_frame := false
@onready var open_hand: Label = %OpenHand
@onready var closed_hand: Label = %ClosedHand
@ -41,7 +40,6 @@ func reset() -> void:
func select_prop() -> void:
_selected_this_frame = true
if state == State.NONE:
prop_selected()
@ -49,10 +47,3 @@ func select_prop() -> void:
func deselect() -> void:
if state == State.SELECTED:
reset()
func _process(_delta: float) -> void:
if not _selected_this_frame:
deselect()
_selected_this_frame = false

View File

@ -7,9 +7,6 @@ const COLOR_VISIBLE := Color("#ffffffee")
const COLOR_DISABLED := Color("#cccccc44")
const COLOR_INVISIBLE := Color("#ffffff00")
var _current_interactive: Interactive
var _set_this_frame := false
@onready var interact_name: Label = %InteractName
@onready var interact_verb: Label = %InteractVerb
@ -37,13 +34,6 @@ func _to_invisible() -> void:
func set_interactive(prop: Interactive) -> void:
if prop != _current_interactive:
_set_new_interactive(prop)
_set_this_frame = true
func _set_new_interactive(prop: Interactive) -> void:
_current_interactive = prop
if prop:
interact_name.text = prop.label
interact_verb.text = prop.verb
@ -53,10 +43,3 @@ func _set_new_interactive(prop: Interactive) -> void:
_to_disabled()
else:
_to_invisible()
func _process(_delta: float) -> void:
if not _set_this_frame:
set_interactive(null)
_set_this_frame = false

View File

@ -427,10 +427,10 @@ anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -19.5065
offset_top = -22.2032
offset_right = -19.5065
offset_bottom = -22.2032
offset_left = -17.6994
offset_top = -20.4734
offset_right = -17.6994
offset_bottom = -20.4734
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("4_ud8na")

View File

@ -61,6 +61,8 @@ func _ready() -> void:
# Set material gunk mask to our mask viewport texture
mat_instance.set_shader_parameter("gunk_mask", mask_viewport.get_texture())
# Overlay mesh with gunk material
if mesh_instance.material_overlay:
mat_instance.next_pass = mesh_instance.material_overlay
mesh_instance.material_overlay = mat_instance
_deferred_init.call_deferred()