immersive-home/app/content/ui/menu/menu.gd

56 lines
1.4 KiB
GDScript3
Raw Permalink Normal View History

2023-10-30 02:21:50 +02:00
extends Node3D
const Notification = preload ("res://content/ui/components/notification/notification.tscn")
2023-11-28 00:46:05 +02:00
@onready var animation_player = $AnimationPlayer
2024-05-09 13:40:41 +03:00
@onready var open_sound = $OpenSound
@onready var close_sound = $CloseSound
2023-12-13 23:22:52 +02:00
@onready var notify_place = $AnimationContainer/NotifyPlace
2023-11-16 20:23:17 +02:00
var show_menu = R.state(false)
func _ready():
2024-05-23 20:03:37 +03:00
App.main.remove_child.call_deferred(self)
R.effect(func(_arg):
if show_menu.value:
2024-05-22 19:38:28 +03:00
App.main.add_child(self)
move_into_view()
animation_player.play_backwards("hide_menu")
2024-05-09 13:40:41 +03:00
open_sound.play()
close_sound.stop()
else:
animation_player.play("hide_menu")
2024-05-09 13:40:41 +03:00
close_sound.play()
open_sound.stop()
)
animation_player.animation_finished.connect(func(_animation):
if show_menu.value == false:
2024-05-22 19:38:28 +03:00
App.main.remove_child(self)
)
EventSystem.on_action_down.connect(func(action):
if action.name == "menu_button":
toggle_open()
)
2023-10-30 02:21:50 +02:00
2023-12-13 23:22:52 +02:00
EventSystem.on_notify.connect(func(event: EventNotify):
var notification_node=Notification.instantiate()
notification_node.text=event.message
notification_node.type=event.type
2023-12-13 23:22:52 +02:00
for child in notify_place.get_children():
2024-04-25 17:05:52 +03:00
child.position += Vector3(0, 0.06, 0)
2023-12-13 23:22:52 +02:00
notify_place.add_child(notification_node)
)
2024-05-22 19:38:28 +03:00
func toggle_open():
show_menu.value = !show_menu.value
func move_into_view():
2024-05-22 19:38:28 +03:00
var camera_transform = App.camera.global_transform
camera_transform.origin -= camera_transform.basis.z * 0.5
global_transform = camera_transform