StreamOverlay/UI/Panels/User/internal_user_live.gd
Mario Steele cc01a207fc Updated InternalUserLive
Added Offline details to Live panel.
When user has an Offline Image, we load the image to display in the
Stream Preview, otherwise we do a Generic Twitch Logo, with text saying
the Stream is Offline.
2026-03-10 10:25:17 -05:00

84 lines
2.3 KiB
GDScript

extends PanelContainer
var _offline_color := Color.html("d36dff4e")
var _offline_no_thumbnail := preload("res://assets/bootstrap/twitch_large.svg")
var chatter: Chatter:
set(value):
chatter = value
if not chatter:
live = null
clear()
return
live = Globals.live_streamers[chatter.twitch_id] if chatter.twitch_id in Globals.live_streamers.keys() else null
_populate_view()
var live: TwitchStream
var _ticks: int = 0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
%StreamTitle.pressed.connect(_open_stream)
%RaidCurrentUser.pressed.connect(_raid_stream)
if not chatter:
clear()
return
if not live and chatter.twitch_id in Globals.live_streamers.keys():
live = Globals.live_streamers[chatter.twitch_id]
_populate_view()
elif not live:
clear()
return
func clear() -> void:
%StreamTitle.text = "Not Live"
%StreamViewerCount.text = "0"
%StreamTime.text = "00:00:00"
%StreamThumbnail.visible = false
%OfflineThumbnail.visible = true
%NoThumbText.visible = true
if chatter:
if chatter.user.offline_image_url != "":
%OfflineThumbnail.texture = await ImageLoader.load_image(chatter.user.offline_image_url)
%OfflineThumbnail.self_modulate = Color.WHITE
%NoThumbText.visible = false
return
%OfflineThumbnail.texture = _offline_no_thumbnail
%OfflineThumbnail.self_modulate = _offline_color
func _populate_view() -> void:
if not live:
set_process(false)
clear()
return
set_process(true)
%StreamTitle.text = live.title
%StreamViewerCount.text = str(live.viewer_count)
var url := live.thumbnail_url.format({"width": 640, "height": 360})
%StreamThumbnail.texture = await ImageLoader.load_image(url)
%StreamThumbnail.visible = true
%OfflineThumbnail.visible = false
func _process(_d: float) -> void:
if not live:
set_process(false)
return
_ticks += 1
if _ticks < 30: return
_ticks = 0
var system_unix = Time.get_unix_time_from_system()
var stream_start_unix = Time.get_unix_time_from_datetime_string(live.started_at)
var elapsed = Time.get_datetime_string_from_unix_time((system_unix - stream_start_unix), true)
%StreamTime.text = elapsed.split(" ")[1]
func _open_stream() -> void:
if not live: return
OS.shell_open("https://twitch.tv/%s" % live.user_login)
func _raid_stream() -> void:
if not live: return
pass