Character setup in Lobby UI (#12007)

This commit is contained in:
Flipp Syder
2022-10-17 23:45:32 -07:00
committed by GitHub
parent c828c53b91
commit 3f0773e1f4
6 changed files with 157 additions and 84 deletions

View File

@@ -76,7 +76,7 @@ namespace Content.Client.Gameplay
UserInterfaceManager.PopupRoot.AddChild(_fpsCounter); UserInterfaceManager.PopupRoot.AddChild(_fpsCounter);
_fpsCounter.Visible = _configurationManager.GetCVar(CCVars.HudFpsCounterVisible); _fpsCounter.Visible = _configurationManager.GetCVar(CCVars.HudFpsCounterVisible);
_configurationManager.OnValueChanged(CCVars.HudFpsCounterVisible, (show) => { _fpsCounter.Visible = show; }); _configurationManager.OnValueChanged(CCVars.HudFpsCounterVisible, (show) => { _fpsCounter.Visible = show; });
_configurationManager.OnValueChanged(CCVars.UILayout, _ => ReloadMainScreen()); _configurationManager.OnValueChanged(CCVars.UILayout, ReloadMainScreenValueChange);
} }
protected override void Shutdown() protected override void Shutdown()
@@ -88,12 +88,18 @@ namespace Content.Client.Gameplay
_eyeManager.MainViewport = UserInterfaceManager.MainViewport; _eyeManager.MainViewport = UserInterfaceManager.MainViewport;
_fpsCounter.Dispose(); _fpsCounter.Dispose();
_uiManager.ClearWindows(); _uiManager.ClearWindows();
_configurationManager.UnsubValueChanged(CCVars.UILayout, ReloadMainScreenValueChange);
UnloadMainScreen(); UnloadMainScreen();
} }
private void ReloadMainScreenValueChange(string _)
{
ReloadMainScreen();
}
public void ReloadMainScreen() public void ReloadMainScreen()
{ {
if (_uiManager.ActiveScreen == null) if (_uiManager.ActiveScreen?.GetWidget<MainViewport>() == null)
{ {
return; return;
} }

View File

@@ -39,60 +39,45 @@ namespace Content.Client.Lobby
private ClientGameTicker _gameTicker = default!; private ClientGameTicker _gameTicker = default!;
protected override Type? LinkedScreenType { get; } = typeof(LobbyGui); protected override Type? LinkedScreenType { get; } = typeof(LobbyGui);
private LobbyGui Lobby => (LobbyGui) _userInterfaceManager.ActiveScreen!; private LobbyGui? _lobby;
protected override void Startup() protected override void Startup()
{ {
if (_userInterfaceManager.ActiveScreen == null)
{
return;
}
_lobby = (LobbyGui) _userInterfaceManager.ActiveScreen;
var chatController = _userInterfaceManager.GetUIController<ChatUIController>(); var chatController = _userInterfaceManager.GetUIController<ChatUIController>();
_gameTicker = _entityManager.System<ClientGameTicker>(); _gameTicker = _entityManager.System<ClientGameTicker>();
_characterSetup = new CharacterSetupGui(_entityManager, _resourceCache, _preferencesManager, _characterSetup = new CharacterSetupGui(_entityManager, _resourceCache, _preferencesManager,
_prototypeManager, _configurationManager); _prototypeManager, _configurationManager);
LayoutContainer.SetAnchorPreset(_characterSetup, LayoutContainer.LayoutPreset.Wide); LayoutContainer.SetAnchorPreset(_characterSetup, LayoutContainer.LayoutPreset.Wide);
_lobby.CharacterSetupState.AddChild(_characterSetup);
chatController.SetMainChat(true); chatController.SetMainChat(true);
_characterSetup.CloseButton.OnPressed += _ => _characterSetup.CloseButton.OnPressed += _ =>
{ {
_userInterfaceManager.StateRoot.AddChild(Lobby); _lobby.SwitchState(LobbyGui.LobbyGuiState.Default);
_userInterfaceManager.StateRoot.RemoveChild(_characterSetup);
}; };
_characterSetup.SaveButton.OnPressed += _ => _characterSetup.SaveButton.OnPressed += _ =>
{ {
_characterSetup.Save(); _characterSetup.Save();
Lobby?.CharacterPreview.UpdateUI(); _lobby.CharacterPreview.UpdateUI();
}; };
LayoutContainer.SetAnchorPreset(Lobby, LayoutContainer.LayoutPreset.Wide); LayoutContainer.SetAnchorPreset(_lobby, LayoutContainer.LayoutPreset.Wide);
_voteManager.SetPopupContainer(Lobby.VoteContainer); _voteManager.SetPopupContainer(_lobby.VoteContainer);
Lobby.ServerName.Text = _baseClient.GameInfo?.ServerName; //The eye of refactor gazes upon you... _lobby.ServerName.Text = _baseClient.GameInfo?.ServerName; //The eye of refactor gazes upon you...
UpdateLobbyUi(); UpdateLobbyUi();
Lobby.CharacterPreview.CharacterSetupButton.OnPressed += _ => _lobby.CharacterPreview.CharacterSetupButton.OnPressed += OnSetupPressed;
{ _lobby.ReadyButton.OnPressed += OnReadyPressed;
SetReady(false); _lobby.ReadyButton.OnToggled += OnReadyToggled;
_userInterfaceManager.StateRoot.RemoveChild(Lobby);
_userInterfaceManager.StateRoot.AddChild(_characterSetup);
};
Lobby.ReadyButton.OnPressed += _ =>
{
if (!_gameTicker.IsGameStarted)
{
return;
}
new LateJoinGui().OpenCentered();
};
Lobby.ReadyButton.OnToggled += args =>
{
SetReady(args.Pressed);
};
Lobby.LeaveButton.OnPressed += _ => _consoleHost.ExecuteCommand("disconnect");
Lobby.OptionsButton.OnPressed += _ => _userInterfaceManager.GetUIController<OptionsUIController>().ToggleWindow();
_gameTicker.InfoBlobUpdated += UpdateLobbyUi; _gameTicker.InfoBlobUpdated += UpdateLobbyUi;
_gameTicker.LobbyStatusUpdated += LobbyStatusUpdated; _gameTicker.LobbyStatusUpdated += LobbyStatusUpdated;
@@ -107,16 +92,43 @@ namespace Content.Client.Lobby
_gameTicker.LobbyStatusUpdated -= LobbyStatusUpdated; _gameTicker.LobbyStatusUpdated -= LobbyStatusUpdated;
_gameTicker.LobbyLateJoinStatusUpdated -= LobbyLateJoinStatusUpdated; _gameTicker.LobbyLateJoinStatusUpdated -= LobbyLateJoinStatusUpdated;
_lobby!.CharacterPreview.CharacterSetupButton.OnPressed -= OnSetupPressed;
_lobby!.ReadyButton.OnPressed -= OnReadyPressed;
_lobby!.ReadyButton.OnToggled -= OnReadyToggled;
_lobby = null;
_characterSetup?.Dispose(); _characterSetup?.Dispose();
_characterSetup = null; _characterSetup = null;
} }
private void OnSetupPressed(BaseButton.ButtonEventArgs args)
{
SetReady(false);
_lobby!.SwitchState(LobbyGui.LobbyGuiState.CharacterSetup);
}
private void OnReadyPressed(BaseButton.ButtonEventArgs args)
{
if (!_gameTicker.IsGameStarted)
{
return;
}
new LateJoinGui().OpenCentered();
}
private void OnReadyToggled(BaseButton.ButtonToggledEventArgs args)
{
SetReady(args.Pressed);
}
public override void FrameUpdate(FrameEventArgs e) public override void FrameUpdate(FrameEventArgs e)
{ {
if (_gameTicker.IsGameStarted) if (_gameTicker.IsGameStarted)
{ {
Lobby.StartTime.Text = string.Empty; _lobby!.StartTime.Text = string.Empty;
Lobby.StationTime.Text = Loc.GetString("lobby-state-player-status-station-time", ("stationTime", _gameTiming.CurTime.Subtract(_gameTicker.RoundStartTimeSpan).ToString("hh\\:mm"))); _lobby!.StationTime.Text = Loc.GetString("lobby-state-player-status-station-time", ("stationTime", _gameTiming.CurTime.Subtract(_gameTicker.RoundStartTimeSpan).ToString("hh\\:mm")));
return; return;
} }
@@ -140,8 +152,8 @@ namespace Content.Client.Lobby
} }
} }
Lobby.StationTime.Text = Loc.GetString("lobby-state-player-status-station-time", ("stationTime", TimeSpan.Zero.ToString("hh\\:mm"))); _lobby!.StationTime.Text = Loc.GetString("lobby-state-player-status-station-time", ("stationTime", TimeSpan.Zero.ToString("hh\\:mm")));
Lobby.StartTime.Text = Loc.GetString("lobby-state-round-start-countdown-text", ("timeLeft", text)); _lobby!.StartTime.Text = Loc.GetString("lobby-state-round-start-countdown-text", ("timeLeft", text));
} }
private void LobbyStatusUpdated() private void LobbyStatusUpdated()
@@ -152,31 +164,31 @@ namespace Content.Client.Lobby
private void LobbyLateJoinStatusUpdated() private void LobbyLateJoinStatusUpdated()
{ {
Lobby.ReadyButton.Disabled = _gameTicker.DisallowedLateJoin; _lobby!.ReadyButton.Disabled = _gameTicker.DisallowedLateJoin;
} }
private void UpdateLobbyUi() private void UpdateLobbyUi()
{ {
if (_gameTicker.IsGameStarted) if (_gameTicker.IsGameStarted)
{ {
Lobby.ReadyButton.Text = Loc.GetString("lobby-state-ready-button-join-state"); _lobby!.ReadyButton.Text = Loc.GetString("lobby-state-ready-button-join-state");
Lobby.ReadyButton.ToggleMode = false; _lobby!.ReadyButton.ToggleMode = false;
Lobby.ReadyButton.Pressed = false; _lobby!.ReadyButton.Pressed = false;
Lobby.ObserveButton.Disabled = false; _lobby!.ObserveButton.Disabled = false;
} }
else else
{ {
Lobby.StartTime.Text = string.Empty; _lobby!.StartTime.Text = string.Empty;
Lobby.ReadyButton.Text = Loc.GetString("lobby-state-ready-button-ready-up-state"); _lobby!.ReadyButton.Text = Loc.GetString("lobby-state-ready-button-ready-up-state");
Lobby.ReadyButton.ToggleMode = true; _lobby!.ReadyButton.ToggleMode = true;
Lobby.ReadyButton.Disabled = false; _lobby!.ReadyButton.Disabled = false;
Lobby.ReadyButton.Pressed = _gameTicker.AreWeReady; _lobby!.ReadyButton.Pressed = _gameTicker.AreWeReady;
Lobby.ObserveButton.Disabled = true; _lobby!.ObserveButton.Disabled = true;
} }
if (_gameTicker.ServerInfoBlob != null) if (_gameTicker.ServerInfoBlob != null)
{ {
Lobby.ServerInfo.SetInfoBlob(_gameTicker.ServerInfoBlob); _lobby!.ServerInfo.SetInfoBlob(_gameTicker.ServerInfoBlob);
} }
} }
@@ -184,11 +196,11 @@ namespace Content.Client.Lobby
{ {
if (_gameTicker.LobbyBackground != null) if (_gameTicker.LobbyBackground != null)
{ {
Lobby.Background.Texture = _resourceCache.GetResource<TextureResource>(_gameTicker.LobbyBackground ); _lobby!.Background.Texture = _resourceCache.GetResource<TextureResource>(_gameTicker.LobbyBackground );
} }
else else
{ {
Lobby.Background.Texture = null; _lobby!.Background.Texture = null;
} }
} }

View File

@@ -1,4 +1,4 @@
<lobbyUi:LobbyGui xmlns="https://spacestation14.io" <lobbyUi:LobbyGui xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maths="clr-namespace:Robust.Shared.Maths;assembly=Robust.Shared.Maths" xmlns:maths="clr-namespace:Robust.Shared.Maths;assembly=Robust.Shared.Maths"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls" xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
@@ -9,37 +9,42 @@
xmlns:info="clr-namespace:Content.Client.Info" xmlns:info="clr-namespace:Content.Client.Info"
xmlns:widgets="clr-namespace:Content.Client.UserInterface.Systems.Chat.Widgets"> xmlns:widgets="clr-namespace:Content.Client.UserInterface.Systems.Chat.Widgets">
<!-- Background --> <!-- Background -->
<TextureRect Access="Public" Name = "Background" Stretch="KeepAspectCovered"/> <TextureRect Access="Public" VerticalExpand="True" HorizontalExpand="True" Name = "Background" Stretch="KeepAspectCovered"/>
<BoxContainer Name="MainContainer" Orientation="Horizontal" Margin="10 10 10 10" SeparationOverride="2"> <BoxContainer Name="MainContainer" VerticalExpand="True" HorizontalExpand="True" Orientation="Horizontal" Margin="10 10 10 10" SeparationOverride="2">
<SplitContainer State="Auto" HorizontalExpand="True"> <SplitContainer State="Auto" HorizontalExpand="True">
<!-- LHS Controls --> <!-- LHS Controls -->
<BoxContainer Orientation="Vertical" SeparationOverride="4" HorizontalExpand="True"> <BoxContainer Name="LeftSide" Orientation="Vertical" SeparationOverride="4" HorizontalExpand="True">
<!-- Left Top Panel --> <Control Name="DefaultState" VerticalExpand="True">
<PanelContainer StyleClasses="AngleRect" HorizontalAlignment="Left" Name = "LeftSideTop" VerticalAlignment="Top" > <!-- Left Top Panel -->
<BoxContainer Orientation="Vertical" HorizontalAlignment="Center" MaxWidth="620"> <PanelContainer StyleClasses="AngleRect" HorizontalAlignment="Left" Name = "LeftSideTop" VerticalAlignment="Top" >
<info:LinkBanner Name="LinkBanner" VerticalExpand="false" HorizontalAlignment="Center" Margin="3 3 3 3"/> <BoxContainer Orientation="Vertical" HorizontalAlignment="Center" MaxWidth="620">
<controls:StripeBack> <info:LinkBanner Name="LinkBanner" VerticalExpand="false" HorizontalAlignment="Center" Margin="3 3 3 3"/>
<BoxContainer Orientation="Horizontal" SeparationOverride="6" Margin="3 3 3 3"> <controls:StripeBack>
<cc:UICommandButton Command="observe" Name="ObserveButton" Access="Public" Text="{Loc 'ui-lobby-observe-button'}" StyleClasses="ButtonBig" WindowType="{x:Type lobbyUi:ObserveWarningWindow}"/> <BoxContainer Orientation="Horizontal" SeparationOverride="6" Margin="3 3 3 3">
<Label Name="StartTime" <cc:UICommandButton Command="observe" Name="ObserveButton" Access="Public" Text="{Loc 'ui-lobby-observe-button'}" StyleClasses="ButtonBig" WindowType="{x:Type lobbyUi:ObserveWarningWindow}"/>
Access="Public" <Label Name="StartTime"
Align="Right" Access="Public"
FontColorOverride="{x:Static maths:Color.DarkGray}" Align="Right"
StyleClasses="LabelBig" HorizontalExpand="True" /> FontColorOverride="{x:Static maths:Color.DarkGray}"
<Button Name="ReadyButton" Access="Public" ToggleMode="True" Text="{Loc 'ui-lobby-ready-up-button'}" StyleClasses="LabelBig" HorizontalExpand="True" />
StyleClasses="ButtonBig" /> <Button Name="ReadyButton" Access="Public" ToggleMode="True" Text="{Loc 'ui-lobby-ready-up-button'}"
</BoxContainer> StyleClasses="ButtonBig" />
</controls:StripeBack> </BoxContainer>
</controls:StripeBack>
</BoxContainer>
</PanelContainer>
<!-- Voting Popups -->
<BoxContainer Orientation="Vertical" SeparationOverride="4" Name="VoteContainer" Access="Public" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<!-- Vertical Padding-->
<Control VerticalExpand="True"/>
<!-- Left Bot Panel -->
<BoxContainer Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Bottom" MaxWidth="620">
<info:DevInfoBanner Name="DevInfoBanner" VerticalExpand="false" Margin="3 3 3 3"/>
</BoxContainer> </BoxContainer>
</PanelContainer> </Control>
<!-- Voting Popups --> <!-- Character setup state -->
<BoxContainer Orientation="Vertical" SeparationOverride="4" Name="VoteContainer" Access="Public" HorizontalAlignment="Left" VerticalAlignment="Top"/> <!-- This is injected on startup. Funky! -->
<!-- Vertical Padding--> <Control Access="Public" Visible="False" Name="CharacterSetupState" VerticalExpand="True" />
<Control VerticalExpand="True"/>
<!-- Left Bot Panel -->
<BoxContainer Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Bottom" MaxWidth="620">
<info:DevInfoBanner Name="DevInfoBanner" VerticalExpand="false" Margin="3 3 3 3"/>
</BoxContainer>
</BoxContainer> </BoxContainer>
<!-- Right Panel --> <!-- Right Panel -->
<PanelContainer Name="RightSide" StyleClasses="AngleRect" HorizontalAlignment= "Right" VerticalExpand="True" VerticalAlignment="Stretch"> <PanelContainer Name="RightSide" StyleClasses="AngleRect" HorizontalAlignment= "Right" VerticalExpand="True" VerticalAlignment="Stretch">

View File

@@ -1,8 +1,12 @@
using Content.Client.Chat.UI; using Content.Client.Chat.UI;
using Content.Client.Info; using Content.Client.Info;
using Content.Client.Preferences; using Content.Client.Preferences;
using Content.Client.Preferences.UI;
using Content.Client.UserInterface.Systems.EscapeMenu;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.Console;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.State;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
@@ -17,10 +21,55 @@ namespace Content.Client.Lobby.UI
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
internal sealed partial class LobbyGui : UIScreen internal sealed partial class LobbyGui : UIScreen
{ {
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
public LobbyGui() public LobbyGui()
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
SetAnchorPreset(MainContainer, LayoutPreset.Wide); SetAnchorPreset(MainContainer, LayoutPreset.Wide);
SetAnchorPreset(Background, LayoutPreset.Wide);
LeaveButton.OnPressed += _ => _consoleHost.ExecuteCommand("disconnect");
OptionsButton.OnPressed += _ => _userInterfaceManager.GetUIController<OptionsUIController>().ToggleWindow();
}
public void SwitchState(LobbyGuiState state)
{
DefaultState.Visible = false;
CharacterSetupState.Visible = false;
switch (state)
{
case LobbyGuiState.Default:
DefaultState.Visible = true;
RightSide.Visible = true;
break;
case LobbyGuiState.CharacterSetup:
CharacterSetupState.Visible = true;
var actualWidth = (float) _userInterfaceManager.RootControl.PixelWidth;
var setupWidth = (float) LeftSide.PixelWidth;
if (1 - (setupWidth / actualWidth) > 0.30)
{
RightSide.Visible = false;
}
break;
}
}
public enum LobbyGuiState : byte
{
/// <summary>
/// The default state, i.e., what's seen on launch.
/// </summary>
Default,
/// <summary>
/// The character setup state.
/// </summary>
CharacterSetup
} }
} }
} }

View File

@@ -2,9 +2,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client" xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:parallax="clr-namespace:Content.Client.Parallax" xmlns:parallax="clr-namespace:Content.Client.Parallax"
xmlns:style="clr-namespace:Content.Client.Stylesheets"> xmlns:style="clr-namespace:Content.Client.Stylesheets"
<parallax:ParallaxControl /> VerticalExpand="True">
<Control Margin="20 20 20 20"> <Control>
<PanelContainer Name="BackgroundPanel" /> <PanelContainer Name="BackgroundPanel" />
<BoxContainer Orientation="Vertical" SeparationOverride="0"> <BoxContainer Orientation="Vertical" SeparationOverride="0">
<BoxContainer Orientation="Horizontal" MinSize="0 40"> <BoxContainer Orientation="Horizontal" MinSize="0 40">

View File

@@ -13,6 +13,7 @@ using Robust.Client.Graphics;
using Robust.Client.ResourceManagement; using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;