2024-01-23 19:02:41 +02:00
|
|
|
extends Node3D
|
|
|
|
|
2024-03-12 13:23:39 +02:00
|
|
|
const Room = preload ("res://content/system/house/room/room.tscn")
|
2024-04-28 21:13:09 +03:00
|
|
|
const RoomsMap = preload ("rooms_map.gd")
|
2024-01-23 19:02:41 +02:00
|
|
|
|
|
|
|
@onready var room_button = $Button
|
|
|
|
@onready var input = $Input
|
2024-04-28 21:13:09 +03:00
|
|
|
@onready var rooms_map: RoomsMap = $Rooms
|
2024-05-23 20:03:37 +03:00
|
|
|
@onready var sync_room_button: Button3D = $SyncRoomsButton
|
|
|
|
@onready var delete_button: Button3D = $DeleteButton
|
|
|
|
@onready var sync_room_label: Label3D = $SyncRoomsLabel
|
2024-01-23 19:02:41 +02:00
|
|
|
|
2024-04-28 21:13:09 +03:00
|
|
|
var editing_room = R.state(false)
|
2024-01-23 19:02:41 +02:00
|
|
|
|
2024-04-28 21:13:09 +03:00
|
|
|
func _ready():
|
2024-03-12 13:23:39 +02:00
|
|
|
|
2024-04-28 21:13:09 +03:00
|
|
|
R.effect(func(_arg):
|
|
|
|
if rooms_map.selected_room.value == null:
|
|
|
|
room_button.label="add"
|
|
|
|
elif editing_room.value:
|
|
|
|
room_button.label="save"
|
|
|
|
else:
|
|
|
|
room_button.label="edit"
|
|
|
|
)
|
2024-01-23 19:02:41 +02:00
|
|
|
|
2024-04-28 21:13:09 +03:00
|
|
|
R.effect(func(_arg):
|
|
|
|
input.disabled=editing_room.value == false
|
|
|
|
)
|
2024-01-23 19:02:41 +02:00
|
|
|
|
2024-04-28 21:13:09 +03:00
|
|
|
R.effect(func(_arg):
|
|
|
|
if rooms_map.selected_room.value == null:
|
|
|
|
var i=1
|
|
|
|
while rooms_map.get_room("Room %s" % i) != null:
|
|
|
|
i += 1
|
2024-03-12 13:23:39 +02:00
|
|
|
|
2024-04-28 21:13:09 +03:00
|
|
|
input.text="Room %s" % i
|
2024-01-23 19:02:41 +02:00
|
|
|
else:
|
2024-04-28 21:13:09 +03:00
|
|
|
input.text=rooms_map.selected_room.value
|
|
|
|
)
|
2024-01-23 19:02:41 +02:00
|
|
|
|
2024-05-23 20:03:37 +03:00
|
|
|
R.effect(func(_arg):
|
|
|
|
sync_room_button.visible=editing_room.value
|
|
|
|
sync_room_label.visible=editing_room.value
|
|
|
|
sync_room_button.disabled=!editing_room.value
|
2024-05-24 12:02:50 +03:00
|
|
|
delete_button.visible=rooms_map.selected_room.value != null
|
|
|
|
delete_button.disabled=rooms_map.selected_room.value == null
|
2024-05-23 20:03:37 +03:00
|
|
|
)
|
|
|
|
|
2024-03-21 11:51:58 +02:00
|
|
|
if !Store.house.is_loaded(): await Store.house.on_loaded
|
|
|
|
|
2024-05-23 20:03:37 +03:00
|
|
|
if App.main.meta_scene_manager == null:
|
|
|
|
remove_child(sync_room_button)
|
|
|
|
remove_child(sync_room_label)
|
|
|
|
else:
|
|
|
|
sync_room_button.on_button_up.connect(func():
|
|
|
|
App.main.meta_scene_manager.create_scene_anchors()
|
|
|
|
|
|
|
|
await get_tree().create_timer(1.0).timeout
|
|
|
|
|
|
|
|
var data=MetaTools.spatial_entites.get_corners_and_height()
|
|
|
|
|
|
|
|
App.house.editing_room.state_machine.current_state.create_from_corners(data.corners, data.height)
|
|
|
|
)
|
|
|
|
|
|
|
|
delete_button.on_button_up.connect(func():
|
|
|
|
var selected_room=rooms_map.selected_room
|
|
|
|
|
|
|
|
if selected_room.value != null:
|
|
|
|
App.house.delete_room(selected_room.value)
|
|
|
|
selected_room.value=null
|
|
|
|
editing_room.value=false
|
|
|
|
rooms_map.selectable.value=true
|
|
|
|
)
|
|
|
|
|
2024-01-23 19:02:41 +02:00
|
|
|
room_button.on_button_down.connect(func():
|
2024-04-28 21:13:09 +03:00
|
|
|
var selected_room=rooms_map.selected_room
|
|
|
|
|
|
|
|
if selected_room.value == null:
|
2024-03-12 13:23:39 +02:00
|
|
|
var room_name=input.text
|
2024-04-28 21:13:09 +03:00
|
|
|
if rooms_map.get_room(room_name) != null:
|
2024-01-23 19:02:41 +02:00
|
|
|
EventSystem.notify("Name already taken", EventNotify.Type.WARNING)
|
|
|
|
return
|
|
|
|
|
2024-05-22 19:38:28 +03:00
|
|
|
App.house.create_room(room_name)
|
|
|
|
App.house.edit_room(room_name)
|
2024-04-28 21:13:09 +03:00
|
|
|
selected_room.value=room_name
|
|
|
|
editing_room.value=true
|
|
|
|
rooms_map.selectable.value=false
|
2024-01-23 19:02:41 +02:00
|
|
|
else:
|
2024-04-28 21:13:09 +03:00
|
|
|
editing_room.value=!editing_room.value
|
|
|
|
rooms_map.selectable.value=!editing_room.value
|
2024-01-23 19:02:41 +02:00
|
|
|
|
2024-04-28 21:13:09 +03:00
|
|
|
if editing_room.value == false:
|
2024-05-22 19:38:28 +03:00
|
|
|
if !App.house.is_valid_room(selected_room.value):
|
2024-03-17 19:12:21 +02:00
|
|
|
EventSystem.notify("Room was deleted as it had less than 3 corners.", EventNotify.Type.WARNING)
|
2024-05-22 19:38:28 +03:00
|
|
|
App.house.delete_room(selected_room.value)
|
2024-04-28 21:13:09 +03:00
|
|
|
selected_room.value=null
|
|
|
|
return
|
|
|
|
|
|
|
|
if selected_room.value != null&&selected_room.value != input.text:
|
2024-05-22 19:38:28 +03:00
|
|
|
App.house.rename_room(selected_room.value, input.text)
|
2024-04-28 21:13:09 +03:00
|
|
|
selected_room.value=input.text
|
|
|
|
|
2024-05-22 19:38:28 +03:00
|
|
|
App.house.edit_room(null)
|
2024-01-23 19:02:41 +02:00
|
|
|
else:
|
2024-05-22 19:38:28 +03:00
|
|
|
App.house.edit_room(selected_room.value)
|
2024-01-23 19:02:41 +02:00
|
|
|
)
|