85 lines
2.2 KiB
GDScript3
85 lines
2.2 KiB
GDScript3
@tool
|
|
extends Polygon2D
|
|
class_name SetPiece
|
|
|
|
|
|
# Declare member variables here. Examples:
|
|
# var a = 2
|
|
# var b = "text"
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
_update_polygon_from_resource()
|
|
self.color.a = 0.25
|
|
if Engine.is_editor_hint():
|
|
self.color.a = 0.25
|
|
notify_property_list_changed()
|
|
pass
|
|
else:
|
|
hide()
|
|
pass # Replace with function body
|
|
|
|
|
|
func _update_polygon_from_resource() -> void:
|
|
if points_resource and points_resource.points.size() > 0:
|
|
polygon = points_resource.points
|
|
|
|
signal interacted
|
|
signal walked
|
|
signal looked
|
|
signal touched
|
|
signal talked
|
|
signal entered(lab)
|
|
signal exited(lab)
|
|
|
|
@export var label: String
|
|
@export var points_resource: PolygonPointsResource:
|
|
set(value):
|
|
points_resource = value
|
|
_update_polygon_from_resource()
|
|
|
|
var is_in = false
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta):
|
|
if Engine.is_editor_hint():
|
|
self.color.a = 0.25
|
|
else:
|
|
if Geometry2D.is_point_in_polygon(to_local(get_global_mouse_position()), self.polygon):
|
|
if is_in == false:
|
|
is_in = true
|
|
print("ENTERED0", label)
|
|
emit_signal("entered", label)
|
|
else:
|
|
if is_in == true:
|
|
emit_signal("exited", label)
|
|
is_in = false
|
|
|
|
|
|
|
|
func _input(event):
|
|
if not Engine.is_editor_hint():
|
|
if Geometry2D.is_point_in_polygon(to_local(get_global_mouse_position()), self.polygon):
|
|
if event is InputEventMouseButton and event.is_action("interact"):
|
|
get_viewport().set_input_as_handled()
|
|
|
|
# Check if interacted signal has connections - it takes precedence
|
|
if interacted.get_connections().size() > 0:
|
|
emit_signal("interacted")
|
|
return
|
|
|
|
# Otherwise, emit action-specific signal based on current cursor
|
|
match ActionState.current_action:
|
|
ActionState.Action.WALK:
|
|
if walked.get_connections().size() > 0:
|
|
emit_signal("walked")
|
|
ActionState.Action.LOOK:
|
|
if looked.get_connections().size() > 0:
|
|
emit_signal("looked")
|
|
ActionState.Action.TOUCH:
|
|
if touched.get_connections().size() > 0:
|
|
emit_signal("touched")
|
|
ActionState.Action.TALK:
|
|
if talked.get_connections().size() > 0:
|
|
emit_signal("talked")
|