From ae34cb934adbb2e63211765862f7e892aa01c46f Mon Sep 17 00:00:00 2001 From: henry Date: Mon, 22 Jun 2026 12:58:25 +0100 Subject: [PATCH] Added segment lines to notification display. --- scripts/notification_display.gd | 50 +++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/scripts/notification_display.gd b/scripts/notification_display.gd index 645601f..e310866 100644 --- a/scripts/notification_display.gd +++ b/scripts/notification_display.gd @@ -9,6 +9,10 @@ var _sprite_size: Vector2 = Vector2.ZERO var _origin_offset: float = 0.0 var _follow_player: bool = false +var _connector_line: Line2D = null +var _connector_visible: bool = false + + func show_notification(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: float) -> void: label.add_theme_font_size_override("font_size", 8) label.text = weapon_name @@ -51,10 +55,17 @@ func show_notification(weapon_name: String, player_node: Node2D, player_sprite_s # Wait for fade-in to finish, then resume following await tween.finished - # _follow_player = true + _follow_player = true + + # Create connector line from notification to player origin + _connector_line = Line2D.new() + _connector_line.default_color = Color.WHITE + _connector_line.width = 1.0 + add_child(_connector_line) + _connector_visible = true # Stay fully visible for a moment before fading - await get_tree().create_timer(0.25).timeout + await get_tree().create_timer(0.5).timeout # Record current position as the fade-out starting point await get_tree().process_frame @@ -73,6 +84,8 @@ func show_notification(weapon_name: String, player_node: Node2D, player_sprite_s func _process(_delta: float) -> void: if _follow_player and _player: _update_position() + if _connector_visible and _player: + _update_connector() func _update_position() -> void: @@ -110,3 +123,36 @@ func _update_position() -> void: notif_y = clamp(notif_y, 0, viewport_size.y - size.y) position = Vector2(notif_x, notif_y) + + +func _update_connector() -> void: + if _connector_line == null or _player == null: + return + + # Icon position in the notification's local space + var icon_pos = _container.position + icon.position + var icon_mid_y = icon_pos.y + icon.size.y / 2.0 + + # Point 0: edge of the container closest to the icon, at icon's vertical midpoint + var point0: Vector2 + var direction: float + + if _container.get_child(0) == icon: + # Icon on the left (not flipped) — container's left edge, line goes left toward player + point0 = Vector2(_container.position.x, icon_mid_y) + direction = -1.0 + else: + # Icon on the right (flipped) — container's right edge, line goes right toward player + point0 = Vector2(_container.position.x + _container.size.x, icon_mid_y) + direction = 1.0 + + # Point 1: 8px straight from point 0 toward the player + const SEGMENT_ORIGIN: float = 8.0 # length of initial segment from origin + var point1 = Vector2(point0.x + SEGMENT_ORIGIN * direction, icon_mid_y) + + # Point 2: player's origin + ENDPOINT_OFFSET, converted to notification's local space + const ENDPOINT_OFFSET = Vector2(4, 7) # offset from player's origin to connector endpoint + var target = _player.position + Vector2(+ENDPOINT_OFFSET.x, _origin_offset + ENDPOINT_OFFSET.y) + var point2 = target - position + + _connector_line.points = PackedVector2Array([point0, point1, point2])