2024-04-25 01:22:27 +03:00
|
|
|
extends Node3D
|
|
|
|
|
|
|
|
signal on_select_device(device_id)
|
|
|
|
|
|
|
|
const ButtonScene = preload ("res://content/ui/components/button/button.tscn")
|
|
|
|
|
|
|
|
@onready var grid_container = $GridContainer3D
|
|
|
|
@onready var pagination = $Pagination3D
|
2024-04-26 16:23:18 +03:00
|
|
|
@onready var search_input: Input3D = $Input
|
2024-04-25 01:22:27 +03:00
|
|
|
|
|
|
|
var page = R.state(0)
|
|
|
|
var page_size = 28.0
|
2024-04-26 16:23:18 +03:00
|
|
|
var search = R.state("")
|
2024-04-25 01:22:27 +03:00
|
|
|
|
|
|
|
func _ready():
|
2024-04-26 16:23:18 +03:00
|
|
|
var devices = R.computed(func(_arg):
|
|
|
|
var devices=Store.devices.state.devices
|
|
|
|
|
|
|
|
if search.value != "":
|
|
|
|
return devices.filter(func(device):
|
|
|
|
var info=device.values()[0]
|
|
|
|
return info["name"].to_lower().find(search.value.to_lower()) != - 1
|
|
|
|
)
|
|
|
|
|
|
|
|
return devices
|
|
|
|
)
|
2024-04-25 01:22:27 +03:00
|
|
|
|
|
|
|
var pages = R.computed(func(_arg):
|
2024-04-26 16:23:18 +03:00
|
|
|
return ceil(devices.value.size() / page_size)
|
2024-04-25 01:22:27 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var visible_devices = R.computed(func(_arg):
|
2024-04-26 16:23:18 +03:00
|
|
|
return devices.value.slice(page.value * page_size, page.value * page_size + page_size)
|
2024-04-25 01:22:27 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
R.bind(pagination, "pages", pages)
|
|
|
|
R.bind(pagination, "page", page, pagination.on_page_changed)
|
2024-04-26 16:23:18 +03:00
|
|
|
R.bind(search_input, "text", search, search_input.on_text_changed)
|
|
|
|
|
|
|
|
search_input.on_text_changed.connect(func(_arg):
|
|
|
|
page.value=0
|
|
|
|
)
|
2024-04-25 01:22:27 +03:00
|
|
|
|
|
|
|
R.effect(func(_arg):
|
|
|
|
for child in grid_container.get_children():
|
|
|
|
grid_container.remove_child(child)
|
|
|
|
child.free()
|
|
|
|
|
|
|
|
for device in visible_devices.value:
|
|
|
|
var info=device.values()[0]
|
|
|
|
|
|
|
|
var button_instance=ButtonScene.instantiate()
|
|
|
|
button_instance.label=info["name"]
|
2024-04-25 14:19:12 +03:00
|
|
|
button_instance.font_size=8
|
2024-04-25 17:31:55 +03:00
|
|
|
button_instance.on_button_up.connect(func():
|
2024-04-25 01:22:27 +03:00
|
|
|
on_select_device.emit(device.keys()[0])
|
|
|
|
)
|
|
|
|
grid_container.add_child(button_instance)
|
|
|
|
|
|
|
|
)
|