mirror of
https://codeberg.org/Ikatono/TierMaker.git
synced 2025-10-28 20:45:35 -05:00
improved Twitch connection menu experience
This commit is contained in:
@@ -6,17 +6,33 @@ using System.Net.NetworkInformation;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public partial class settings_popup : PopupPanel
|
||||
public partial class settings_popup : PanelContainer
|
||||
{
|
||||
private defer_manager _Deferer = null;
|
||||
private defer_manager Deferer
|
||||
{ get
|
||||
{
|
||||
_Deferer ??= GetNode<defer_manager>("/root/DeferManager");
|
||||
return _Deferer;
|
||||
}
|
||||
}
|
||||
public string Channel => GetNode<LineEdit>("%ChannelNameEdit").Text;
|
||||
[Signal]
|
||||
public delegate void BeforeOkEventHandler();
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
Transient = true;
|
||||
Exclusive = true;
|
||||
DisplayServer.WindowSetMinSize(
|
||||
DisplayServer.WindowGetMinSize().Union(Size));
|
||||
GetNode<TwitchChatWatcher>("/root/TwitchChatWatcher")
|
||||
.Connect(TwitchChatWatcher.SignalName.SocketConnected,
|
||||
new Callable(this, nameof(SocketConnected)),
|
||||
(uint)ConnectFlags.Deferred);
|
||||
GetNode<TwitchChatWatcher>("/root/TwitchChatWatcher")
|
||||
.Connect(TwitchChatWatcher.SignalName.SocketDisconnected,
|
||||
new Callable(this, nameof(SocketDisconnected)),
|
||||
(uint)ConnectFlags.Deferred);
|
||||
}
|
||||
private readonly ConcurrentQueue<Action> ActionQueue = new();
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
@@ -27,25 +43,43 @@ public partial class settings_popup : PopupPanel
|
||||
// a?.Invoke();
|
||||
// }
|
||||
}
|
||||
public void ShowPopup()
|
||||
{
|
||||
Visible = true;
|
||||
}
|
||||
public void ClosePopup()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
public void _on_cancel_button_pressed()
|
||||
{
|
||||
GD.Print("Cancel pressed");
|
||||
Hide();
|
||||
ClosePopup();
|
||||
}
|
||||
public void _on_ok_button_pressed()
|
||||
{
|
||||
GD.Print("OK pressed");
|
||||
GetNode<ConfigStretchContainer>("%ConfigStretchContainer").Apply();
|
||||
ClosePopup();
|
||||
}
|
||||
public void _on_connect_button_pressed()
|
||||
{
|
||||
var tcw = GetNode<TwitchChatWatcher>("/root/TwitchChatWatcher");
|
||||
string chName = GetNode<LineEdit>("%ChannelNameEdit").Text;
|
||||
//string chName = GetNode<LineEdit>("%ChannelNameEdit").Text;
|
||||
Task.Run(tcw.ConnectAsync).ContinueWith(t => tcw.Authenticate(null, null))
|
||||
.ContinueWith(t => tcw.RequestTags())
|
||||
.ContinueWith(t => tcw.JoinChannel(chName))
|
||||
//.ContinueWith(t => tcw.JoinChannel(chName))
|
||||
.ContinueWith(FinishConnection);
|
||||
ProcessMode = ProcessModeEnum.Disabled;
|
||||
}
|
||||
public void _on_join_channel_button_pressed()
|
||||
{
|
||||
var channel = Channel;
|
||||
if (string.IsNullOrWhiteSpace(channel))
|
||||
return;
|
||||
var tcw = GetNode<TwitchChatWatcher>("/root/TwitchChatWatcher");
|
||||
_ = Task.Run(() => tcw.JoinChannel(channel));
|
||||
}
|
||||
private void FinishConnection(Task t)
|
||||
{
|
||||
GD.Print(t.Status);
|
||||
if (t.IsCompletedSuccessfully)
|
||||
{
|
||||
CallDeferred(nameof(SuccessfulConnection));
|
||||
@@ -53,12 +87,15 @@ public partial class settings_popup : PopupPanel
|
||||
else
|
||||
{
|
||||
GD.PrintErr(t.Exception);
|
||||
ActionQueue.Enqueue(() => ProcessMode = ProcessModeEnum.Inherit);
|
||||
CallDeferred(nameof(UnlockPopup));
|
||||
}
|
||||
}
|
||||
private void UnlockPopup()
|
||||
{
|
||||
ProcessMode = ProcessModeEnum.Inherit;
|
||||
}
|
||||
private void SuccessfulConnection()
|
||||
{
|
||||
GD.Print("Running completion task");
|
||||
var tcw = GetNode<TwitchChatWatcher>("/root/TwitchChatWatcher");
|
||||
if (tcw.State != System.Net.WebSockets.WebSocketState.Open)
|
||||
throw new Exception("Websocket closed");
|
||||
@@ -69,7 +106,14 @@ public partial class settings_popup : PopupPanel
|
||||
StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries),
|
||||
GetNode<TextEdit>("%BlackListEdit").Text.Split('\n',
|
||||
StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries));
|
||||
ProcessMode = ProcessModeEnum.Inherit;
|
||||
Hide();
|
||||
UnlockPopup();
|
||||
}
|
||||
private void SocketConnected()
|
||||
{
|
||||
GetNode<BaseButton>("%ConnectButton").Disabled = true;
|
||||
}
|
||||
private void SocketDisconnected()
|
||||
{
|
||||
GetNode<BaseButton>("%ConnectButton").Disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user