Created UserList control
This is the control that handles showing the list of saved users, as well as filtering through such users.
This commit is contained in:
parent
f0658fb87b
commit
6633b239cb
3 changed files with 114 additions and 0 deletions
57
UI/Controls/user_list.gd
Normal file
57
UI/Controls/user_list.gd
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
extends PanelContainer
|
||||||
|
|
||||||
|
signal user_selected(chatter: Chatter)
|
||||||
|
|
||||||
|
const USER_ENTRY = preload("res://UI/Controls/user_entry.tscn")
|
||||||
|
var entries_list: Array[UserEntry] = []
|
||||||
|
|
||||||
|
var filtering_live: bool = false:
|
||||||
|
set(value):
|
||||||
|
filtering_live = value
|
||||||
|
if value:
|
||||||
|
filter_live_users()
|
||||||
|
else:
|
||||||
|
reset_filter()
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready() -> void:
|
||||||
|
%FilterLive.pressed.connect(func(): filtering_live = !filtering_live)
|
||||||
|
|
||||||
|
|
||||||
|
func clear_list() -> void:
|
||||||
|
for node in %UserList.get_children():
|
||||||
|
node.queue_free()
|
||||||
|
|
||||||
|
func update_list() -> void:
|
||||||
|
for chatter: Chatter in Globals.context.chatters.all():
|
||||||
|
if entries_list.any(func(x: UserEntry): return x.chatter.id == chatter.id):
|
||||||
|
continue
|
||||||
|
var inst := USER_ENTRY.instantiate()
|
||||||
|
inst.chatter = chatter
|
||||||
|
entries_list.append(inst)
|
||||||
|
inst.tree_exiting.connect(entries_list.erase.bind(inst))
|
||||||
|
inst.user_selected.connect(user_selected.emit)
|
||||||
|
%UserList.add_child(inst)
|
||||||
|
entries_list.sort_custom(func(x: UserEntry, y: UserEntry): return x.chatter.id < y.chatter.id)
|
||||||
|
var i = 0
|
||||||
|
for entry: UserEntry in entries_list:
|
||||||
|
%UserList.move_child(entry,i)
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
func populate_list() -> void:
|
||||||
|
for chatter: Chatter in Globals.context.chatters.all():
|
||||||
|
var inst := USER_ENTRY.instantiate()
|
||||||
|
inst.chatter = chatter
|
||||||
|
entries_list.append(inst)
|
||||||
|
inst.tree_exiting.connect(entries_list.erase.bind(inst))
|
||||||
|
inst.user_selected.connect(user_selected.emit)
|
||||||
|
%UserList.add_child(inst)
|
||||||
|
|
||||||
|
func reset_filter() -> void:
|
||||||
|
for entry: UserEntry in %UserList.get_children():
|
||||||
|
entry.visible = true
|
||||||
|
|
||||||
|
func filter_live_users() -> void:
|
||||||
|
reset_filter()
|
||||||
|
for entry: UserEntry in %UserList.get_children():
|
||||||
|
entry.visible = entry.chatter.twitch_id in Globals.live_streamers.keys()
|
||||||
1
UI/Controls/user_list.gd.uid
Normal file
1
UI/Controls/user_list.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bgur6pwnuh27h
|
||||||
56
UI/Controls/user_list.tscn
Normal file
56
UI/Controls/user_list.tscn
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
[gd_scene format=3 uid="uid://cdm7rbq5547xp"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://bgur6pwnuh27h" path="res://UI/Controls/user_list.gd" id="1_cj73x"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bb2asei1pibev" path="res://UI/assets/bootstrap/arrow-repeat.png" id="1_o0xn2"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://c4le71w5j6nq5" path="res://UI/assets/simple/twitch.svg" id="2_cj73x"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://cnofay0htsof1" path="res://UI/assets/bootstrap/sort-up.svg" id="3_7xwno"]
|
||||||
|
|
||||||
|
[node name="UserList" type="PanelContainer" unique_id=1448466108]
|
||||||
|
script = ExtResource("1_cj73x")
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="." unique_id=128633507]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer" unique_id=1963562084]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="Filter" type="LineEdit" parent="VBoxContainer/HBoxContainer" unique_id=557386234]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
placeholder_text = "Filter"
|
||||||
|
|
||||||
|
[node name="Refresh" type="Button" parent="VBoxContainer/HBoxContainer" unique_id=1543716134]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(32, 32)
|
||||||
|
layout_mode = 2
|
||||||
|
icon = ExtResource("1_o0xn2")
|
||||||
|
icon_alignment = 1
|
||||||
|
expand_icon = true
|
||||||
|
|
||||||
|
[node name="FilterLive" type="Button" parent="VBoxContainer/HBoxContainer" unique_id=736301841]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(32, 32)
|
||||||
|
layout_mode = 2
|
||||||
|
icon = ExtResource("2_cj73x")
|
||||||
|
icon_alignment = 1
|
||||||
|
expand_icon = true
|
||||||
|
|
||||||
|
[node name="Sort" type="Button" parent="VBoxContainer/HBoxContainer" unique_id=429146136]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(32, 32)
|
||||||
|
layout_mode = 2
|
||||||
|
icon = ExtResource("3_7xwno")
|
||||||
|
icon_alignment = 1
|
||||||
|
expand_icon = true
|
||||||
|
|
||||||
|
[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer" unique_id=2048134332]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_vertical = 3
|
||||||
|
horizontal_scroll_mode = 3
|
||||||
|
|
||||||
|
[node name="UserList" type="VBoxContainer" parent="VBoxContainer/ScrollContainer" unique_id=1488715496]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
size_flags_vertical = 3
|
||||||
Loading…
Add table
Add a link
Reference in a new issue