make tabs modular

This commit is contained in:
Nitwel 2024-01-23 17:48:13 +01:00
parent 83ee764b45
commit ccb6478ae7
12 changed files with 134 additions and 91 deletions

View File

@ -50,7 +50,16 @@ const IconFont = preload("res://assets/icons/icons.tres")
@export var toggleable: bool = false
@export var disabled: bool = false
@export var initial_active: bool = false
var external_value: Proxy = null
var external_value: Proxy = null:
set(value):
print("set external value", value)
external_value = value
if value != null:
value.on_set.connect(func(_value):
print("external value changed", _value)
update_animation()
)
var active: bool = false:
get:
if external_value != null:

View File

@ -0,0 +1,27 @@
extends Node3D
class_name Tabs3D
signal on_select(selected: int)
var selected: Node3D
@export var initial_selected: Node3D
var proxy_group = ProxyGroup.new()
func _ready():
if initial_selected != null:
selected = initial_selected
on_select.emit(selected.get_index())
for option in get_children():
if option is Button3D == false:
continue
var proxy = proxy_group.proxy(func():
return selected == option
, func(value: bool):
if value == true:
selected = option
on_select.emit(selected.get_index())
)
option.external_value = proxy

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://doavdm6fskmrt"]
[ext_resource type="Script" path="res://content/ui/components/tabs/tabs.gd" id="1_xt6wm"]
[node name="Tabs" type="Node3D"]
script = ExtResource("1_xt6wm")

View File

@ -0,0 +1,20 @@
extends Node3D
class_name TabsContent3D
@export var tabs: Tabs3D
var children: Array = []
func _ready():
children = get_children()
for child in children:
child.visible = true
remove_child(child)
tabs.on_select.connect(func(index):
for child in get_children():
remove_child(child)
add_child(children[index])
)

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://wewhef3qmulp"]
[ext_resource type="Script" path="res://content/ui/components/tabs/tabs_content.gd" id="1_ljgkj"]
[node name="TabsContent" type="Node3D"]
script = ExtResource("1_ljgkj")

View File

@ -3,16 +3,6 @@ extends Node3D
const Proxy = preload("res://lib/utils/proxy.gd")
const Notification = preload("res://content/ui/components/notification/notification.tscn")
@onready var nav_view = $AnimationContainer/Navigation/View
@onready var nav_edit: Button3D = $AnimationContainer/Navigation/Edit
@onready var nav_room = $AnimationContainer/Navigation/Room
@onready var nav_automate = $AnimationContainer/Navigation/Automate
@onready var nav_settings = $AnimationContainer/Navigation/Settings
@onready var menu_view: Node3D = $AnimationContainer/Content/ViewMenu
@onready var menu_edit: Node3D = $AnimationContainer/Content/EditMenu
@onready var menu_room: Node3D = $AnimationContainer/Content/RoomMenu
@onready var menu_settings: Node3D = $AnimationContainer/Content/SettingsMenu
@onready var menu_root = $AnimationContainer
@onready var content = $AnimationContainer/Content
@onready var nav = $AnimationContainer/Navigation
@ -42,61 +32,3 @@ func _ready():
notify_place.add_child(notification_node)
)
var nav_buttons = [
nav_view,
nav_edit,
nav_room,
nav_automate,
nav_settings
]
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
for child in content.get_children():
content.remove_child(child)
var old_nav = selected_nav
selected_nav = nav
if old_nav != null:
old_nav.update_animation()
if selected_nav != null:
selected_nav.update_animation()
var menu = _nav_to_menu(selected_nav)
if menu != null:
content.add_child(menu)
menu.visible = true
func _is_valid_nav(nav):
return nav == nav_view || nav == nav_edit || nav == nav_room || nav == nav_automate || nav == nav_settings
func _nav_to_menu(nav):
match nav:
nav_view:
return menu_view
nav_edit:
return menu_edit
nav_room:
return menu_room
nav_automate:
return null
nav_settings:
return menu_settings
return null

View File

@ -1,10 +1,12 @@
[gd_scene load_steps=17 format=3 uid="uid://c3kdssrmv84kv"]
[gd_scene load_steps=19 format=3 uid="uid://c3kdssrmv84kv"]
[ext_resource type="Script" path="res://content/ui/menu/menu.gd" id="1_ng4u3"]
[ext_resource type="Material" uid="uid://bnwimm214q67g" path="res://assets/materials/sec-500.material" id="2_0x5at"]
[ext_resource type="Script" path="res://content/functions/movable.gd" id="2_8coxu"]
[ext_resource type="Script" path="res://content/ui/components/tabs/tabs.gd" id="4_eavfx"]
[ext_resource type="PackedScene" uid="uid://crrb0l3ekuotj" path="res://content/ui/menu/edit/edit_menu.tscn" id="4_r2raj"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="5_w4i01"]
[ext_resource type="Script" path="res://content/ui/components/tabs/tabs_content.gd" id="6_7rntr"]
[ext_resource type="ArrayMesh" uid="uid://cbqhhnknyium2" path="res://assets/immersive_home_panels/immersive_home_panels.obj" id="7_f4u4o"]
[ext_resource type="PackedScene" uid="uid://ddpxthb414unp" path="res://content/ui/menu/view/view_menu.tscn" id="8_71pkg"]
[ext_resource type="PackedScene" uid="uid://c01gkeldvjwtr" path="res://content/ui/menu/room/room_menu.tscn" id="10_u4i1x"]
@ -182,51 +184,58 @@ skeleton = NodePath("../..")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.21, 0, 0.15)
shape = SubResource("ConvexPolygonShape3D_mgnm0")
[node name="Navigation" type="Node3D" parent="AnimationContainer"]
[node name="Tabs" type="Node3D" parent="AnimationContainer" node_paths=PackedStringArray("initial_selected")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06, 0, 0)
script = ExtResource("4_eavfx")
initial_selected = NodePath("View")
[node name="View" parent="AnimationContainer/Navigation" instance=ExtResource("5_w4i01")]
[node name="View" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.03)
label = "visibility"
icon = true
toggleable = true
[node name="Edit" parent="AnimationContainer/Navigation" instance=ExtResource("5_w4i01")]
[node name="Edit" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.09)
label = "widgets"
icon = true
toggleable = true
[node name="Room" parent="AnimationContainer/Navigation" instance=ExtResource("5_w4i01")]
[node name="Room" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.15)
label = "view_in_ar"
icon = true
toggleable = true
[node name="Automate" parent="AnimationContainer/Navigation" instance=ExtResource("5_w4i01")]
[node name="Automate" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.21)
label = "schema"
icon = true
toggleable = true
[node name="Settings" parent="AnimationContainer/Navigation" instance=ExtResource("5_w4i01")]
[node name="Settings" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.27)
label = "settings"
icon = true
toggleable = true
[node name="Content" type="Node3D" parent="AnimationContainer"]
[node name="TabsContent" type="Node3D" parent="AnimationContainer" node_paths=PackedStringArray("tabs")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06, 0, 0)
script = ExtResource("6_7rntr")
tabs = NodePath("../Tabs")
[node name="EditMenu" parent="AnimationContainer/Content" instance=ExtResource("4_r2raj")]
[node name="RoomMenu" parent="AnimationContainer/Content" instance=ExtResource("10_u4i1x")]
[node name="ViewMenu" parent="AnimationContainer/TabsContent" instance=ExtResource("8_71pkg")]
visible = false
[node name="SettingsMenu" parent="AnimationContainer/Content" instance=ExtResource("11_7wm6b")]
[node name="EditMenu" parent="AnimationContainer/TabsContent" instance=ExtResource("4_r2raj")]
[node name="RoomMenu" parent="AnimationContainer/TabsContent" instance=ExtResource("10_u4i1x")]
visible = false
[node name="ViewMenu" parent="AnimationContainer/Content" instance=ExtResource("8_71pkg")]
[node name="AutomateMenu" type="Node3D" parent="AnimationContainer/TabsContent"]
visible = false
[node name="SettingsMenu" parent="AnimationContainer/TabsContent" instance=ExtResource("11_7wm6b")]
visible = false
[node name="NotifyPlace" type="Marker3D" parent="AnimationContainer"]

View File

@ -29,3 +29,11 @@ icon = true
[node name="Input" parent="Interface" instance=ExtResource("4_pbj71")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.12, 0.005, 0.27)
text = "New Room 1"
[node name="Button2" parent="." instance=ExtResource("4_cghmp")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, 0, 0)
label = "Overview"
[node name="Button" parent="." instance=ExtResource("4_cghmp")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.09, 0, 0)
label = "Rooms"

View File

@ -23,14 +23,14 @@ mesh = SubResource("BoxMesh_e51x8")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.007, 0)
[node name="Label3D" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.134377, 0, 0.253575)
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.124377, 0, 0.263575)
pixel_size = 0.001
text = "Spawn Ball"
font_size = 18
outline_size = 0
[node name="Button" parent="Content" instance=ExtResource("1_faxng")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0458097, 0, 0.253575)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0358097, 0, 0.263575)
label = "sports_basketball"
icon = true
@ -109,11 +109,11 @@ outline_size = 0
script = ExtResource("3_qmg6q")
[node name="Save" parent="Content" instance=ExtResource("1_faxng")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.04, 0, 0.17)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, 0, 0.12)
label = "save"
icon = true
[node name="ClearSave" parent="Content" instance=ExtResource("1_faxng")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.1, 0, 0.17)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.09, 0, 0.12)
label = "close"
icon = true

View File

@ -49,15 +49,15 @@ func load():
var json_text = save_file.get_line()
var save_data = JSON.parse_string(json_text)
if save_data.has("version") == false:
save()
return
var save_tree = save_data["tree"]
if save_tree == null:
return
if save_tree.has("version") == false:
save()
return
if save_tree is Array:
for tree in save_tree:
_build_save_tree(tree)

View File

@ -1,4 +1,7 @@
extends RefCounted
class_name Proxy
signal on_set(new_value: Variant)
var gettable: Callable
var settable: Callable
@ -7,8 +10,12 @@ func _init(gettable: Callable, settable: Callable):
self.gettable = gettable
self.settable = settable
var value: Variant:
get:
return gettable.call()
set(new_value):
settable.call(new_value)
settable.call(new_value)
on_set.emit(new_value)

19
lib/utils/proxy_group.gd Normal file
View File

@ -0,0 +1,19 @@
extends RefCounted
class_name ProxyGroup
var proxies = []
func proxy(_get: Callable, _set: Callable):
var _proxy
_proxy = Proxy.new(_get, func(value):
_set.call(value)
for p in proxies:
if p != _proxy:
p.on_set.emit(value)
)
proxies.append(_proxy)
return _proxy