Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect & Go Lobby #43

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions Content.Client/MainMenu/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Robust.Client.UserInterface.Controls;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.Console;
using Robust.Shared.Network;
using Robust.Shared.Utility;
using UsernameHelpers = Robust.Shared.AuthLib.UsernameHelpers;
Expand All @@ -26,11 +27,13 @@ public sealed class MainScreen : Robust.Client.State.State
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly IConsoleHost _console = default!;

private ISawmill _sawmill = default!;

private MainMenuControl _mainMenuControl = default!;
private bool _isConnecting;
private bool _shouldGoLobby;

// ReSharper disable once InconsistentNaming
private static readonly Regex IPv6Regex = new(@"\[(.*:.*:.*)](?::(\d+))?");
Expand All @@ -46,16 +49,19 @@ protected override void Startup()
_mainMenuControl.QuitButton.OnPressed += QuitButtonPressed;
_mainMenuControl.OptionsButton.OnPressed += OptionsButtonPressed;
_mainMenuControl.DirectConnectButton.OnPressed += DirectConnectButtonPressed;
_mainMenuControl.GoLobbyButton.OnPressed += GoLobbyButtonPressed;
_mainMenuControl.AddressBox.OnTextEntered += AddressBoxEntered;
_mainMenuControl.ChangelogButton.OnPressed += ChangelogButtonPressed;

_client.RunLevelChanged += RunLevelChanged;
_client.PlayerJoinedGame += OnPlayerJoinedGame;
}

/// <inheritdoc />
protected override void Shutdown()
{
_client.RunLevelChanged -= RunLevelChanged;
_client.PlayerJoinedGame -= OnPlayerJoinedGame;
_netManager.ConnectFailed -= _onConnectFailed;

_mainMenuControl.Dispose();
Expand All @@ -82,12 +88,18 @@ private void DirectConnectButtonPressed(BaseButton.ButtonEventArgs args)
TryConnect(input.Text);
}

private void GoLobbyButtonPressed(BaseButton.ButtonEventArgs obj)
{
var input = _mainMenuControl.AddressBox;
TryConnect(input.Text);

_shouldGoLobby = true;
}

private void AddressBoxEntered(LineEdit.LineEditEventArgs args)
{
if (_isConnecting)
{
return;
}

TryConnect(args.Text);
}
Expand Down Expand Up @@ -141,6 +153,15 @@ private void RunLevelChanged(object? obj, RunLevelChangedEventArgs args)
}
}

private void OnPlayerJoinedGame(object? sender, PlayerEventArgs e)
{
if (_shouldGoLobby)
{
_console.ExecuteCommand("golobby");
_shouldGoLobby = false;
}
}

private void ParseAddress(string address, out string ip, out ushort port)
{
var match6 = IPv6Regex.Match(address);
Expand Down Expand Up @@ -190,6 +211,7 @@ private void _setConnectingState(bool state)
{
_isConnecting = state;
_mainMenuControl.DirectConnectButton.Disabled = state;
_mainMenuControl.GoLobbyButton.Disabled = state;
}
}
}
5 changes: 5 additions & 0 deletions Content.Client/MainMenu/UI/MainMenuControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
Text="{Loc 'main-menu-direct-connect-button'}"
TextAlign="Center"
StyleIdentifier="mainMenu"/>
<Button Name="GoLobbyButton"
Access="Public"
Text="{Loc 'main-menu-go-lobby-button'}"
TextAlign="Center"
StyleIdentifier="mainMenu"/>
<Button Name="OptionsButton"
Access="Public"
Text="{Loc 'main-menu-options-button'}"
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/main-menu/main-menu.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ main-menu-address-label = Server Address:
main-menu-join-public-server-button = Join Public Server
main-menu-join-public-server-button-tooltip = Cannot connect to public server with a debug build.
main-menu-direct-connect-button = Direct Connect
main-menu-go-lobby-button = Connect & Go to Lobby
main-menu-options-button = Options
main-menu-quit-button = Quit
Loading