add 3D containers
This commit is contained in:
parent
58c4c9a6d6
commit
280b986455
|
@ -42,7 +42,7 @@ pose = &"aim"
|
||||||
mesh = SubResource("BoxMesh_ir3co")
|
mesh = SubResource("BoxMesh_ir3co")
|
||||||
|
|
||||||
[node name="Menu" parent="XROrigin3D/XRControllerLeft" instance=ExtResource("3_1tbp3")]
|
[node name="Menu" parent="XROrigin3D/XRControllerLeft" instance=ExtResource("3_1tbp3")]
|
||||||
transform = Transform3D(-4.37114e-08, 0, -1, -0.707107, 0.707107, 3.09086e-08, 0.707107, 0.707107, -3.09086e-08, 0.183517, 0, -0.0534939)
|
transform = Transform3D(1, -0.000382732, -0.000120985, 8.65898e-05, 0.5, -0.866025, 0.000391948, 0.866025, 0.5, 0.0669508, 0.0876772, -0.101157)
|
||||||
|
|
||||||
[node name="XRControllerRight" type="XRController3D" parent="XROrigin3D"]
|
[node name="XRControllerRight" type="XRController3D" parent="XROrigin3D"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.488349, 0.559219, -0.2988)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.488349, 0.559219, -0.2988)
|
||||||
|
|
|
@ -18,6 +18,6 @@ mesh = SubResource("BoxMesh_aa3i4")
|
||||||
shape = SubResource("BoxShape3D_28fjq")
|
shape = SubResource("BoxShape3D_28fjq")
|
||||||
|
|
||||||
[node name="Label" type="Label3D" parent="."]
|
[node name="Label" type="Label3D" parent="."]
|
||||||
transform = Transform3D(-2.18557e-09, -0.05, -2.18557e-09, 0, -2.18557e-09, 0.05, -0.05, 2.18557e-09, 9.55343e-17, 0, 0.00918245, 0)
|
transform = Transform3D(0.05, 0, 0, 0, -2.18557e-09, 0.05, 0, -0.05, -2.18557e-09, 0, 0.00918245, 0)
|
||||||
text = "Text"
|
text = "Text"
|
||||||
autowrap_mode = 3
|
autowrap_mode = 3
|
||||||
|
|
|
@ -18,6 +18,6 @@ mesh = SubResource("BoxMesh_aa3i4")
|
||||||
shape = SubResource("BoxShape3D_28fjq")
|
shape = SubResource("BoxShape3D_28fjq")
|
||||||
|
|
||||||
[node name="Label" type="Label3D" parent="."]
|
[node name="Label" type="Label3D" parent="."]
|
||||||
transform = Transform3D(-2.18557e-09, -0.05, -2.18557e-09, 0, -2.18557e-09, 0.05, -0.05, 2.18557e-09, 9.55343e-17, 0, 0.00918245, 0)
|
transform = Transform3D(0.05, 0, 0, 0, -2.18557e-09, 0.05, 0, -0.05, -2.18557e-09, 0, 0.00918245, 0)
|
||||||
text = "Text"
|
text = "Text"
|
||||||
autowrap_mode = 3
|
autowrap_mode = 3
|
||||||
|
|
15
content/ui/menu/container3d.gd
Normal file
15
content/ui/menu/container3d.gd
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
extends Node3D
|
||||||
|
class_name Container3D
|
||||||
|
|
||||||
|
@export var size := Vector3(1.0, 1.0, 1.0) :
|
||||||
|
set(value):
|
||||||
|
size = value
|
||||||
|
_update_container()
|
||||||
|
|
||||||
|
@export var padding: Vector4 = Vector4(0, 0, 0, 0) :
|
||||||
|
set(value):
|
||||||
|
padding = value
|
||||||
|
_update_container()
|
||||||
|
|
||||||
|
func _update_container():
|
||||||
|
pass
|
42
content/ui/menu/grid.gd
Normal file
42
content/ui/menu/grid.gd
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
@tool
|
||||||
|
extends Container3D
|
||||||
|
class_name GridContainer3D
|
||||||
|
|
||||||
|
|
||||||
|
@export var columns := 5 :
|
||||||
|
set(value):
|
||||||
|
columns = value
|
||||||
|
_update_container()
|
||||||
|
|
||||||
|
@export var rows := 1 :
|
||||||
|
set(value):
|
||||||
|
rows = value
|
||||||
|
_update_container()
|
||||||
|
|
||||||
|
@export var depth_gap := 1.0 :
|
||||||
|
set(value):
|
||||||
|
depth_gap = value
|
||||||
|
_update_container()
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
_update_container()
|
||||||
|
|
||||||
|
func get_gaps() -> Vector3:
|
||||||
|
return Vector3(
|
||||||
|
(float(size.x) / (columns - 1 )) if columns != 1 else 0.0,
|
||||||
|
(float(size.y) / (rows - 1)) if rows != 1 else 0.0,
|
||||||
|
depth_gap
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func _update_container():
|
||||||
|
var i := 0
|
||||||
|
var gaps := get_gaps()
|
||||||
|
|
||||||
|
for child in get_children():
|
||||||
|
var x := (i % columns) * gaps.x
|
||||||
|
var y := ((i / columns) % rows) * gaps.y
|
||||||
|
var z := (i / (columns * rows)) * gaps.z
|
||||||
|
|
||||||
|
child.set_position(Vector3(x, -y, z))
|
||||||
|
i += 1
|
|
@ -6,7 +6,7 @@ const Switch = preload("res://content/entities/switch/switch.tscn")
|
||||||
const Light = preload("res://content/entities/light/light.tscn")
|
const Light = preload("res://content/entities/light/light.tscn")
|
||||||
const Sensor = preload("res://content/entities/sensor/sensor.tscn")
|
const Sensor = preload("res://content/entities/sensor/sensor.tscn")
|
||||||
|
|
||||||
@onready var devices_node = $Devices
|
@onready var devices_node: GridContainer3D = $Devices
|
||||||
var devices
|
var devices
|
||||||
|
|
||||||
var selected_device = null
|
var selected_device = null
|
||||||
|
@ -16,30 +16,18 @@ func _ready():
|
||||||
render_devices()
|
render_devices()
|
||||||
|
|
||||||
func render_devices():
|
func render_devices():
|
||||||
var x = 0
|
|
||||||
var y = 0
|
|
||||||
|
|
||||||
for device in devices:
|
for device in devices:
|
||||||
var info = device.values()[0]
|
var info = device.values()[0]
|
||||||
|
|
||||||
var device_instance = Device.instantiate()
|
var device_instance = Device.instantiate()
|
||||||
device_instance.set_position(Vector3(y * 0.08, 0, -x * 0.08))
|
|
||||||
device_instance.click.connect(_on_device_click)
|
device_instance.click.connect(_on_device_click)
|
||||||
device_instance.id = device.keys()[0]
|
device_instance.id = device.keys()[0]
|
||||||
|
|
||||||
devices_node.add_child(device_instance)
|
devices_node.add_child(device_instance)
|
||||||
|
|
||||||
device_instance.set_device_name(info["name"])
|
device_instance.set_device_name(info["name"])
|
||||||
|
|
||||||
x += 1
|
devices_node._update_container()
|
||||||
if x % 5 == 0:
|
|
||||||
x = 0
|
|
||||||
y += 1
|
|
||||||
|
|
||||||
func render_entities():
|
func render_entities():
|
||||||
var x = 0
|
|
||||||
var y = 0
|
|
||||||
|
|
||||||
var info
|
var info
|
||||||
|
|
||||||
for device in devices:
|
for device in devices:
|
||||||
|
@ -54,17 +42,11 @@ func render_entities():
|
||||||
|
|
||||||
for entity in entities:
|
for entity in entities:
|
||||||
var entity_instance = Entity.instantiate()
|
var entity_instance = Entity.instantiate()
|
||||||
entity_instance.set_position(Vector3(y * 0.08, 0, -x * 0.08))
|
|
||||||
entity_instance.click.connect(_on_entity_click)
|
entity_instance.click.connect(_on_entity_click)
|
||||||
|
|
||||||
devices_node.add_child(entity_instance)
|
devices_node.add_child(entity_instance)
|
||||||
|
|
||||||
entity_instance.set_entity_name(entity)
|
entity_instance.set_entity_name(entity)
|
||||||
|
|
||||||
x += 1
|
devices_node._update_container()
|
||||||
if x % 5 == 0:
|
|
||||||
x = 0
|
|
||||||
y += 1
|
|
||||||
|
|
||||||
func _on_device_click(device_id):
|
func _on_device_click(device_id):
|
||||||
selected_device = device_id
|
selected_device = device_id
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
[gd_scene load_steps=4 format=3 uid="uid://c3kdssrmv84kv"]
|
[gd_scene load_steps=5 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://bertj8bp8b5l1" path="res://assets/materials/interface.tres" id="2_nsukb"]
|
[ext_resource type="Material" uid="uid://bertj8bp8b5l1" path="res://assets/materials/interface.tres" id="2_nsukb"]
|
||||||
|
[ext_resource type="Script" path="res://content/ui/menu/grid.gd" id="3_35a5r"]
|
||||||
|
|
||||||
[sub_resource type="PlaneMesh" id="PlaneMesh_6t3dn"]
|
[sub_resource type="PlaneMesh" id="PlaneMesh_6t3dn"]
|
||||||
material = ExtResource("2_nsukb")
|
material = ExtResource("2_nsukb")
|
||||||
|
@ -11,7 +12,11 @@ size = Vector2(0.3, 0.3)
|
||||||
script = ExtResource("1_ng4u3")
|
script = ExtResource("1_ng4u3")
|
||||||
|
|
||||||
[node name="Background" type="MeshInstance3D" parent="."]
|
[node name="Background" type="MeshInstance3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0, 0.15)
|
||||||
mesh = SubResource("PlaneMesh_6t3dn")
|
mesh = SubResource("PlaneMesh_6t3dn")
|
||||||
|
|
||||||
[node name="Devices" type="Node3D" parent="."]
|
[node name="Devices" type="Node3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.149223, 0, 0.150667)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, 0, 0.03)
|
||||||
|
script = ExtResource("3_35a5r")
|
||||||
|
depth_gap = 0.06
|
||||||
|
size = Vector3(0.24, 0.1, 0.1)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user