immersive-home/app/content/ui/menu/room/views/rooms.gd

73 lines
1.9 KiB
GDScript3
Raw Normal View History

2024-01-23 19:02:41 +02:00
extends Node3D
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-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-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-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-03-21 11:51:58 +02:00
if !Store.house.is_loaded(): await Store.house.on_loaded
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:
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
House.body.create_room(room_name, 0)
2024-01-27 16:13:43 +02:00
House.body.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:
if !House.body.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-04-28 21:13:09 +03:00
House.body.delete_room(selected_room.value)
selected_room.value=null
return
if selected_room.value != null&&selected_room.value != input.text:
House.body.rename_room(selected_room.value, input.text)
selected_room.value=input.text
House.body.edit_room(null)
2024-01-23 19:02:41 +02:00
else:
2024-04-28 21:13:09 +03:00
House.body.edit_room(selected_room.value)
2024-01-23 19:02:41 +02:00
)