Created SearchTwitchUser control
This control handles searching for a user on Twitch, and allows saving them to the database.
This commit is contained in:
parent
6633b239cb
commit
a138ef7a0b
3 changed files with 124 additions and 0 deletions
55
UI/Controls/search_twitch_user.gd
Normal file
55
UI/Controls/search_twitch_user.gd
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
extends PanelContainer
|
||||
|
||||
signal dlg_closed()
|
||||
signal users_updated()
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
%SearchUser.text_submitted.connect(_handle_search_user)
|
||||
%SearchId.text_submitted.connect(_handle_search_id)
|
||||
%SaveUser.pressed.connect(_handle_save_user)
|
||||
%UpdateUser.pressed.connect(_handle_update_user)
|
||||
%ClearUser.pressed.connect(%TwitchUserInfo.clear)
|
||||
|
||||
func _handle_search_user(user: String) -> void:
|
||||
%TwitchUserInfo.show_busy()
|
||||
var t_user := await Globals.twitcher.get_user(user)
|
||||
if t_user == null:
|
||||
%TwitchUserInfo.show_normal()
|
||||
DisplayServer.dialog_show("Failed to find Twitch User", "Failed to find the Twitch user going by %s" % user, ["Ok"], dlg_closed.emit)
|
||||
await dlg_closed
|
||||
return
|
||||
|
||||
%TwitchUserInfo.populate_from_twitch_user(t_user)
|
||||
|
||||
func _handle_search_id(id: String) -> void:
|
||||
%TwitchUserInfo.show_busy()
|
||||
var t_user := await Globals.twitcher.get_user_by_id(id)
|
||||
if t_user == null:
|
||||
%TwitchUserInfo.show_normal()
|
||||
DisplayServer.dialog_show("Failed to find Twitch User", "Unable to find a Twitch user with the associated id %s" % id, ["Ok"], dlg_closed.emit)
|
||||
await dlg_closed
|
||||
return
|
||||
|
||||
%TwitchUserInfo.populate_from_twitch_user(t_user)
|
||||
|
||||
func _handle_save_user() -> void:
|
||||
var user: TwitchUser = %TwitchUserInfo.t_user
|
||||
var chatter: Chatter = Globals.context.chatters.find_one(Condition.new().equal("twitch_id", user.id))
|
||||
if chatter:
|
||||
DisplayServer.dialog_show("Add Twitch User", "This user already exists in the database.", ["Ok"], dlg_closed.emit)
|
||||
await dlg_closed
|
||||
return
|
||||
|
||||
chatter = Chatter.new()
|
||||
chatter.twitch_id = user.id
|
||||
chatter.user = user
|
||||
chatter.first_added = Time.get_unix_time_from_system()
|
||||
chatter.first_seen = -1
|
||||
chatter.last_seen = -1
|
||||
Globals.context.chatters.append(chatter)
|
||||
%TwitchUserInfo.clear()
|
||||
users_updated.emit()
|
||||
|
||||
func _handle_update_user() -> void:
|
||||
pass
|
||||
1
UI/Controls/search_twitch_user.gd.uid
Normal file
1
UI/Controls/search_twitch_user.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dgd1pmou5c35b
|
||||
68
UI/Controls/search_twitch_user.tscn
Normal file
68
UI/Controls/search_twitch_user.tscn
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
[gd_scene format=3 uid="uid://2ifvkmqd0q3i"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://bexdhdpprh6aa" path="res://UI/assets/font_awesome/magnifying-glass-location.svg" id="1_c6q78"]
|
||||
[ext_resource type="Script" uid="uid://dgd1pmou5c35b" path="res://UI/Controls/search_twitch_user.gd" id="1_k513e"]
|
||||
[ext_resource type="PackedScene" uid="uid://bk7elsy5s3equ" path="res://UI/Controls/twitch_user_info.tscn" id="2_k513e"]
|
||||
[ext_resource type="Texture2D" uid="uid://bqgx2li6ejy4q" path="res://UI/assets/bootstrap/floppy-fill.png" id="3_hc0ai"]
|
||||
[ext_resource type="Texture2D" uid="uid://ch7pe2qtxu5vt" path="res://UI/assets/font_awesome/user-pen.svg" id="4_21lmp"]
|
||||
[ext_resource type="Texture2D" uid="uid://di8hel7cykf1y" path="res://UI/assets/font_awesome/eraser.svg" id="5_c6q78"]
|
||||
|
||||
[node name="SearchTwitchUser" type="PanelContainer" unique_id=83637811]
|
||||
script = ExtResource("1_k513e")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="." unique_id=574238165]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Search" type="HBoxContainer" parent="VBoxContainer" unique_id=335042598]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ico" type="TextureRect" parent="VBoxContainer/Search" unique_id=2076335426]
|
||||
custom_minimum_size = Vector2(32, 32)
|
||||
layout_mode = 2
|
||||
texture = ExtResource("1_c6q78")
|
||||
expand_mode = 1
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="SearchUser" type="LineEdit" parent="VBoxContainer/Search" unique_id=1739256223]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
placeholder_text = "search by username"
|
||||
|
||||
[node name="SearchId" type="LineEdit" parent="VBoxContainer/Search" unique_id=778191154]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
placeholder_text = "search by user ID"
|
||||
|
||||
[node name="TwitchUserInfo" parent="VBoxContainer" unique_id=1944732530 instance=ExtResource("2_k513e")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer" unique_id=663178970]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="SaveUser" type="Button" parent="VBoxContainer/HBoxContainer" unique_id=1903961333]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Save new user"
|
||||
icon = ExtResource("3_hc0ai")
|
||||
expand_icon = true
|
||||
|
||||
[node name="UpdateUser" type="Button" parent="VBoxContainer/HBoxContainer" unique_id=1835546110]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Update User"
|
||||
icon = ExtResource("4_21lmp")
|
||||
expand_icon = true
|
||||
|
||||
[node name="ClearUser" type="Button" parent="VBoxContainer/HBoxContainer" unique_id=2034415437]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Clear"
|
||||
icon = ExtResource("5_c6q78")
|
||||
expand_icon = true
|
||||
Loading…
Add table
Add a link
Reference in a new issue