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

80 lines
1.6 KiB
GDScript3
Raw Normal View History

2023-10-30 02:21:50 +02:00
extends Node3D
2023-11-16 20:23:17 +02:00
@onready var nav_view = $Navigation/View
@onready var nav_edit: Button3D = $Navigation/Edit
@onready var menu_edit: Node3D = $Content/EditMenu
@onready var nav_room = $Navigation/Room
2023-11-18 16:32:37 +02:00
@onready var menu_room: Node3D = $Content/RoomMenu
2023-11-16 20:23:17 +02:00
@onready var nav_automate = $Navigation/Automate
@onready var nav_settings = $Navigation/Settings
enum Menu {
VIEW,
EDIT,
ROOM,
AUTOMATE,
SETTINGS
}
var selected_menu := Menu.EDIT
2023-10-30 02:21:50 +02:00
func _ready():
2023-11-18 16:32:37 +02:00
select_menu(selected_menu)
2023-11-16 20:23:17 +02:00
func _on_click(event):
if event.target == nav_view:
select_menu(Menu.VIEW)
elif event.target == nav_edit:
select_menu(Menu.EDIT)
elif event.target == nav_room:
select_menu(Menu.ROOM)
elif event.target == nav_automate:
select_menu(Menu.AUTOMATE)
elif event.target == nav_settings:
select_menu(Menu.SETTINGS)
func select_menu(menu: Menu):
selected_menu = menu
for child in $Content.get_children():
if child.is_visible():
2023-11-18 16:32:37 +02:00
$Content.remove_child(child)
2023-11-16 20:23:17 +02:00
var menu_node = enum_to_menu(menu)
var nav_node = enum_to_nav(menu)
2023-11-18 15:27:42 +02:00
if nav_node != null:
nav_node.disabled = true
2023-11-16 20:23:17 +02:00
if menu_node != null:
2023-11-18 16:32:37 +02:00
$Content.add_child(menu_node)
2023-11-16 20:23:17 +02:00
for child in $Navigation.get_children():
if child.active && child != nav_node:
child.active = false
child.disabled = false
2023-10-30 02:21:50 +02:00
2023-11-16 20:23:17 +02:00
func enum_to_nav(menu: Menu):
match menu:
Menu.VIEW:
return nav_view
Menu.EDIT:
return nav_edit
Menu.ROOM:
return nav_room
Menu.AUTOMATE:
return nav_automate
Menu.SETTINGS:
return nav_settings
func enum_to_menu(menu: Menu):
match menu:
Menu.VIEW:
return null
Menu.EDIT:
return menu_edit
Menu.ROOM:
2023-11-18 16:32:37 +02:00
return menu_room
2023-11-16 20:23:17 +02:00
Menu.AUTOMATE:
return null
Menu.SETTINGS:
return null