Re-organize all projects (#4166)
This commit is contained in:
97
Content.Client/Launcher/LauncherConnecting.cs
Normal file
97
Content.Client/Launcher/LauncherConnecting.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using Robust.Client;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
namespace Content.Client.Launcher
|
||||
{
|
||||
public class LauncherConnecting : Robust.Client.State.State
|
||||
{
|
||||
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
|
||||
[Dependency] private readonly IClientNetManager _clientNetManager = default!;
|
||||
[Dependency] private readonly IGameController _gameController = default!;
|
||||
[Dependency] private readonly IBaseClient _baseClient = default!;
|
||||
|
||||
private LauncherConnectingGui? _control;
|
||||
|
||||
private Page _currentPage;
|
||||
private string? _connectFailReason;
|
||||
|
||||
public string? Address => _gameController.LaunchState.Ss14Address ?? _gameController.LaunchState.ConnectAddress;
|
||||
|
||||
public string? ConnectFailReason
|
||||
{
|
||||
get => _connectFailReason;
|
||||
private set
|
||||
{
|
||||
_connectFailReason = value;
|
||||
ConnectFailReasonChanged?.Invoke(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Page CurrentPage
|
||||
{
|
||||
get => _currentPage;
|
||||
private set
|
||||
{
|
||||
_currentPage = value;
|
||||
PageChanged?.Invoke(value);
|
||||
}
|
||||
}
|
||||
|
||||
public ClientConnectionState ConnectionState => _clientNetManager.ClientConnectState;
|
||||
|
||||
public event Action<Page>? PageChanged;
|
||||
public event Action<string?>? ConnectFailReasonChanged;
|
||||
public event Action<ClientConnectionState>? ConnectionStateChanged;
|
||||
|
||||
public override void Startup()
|
||||
{
|
||||
_control = new LauncherConnectingGui(this);
|
||||
|
||||
_userInterfaceManager.StateRoot.AddChild(_control);
|
||||
|
||||
_clientNetManager.ConnectFailed += (_, args) =>
|
||||
{
|
||||
ConnectFailReason = args.Reason;
|
||||
CurrentPage = Page.ConnectFailed;
|
||||
};
|
||||
|
||||
_clientNetManager.ClientConnectStateChanged += state => ConnectionStateChanged?.Invoke(state);
|
||||
|
||||
CurrentPage = Page.Connecting;
|
||||
}
|
||||
|
||||
public void RetryConnect()
|
||||
{
|
||||
if (_gameController.LaunchState.ConnectEndpoint != null)
|
||||
{
|
||||
_baseClient.ConnectToServer(_gameController.LaunchState.ConnectEndpoint);
|
||||
CurrentPage = Page.Connecting;
|
||||
}
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
_gameController.Shutdown("Exit button pressed");
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
_control?.Dispose();
|
||||
}
|
||||
|
||||
public void SetDisconnected()
|
||||
{
|
||||
CurrentPage = Page.Disconnected;
|
||||
}
|
||||
|
||||
public enum Page : byte
|
||||
{
|
||||
Connecting,
|
||||
ConnectFailed,
|
||||
Disconnected,
|
||||
}
|
||||
}
|
||||
}
|
||||
54
Content.Client/Launcher/LauncherConnectingGui.xaml
Normal file
54
Content.Client/Launcher/LauncherConnectingGui.xaml
Normal file
@@ -0,0 +1,54 @@
|
||||
<Control xmlns="https://spacestation14.io"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
|
||||
xmlns:cuic="clr-namespace:Content.Client.UserInterface"
|
||||
xmlns:parallax="clr-namespace:Content.Client.Parallax"
|
||||
xmlns:ui="clr-namespace:Content.Client.HUD.UI">
|
||||
<parallax:ParallaxControl />
|
||||
<Control HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<PanelContainer StyleClasses="AngleRect" />
|
||||
<VBoxContainer MinSize="300 200">
|
||||
<HBoxContainer>
|
||||
<Label Margin="8 0 0 0" Text="{Loc 'connecting-title'}"
|
||||
StyleClasses="LabelHeading" VAlign="Center" />
|
||||
<Button Name="ExitButton" Text="{Loc 'connecting-exit'}"
|
||||
HorizontalAlignment="Right" HorizontalExpand="True" />
|
||||
</HBoxContainer>
|
||||
<ui:HighDivider />
|
||||
<VBoxContainer VerticalExpand="True" Margin="4 4 4 0">
|
||||
<Control VerticalExpand="True" Margin="0 0 0 8">
|
||||
<VBoxContainer Name="ConnectingStatus">
|
||||
<Label Text="{Loc 'connecting-in-progress'}" Align="Center" />
|
||||
<!-- Who the fuck named these cont- oh wait I did -->
|
||||
<Label Name="ConnectStatus" StyleClasses="LabelSubText" Align="Center" />
|
||||
</VBoxContainer>
|
||||
<VBoxContainer Name="ConnectFail" Visible="False">
|
||||
<Label Name="ConnectFailReason" Align="Center" />
|
||||
<Button Name="RetryButton" Text="{Loc 'connecting-retry'}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalExpand="True" VerticalAlignment="Bottom" />
|
||||
</VBoxContainer>
|
||||
<VBoxContainer Name="Disconnected">
|
||||
<Label Text="{Loc 'connecting-disconnected'}" Align="Center" />
|
||||
<Label Name="DisconnectReason" Align="Center" />
|
||||
<Button Name="ReconnectButton" Text="{Loc 'connecting-reconnect'}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalExpand="True" VerticalAlignment="Bottom" />
|
||||
</VBoxContainer>
|
||||
</Control>
|
||||
<Label Name="ConnectingAddress" StyleClasses="LabelSubText" HorizontalAlignment="Center" />
|
||||
</VBoxContainer>
|
||||
<PanelContainer>
|
||||
<PanelContainer.PanelOverride>
|
||||
<gfx:StyleBoxFlat BackgroundColor="#444" ContentMarginTopOverride="2" />
|
||||
</PanelContainer.PanelOverride>
|
||||
</PanelContainer>
|
||||
|
||||
<HBoxContainer Margin="12 0 4 0" VerticalAlignment="Bottom">
|
||||
<Label Text="{Loc 'connecting-tip'}" StyleClasses="LabelSubText" />
|
||||
<Label Text="{Loc 'connecting-version'}" StyleClasses="LabelSubText"
|
||||
HorizontalAlignment="Right" HorizontalExpand="True" />
|
||||
</HBoxContainer>
|
||||
</VBoxContainer>
|
||||
</Control>
|
||||
</Control>
|
||||
61
Content.Client/Launcher/LauncherConnectingGui.xaml.cs
Normal file
61
Content.Client/Launcher/LauncherConnectingGui.xaml.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Content.Client.Stylesheets;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
namespace Content.Client.Launcher
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class LauncherConnectingGui : Control
|
||||
{
|
||||
private readonly LauncherConnecting _state;
|
||||
|
||||
public LauncherConnectingGui(LauncherConnecting state)
|
||||
{
|
||||
_state = state;
|
||||
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
LayoutContainer.SetAnchorPreset(this, LayoutContainer.LayoutPreset.Wide);
|
||||
|
||||
Stylesheet = IoCManager.Resolve<IStylesheetManager>().SheetSpace;
|
||||
|
||||
ReconnectButton.OnPressed += _ => _state.RetryConnect();
|
||||
RetryButton.OnPressed += _ => _state.RetryConnect();
|
||||
ExitButton.OnPressed += _ => _state.Exit();
|
||||
|
||||
var addr = state.Address;
|
||||
if (addr != null)
|
||||
ConnectingAddress.Text = addr;
|
||||
|
||||
state.PageChanged += OnPageChanged;
|
||||
state.ConnectFailReasonChanged += ConnectFailReasonChanged;
|
||||
state.ConnectionStateChanged += ConnectionStateChanged;
|
||||
|
||||
ConnectionStateChanged(state.ConnectionState);
|
||||
}
|
||||
|
||||
private void ConnectFailReasonChanged(string? reason)
|
||||
{
|
||||
ConnectFailReason.Text = reason == null
|
||||
? null
|
||||
: Loc.GetString("connecting-fail-reason", ("reason", reason));
|
||||
}
|
||||
|
||||
private void OnPageChanged(LauncherConnecting.Page page)
|
||||
{
|
||||
ConnectingStatus.Visible = page == LauncherConnecting.Page.Connecting;
|
||||
ConnectFail.Visible = page == LauncherConnecting.Page.ConnectFailed;
|
||||
Disconnected.Visible = page == LauncherConnecting.Page.Disconnected;
|
||||
}
|
||||
|
||||
private void ConnectionStateChanged(ClientConnectionState state)
|
||||
{
|
||||
ConnectStatus.Text = Loc.GetString($"connecting-state-{state}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user