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

64 lines
1.6 KiB
GDScript3
Raw Normal View History

2024-04-28 21:13:09 +03:00
extends Node3D
const ConstructRoomMesh = preload ("res://lib/utils/mesh/construct_room_mesh.gd")
const material_selected = preload ("../room_selected.tres")
const material_unselected = preload ("../room_unselected.tres")
@onready var door_button = $Button
2024-04-29 19:19:06 +03:00
@onready var delete_button = $DeleteButton
2024-04-28 21:13:09 +03:00
@onready var door_label = $Label3D
@onready var rooms_map = $Rooms
@onready var doors_map = $Doors
var editing_door = R.state(false)
func _ready():
2024-04-29 18:18:15 +03:00
rooms_map.selectable.value = false
var button_icon = R.computed(func(_arg):
if doors_map.selected_door.value == null:
return "add"
elif editing_door.value == false:
return "edit"
else:
return "save"
2024-04-28 21:13:09 +03:00
)
2024-04-29 18:18:15 +03:00
R.bind(door_button, "label", button_icon)
var button_label = R.computed(func(_arg):
if doors_map.selected_door.value == null:
return "Add Door"
elif editing_door.value == false:
return "Edit Door"
else:
return "Save Door"
)
R.bind(door_label, "text", button_label)
2024-04-29 19:19:06 +03:00
R.effect(func(_arg):
delete_button.disabled=doors_map.selected_door.value == null
delete_button.visible=doors_map.selected_door.value != null
)
2024-04-28 21:13:09 +03:00
door_button.on_button_up.connect(func():
2024-04-29 18:18:15 +03:00
if doors_map.selected_door.value == null:
2024-05-22 19:38:28 +03:00
var id=App.house.doors.add()
2024-04-29 18:18:15 +03:00
editing_door.value=true
doors_map.selected_door.value=id
elif editing_door.value == false:
editing_door.value=true
2024-05-22 19:38:28 +03:00
App.house.doors.edit(doors_map.selected_door.value)
2024-04-29 18:18:15 +03:00
else:
2024-05-22 19:38:28 +03:00
App.house.doors.save()
2024-04-29 18:18:15 +03:00
editing_door.value=false
2024-04-28 21:13:09 +03:00
)
2024-04-29 19:19:06 +03:00
delete_button.on_button_up.connect(func():
if doors_map.selected_door.value != null:
2024-05-22 19:38:28 +03:00
App.house.doors.delete(doors_map.selected_door.value)
2024-04-29 19:19:06 +03:00
doors_map.selected_door.value=null
)
2024-04-28 21:13:09 +03:00