diff --git a/assets/fonts/ui_font_500.tres b/assets/fonts/ui_font_500.tres index 3f69c7e..4dfa14d 100644 --- a/assets/fonts/ui_font_500.tres +++ b/assets/fonts/ui_font_500.tres @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1d0d7c19b4862ffa6c78a12151cbd01acb0f1f23400a7c75ad795680b61b6a1a -size 301 +oid sha256:26d5c6e9529db2b628074d05b9764878eaf60f35c6042f82944c2f12065766df +size 339 diff --git a/content/entities/sensor/sensor.gd b/content/entities/sensor/sensor.gd index ac22e43..998c0e6 100644 --- a/content/entities/sensor/sensor.gd +++ b/content/entities/sensor/sensor.gd @@ -1,8 +1,9 @@ extends Entity -const Entity = preload("../entity.gd") +const Entity = preload ("../entity.gd") @onready var label: Label3D = $Label +@onready var collision_shape = $CollisionShape3D # Called when the node enters the scene tree for the first time. func _ready(): @@ -21,7 +22,16 @@ func set_text(stateInfo): if stateInfo["attributes"]["friendly_name"] != null: text = stateInfo["attributes"]["friendly_name"] + "\n" + text - if stateInfo["attributes"].has("unit_of_measurement") && stateInfo["attributes"]["unit_of_measurement"] != null: + if stateInfo["attributes"].has("unit_of_measurement")&&stateInfo["attributes"]["unit_of_measurement"] != null: text += " " + stateInfo["attributes"]["unit_of_measurement"] - label.text = text \ No newline at end of file + label.text = text + + var font = label.get_font() + var width = 0 + var height = 0 + + var size = font.get_multiline_string_size(text, HORIZONTAL_ALIGNMENT_CENTER, label.width, label.font_size) + + collision_shape.shape.size.x = size.x * label.pixel_size * 0.5 + collision_shape.shape.size.y = size.y * label.pixel_size * 0.25 diff --git a/content/entities/sensor/sensor.tscn b/content/entities/sensor/sensor.tscn index b8fc03e..024519d 100644 --- a/content/entities/sensor/sensor.tscn +++ b/content/entities/sensor/sensor.tscn @@ -1,24 +1,27 @@ -[gd_scene load_steps=5 format=3 uid="uid://xsiy71rsqulj"] +[gd_scene load_steps=6 format=3 uid="uid://xsiy71rsqulj"] [ext_resource type="Script" path="res://content/entities/sensor/sensor.gd" id="1_57ac8"] +[ext_resource type="FontVariation" uid="uid://d2ofyimg5s65q" path="res://assets/fonts/ui_font_500.tres" id="2_4np3x"] [ext_resource type="Script" path="res://content/functions/movable.gd" id="2_fpq5q"] [ext_resource type="Script" path="res://content/functions/occludable.gd" id="3_l3sp5"] -[sub_resource type="SphereShape3D" id="SphereShape3D_r20gc"] -radius = 0.1 +[sub_resource type="BoxShape3D" id="BoxShape3D_phuot"] +resource_local_to_scene = true +size = Vector3(0.18, 0.03, 0.02) [node name="Sensor" type="StaticBody3D" groups=["entity"]] collision_mask = 0 script = ExtResource("1_57ac8") [node name="CollisionShape3D" type="CollisionShape3D" parent="."] -shape = SubResource("SphereShape3D_r20gc") +shape = SubResource("BoxShape3D_phuot") [node name="Label" type="Label3D" parent="."] transform = Transform3D(0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 0, 0, 0) pixel_size = 0.001 text = "some text " +font = ExtResource("2_4np3x") font_size = 80 [node name="Movable" type="Node" parent="."]