This commit is contained in:
2026-04-05 23:11:56 -07:00
parent 351af5ad47
commit 6a64717c9d
10 changed files with 126 additions and 166 deletions

View File

@@ -9,6 +9,13 @@ var current_action: int = Action.WALK:
signal action_changed(new_action: int)
# Centralized SetPiece hover tracking
var current_scene: Node = null
var hovered_setpieces: Array[SetPiece] = []
var top_hovered_setpiece: SetPiece = null
signal hover_changed(piece: SetPiece)
func get_action_name() -> String:
match current_action:
Action.WALK: return "walk"
@@ -19,3 +26,39 @@ func get_action_name() -> String:
func get_action_enum() -> int:
return current_action
func set_current_scene(scene: Node) -> void:
current_scene = scene
hovered_setpieces.clear()
top_hovered_setpiece = null
func get_top_hovered_setpiece() -> SetPiece:
return top_hovered_setpiece
func _process(_delta: float) -> void:
if not current_scene:
return
var global_mouse_pos = get_viewport().get_mouse_position()
var camera = get_viewport().get_camera_2d()
if camera:
global_mouse_pos = camera.get_global_mouse_position()
# Find all SetPieces in current scene
var new_hovered: Array[SetPiece] = []
for piece in current_scene.find_children("*", "SetPiece", true, false):
if piece is SetPiece:
var local_pos = piece.to_local(global_mouse_pos)
if piece.polygon.size() > 0 and Geometry2D.is_point_in_polygon(local_pos, piece.polygon):
new_hovered.append(piece)
# Sort by priority (highest first)
new_hovered.sort_custom(func(a, b): return b.priority > a.priority)
# Check if top piece changed
var new_top = new_hovered[0] if new_hovered.size() > 0 else null
if new_top != top_hovered_setpiece:
top_hovered_setpiece = new_top
hover_changed.emit(top_hovered_setpiece)
hovered_setpieces = new_hovered

View File

@@ -14,6 +14,7 @@ func _ready():
# get_scene().connect("transitioned", Callable($SceneViewport/label, "_on_transitioned"))
get_scene().connect("transitioned", Callable(self, "_on_transitioned"))
reset_camera(get_scene())
ActionState.set_current_scene(get_scene())
pass # Replace with function body.
@@ -21,6 +22,7 @@ func _ready():
func _on_transitioned(scene):
reset_camera(scene)
$SceneViewport/label._on_transitioned(scene)
ActionState.set_current_scene(scene)
camera.position = Vector2(0,0 )
#scene.connect("transitioned", $SceneViwport/label, "_on_transitioned")
scene.connect("transitioned", Callable(self, "_on_transitioned"))

View File

@@ -40,75 +40,37 @@ signal exited(lab)
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
emit_signal("entered", label)
else:
if is_in == true:
emit_signal("exited", label)
is_in = false
func _get_overlapping_setpieces() -> Array[SetPiece]:
var overlapping: Array[SetPiece] = []
var mouse_pos = to_local(get_global_mouse_position())
for child in get_tree().get_nodes_in_group("set-piece"):
if child is SetPiece and child != self:
if child.polygon.size() > 0 and Geometry2D.is_point_in_polygon(mouse_pos, child.polygon):
overlapping.append(child)
return overlapping
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 Input.is_action_just_released("interact"):
# Check if a script is running that shouldn't be interrupted
var script_builder = get_node_or_null("/root/Node2D/GameScript")
if script_builder and script_builder.current_script and not script_builder.current_script.can_interrupt:
return # Let the script handle the input
# Find all overlapping SetPieces and check if this one has highest priority
var overlapping = _get_overlapping_setpieces()
overlapping.append(self)
var max_priority = self.priority
for piece in overlapping:
if piece.priority > max_priority:
max_priority = piece.priority
# Only process if this SetPiece has the highest priority
if self.priority < max_priority:
return
print("MAX PRIOORITY", max_priority)
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")
if event is InputEventMouseButton and Input.is_action_just_released("interact"):
# Check if a script is running that shouldn't be interrupted
var script_builder = get_node_or_null("/root/Node2D/GameScript")
if script_builder and script_builder.current_script and not script_builder.current_script.can_interrupt:
return # Let the script handle the input
# Check if this is the top-priority hovered SetPiece
var top_piece = ActionState.get_top_hovered_setpiece()
if top_piece != self:
return
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")

View File

@@ -10,9 +10,7 @@ func _ready():
super()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
super(delta)
func default_script(scene: Scene):
var path = NavigationServer2D.map_get_path(scene.map, scene.pathfind.to_local(scene.ego.global_position), scene.pathfind.to_local($"exit".global_position), true)

View File

@@ -1,22 +1,12 @@
extends Node2D
var hovered_setpieces: Array[Dictionary] = []
@onready var label : Label = $"label"
func _ready():
_connect_setpieces(get_parent())
ActionState.hover_changed.connect(_on_hover_changed)
func _on_transitioned(s):
hovered_setpieces.clear()
func _on_transitioned(_s):
$label.hide()
_connect_setpieces(get_parent())
func _connect_setpieces(scene: Node) -> void:
for n in scene.find_children("*", "SetPiece", true, false):
print("LOOKING AT", n)
n.connect("entered", Callable(self, "_on_setpiece_entered"))
n.connect("exited", Callable(self, "_on_setpiece_exited"))
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
@@ -70,47 +60,11 @@ func _process(delta):
global_position = mouse_pos
func _on_setpiece_entered(lab: String) -> void:
var piece = get_setpiece_by_label(lab)
if piece:
var entry = {"label": lab, "priority": piece.priority}
if not _has_entry_with_label(lab):
hovered_setpieces.append(entry)
_update_label()
func _on_setpiece_exited(lab: String) -> void:
for i in range(hovered_setpieces.size()):
if hovered_setpieces[i].label == lab:
hovered_setpieces.remove_at(i)
break
_update_label()
func _has_entry_with_label(lab: String) -> bool:
for entry in hovered_setpieces:
if entry.label == lab:
return true
return false
func get_setpiece_by_label(lab: String) -> SetPiece:
var scene = get_parent()
for child in scene.find_children("*", "SetPiece", true, false):
if child is SetPiece and child.label == lab:
return child
return null
func _update_label() -> void:
if hovered_setpieces.is_empty():
func _on_hover_changed(piece: SetPiece) -> void:
if piece == null:
$label.hide()
return
hovered_setpieces.sort_custom(func(a, b): return b.priority < a.priority)
var top_entry = hovered_setpieces[0]
print(hovered_setpieces, top_entry, top_entry.label)
$label.show()
$label.text = top_entry.label
var size = label.label_settings.font.get_string_size(top_entry.label, HORIZONTAL_ALIGNMENT_LEFT, 200, 32)
label.size = size
else:
$label.show()
$label.text = piece.label
var size = label.label_settings.font.get_string_size(piece.label, HORIZONTAL_ALIGNMENT_LEFT, 200, 32)
label.size = size

View File

@@ -1,12 +1,12 @@
[gd_scene format=3 uid="uid://bncmzju9ibkv"]
[gd_scene format=3 uid="uid://bncm0jvaibkv"]
[ext_resource type="Script" uid="uid://31tmx5rtcbd9h" path="res://scenes/kq4_008_back_of_fishermans_shack/kq4_008_back_of_fishermans_shack.gd" id="1_abc"]
[ext_resource type="Texture2D" uid="uid://1qgkzu9kzrsb2" path="res://scenes/kq4_008_back_of_fishermans_shack/008_caption_1_2562276282_generated.png" id="2_abc"]
[ext_resource type="Script" uid="uid://bounwnqg34t5k" path="res://SetPiece_.gd" id="5_setpiece"]
[ext_resource type="Resource" uid="uid://2yu2h2auhjq02" path="res://scenes/kq4_008_back_of_fishermans_shack/cottage_polygon.tres" id="6_cottage"]
[ext_resource type="Resource" uid="uid://ie9kcj20t0tl" path="res://scenes/kq4_008_back_of_fishermans_shack/window_polygon.tres" id="7_window"]
[ext_resource type="Script" uid="uid://byyjtrc2du8x4" path="res://scenes/kq4_008_back_of_fishermans_shack/kq4_008_back_of_fishermans_shack.gd" id="1_abc"]
[ext_resource type="Texture2D" uid="uid://eoil2lsscfe0" path="res://scenes/kq4_008_back_of_fishermans_shack/008_caption_1_2562276282_generated.png" id="2_varlw"]
[ext_resource type="Script" uid="uid://xmphq3i0wbg3" path="res://ScalePoint_.gd" id="3_abc"]
[ext_resource type="PackedScene" uid="uid://c4vc1wx7k6cw" path="res://TransitionPiece.tscn" id="4_abc"]
[ext_resource type="Script" uid="uid://bounwnqg34t5k" path="res://SetPiece_.gd" id="5_setpiece"]
[ext_resource type="Resource" path="res://scenes/kq4_008_back_of_fishermans_shack/cottage_polygon.tres" id="6_cottage"]
[ext_resource type="Resource" path="res://scenes/kq4_008_back_of_fishermans_shack/window_polygon.tres" id="7_window"]
[sub_resource type="NavigationPolygon" id="NavigationPolygon_ppo6b"]
vertices = PackedVector2Array(366.85156, 1243.1484, -140.97656, 1182.2422, -76.0625, 588.09375, -30.171875, 216.07031, 1221.4063, 226.97656, 1994.1406, 468.39844, 2011.7969, 1321.9766, 1052.7422, 1419.8672, -76.0625, 588.0781)
@@ -19,7 +19,7 @@ script = ExtResource("1_abc")
[node name="bg" type="Sprite2D" parent="." unique_id=874052749]
scale = Vector2(0.78, 0.78)
texture = ExtResource("2_abc")
texture = ExtResource("2_varlw")
centered = false
[node name="StartScalePoint" type="Node2D" parent="." unique_id=1640687858]
@@ -92,16 +92,18 @@ position = Vector2(118, 514)
[node name="exit" parent="kq4_014_green_meadow" index="1"]
position = Vector2(151, 615)
[node name="cottage" type="Polygon2D" parent="." groups=["set-piece"]]
[node name="cottage" type="Polygon2D" parent="." unique_id=126943413 groups=["set-piece"]]
scale = Vector2(6, 6)
color = Color(0.5, 0.5, 0.5, 0.25)
polygon = PackedVector2Array(316, 178, 177, 187, 122, 187, 0, 136, 0, 12, 78, 2, 317, 0, 319, 139)
script = ExtResource("5_setpiece")
label = "Cottage"
points_resource = ExtResource("6_cottage")
[node name="window" type="Polygon2D" parent="." groups=["set-piece"]]
[node name="window" type="Polygon2D" parent="." unique_id=896628572 groups=["set-piece"]]
scale = Vector2(6, 6)
color = Color(0.5, 0.5, 0.5, 0.25)
polygon = PackedVector2Array(298, 74, 306, 187, 0, 189, 16, 91, 68, 27, 234, 35, 277, 48)
script = ExtResource("5_setpiece")
label = "Window"
points_resource = ExtResource("7_window")
@@ -115,5 +117,5 @@ points_resource = ExtResource("7_window")
[editable path="kq4_009_shady_wooded_area"]
[editable path="kq4_002_meadow"]
[editable path="kq4_007_fishermans_shack"]
[editable path="kq4_014_green_meadow"]
[editable path="kq4_007_fishermans_shack"]

View File

@@ -1,13 +1,12 @@
[gd_scene format=3 uid="uid://3ujj97iw54vo5"]
[gd_scene format=3 uid="uid://bsog5s257pres"]
[ext_resource type="Script" uid="uid://32lvmgp4avr38" path="res://scenes/kq4_010_forest_path/kq4_010_forest_path.gd" id="1_abc"]
[ext_resource type="Texture2D" uid="uid://dklgpyc5de7gm" path="res://scenes/kq4_010_forest_path/010_caption_1_114607644_generated.png" id="2_abc"]
[ext_resource type="Script" uid="uid://b0qsh2bdchnsv" path="res://scenes/kq4_010_forest_path/kq4_010_forest_path.gd" id="1_abc"]
[ext_resource type="Texture2D" uid="uid://bymj06q3cdhwf" path="res://scenes/kq4_010_forest_path/010_caption_1_114607644_generated.png" id="2_5ewto"]
[ext_resource type="Script" uid="uid://xmphq3i0wbg3" path="res://ScalePoint_.gd" id="3_abc"]
[ext_resource type="PackedScene" uid="uid://c4vc1wx7k6cw" path="res://TransitionPiece.tscn" id="4_abc"]
[ext_resource type="Resource" path="res://scenes/kq4_010_forest_path/flowers_polygon_0.tres" id="5_flowers"]
[ext_resource type="Script" uid="uid://bounwnqg34t5k" path="res://SetPiece_.gd" id="5_setpiece"]
[ext_resource type="Resource" uid="uid://2l2s6dgizs125" path="res://scenes/kq4_010_forest_path/flowers_polygon_0.tres" id="5_flowers"]
[ext_resource type="Resource" uid="uid://3fuj0q7ii26p9" path="res://scenes/kq4_010_forest_path/trees_polygon_0.tres" id="6_trees"]
[ext_resource type="Resource" path="res://scenes/kq4_010_forest_path/trees_polygon_0.tres" id="6_trees"]
[sub_resource type="NavigationPolygon" id="NavigationPolygon_ppo6b"]
vertices = PackedVector2Array(366.85156, 1243.1484, -140.97656, 1182.2422, -76.0625, 588.09375, -30.171875, 216.07031, 1221.4063, 226.97656, 1994.1406, 468.39844, 2011.7969, 1321.9766, 1052.7422, 1419.8672, -76.0625, 588.0781)
@@ -20,7 +19,7 @@ script = ExtResource("1_abc")
[node name="bg" type="Sprite2D" parent="." unique_id=874052749]
scale = Vector2(0.78, 0.78)
texture = ExtResource("2_abc")
texture = ExtResource("2_5ewto")
centered = false
[node name="StartScalePoint" type="Node2D" parent="." unique_id=1640687858]
@@ -93,7 +92,7 @@ position = Vector2(118, 514)
[node name="exit" parent="kq4_016_graveyard" index="1"]
position = Vector2(151, 615)
[node name="kq4_009_shady_wooded_area" parent="." instance=ExtResource("4_abc")]
[node name="kq4_009_shady_wooded_area" parent="." unique_id=1871441208 instance=ExtResource("4_abc")]
position = Vector2(-150, 100)
polygon = PackedVector2Array(-108, 454, -87, 649, 376, 658, 348, 381)
appear_at_node = "kq4_010_forest_path"
@@ -109,7 +108,7 @@ position = Vector2(100, 480)
[node name="flowers" type="Polygon2D" parent="." unique_id=123456781]
scale = Vector2(6, 6)
color = Color(0.7, 0.7, 0.7, 0.25)
polygon = PackedVector2Array(168, 1047, 176, 1049, 180, 1070, 172, 1072)
polygon = PackedVector2Array(50, 182, 45, 107, 227, 51, 210, 125, 291, 159)
script = ExtResource("5_setpiece")
label = "Flowers"
points_resource = ExtResource("5_flowers")
@@ -122,15 +121,15 @@ script = ExtResource("5_setpiece")
label = "Pine Trees"
points_resource = ExtResource("6_trees")
[connection signal="looked" from="flowers" to="." method="_on_flowers_looked"]
[connection signal="looked" from="pine_trees" to="." method="_on_pine_trees_looked"]
[connection signal="interacted" from="kq4_004_ogres_cottage" to="." method="_on_ogres_cottage_interacted"]
[connection signal="interacted" from="kq4_011_enchanted_grove" to="." method="_on_enchanted_grove_interacted"]
[connection signal="interacted" from="kq4_016_graveyard" to="." method="_on_graveyard_interacted"]
[connection signal="interacted" from="kq4_009_shady_wooded_area" to="." method="_on_shady_wooded_area_interacted"]
[connection signal="looked" from="flowers" to="." method="_on_flowers_looked"]
[connection signal="looked" from="pine_trees" to="." method="_on_pine_trees_looked"]
[editable path="kq4_003_fountain_pool"]
[editable path="kq4_004_ogres_cottage"]
[editable path="kq4_011_enchanted_grove"]
[editable path="kq4_016_graveyard"]
[editable path="kq4_009_shady_wooded_area"]
[editable path="kq4_009_shady_wooded_area"]

View File

@@ -47,6 +47,7 @@ polygon = PackedVector2Array(-108, 454, -87, 649, 376, 658, 348, 381)
appear_at_node = "kq4_020_meadow"
target = "uid://tkeyuep0ivo6"
label = "Green Meadow"
priority = 100
[node name="entrance" parent="kq4_014_green_meadow" index="0"]
position = Vector2(133, 643)

View File

@@ -1,7 +1,7 @@
[gd_scene format=3 uid="uid://dtay26ehvtu2m"]
[ext_resource type="Script" uid="uid://kx10aka2qsq7" path="res://scenes/kq4_026_river_meadow/kq4_026_river_meadow.gd" id="1_abc"]
[ext_resource type="Texture2D" uid="uid://dr5lmofiyx76m" path="res://scenes/kq4_026_river_meadow/026_caption_1_1643434186_generated.png" id="2_abc"]
[ext_resource type="Texture2D" uid="uid://5ppiyi4oa1qm" path="res://scenes/kq4_026_river_meadow/026_caption_1_1643434186_generated.png" id="2_4jgbp"]
[ext_resource type="Script" uid="uid://xmphq3i0wbg3" path="res://ScalePoint_.gd" id="3_abc"]
[ext_resource type="PackedScene" uid="uid://c4vc1wx7k6cw" path="res://TransitionPiece.tscn" id="4_abc"]
@@ -16,7 +16,7 @@ script = ExtResource("1_abc")
[node name="bg" type="Sprite2D" parent="." unique_id=874052749]
scale = Vector2(0.78, 0.78)
texture = ExtResource("2_abc")
texture = ExtResource("2_4jgbp")
centered = false
[node name="StartScalePoint" type="Node2D" parent="." unique_id=1640687858]
@@ -97,4 +97,4 @@ position = Vector2(-64, 534)
[editable path="kq4_020_meadow"]
[editable path="kq4_027_forest_path"]
[editable path="kq4_002_meadow"]
[editable path="kq4_025_beach_at_river_delta"]
[editable path="kq4_025_beach_at_river_delta"]

View File

@@ -1,10 +1,10 @@
[gd_scene format=3 uid="uid://1fpyosj18xls7"]
[gd_scene format=3 uid="uid://c8aq5g1juqdam"]
[ext_resource type="Script" uid="uid://3ofmq34xm3qb0" path="res://scenes/kq4_027_forest_path/kq4_027_forest_path.gd" id="1_abc"]
[ext_resource type="Texture2D" uid="uid://1tsm5mtf1ls7d" path="res://scenes/kq4_027_forest_path/027_caption_1_2465011857_generated.png" id="2_abc"]
[ext_resource type="Script" uid="uid://bmkjmpo6ool0n" path="res://scenes/kq4_027_forest_path/kq4_027_forest_path.gd" id="1_abc"]
[ext_resource type="Texture2D" uid="uid://dlo8rtjj0hm2r" path="res://scenes/kq4_027_forest_path/027_caption_1_2465011857_generated.png" id="2_o2cvp"]
[ext_resource type="Script" uid="uid://xmphq3i0wbg3" path="res://ScalePoint_.gd" id="3_abc"]
[ext_resource type="PackedScene" uid="uid://c4vc1wx7k6cw" path="res://TransitionPiece.tscn" id="4_abc"]
[ext_resource type="Resource" uid="uid://16sx5suqmeus6" path="res://scenes/kq4_027_forest_path/forest_polygon_0.tres" id="5_forest"]
[ext_resource type="Resource" path="res://scenes/kq4_027_forest_path/forest_polygon_0.tres" id="5_forest"]
[ext_resource type="Script" uid="uid://bounwnqg34t5k" path="res://SetPiece_.gd" id="6_setpiece"]
[sub_resource type="NavigationPolygon" id="NavigationPolygon_ppo6b"]
@@ -18,7 +18,7 @@ script = ExtResource("1_abc")
[node name="bg" type="Sprite2D" parent="." unique_id=874052749]
scale = Vector2(0.78, 0.78)
texture = ExtResource("2_abc")
texture = ExtResource("2_o2cvp")
centered = false
[node name="StartScalePoint" type="Node2D" parent="." unique_id=1640687858]
@@ -90,12 +90,7 @@ position = Vector2(506, 555)
[node name="exit" parent="kq4_026_river_meadow" index="1"]
position = Vector2(-64, 534)
[connection signal="interacted" from="kq4_021_bridge_over_stream" to="." method="_on_bridge_over_stream_interacted"]
[connection signal="interacted" from="kq4_028_mine_entrance" to="." method="_on_mine_entrance_interacted"]
[connection signal="interacted" from="kq4_003_fountain_pool" to="." method="_on_fountain_pool_interacted"]
[connection signal="interacted" from="kq4_026_river_meadow" to="." method="_on_river_meadow_interacted"]
[node name="forest" type="Polygon2D" parent="." groups=["set-piece"]]
[node name="forest" type="Polygon2D" parent="." unique_id=1158144566 groups=["set-piece"]]
scale = Vector2(6, 6)
color = Color(0.5, 0.5, 0.5, 0.25)
polygon = PackedVector2Array(317, 189, 222, 62, 104, 153, 279, 189, 0, 189, 84, 73, 317, 0)
@@ -103,9 +98,13 @@ script = ExtResource("6_setpiece")
label = "Forest"
points_resource = ExtResource("5_forest")
[connection signal="interacted" from="kq4_021_bridge_over_stream" to="." method="_on_bridge_over_stream_interacted"]
[connection signal="interacted" from="kq4_028_mine_entrance" to="." method="_on_mine_entrance_interacted"]
[connection signal="interacted" from="kq4_003_fountain_pool" to="." method="_on_fountain_pool_interacted"]
[connection signal="interacted" from="kq4_026_river_meadow" to="." method="_on_river_meadow_interacted"]
[connection signal="looked" from="forest" to="." method="_on_forest_looked"]
[editable path="kq4_021_bridge_over_stream"]
[editable path="kq4_028_mine_entrance"]
[editable path="kq4_003_fountain_pool"]
[editable path="kq4_026_river_meadow"]
[editable path="kq4_026_river_meadow"]