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

@ -1,7 +1,7 @@
extends Node3D extends Node3D
const Room = preload("./room/room.tscn") const Room = preload ("./room/room.tscn")
const RoomType = preload("./room/room.gd") const RoomType = preload ("./room/room.gd")
@onready var levels = $Levels @onready var levels = $Levels
@onready var collision_shape = $Levels/CollisionShape3D @onready var collision_shape = $Levels/CollisionShape3D
@ -89,7 +89,6 @@ func is_valid_room(room_name):
return return
return room.wall_corners.get_child_count() >= 3 return room.wall_corners.get_child_count() >= 3
func delete_room(room_name): func delete_room(room_name):
var room = find_room(room_name) var room = find_room(room_name)
@ -111,7 +110,7 @@ func delete_room(room_name):
Store.house.save_local() Store.house.save_local()
func is_editiong(room_name): func is_editiong(room_name):
return editing_room != null && editing_room.name == room_name return editing_room != null&&editing_room.name == room_name
func find_room(room_name): func find_room(room_name):
for room in get_rooms(0): for room in get_rooms(0):
@ -125,6 +124,21 @@ func find_room_at(entity_position: Vector3):
return room return room
return null 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): func get_level(level: int):
return levels.get_child(level) return levels.get_child(level)
@ -206,7 +220,6 @@ func update_mini_view():
camera_position.y *= 0.5 camera_position.y *= 0.5
camera_direction.y = 0.0 camera_direction.y = 0.0
var target_position = camera_position + camera_direction.normalized() * 0.2 var target_position = camera_position + camera_direction.normalized() * 0.2
levels.global_position = target_position - center * 0.1 levels.global_position = target_position - center * 0.1
else: else:

View File

@ -2,7 +2,7 @@
extends StaticBody3D extends StaticBody3D
class_name Input3D class_name Input3D
var text_handler = preload("res://content/ui/components/input/text_handler.gd").new() var text_handler = preload ("res://content/ui/components/input/text_handler.gd").new()
@onready var caret: MeshInstance3D = $Label/Caret @onready var caret: MeshInstance3D = $Label/Caret
@onready var mesh_box: MeshInstance3D = $Box @onready var mesh_box: MeshInstance3D = $Box
@ -26,13 +26,27 @@ var text_handler = preload("res://content/ui/components/input/text_handler.gd").
get: get:
return text_handler.text return text_handler.text
set(value): set(value):
var focused = Engine.is_editor_hint() == false && EventSystem.is_focused(self) == false var focused = Engine.is_editor_hint() == false&&EventSystem.is_focused(self) == false
if !is_node_ready(): await ready if !is_node_ready(): await ready
text_handler.set_text(value, focused) text_handler.set_text(value, focused)
label.text = text_handler.get_display_text() 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 keyboard_input: bool = false
var input_plane = Plane(Vector3.UP, Vector3.ZERO) var input_plane = Plane(Vector3.UP, Vector3.ZERO)
@ -44,20 +58,23 @@ func _ready():
return return
EventSystem.on_key_down.connect(func(event): EventSystem.on_key_down.connect(func(event):
if EventSystem.is_focused(self) == false: if EventSystem.is_focused(self) == false||disabled:
return 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()) 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())
caret.position.x = text_handler.get_caret_position() caret.position.x=text_handler.get_caret_position()
label.text = text_handler.get_display_text() label.text=text_handler.get_display_text()
) )
func _input(event): func _input(event):
if event is InputEventKey && EventSystem.is_focused(self) && event.pressed: if event is InputEventKey&&EventSystem.is_focused(self)&&event.pressed:
if event.keycode == KEY_F1: if event.keycode == KEY_F1:
keyboard_input = !keyboard_input keyboard_input = !keyboard_input
return return
if disabled:
return
if keyboard_input: 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()) 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() caret.position.x = text_handler.get_caret_position()
@ -66,14 +83,20 @@ func _process(_delta):
if Engine.is_editor_hint(): if Engine.is_editor_hint():
return return
if get_tree().debug_collisions_hint && OS.get_name() != "Android": if get_tree().debug_collisions_hint&&OS.get_name() != "Android":
_draw_debug_text_gaps() _draw_debug_text_gaps()
func _on_press_down(event): func _on_press_down(event):
if disabled:
return
var pos_x = label.to_local(event.ray.get_collision_point()).x var pos_x = label.to_local(event.ray.get_collision_point()).x
text_handler.update_caret_position(pos_x) text_handler.update_caret_position(pos_x)
func _on_press_move(event): func _on_press_move(event):
if disabled:
return
var ray_pos = event.ray.global_position var ray_pos = event.ray.global_position
var ray_dir = -event.ray.global_transform.basis.z 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() label.text = text_handler.get_display_text()
func _on_focus_in(_event): func _on_focus_in(_event):
if disabled:
return
caret.position.x = text_handler.get_caret_position() caret.position.x = text_handler.get_caret_position()
label.text = text_handler.get_display_text() label.text = text_handler.get_display_text()
caret.show() caret.show()
@ -113,9 +139,11 @@ func update_caret_position(event):
text_handler.update_caret_position(pos_x) text_handler.update_caret_position(pos_x)
caret.position.x = text_handler.get_caret_position() caret.position.x = text_handler.get_caret_position()
func _on_focus_out(_event): func _on_focus_out(_event):
if disabled:
return
animation.stop() animation.stop()
caret.hide() caret.hide()

View File

@ -1,11 +1,10 @@
extends Node3D extends Node3D
const Room = preload("res://content/system/house/room/room.tscn") const Room = preload ("res://content/system/house/room/room.tscn")
const RoomType = preload("res://content/system/house/room/room.gd") 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 material_selected = preload ("../room_selected.tres")
const material_unselected = preload ("../room_unselected.tres")
@onready var room_button = $Button @onready var room_button = $Button
@onready var input = $Input @onready var input = $Input
@ -13,32 +12,41 @@ const material_unselected = preload("../room_unselected.tres")
var selected_room = null: var selected_room = null:
set(value): set(value):
if selected_room != null && value == null: if selected_room != null&&value == null:
room_button.label = "add" room_button.label = "add"
input.text = "Room %s" % (rooms_map.get_child_count() + 1) input.text = "Room %s" % (rooms_map.get_child_count() + 1)
if selected_room != null: var old_room = get_room(selected_room)
var old_room = get_room(selected_room)
if old_room != null: if old_room != null:
old_room.get_node("MeshInstance3D").material_override = material_unselected old_room.get_node("MeshInstance3D").material_override = material_unselected
if value != null: if value != null:
room_button.label = "edit"
input.text = value input.text = value
edit_room = false edit_room = false
var new_room = get_room(value) var new_room = get_room(value)
if new_room != null: if new_room != null:
new_room.get_node("MeshInstance3D").material_override = material_selected new_room.get_node("MeshInstance3D").material_override = material_selected
selected_room = value selected_room = value
var edit_room = false: var edit_room = false:
set(value): set(value):
if value == edit_room:
return
edit_room = value edit_room = value
if value: if value:
room_button.label = "save" room_button.label = "save"
input.disabled = false
else: else:
room_button.label = "edit" 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(): func _ready():
if Store.house.is_loaded(): if Store.house.is_loaded():
@ -50,33 +58,36 @@ func _ready():
room_button.on_button_down.connect(func(): room_button.on_button_down.connect(func():
if selected_room == null: if selected_room == null:
var room_name = input.text var room_name=input.text
if get_room(room_name) != null: if get_room(room_name) != null:
EventSystem.notify("Name already taken", EventNotify.Type.WARNING) EventSystem.notify("Name already taken", EventNotify.Type.WARNING)
return return
House.body.create_room(room_name, 0) House.body.create_room(room_name, 0)
House.body.edit_room(room_name) House.body.edit_room(room_name)
selected_room = room_name selected_room=room_name
edit_room = true edit_room=true
else: else:
if edit_room: if edit_room:
edit_room = false edit_room=false
if !House.body.is_valid_room(selected_room): if !House.body.is_valid_room(selected_room):
House.body.delete_room(selected_room) House.body.delete_room(selected_room)
selected_room = null selected_room=null
else: else:
House.body.edit_room(null) House.body.edit_room(null)
_generate_room_map() _generate_room_map()
else: else:
edit_room = true edit_room=true
House.body.edit_room(selected_room) House.body.edit_room(selected_room)
) )
func get_room(room_name): func get_room(room_name):
if rooms_map.has_node("%s" % room_name): if room_name == null:
return rooms_map.get_node("%s" % room_name) return null
if rooms_map.has_node("%s"% room_name):
return rooms_map.get_node("%s"% room_name)
return null return null
func _on_click(event: EventPointer): func _on_click(event: EventPointer):

View File

@ -18,3 +18,4 @@ icon = true
[node name="Input" parent="." instance=ExtResource("2_hstw7")] [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) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.12, 0.005, 0.27)
text = "Room 1" text = "Room 1"
disabled = true

View File

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