Skip to content

Commit

Permalink
For those that use debug.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepyyapril committed Dec 17, 2024
1 parent 3da7b19 commit 1c042e1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
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

0 comments on commit 1c042e1

Please sign in to comment.