fix: so many bugs, feat: cancel tournaments
This commit is contained in:
@@ -8,12 +8,55 @@ public partial class ConnectButtonUI : Button
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Connection.Instance.OnWsConnectionSuccess += () => GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH);
|
||||
Connection.Instance.OnWsConnectionFailed += () => ErrorLabel.Text = "Couldn't connect to server! " + Connection.Instance.LastError;
|
||||
Connection.Instance.OnWsConnectionSuccess += OnConnectionSuccess;
|
||||
Connection.Instance.OnWsConnectionFailed += OnConnectionFailed;
|
||||
|
||||
if (Connection.Instance.LastUsedConnectionAddress.Length > 0)
|
||||
{
|
||||
AddressField.Text = Connection.Instance.LastUsedConnectionAddress;
|
||||
}
|
||||
|
||||
if (Connection.Instance.LastError.Length > 0)
|
||||
{
|
||||
ErrorLabel.Text = Connection.Instance.LastError;
|
||||
}
|
||||
|
||||
AddressField.GuiInput += e =>
|
||||
{
|
||||
if (AddressField.HasFocus() && e is InputEventKey inputEventKey && inputEventKey.IsPressed())
|
||||
{
|
||||
if (inputEventKey.KeyLabel == Key.Enter)
|
||||
{
|
||||
Connection.Instance.Connect(AddressField.Text);
|
||||
GetViewport().SetInputAsHandled();
|
||||
}
|
||||
|
||||
if (inputEventKey.KeyLabel == Key.Space)
|
||||
{
|
||||
GetViewport().SetInputAsHandled();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
Connection.Instance.OnWsConnectionSuccess -= OnConnectionSuccess;
|
||||
Connection.Instance.OnWsConnectionFailed -= OnConnectionFailed;
|
||||
}
|
||||
|
||||
public override void _Pressed()
|
||||
{
|
||||
Connection.Instance.Connect(AddressField.Text);
|
||||
}
|
||||
|
||||
private void OnConnectionSuccess()
|
||||
{
|
||||
GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH);
|
||||
}
|
||||
|
||||
private void OnConnectionFailed()
|
||||
{
|
||||
ErrorLabel.Text = "Couldn't connect to server! " + Connection.Instance.LastError;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user