add submenu to rooms menu

This commit is contained in:
Nitwel 2024-01-23 18:02:41 +01:00
parent ccb6478ae7
commit 0875d37ec2
9 changed files with 201 additions and 151 deletions

View File

@ -42,7 +42,7 @@ transform = Transform3D(1, -7.45058e-09, -2.22045e-16, 7.45058e-09, 1, 0, 0, 0,
shape = SubResource("CapsuleShape3D_dopke")
[node name="ThumbTip" type="BoneAttachment3D" parent="XRHandLeft"]
transform = Transform3D(0.937246, 0.0284254, -0.347508, 0.0184905, 0.991216, 0.130949, 0.348178, -0.129157, 0.928487, 0.0498668, 0.0560917, -0.112777)
transform = Transform3D(0.937246, 0.0284254, -0.347508, 0.0184905, 0.991216, 0.130949, 0.348178, -0.129157, 0.928488, 0.0498668, 0.0560917, -0.112777)
bone_name = "Thumb_Tip_L"
bone_idx = 4
use_external_skeleton = true
@ -52,7 +52,7 @@ external_skeleton = NodePath("../left_hand/Armature_001/Skeleton3D")
gizmo_extents = 0.02
[node name="MiddleTip" type="BoneAttachment3D" parent="XRHandLeft"]
transform = Transform3D(0.0812012, -0.650531, -0.755125, 0.996576, 0.064817, 0.051326, 0.0155558, -0.756708, 0.653567, 0.032112, 0.00654224, -0.171612)
transform = Transform3D(0.0812012, -0.650531, -0.755125, 0.996577, 0.064817, 0.051326, 0.0155558, -0.756708, 0.653568, 0.032112, 0.00654224, -0.171612)
bone_name = "Middle_Tip_L"
bone_idx = 14
use_external_skeleton = true
@ -94,7 +94,7 @@ hand_skeleton = NodePath("right_hand/Armature/Skeleton3D")
transform = Transform3D(1, 0, 4.7579e-13, 0, 1, 0, -1.34149e-12, 1.77636e-15, 1, 0, 0, 0)
[node name="IndexTip" type="BoneAttachment3D" parent="XRHandRight"]
transform = Transform3D(0.19221, 0.669966, 0.717078, -0.091543, -0.715277, 0.69282, 0.977075, -0.19881, -0.0761527, -0.0345978, -0.164767, -0.0355401)
transform = Transform3D(0.19221, 0.669966, 0.717079, -0.091543, -0.715277, 0.69282, 0.977075, -0.19881, -0.0761527, -0.0345977, -0.164767, -0.0355401)
bone_name = "Index_Tip_R"
bone_idx = 9
use_external_skeleton = true

View File

@ -3,8 +3,6 @@
extends Node3D
class_name Button3D
const Proxy = preload("res://lib/utils/proxy.gd")
signal on_button_down()
signal on_button_up()
@ -38,7 +36,7 @@ const IconFont = preload("res://assets/icons/icons.tres")
if value:
label_node.font = IconFont
label_node.font_size = 48
label_node.font_size = 36
label_node.width = 1000
label_node.autowrap_mode = TextServer.AUTOWRAP_OFF
else:
@ -52,11 +50,11 @@ const IconFont = preload("res://assets/icons/icons.tres")
@export var initial_active: bool = false
var external_value: Proxy = null:
set(value):
print("set external value", value)
if !is_node_ready(): await ready
external_value = value
if value != null:
value.on_set.connect(func(_value):
print("external value changed", _value)
update_animation()
)
@ -66,6 +64,8 @@ var active: bool = false:
return external_value.value
return active
set(value):
if !is_node_ready(): await ready
if external_value != null:
external_value.value = value
else:

View File

@ -25,3 +25,4 @@ func _ready():
)
option.external_value = proxy
option.toggleable = true

View File

@ -187,7 +187,7 @@ shape = SubResource("ConvexPolygonShape3D_mgnm0")
[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")
initial_selected = NodePath("")
[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)

View File

@ -1,46 +1,8 @@
extends Node3D
const Room = preload("res://content/system/house/room/room.tscn")
const RoomType = preload("res://content/system/house/room/room.gd")
const material_selected = preload("./room_selected.tres")
const material_unselected = preload("./room_unselected.tres")
const window_scene = preload("./window.tscn")
@onready var background = $Background
@onready var room_button = $Interface/Button
@onready var input = $Interface/Input
@onready var rooms_map = $Interface/Rooms
var selected_room = null:
set(value):
if selected_room != null && value == null:
room_button.label = "add"
input.text = "New Room %s" % (rooms_map.get_child_count() + 1)
if selected_room != null:
var old_room = get_room(selected_room)
if old_room != null:
old_room.get_node("MeshInstance3D").material_override = material_unselected
if value != null:
input.text = value
edit_room = false
var new_room = get_room(value)
if new_room != null:
new_room.get_node("MeshInstance3D").material_override = material_selected
selected_room = value
var edit_room = false:
set(value):
edit_room = value
if value:
room_button.label = "save"
else:
room_button.label = "edit"
func _ready():
background.visible = false
@ -52,90 +14,3 @@ func _ready():
# var mesh = room.wall_mesh
pass
)
room_button.on_button_down.connect(func():
if selected_room == null:
var room_name = input.text
if get_room(room_name) != null:
EventSystem.notify("Name already taken", EventNotify.Type.WARNING)
return
House.body.create_room(room_name, 0)
selected_room = room_name
edit_room = true
else:
if edit_room:
edit_room = false
if !House.body.is_valid_room(selected_room):
House.body.delete_room(selected_room)
selected_room = null
else:
House.body.edit_room(null)
_generate_room_map()
else:
edit_room = true
House.body.edit_room(selected_room)
)
func get_room(room_name):
if rooms_map.has_node("%s" % room_name):
return rooms_map.get_node("%s" % room_name)
return null
func _on_click(event: EventPointer):
if event.target.get_parent() == rooms_map:
var room_name = event.target.name
if selected_room == room_name:
selected_room = null
House.body.edit_room(null)
return
selected_room = room_name
func _generate_room_map():
var rooms = House.body.get_rooms(0)
var target_size = Vector3(0.3, 1, 0.24)
for old_room in rooms_map.get_children():
old_room.queue_free()
await old_room.tree_exited
var aabb = House.body.get_level_aabb(0)
var current_min = aabb.position
var current_max = aabb.position + aabb.size
for room in rooms:
var mesh = room.ceiling_mesh.mesh
if mesh == null:
continue
var body = StaticBody3D.new()
body.name = room.name
var mesh_instance = MeshInstance3D.new()
mesh_instance.name = "MeshInstance3D"
mesh_instance.mesh = mesh
mesh_instance.material_override = material_unselected if selected_room != room.name else material_selected
body.add_child(mesh_instance)
var collision_shape = CollisionShape3D.new()
collision_shape.shape = mesh.create_trimesh_shape()
body.add_child(collision_shape)
rooms_map.add_child(body)
if current_min == null:
return
var current_size = current_max - current_min
var target_scale = target_size / current_size
var scale_value = min(target_scale.x, target_scale.z)
rooms_map.position.x = -current_min.x * scale_value
rooms_map.position.z = -current_min.z * scale_value
rooms_map.scale = Vector3(scale_value, scale_value, scale_value)

View File

@ -1,9 +1,12 @@
[gd_scene load_steps=6 format=3 uid="uid://c01gkeldvjwtr"]
[gd_scene load_steps=9 format=3 uid="uid://c01gkeldvjwtr"]
[ext_resource type="Script" path="res://content/ui/menu/room/room_menu.gd" id="1_ch4jb"]
[ext_resource type="Material" uid="uid://bujy3egn1oqac" path="res://assets/materials/pri-500.material" id="2_7m4yn"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="4_cghmp"]
[ext_resource type="PackedScene" uid="uid://blrhy2uccrdn4" path="res://content/ui/components/input/input.tscn" id="4_pbj71"]
[ext_resource type="Script" path="res://content/ui/components/tabs/tabs.gd" id="5_ddrep"]
[ext_resource type="PackedScene" uid="uid://dd71loi64gnmp" path="res://content/ui/menu/room/views/overview.tscn" id="6_206ad"]
[ext_resource type="Script" path="res://content/ui/components/tabs/tabs_content.gd" id="6_ba00g"]
[ext_resource type="PackedScene" uid="uid://bpta22fahai46" path="res://content/ui/menu/room/views/rooms.tscn" id="7_2f8e0"]
[sub_resource type="BoxMesh" id="BoxMesh_e37nn"]
size = Vector3(0.3, 0.01, 0.3)
@ -18,22 +21,21 @@ mesh = SubResource("BoxMesh_e37nn")
[node name="Interface" type="Node3D" parent="."]
[node name="Rooms" type="Node3D" parent="Interface"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0.01, 0.12)
[node name="Tabs3D" type="Node3D" parent="Interface"]
script = ExtResource("5_ddrep")
[node name="Button" parent="Interface" instance=ExtResource("4_cghmp")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.27, 0, 0.27)
label = "add"
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)
[node name="Overview" parent="Interface/Tabs3D" instance=ExtResource("4_cghmp")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, 0, -0.02)
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)
[node name="Rooms" parent="Interface/Tabs3D" instance=ExtResource("4_cghmp")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.09, 0, -0.02)
label = "Rooms"
[node name="TabsContent3D" type="Node3D" parent="Interface" node_paths=PackedStringArray("tabs")]
script = ExtResource("6_ba00g")
tabs = NodePath("../Tabs3D")
[node name="Overview" parent="Interface/TabsContent3D" instance=ExtResource("6_206ad")]
[node name="Rooms" parent="Interface/TabsContent3D" instance=ExtResource("7_2f8e0")]

View File

@ -0,0 +1,22 @@
[gd_scene load_steps=2 format=3 uid="uid://dd71loi64gnmp"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="1_fteh8"]
[node name="Overview" type="Node3D"]
[node name="Button2" parent="." instance=ExtResource("1_fteh8")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.04, 0, 0.07)
label = "add"
icon = true
[node name="Button3" parent="." instance=ExtResource("1_fteh8")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.1, 0, 0.07)
label = "healing"
icon = true
[node name="Label3D" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.06, 0.01, 0.02)
pixel_size = 0.001
text = "Reference"
font_size = 18
outline_size = 0

View File

@ -0,0 +1,130 @@
extends Node3D
const Room = preload("res://content/system/house/room/room.tscn")
const RoomType = preload("res://content/system/house/room/room.gd")
const material_selected = preload("../room_selected.tres")
const material_unselected = preload("../room_unselected.tres")
@onready var room_button = $Button
@onready var input = $Input
@onready var rooms_map = $Rooms
var selected_room = null:
set(value):
if selected_room != null && value == null:
room_button.label = "add"
input.text = "New Room %s" % (rooms_map.get_child_count() + 1)
if selected_room != null:
var old_room = get_room(selected_room)
if old_room != null:
old_room.get_node("MeshInstance3D").material_override = material_unselected
if value != null:
input.text = value
edit_room = false
var new_room = get_room(value)
if new_room != null:
new_room.get_node("MeshInstance3D").material_override = material_selected
selected_room = value
var edit_room = false:
set(value):
edit_room = value
if value:
room_button.label = "save"
else:
room_button.label = "edit"
func _ready():
room_button.on_button_down.connect(func():
if selected_room == null:
var room_name = input.text
if get_room(room_name) != null:
EventSystem.notify("Name already taken", EventNotify.Type.WARNING)
return
House.body.create_room(room_name, 0)
selected_room = room_name
edit_room = true
else:
if edit_room:
edit_room = false
if !House.body.is_valid_room(selected_room):
House.body.delete_room(selected_room)
selected_room = null
else:
House.body.edit_room(null)
_generate_room_map()
else:
edit_room = true
House.body.edit_room(selected_room)
)
func get_room(room_name):
if rooms_map.has_node("%s" % room_name):
return rooms_map.get_node("%s" % room_name)
return null
func _on_click(event: EventPointer):
if event.target.get_parent() == rooms_map:
var room_name = event.target.name
if selected_room == room_name:
selected_room = null
House.body.edit_room(null)
return
selected_room = room_name
func _generate_room_map():
var rooms = House.body.get_rooms(0)
var target_size = Vector3(0.3, 1, 0.24)
for old_room in rooms_map.get_children():
old_room.queue_free()
await old_room.tree_exited
var aabb = House.body.get_level_aabb(0)
var current_min = aabb.position
var current_max = aabb.position + aabb.size
for room in rooms:
var mesh = room.ceiling_mesh.mesh
if mesh == null:
continue
var body = StaticBody3D.new()
body.name = room.name
var mesh_instance = MeshInstance3D.new()
mesh_instance.name = "MeshInstance3D"
mesh_instance.mesh = mesh
mesh_instance.material_override = material_unselected if selected_room != room.name else material_selected
body.add_child(mesh_instance)
var collision_shape = CollisionShape3D.new()
collision_shape.shape = mesh.create_trimesh_shape()
body.add_child(collision_shape)
rooms_map.add_child(body)
if current_min == null:
return
var current_size = current_max - current_min
var target_scale = target_size / current_size
var scale_value = min(target_scale.x, target_scale.z)
rooms_map.position.x = -current_min.x * scale_value
rooms_map.position.z = -current_min.z * scale_value
rooms_map.scale = Vector3(scale_value, scale_value, scale_value)

View File

@ -0,0 +1,20 @@
[gd_scene load_steps=4 format=3 uid="uid://bpta22fahai46"]
[ext_resource type="Script" path="res://content/ui/menu/room/views/rooms.gd" id="1_3a1oa"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="1_y3lty"]
[ext_resource type="PackedScene" uid="uid://blrhy2uccrdn4" path="res://content/ui/components/input/input.tscn" id="2_hstw7"]
[node name="Rooms" type="Node3D"]
script = ExtResource("1_3a1oa")
[node name="Rooms" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0.01, 0.12)
[node name="Button" parent="." instance=ExtResource("1_y3lty")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.27, 0, 0.27)
label = "add"
icon = true
[node name="Input" parent="." instance=ExtResource("2_hstw7")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.12, 0.005, 0.27)
text = ""