feat(navigation): add NavigationArrow component for within-floor room navigation
This commit is contained in:
40
scripts/objects/navigation_arrow.gd
Normal file
40
scripts/objects/navigation_arrow.gd
Normal file
@@ -0,0 +1,40 @@
|
||||
## NavigationArrow — tappable button that navigates camera to a specific floor and room.
|
||||
class_name NavigationArrow extends Node2D
|
||||
|
||||
const BUTTON_HALF_SIZE: float = 48.0
|
||||
|
||||
@export var target_floor: int = 0
|
||||
@export var target_room: int = 0
|
||||
@export var label_text: String = "→"
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var label: Label = get_node_or_null("Label") as Label
|
||||
if label != null:
|
||||
label.text = label_text
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
var screen_pos: Vector2
|
||||
if event is InputEventScreenTouch and event.pressed:
|
||||
screen_pos = event.position
|
||||
elif event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
screen_pos = event.position
|
||||
else:
|
||||
return
|
||||
var canvas_transform: Transform2D = get_viewport().get_canvas_transform()
|
||||
var world_pos: Vector2 = canvas_transform.affine_inverse() * screen_pos
|
||||
var local_pos: Vector2 = to_local(world_pos)
|
||||
if abs(local_pos.x) <= BUTTON_HALF_SIZE and abs(local_pos.y) <= BUTTON_HALF_SIZE:
|
||||
_on_pressed()
|
||||
|
||||
|
||||
func _on_pressed() -> void:
|
||||
RoomNavigator.go_to_room(target_floor, target_room)
|
||||
_play_bounce()
|
||||
|
||||
|
||||
func _play_bounce() -> void:
|
||||
var tween: Tween = create_tween()
|
||||
tween.tween_property(self, "scale", Vector2(1.15, 1.15), 0.08)
|
||||
tween.tween_property(self, "scale", Vector2(1.0, 1.0), 0.08)
|
||||
Reference in New Issue
Block a user