add room renaming and disable input option
This commit is contained in:
parent
7b0a753078
commit
e2fcc5b08f
|
@ -1,7 +1,7 @@
|
|||
extends Node3D
|
||||
|
||||
const Room = preload("./room/room.tscn")
|
||||
const RoomType = preload("./room/room.gd")
|
||||
const Room = preload ("./room/room.tscn")
|
||||
const RoomType = preload ("./room/room.gd")
|
||||
|
||||
@onready var levels = $Levels
|
||||
@onready var collision_shape = $Levels/CollisionShape3D
|
||||
|
@ -89,7 +89,6 @@ func is_valid_room(room_name):
|
|||
return
|
||||
|
||||
return room.wall_corners.get_child_count() >= 3
|
||||
|
||||
|
||||
func delete_room(room_name):
|
||||
var room = find_room(room_name)
|
||||
|
@ -111,7 +110,7 @@ func delete_room(room_name):
|
|||
Store.house.save_local()
|
||||
|
||||
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):
|
||||
for room in get_rooms(0):
|
||||
|
@ -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:
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
extends StaticBody3D
|
||||
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 mesh_box: MeshInstance3D = $Box
|
||||
|
@ -26,13 +26,27 @@ var text_handler = preload("res://content/ui/components/input/text_handler.gd").
|
|||
get:
|
||||
return text_handler.text
|
||||
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
|
||||
|
||||
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,20 +58,23 @@ 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())
|
||||
caret.position.x = text_handler.get_caret_position()
|
||||
label.text = text_handler.get_display_text()
|
||||
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()
|
||||
label.text=text_handler.get_display_text()
|
||||
)
|
||||
|
||||
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:
|
||||
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()
|
||||
|
@ -66,14 +83,20 @@ func _process(_delta):
|
|||
if Engine.is_editor_hint():
|
||||
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()
|
||||
|
||||
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()
|
||||
|
@ -113,9 +139,11 @@ func update_caret_position(event):
|
|||
text_handler.update_caret_position(pos_x)
|
||||
|
||||
caret.position.x = text_handler.get_caret_position()
|
||||
|
||||
|
||||
func _on_focus_out(_event):
|
||||
if disabled:
|
||||
return
|
||||
|
||||
animation.stop()
|
||||
caret.hide()
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
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 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
|
||||
|
@ -13,32 +12,41 @@ const material_unselected = preload("../room_unselected.tres")
|
|||
|
||||
var selected_room = null:
|
||||
set(value):
|
||||
if selected_room != null && value == null:
|
||||
if selected_room != null&&value == 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
|
||||
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():
|
||||
|
@ -50,33 +58,36 @@ func _ready():
|
|||
|
||||
room_button.on_button_down.connect(func():
|
||||
if selected_room == null:
|
||||
var room_name = input.text
|
||||
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)
|
||||
House.body.edit_room(room_name)
|
||||
selected_room = room_name
|
||||
edit_room = true
|
||||
selected_room=room_name
|
||||
edit_room=true
|
||||
else:
|
||||
if edit_room:
|
||||
edit_room = false
|
||||
edit_room=false
|
||||
|
||||
if !House.body.is_valid_room(selected_room):
|
||||
House.body.delete_room(selected_room)
|
||||
selected_room = null
|
||||
selected_room=null
|
||||
else:
|
||||
House.body.edit_room(null)
|
||||
_generate_room_map()
|
||||
else:
|
||||
edit_room = true
|
||||
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)
|
||||
if room_name == null:
|
||||
return null
|
||||
|
||||
if rooms_map.has_node("%s"% room_name):
|
||||
return rooms_map.get_node("%s"% room_name)
|
||||
return null
|
||||
|
||||
func _on_click(event: EventPointer):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user