add room renaming and disable input option

This commit is contained in:
Nitwel 2024-03-12 12:23:39 +01:00
parent 7b0a753078
commit e2fcc5b08f
5 changed files with 88 additions and 33 deletions

View File

@ -90,7 +90,6 @@ func is_valid_room(room_name):
return room.wall_corners.get_child_count() >= 3
func delete_room(room_name):
var room = find_room(room_name)
@ -125,6 +124,21 @@ func find_room_at(entity_position: Vector3):
return room
return null
func rename_room(old_room: String, new_name: String):
var room = find_room(old_room)
if room == null:
return
room.name = new_name
var store_room = Store.house.get_room(old_room)
if store_room != null:
store_room.name = new_name
Store.house.save_local()
func get_level(level: int):
return levels.get_child(level)
@ -206,7 +220,6 @@ func update_mini_view():
camera_position.y *= 0.5
camera_direction.y = 0.0
var target_position = camera_position + camera_direction.normalized() * 0.2
levels.global_position = target_position - center * 0.1
else:

View File

@ -33,6 +33,20 @@ var text_handler = preload("res://content/ui/components/input/text_handler.gd").
text_handler.set_text(value, focused)
label.text = text_handler.get_display_text()
@export var disabled: bool = false:
set(value):
if !is_node_ready(): await ready
disabled = value
if disabled:
label.modulate = Color(0.7, 0.7, 0.7)
add_to_group("ui_focus_skip")
animation.stop()
caret.hide()
else:
label.modulate = Color(1, 1, 1)
remove_from_group("ui_focus_skip")
var keyboard_input: bool = false
var input_plane = Plane(Vector3.UP, Vector3.ZERO)
@ -44,7 +58,7 @@ func _ready():
return
EventSystem.on_key_down.connect(func(event):
if EventSystem.is_focused(self) == false:
if EventSystem.is_focused(self) == false||disabled:
return
text=EventKey.key_to_string(event.key, event.shift_pressed, text.substr(0, text_handler.caret_position)) + text.substr(text_handler.caret_position, text.length())
@ -58,6 +72,9 @@ func _input(event):
keyboard_input = !keyboard_input
return
if disabled:
return
if keyboard_input:
text = EventKey.key_to_string(event.keycode, event.shift_pressed, text.substr(0, text_handler.caret_position)) + text.substr(text_handler.caret_position, text.length())
caret.position.x = text_handler.get_caret_position()
@ -70,10 +87,16 @@ func _process(_delta):
_draw_debug_text_gaps()
func _on_press_down(event):
if disabled:
return
var pos_x = label.to_local(event.ray.get_collision_point()).x
text_handler.update_caret_position(pos_x)
func _on_press_move(event):
if disabled:
return
var ray_pos = event.ray.global_position
var ray_dir = -event.ray.global_transform.basis.z
@ -92,6 +115,9 @@ func _on_press_move(event):
label.text = text_handler.get_display_text()
func _on_focus_in(_event):
if disabled:
return
caret.position.x = text_handler.get_caret_position()
label.text = text_handler.get_display_text()
caret.show()
@ -114,8 +140,10 @@ func update_caret_position(event):
caret.position.x = text_handler.get_caret_position()
func _on_focus_out(_event):
if disabled:
return
animation.stop()
caret.hide()

View File

@ -6,7 +6,6 @@ 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
@ -17,28 +16,37 @@ var selected_room = null:
room_button.label = "add"
input.text = "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:
room_button.label = "edit"
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):
if value == edit_room:
return
edit_room = value
if value:
room_button.label = "save"
input.disabled = false
else:
room_button.label = "edit"
input.disabled = true
if selected_room != null&&selected_room != input.text:
House.body.rename_room(selected_room, input.text)
selected_room = input.text
func _ready():
if Store.house.is_loaded():
@ -75,6 +83,9 @@ func _ready():
)
func get_room(room_name):
if room_name == null:
return null
if rooms_map.has_node("%s"% room_name):
return rooms_map.get_node("%s"% room_name)
return null

View File

@ -18,3 +18,4 @@ 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 = "Room 1"
disabled = true

View File

@ -43,6 +43,7 @@ horizontal_alignment = 0
[node name="InputURL" parent="Content" instance=ExtResource("4_q3x6k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.18, 0, 0.03)
text = "ws://192.168.0.1:8123"
disabled = null
[node name="LabelToken" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.01, 0, 0.07)
@ -55,6 +56,7 @@ horizontal_alignment = 0
[node name="InputToken" parent="Content" instance=ExtResource("4_q3x6k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.18, 0, 0.07)
text = "..."
disabled = null
[node name="LabelConnect" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.14, 0, 0.12)