make tabs modular
This commit is contained in:
parent
83ee764b45
commit
ccb6478ae7
|
@ -50,7 +50,16 @@ const IconFont = preload("res://assets/icons/icons.tres")
|
||||||
@export var toggleable: bool = false
|
@export var toggleable: bool = false
|
||||||
@export var disabled: bool = false
|
@export var disabled: bool = false
|
||||||
@export var initial_active: 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:
|
var active: bool = false:
|
||||||
get:
|
get:
|
||||||
if external_value != null:
|
if external_value != null:
|
||||||
|
|
27
content/ui/components/tabs/tabs.gd
Normal file
27
content/ui/components/tabs/tabs.gd
Normal 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
|
6
content/ui/components/tabs/tabs.tscn
Normal file
6
content/ui/components/tabs/tabs.tscn
Normal 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")
|
20
content/ui/components/tabs/tabs_content.gd
Normal file
20
content/ui/components/tabs/tabs_content.gd
Normal 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])
|
||||||
|
)
|
6
content/ui/components/tabs/tabs_content.tscn
Normal file
6
content/ui/components/tabs/tabs_content.tscn
Normal 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")
|
|
@ -3,16 +3,6 @@ extends Node3D
|
||||||
const Proxy = preload("res://lib/utils/proxy.gd")
|
const Proxy = preload("res://lib/utils/proxy.gd")
|
||||||
const Notification = preload("res://content/ui/components/notification/notification.tscn")
|
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 menu_root = $AnimationContainer
|
||||||
@onready var content = $AnimationContainer/Content
|
@onready var content = $AnimationContainer/Content
|
||||||
@onready var nav = $AnimationContainer/Navigation
|
@onready var nav = $AnimationContainer/Navigation
|
||||||
|
@ -42,61 +32,3 @@ func _ready():
|
||||||
|
|
||||||
notify_place.add_child(notification_node)
|
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
|
|
||||||
|
|
|
@ -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="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="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/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://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="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="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://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"]
|
[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)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.21, 0, 0.15)
|
||||||
shape = SubResource("ConvexPolygonShape3D_mgnm0")
|
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)
|
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)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.03)
|
||||||
label = "visibility"
|
label = "visibility"
|
||||||
icon = true
|
icon = true
|
||||||
toggleable = 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)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.09)
|
||||||
label = "widgets"
|
label = "widgets"
|
||||||
icon = true
|
icon = true
|
||||||
toggleable = 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)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.15)
|
||||||
label = "view_in_ar"
|
label = "view_in_ar"
|
||||||
icon = true
|
icon = true
|
||||||
toggleable = 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)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.21)
|
||||||
label = "schema"
|
label = "schema"
|
||||||
icon = true
|
icon = true
|
||||||
toggleable = 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)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.27)
|
||||||
label = "settings"
|
label = "settings"
|
||||||
icon = true
|
icon = true
|
||||||
toggleable = 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)
|
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="ViewMenu" parent="AnimationContainer/TabsContent" instance=ExtResource("8_71pkg")]
|
||||||
|
|
||||||
[node name="RoomMenu" parent="AnimationContainer/Content" instance=ExtResource("10_u4i1x")]
|
|
||||||
visible = false
|
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
|
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
|
visible = false
|
||||||
|
|
||||||
[node name="NotifyPlace" type="Marker3D" parent="AnimationContainer"]
|
[node name="NotifyPlace" type="Marker3D" parent="AnimationContainer"]
|
||||||
|
|
|
@ -29,3 +29,11 @@ icon = true
|
||||||
[node name="Input" parent="Interface" instance=ExtResource("4_pbj71")]
|
[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)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.12, 0.005, 0.27)
|
||||||
text = "New Room 1"
|
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"
|
||||||
|
|
|
@ -23,14 +23,14 @@ mesh = SubResource("BoxMesh_e51x8")
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.007, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.007, 0)
|
||||||
|
|
||||||
[node name="Label3D" type="Label3D" parent="Content"]
|
[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
|
pixel_size = 0.001
|
||||||
text = "Spawn Ball"
|
text = "Spawn Ball"
|
||||||
font_size = 18
|
font_size = 18
|
||||||
outline_size = 0
|
outline_size = 0
|
||||||
|
|
||||||
[node name="Button" parent="Content" instance=ExtResource("1_faxng")]
|
[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"
|
label = "sports_basketball"
|
||||||
icon = true
|
icon = true
|
||||||
|
|
||||||
|
@ -109,11 +109,11 @@ outline_size = 0
|
||||||
script = ExtResource("3_qmg6q")
|
script = ExtResource("3_qmg6q")
|
||||||
|
|
||||||
[node name="Save" parent="Content" instance=ExtResource("1_faxng")]
|
[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"
|
label = "save"
|
||||||
icon = true
|
icon = true
|
||||||
|
|
||||||
[node name="ClearSave" parent="Content" instance=ExtResource("1_faxng")]
|
[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"
|
label = "close"
|
||||||
icon = true
|
icon = true
|
||||||
|
|
|
@ -49,15 +49,15 @@ func load():
|
||||||
var json_text = save_file.get_line()
|
var json_text = save_file.get_line()
|
||||||
var save_data = JSON.parse_string(json_text)
|
var save_data = JSON.parse_string(json_text)
|
||||||
|
|
||||||
|
if save_data.has("version") == false:
|
||||||
|
save()
|
||||||
|
return
|
||||||
|
|
||||||
var save_tree = save_data["tree"]
|
var save_tree = save_data["tree"]
|
||||||
|
|
||||||
if save_tree == null:
|
if save_tree == null:
|
||||||
return
|
return
|
||||||
|
|
||||||
if save_tree.has("version") == false:
|
|
||||||
save()
|
|
||||||
return
|
|
||||||
|
|
||||||
if save_tree is Array:
|
if save_tree is Array:
|
||||||
for tree in save_tree:
|
for tree in save_tree:
|
||||||
_build_save_tree(tree)
|
_build_save_tree(tree)
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
extends RefCounted
|
extends RefCounted
|
||||||
|
class_name Proxy
|
||||||
|
|
||||||
|
signal on_set(new_value: Variant)
|
||||||
|
|
||||||
var gettable: Callable
|
var gettable: Callable
|
||||||
var settable: Callable
|
var settable: Callable
|
||||||
|
@ -7,8 +10,12 @@ func _init(gettable: Callable, settable: Callable):
|
||||||
self.gettable = gettable
|
self.gettable = gettable
|
||||||
self.settable = settable
|
self.settable = settable
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var value: Variant:
|
var value: Variant:
|
||||||
get:
|
get:
|
||||||
return gettable.call()
|
return gettable.call()
|
||||||
set(new_value):
|
set(new_value):
|
||||||
settable.call(new_value)
|
settable.call(new_value)
|
||||||
|
on_set.emit(new_value)
|
||||||
|
|
||||||
|
|
19
lib/utils/proxy_group.gd
Normal file
19
lib/utils/proxy_group.gd
Normal 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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user