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

113 lines
2.8 KiB
GDScript3
Raw Normal View History

2023-10-30 02:21:50 +02:00
extends Node3D
2023-11-28 00:46:05 +02:00
const Proxy = preload("res://lib/utils/proxy.gd")
2023-12-13 23:22:52 +02:00
const Notification = preload("res://content/ui/components/notification/notification.tscn")
2023-11-28 00:46:05 +02:00
@onready var _controller := XRHelpers.get_xr_controller(self)
@onready var nav_view = $AnimationContainer/Navigation/View
@onready var nav_edit: Button3D = $AnimationContainer/Navigation/Edit
@onready var menu_edit: Node3D = $AnimationContainer/Content/EditMenu
@onready var nav_room = $AnimationContainer/Navigation/Room
@onready var menu_room: Node3D = $AnimationContainer/Content/RoomMenu
@onready var nav_automate = $AnimationContainer/Navigation/Automate
@onready var nav_settings = $AnimationContainer/Navigation/Settings
@onready var menu_settings: Node3D = $AnimationContainer/Content/SettingsMenu
@onready var menu_root = $AnimationContainer
@onready var content = $AnimationContainer/Content
@onready var nav = $AnimationContainer/Navigation
@onready var animation_player = $AnimationPlayer
2023-12-13 23:22:52 +02:00
@onready var notify_place = $AnimationContainer/NotifyPlace
2023-11-16 20:23:17 +02:00
var selected_nav = null
2023-11-16 20:23:17 +02:00
var show_menu := true:
set(value):
show_menu = value
if value:
animation_player.play_backwards("hide_menu")
AudioPlayer.play_effect("open_menu")
else:
animation_player.play("hide_menu")
AudioPlayer.play_effect("close_menu")
2023-10-30 02:21:50 +02:00
func _ready():
_controller.button_pressed.connect(func(button):
if button == "by_button":
show_menu = !show_menu
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
for child in notify_place.get_children():
child.position += Vector3(0, 0, -0.06)
notify_place.add_child(notification_node)
)
2023-11-28 00:46:05 +02:00
var nav_buttons = [
nav_view,
nav_edit,
nav_room,
nav_automate,
nav_settings
]
2023-11-16 20:23:17 +02:00
2023-11-28 00:46:05 +02:00
for nav_button in nav_buttons:
var getter = func():
return nav_button == selected_nav
var setter = func(value):
if value:
select_menu(nav_button)
nav_button.external_value = Proxy.new(getter, setter)
select_menu(nav_edit)
func select_menu(nav):
if _is_valid_nav(nav) == false || selected_nav == nav:
return
2023-11-16 20:23:17 +02:00
for child in content.get_children():
content.remove_child(child)
2023-11-16 20:23:17 +02:00
2023-11-28 00:46:05 +02:00
var old_nav = selected_nav
2023-11-16 20:23:17 +02:00
selected_nav = nav
2023-11-18 15:27:42 +02:00
2023-11-28 00:46:05 +02:00
if old_nav != null:
old_nav.update_animation()
if selected_nav != null:
2023-11-28 00:46:05 +02:00
selected_nav.update_animation()
var menu = _nav_to_menu(selected_nav)
if menu != null:
content.add_child(menu)
menu.visible = true
2023-11-16 20:23:17 +02:00
func _is_valid_nav(nav):
return nav == nav_view || nav == nav_edit || nav == nav_room || nav == nav_automate || nav == nav_settings
2023-11-16 20:23:17 +02:00
func _nav_to_menu(nav):
match nav:
nav_view:
2023-11-16 20:23:17 +02:00
return null
nav_edit:
2023-11-16 20:23:17 +02:00
return menu_edit
nav_room:
2023-11-18 16:32:37 +02:00
return menu_room
nav_automate:
2023-11-16 20:23:17 +02:00
return null
nav_settings:
return menu_settings
return null