From c803f31e6cbc1fa33fc0a195e26596dc60ebc8b9 Mon Sep 17 00:00:00 2001 From: Mario Steele Date: Sun, 8 Mar 2026 13:24:17 -0500 Subject: [PATCH] Created TwitchUserInfo control Created user control to handle showing TwitchUser information. --- UI/Controls/twitch_user_info.gd | 98 +++++++++++++++++ UI/Controls/twitch_user_info.gd.uid | 1 + UI/Controls/twitch_user_info.tscn | 159 ++++++++++++++++++++++++++++ 3 files changed, 258 insertions(+) create mode 100644 UI/Controls/twitch_user_info.gd create mode 100644 UI/Controls/twitch_user_info.gd.uid create mode 100644 UI/Controls/twitch_user_info.tscn diff --git a/UI/Controls/twitch_user_info.gd b/UI/Controls/twitch_user_info.gd new file mode 100644 index 00000000..f8540b58 --- /dev/null +++ b/UI/Controls/twitch_user_info.gd @@ -0,0 +1,98 @@ +extends PanelContainer + +const CHEVRONS = [ + preload("res://UI/assets/font_awesome/chevron-left.svg"), + preload("res://UI/assets/font_awesome/chevron-right.svg") +] +@export var expanded: bool = false + +signal extra_expanded(is_expanded: bool) + +var is_extra_panel_expanded: bool +var tw_expand: Tween + +var t_user: TwitchUser +var chatter: Chatter + +func _ready() -> void: + toggle_extra_panel(expanded) + %ExpandExtraInfo.pressed.connect(func(): toggle_extra_panel(!is_extra_panel_expanded)) + %LoadingSimple.hide() + +func show_busy() -> void: + %LoadingSimple.show() + +func show_normal() -> void: + %LoadingSimple.hide() + +func populate_from_twitch_user(_t_user: TwitchUser) -> void: + %LoadingSimple.show() + clear() + t_user = _t_user + if not t_user: return + %Username.text = t_user.login + %DisplayName.text = t_user.display_name + %UserId.text = t_user.id + %ProfilePictureURL.text = t_user.profile_image_url + if t_user.profile_image_url: + %AvatarImg.texture = await Globals.twitcher.media.load_profile_image(t_user) + else: + %AvatarImg.texture = preload("res://UI/assets/twitch_user_profile_pic.png") + + %Type.text = t_user.type + %ChannelDescription.text = t_user.description + %BroadcasterType.text = t_user.broadcaster_type + %OfflineImageURL.text = t_user.offline_image_url + %ViewCount.text = str(t_user.view_count) + %LoadingSimple.hide() + +func populate_from_chatter(_chatter: Chatter) -> void: + %LoadingSimple.show() + clear() + chatter = _chatter + if not chatter: return + t_user = await Globals.twitcher.get_user_by_id(chatter.twitch_id) + %Username.text = t_user.login + %DisplayName.text = t_user.display_name + %UserId.text = t_user.id + %ProfilePictureURL.text = t_user.profile_image_url + if t_user.profile_image_url: + %AvatarImg.texture = await Globals.twitcher.media.load_profile_image(t_user) + else: + %AvatarImg.texture = preload("res://UI/assets/twitch_user_profile_pic.png") + + %Type.text = t_user.type + %ChannelDescription.text = t_user.description + %BroadcasterType.text = t_user.broadcaster_type + %OfflineImageURL.text = t_user.offline_image_url + %ViewCount.text = str(t_user.view_count) + %LoadingSimple.hide() + +func clear() -> void: + %AvatarImg.texture = preload("res://UI/assets/twitch_user_profile_pic.png") + %Username.text = "" + %DisplayName.text = "" + %UserId.text = "" + %ProfilePictureURL.text = "" + %ChatColor.color = Color.TRANSPARENT + + %Type.text = "" + %ChannelDescription.text = "" + %BroadcasterType.text = "" + %OfflineImageURL.text = "" + %ViewCount.text = "" + +func toggle_extra_panel(val: bool) -> void: + is_extra_panel_expanded = val + %ExpandExtraInfo.icon = CHEVRONS[0] if is_extra_panel_expanded else CHEVRONS[1] + var min_size_x: float = 400 if is_extra_panel_expanded else 0 + if tw_expand: + tw_expand.kill() + %ExtraInfo.show() + tw_expand = create_tween() + tw_expand.set_ease(Tween.EASE_OUT) + tw_expand.set_trans(Tween.TRANS_CUBIC) + tw_expand.tween_property(%ExtraInfo, ^"custom_minimum_size:x", min_size_x, 0.3) + if !is_extra_panel_expanded: + tw_expand.tween_property(%ExtraInfo, ^"visible", false, 0.0) + tw_expand.tween_callback(extra_expanded.emit.bind(is_extra_panel_expanded)) diff --git a/UI/Controls/twitch_user_info.gd.uid b/UI/Controls/twitch_user_info.gd.uid new file mode 100644 index 00000000..efbb0286 --- /dev/null +++ b/UI/Controls/twitch_user_info.gd.uid @@ -0,0 +1 @@ +uid://bj86xfgm00ay2 diff --git a/UI/Controls/twitch_user_info.tscn b/UI/Controls/twitch_user_info.tscn new file mode 100644 index 00000000..9cfe01ff --- /dev/null +++ b/UI/Controls/twitch_user_info.tscn @@ -0,0 +1,159 @@ +[gd_scene format=3 uid="uid://bk7elsy5s3equ"] + +[ext_resource type="Script" uid="uid://bj86xfgm00ay2" path="res://UI/Controls/twitch_user_info.gd" id="1_2rtl8"] +[ext_resource type="Texture2D" uid="uid://bu2juj2beyws7" path="res://UI/assets/twitch_user_profile_pic.png" id="1_wdavc"] +[ext_resource type="Texture2D" uid="uid://cjiu8qsg8kcvk" path="res://UI/assets/font_awesome/chevron-right.svg" id="2_8x1yt"] +[ext_resource type="Theme" uid="uid://dh11pgqmtpeig" path="res://UI/assets/main_theme.tres" id="2_grpru"] +[ext_resource type="PackedScene" uid="uid://cbr5aed24dvty" path="res://UI/Controls/loading_simple.tscn" id="5_ssps2"] + +[node name="TwitchUserInfo" type="PanelContainer" unique_id=1944732530] +offset_right = 294.0 +offset_bottom = 128.0 +script = ExtResource("1_2rtl8") + +[node name="HBoxContainer" type="HBoxContainer" parent="." unique_id=835428733] +layout_mode = 2 + +[node name="AvatarImg" type="TextureRect" parent="HBoxContainer" unique_id=847416416] +unique_name_in_owner = true +custom_minimum_size = Vector2(0, 128) +layout_mode = 2 +texture = ExtResource("1_wdavc") +expand_mode = 2 +stretch_mode = 4 + +[node name="RefreshAvatar" type="Button" parent="HBoxContainer/AvatarImg" unique_id=470568045] +unique_name_in_owner = true +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme = ExtResource("2_grpru") +theme_type_variation = &"BlankButton" + +[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer" unique_id=2091869482] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="HBoxContainer" type="HBoxContainer" parent="HBoxContainer/VBoxContainer" unique_id=1790412527] +custom_minimum_size = Vector2(420, 0) +layout_mode = 2 + +[node name="DisplayName" type="LineEdit" parent="HBoxContainer/VBoxContainer/HBoxContainer" unique_id=112898446] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +placeholder_text = "display name" + +[node name="UserId" type="LineEdit" parent="HBoxContainer/VBoxContainer/HBoxContainer" unique_id=301550074] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +placeholder_text = "user id" + +[node name="ChannelDescription" type="TextEdit" parent="HBoxContainer/VBoxContainer" unique_id=1913020364] +unique_name_in_owner = true +custom_minimum_size = Vector2(420, 0) +layout_mode = 2 +size_flags_vertical = 3 +placeholder_text = "Channel description" +wrap_mode = 1 +indent_wrapped_lines = true + +[node name="ExpandExtraInfo" type="Button" parent="HBoxContainer" unique_id=943960057] +unique_name_in_owner = true +custom_minimum_size = Vector2(18, 0) +layout_mode = 2 +theme_type_variation = &"BlankButton" +icon = ExtResource("2_8x1yt") +icon_alignment = 1 +expand_icon = true + +[node name="ExtraInfo" type="PanelContainer" parent="HBoxContainer" unique_id=1175412769] +unique_name_in_owner = true +layout_mode = 2 + +[node name="ScrollContainer" type="ScrollContainer" parent="HBoxContainer/ExtraInfo" unique_id=1105674920] +layout_mode = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer/ExtraInfo/ScrollContainer" unique_id=1573319906] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="Username" type="LineEdit" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer" unique_id=1399710760] +unique_name_in_owner = true +layout_mode = 2 +placeholder_text = "username" + +[node name="ProfilePictureURL" type="LineEdit" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer" unique_id=1845036114] +unique_name_in_owner = true +layout_mode = 2 +placeholder_text = "profile picture url" + +[node name="HBoxContainer" type="HBoxContainer" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer" unique_id=655171068] +layout_mode = 2 + +[node name="Label" type="Label" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer/HBoxContainer" unique_id=1450064024] +layout_mode = 2 +text = "Twitch chat color" + +[node name="ChatColor" type="ColorRect" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer/HBoxContainer" unique_id=2056189419] +unique_name_in_owner = true +custom_minimum_size = Vector2(64, 16) +layout_mode = 2 + +[node name="HBoxContainer2" type="HBoxContainer" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer" unique_id=55699403] +layout_mode = 2 + +[node name="Label" type="Label" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer/HBoxContainer2" unique_id=1163546465] +layout_mode = 2 +text = "type" + +[node name="Type" type="LineEdit" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer/HBoxContainer2" unique_id=403251125] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="HBoxContainer3" type="HBoxContainer" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer" unique_id=1302353290] +layout_mode = 2 + +[node name="Label" type="Label" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer/HBoxContainer3" unique_id=2125425960] +layout_mode = 2 +text = "broadcaster type" + +[node name="BroadcasterType" type="LineEdit" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer/HBoxContainer3" unique_id=136580961] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="HBoxContainer4" type="HBoxContainer" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer" unique_id=315878161] +layout_mode = 2 + +[node name="Label" type="Label" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer/HBoxContainer4" unique_id=1792499029] +layout_mode = 2 +text = "offline image url" + +[node name="OfflineImageURL" type="LineEdit" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer/HBoxContainer4" unique_id=1036495270] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="HBoxContainer5" type="HBoxContainer" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer" unique_id=376702304] +layout_mode = 2 + +[node name="Label" type="Label" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer/HBoxContainer5" unique_id=1139447144] +layout_mode = 2 +text = "view count" + +[node name="ViewCount" type="LineEdit" parent="HBoxContainer/ExtraInfo/ScrollContainer/VBoxContainer/HBoxContainer5" unique_id=1793906256] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="LoadingSimple" parent="." unique_id=814067408 instance=ExtResource("5_ssps2")] +unique_name_in_owner = true +visible = false +layout_mode = 2