feat(navigation): add NavigationArrow component for within-floor room navigation
This commit is contained in:
21
scenes/objects/NavigationArrow.tscn
Normal file
21
scenes/objects/NavigationArrow.tscn
Normal file
@@ -0,0 +1,21 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://cozypaw_navarrow"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/objects/navigation_arrow.gd" id="1_navarrow"]
|
||||
|
||||
[node name="NavigationArrow" type="Node2D"]
|
||||
script = ExtResource("1_navarrow")
|
||||
|
||||
[node name="Body" type="ColorRect" parent="."]
|
||||
color = Color(0.30, 0.60, 1.0, 0.85)
|
||||
size = Vector2(96, 96)
|
||||
position = Vector2(-48, -48)
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
offset_left = -24.0
|
||||
offset_top = -18.0
|
||||
offset_right = 24.0
|
||||
offset_bottom = 18.0
|
||||
text = "→"
|
||||
theme_override_font_sizes/font_size = 36
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
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