Оптимизация пространства в лобби (#3686)
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
2f599fb1eb
commit
642b4def12
8 changed files with 205 additions and 53 deletions
|
|
@ -90,15 +90,16 @@ namespace Content.Client.Lobby
|
|||
_voteManager.SetPopupContainer(Lobby.VoteContainer);
|
||||
LayoutContainer.SetAnchorPreset(Lobby, LayoutContainer.LayoutPreset.Wide);
|
||||
|
||||
var lobbyNameCvar = _cfg.GetCVar(CCVars.ServerLobbyName);
|
||||
var serverName = _baseClient.GameInfo?.ServerName ?? string.Empty;
|
||||
// Sunrise-Start
|
||||
//var lobbyNameCvar = _cfg.GetCVar(CCVars.ServerLobbyName);
|
||||
//var serverName = _baseClient.GameInfo?.ServerName ?? string.Empty;
|
||||
|
||||
// Lobby.ServerName.Text = string.IsNullOrEmpty(lobbyNameCvar)
|
||||
// ? Loc.GetString("ui-lobby-title", ("serverName", serverName))
|
||||
// : lobbyNameCvar;
|
||||
|
||||
var width = _cfg.GetCVar(CCVars.ServerLobbyRightPanelWidth);
|
||||
Lobby.RightPanel.SetWidth = width;
|
||||
// var width = _cfg.GetCVar(CCVars.ServerLobbyRightPanelWidth);
|
||||
// Lobby.RightPanel.SetWidth = width;
|
||||
|
||||
UpdateLobbyUi();
|
||||
|
||||
|
|
@ -130,7 +131,7 @@ namespace Content.Client.Lobby
|
|||
|
||||
// Subscribe to resource loaded events
|
||||
_netTexturesManager.ResourceLoaded += OnNetworkResourceLoaded;
|
||||
// Sunrise-end
|
||||
// Sunrise-End
|
||||
|
||||
Lobby.CharacterPreview.CharacterSetupButton.OnPressed += OnSetupPressed;
|
||||
Lobby.ReadyButton.OnPressed += OnReadyPressed;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Linq;
|
||||
using Content.Client._Sunrise.Pets;
|
||||
using Content.Client.Guidebook;
|
||||
using Content.Shared._Sunrise.Pets;
|
||||
using Content.Client.Humanoid;
|
||||
using Content.Client.Inventory;
|
||||
using Content.Client.Lobby.UI;
|
||||
|
|
@ -108,11 +109,11 @@ public sealed partial class LobbyUIController : UIController, IOnStateEntered<Lo
|
|||
|
||||
private LobbyPetPreviewPanel? GetLobbyPetPreview()
|
||||
{
|
||||
if (_stateManager.CurrentState is LobbyState lobby)
|
||||
{
|
||||
return lobby.Lobby?.PetPreview;
|
||||
}
|
||||
|
||||
// Sunrise-Edit
|
||||
// if (_stateManager.CurrentState is LobbyState lobby)
|
||||
// {
|
||||
// return lobby.Lobby?.PetPreview;
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -162,7 +163,6 @@ public sealed partial class LobbyUIController : UIController, IOnStateEntered<Lo
|
|||
private void PreferencesDataLoaded()
|
||||
{
|
||||
PreviewPanel?.SetLoaded(true);
|
||||
PetPreviewPanel?.SetLoaded(true);
|
||||
|
||||
if (_stateManager.CurrentState is not LobbyState)
|
||||
return;
|
||||
|
|
@ -174,7 +174,6 @@ public sealed partial class LobbyUIController : UIController, IOnStateEntered<Lo
|
|||
public void OnStateEntered(LobbyState state)
|
||||
{
|
||||
PreviewPanel?.SetLoaded(_preferencesManager.ServerDataLoaded);
|
||||
PetPreviewPanel?.SetLoaded(_preferencesManager.ServerDataLoaded);
|
||||
ReloadCharacterSetup();
|
||||
RefreshPetPreview();
|
||||
}
|
||||
|
|
@ -182,7 +181,6 @@ public sealed partial class LobbyUIController : UIController, IOnStateEntered<Lo
|
|||
public void OnStateExited(LobbyState state)
|
||||
{
|
||||
PreviewPanel?.SetLoaded(false);
|
||||
PetPreviewPanel?.SetLoaded(false);
|
||||
_profileEditor?.Dispose();
|
||||
_characterSetup?.Dispose();
|
||||
|
||||
|
|
@ -228,13 +226,22 @@ public sealed partial class LobbyUIController : UIController, IOnStateEntered<Lo
|
|||
|
||||
private void RefreshPetPreview()
|
||||
{
|
||||
if (PetPreviewPanel == null)
|
||||
if (PreviewPanel == null)
|
||||
return;
|
||||
|
||||
var currentPetSelection = GetCurrentPetSelection();
|
||||
PetPreviewPanel.SetPetSelection(currentPetSelection);
|
||||
|
||||
PetPreviewPanel.OnChangePetRequested += OpenPetPanel;
|
||||
PreviewPanel.OnChangePetRequested -= OpenPetPanel;
|
||||
PreviewPanel.OnChangePetRequested += OpenPetPanel;
|
||||
|
||||
EntityUid? petDummy = null;
|
||||
if (!string.IsNullOrEmpty(currentPetSelection) &&
|
||||
_prototypeManager.TryIndex<PetSelectionPrototype>(currentPetSelection, out var petSelectionPrototype))
|
||||
{
|
||||
petDummy = EntityManager.SpawnEntity(petSelectionPrototype.PetEntity, MapCoordinates.Nullspace);
|
||||
}
|
||||
|
||||
PreviewPanel.SetPetSprite(petDummy);
|
||||
}
|
||||
|
||||
private void OpenPetPanel()
|
||||
|
|
|
|||
|
|
@ -5,14 +5,17 @@
|
|||
<BoxContainer Name="VBox" Orientation="Vertical">
|
||||
<BoxContainer Name="Loaded" Orientation="Vertical"
|
||||
Visible="False">
|
||||
<Label Name="Summary" HorizontalAlignment="Center" Margin="3 3"/>
|
||||
<BoxContainer Name="ViewBox" Orientation="Horizontal" HorizontalAlignment="Center">
|
||||
<Label Name="Summary" HorizontalAlignment="Center" Margin="3 3" MaxWidth="350" Align="Center"/>
|
||||
<BoxContainer Name="ViewBox" Orientation="Horizontal" HorizontalAlignment="Center" VerticalExpand="True">
|
||||
|
||||
</BoxContainer>
|
||||
<controls:VSpacer/>
|
||||
<Button Name="CharacterSetup" Text="{Loc 'lobby-character-preview-panel-character-setup-button'}"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0 5 0 0"/>
|
||||
<BoxContainer Orientation="Horizontal" HorizontalAlignment="Center" Margin="0 5 0 0">
|
||||
<Button Name="CharacterSetup" Text="{Loc 'lobby-character-preview-panel-character-setup-button'}"
|
||||
Margin="0 0 5 0"/>
|
||||
<Button Name="ChangePetButton" Text="{Loc 'pet-selection-select-lobby'}"
|
||||
MinWidth="80"/>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
<Label Name="Unloaded" Text="{Loc 'lobby-character-preview-panel-unloaded-preferences-label'}"/>
|
||||
</BoxContainer>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
using System.Numerics;
|
||||
using System.Text;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
|
@ -14,12 +16,23 @@ public sealed partial class LobbyCharacterPreviewPanel : Control
|
|||
|
||||
public Button CharacterSetupButton => CharacterSetup;
|
||||
|
||||
public event Action? OnChangePetRequested;
|
||||
|
||||
private EntityUid? _previewDummy;
|
||||
private EntityUid? _petPreviewDummy;
|
||||
private SpriteView? _characterSpriteView;
|
||||
private SpriteView? _petSpriteView;
|
||||
|
||||
public LobbyCharacterPreviewPanel()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
ChangePetButton.OnPressed += OnChangePetButtonPressed;
|
||||
}
|
||||
|
||||
private void OnChangePetButtonPressed(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
OnChangePetRequested?.Invoke();
|
||||
}
|
||||
|
||||
public void SetLoaded(bool value)
|
||||
|
|
@ -28,11 +41,66 @@ public sealed partial class LobbyCharacterPreviewPanel : Control
|
|||
Unloaded.Visible = !value;
|
||||
}
|
||||
|
||||
// Sunrise-Start
|
||||
public void SetSummaryText(string value)
|
||||
{
|
||||
Summary.Text = value;
|
||||
var wrappedText = WrapText(value, 350);
|
||||
Summary.Text = wrappedText;
|
||||
}
|
||||
|
||||
private string WrapText(string text, float maxWidth)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return string.Empty;
|
||||
|
||||
var font = Summary.FontOverride ?? UserInterfaceManager.ThemeDefaults.LabelFont;
|
||||
var uiScale = UIScale;
|
||||
var words = text.Split(' ');
|
||||
var lines = new List<string>();
|
||||
var currentLine = new StringBuilder();
|
||||
|
||||
foreach (var word in words)
|
||||
{
|
||||
var testLine = currentLine.Length > 0 ? $"{currentLine} {word}" : word;
|
||||
var testWidth = MeasureTextWidth(testLine, font, uiScale);
|
||||
|
||||
if (testWidth <= maxWidth * uiScale)
|
||||
{
|
||||
if (currentLine.Length > 0)
|
||||
currentLine.Append(' ');
|
||||
currentLine.Append(word);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentLine.Length > 0)
|
||||
{
|
||||
lines.Add(currentLine.ToString());
|
||||
currentLine.Clear();
|
||||
}
|
||||
currentLine.Append(word);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentLine.Length > 0)
|
||||
lines.Add(currentLine.ToString());
|
||||
|
||||
return string.Join("\n", lines);
|
||||
}
|
||||
|
||||
private float MeasureTextWidth(string text, Font font, float uiScale)
|
||||
{
|
||||
float width = 0;
|
||||
foreach (var rune in text.EnumerateRunes())
|
||||
{
|
||||
if (font.TryGetCharMetrics(rune, uiScale, out var metrics))
|
||||
{
|
||||
width += metrics.Advance;
|
||||
}
|
||||
}
|
||||
return width;
|
||||
}
|
||||
// Sunrise-End
|
||||
|
||||
public void SetSprite(EntityUid uid)
|
||||
{
|
||||
if (_previewDummy != null)
|
||||
|
|
@ -42,22 +110,67 @@ public sealed partial class LobbyCharacterPreviewPanel : Control
|
|||
|
||||
_previewDummy = uid;
|
||||
|
||||
ViewBox.RemoveAllChildren();
|
||||
var spriteView = new SpriteView
|
||||
// Удаляем старый спрайт персонажа
|
||||
if (_characterSpriteView != null)
|
||||
{
|
||||
ViewBox.RemoveChild(_characterSpriteView);
|
||||
_characterSpriteView = null;
|
||||
}
|
||||
|
||||
_characterSpriteView = new SpriteView
|
||||
{
|
||||
OverrideDirection = Direction.South,
|
||||
Scale = new Vector2(4f, 4f),
|
||||
MaxSize = new Vector2(112, 112),
|
||||
Stretch = SpriteView.StretchMode.Fill,
|
||||
};
|
||||
spriteView.SetEntity(uid);
|
||||
ViewBox.AddChild(spriteView);
|
||||
_characterSpriteView.SetEntity(uid);
|
||||
ViewBox.AddChild(_characterSpriteView);
|
||||
}
|
||||
|
||||
public void SetPetSprite(EntityUid? uid)
|
||||
{
|
||||
if (_petPreviewDummy != null && (uid == null || _petPreviewDummy != uid))
|
||||
{
|
||||
_entManager.DeleteEntity(_petPreviewDummy);
|
||||
}
|
||||
|
||||
if (_petSpriteView != null)
|
||||
{
|
||||
ViewBox.RemoveChild(_petSpriteView);
|
||||
_petSpriteView = null;
|
||||
}
|
||||
|
||||
if (uid == null || !uid.Value.IsValid())
|
||||
{
|
||||
_petPreviewDummy = null;
|
||||
return;
|
||||
}
|
||||
|
||||
_petPreviewDummy = uid;
|
||||
|
||||
_petSpriteView = new SpriteView
|
||||
{
|
||||
OverrideDirection = Direction.South,
|
||||
Scale = new Vector2(2f, 2f),
|
||||
MaxSize = new Vector2(80, 80),
|
||||
Stretch = SpriteView.StretchMode.Fill,
|
||||
VerticalAlignment = Control.VAlignment.Bottom,
|
||||
};
|
||||
_petSpriteView.SetEntity(uid.Value);
|
||||
ViewBox.AddChild(_petSpriteView);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing)
|
||||
return;
|
||||
|
||||
ChangePetButton.OnPressed -= OnChangePetButtonPressed;
|
||||
_entManager.DeleteEntity(_previewDummy);
|
||||
_entManager.DeleteEntity(_petPreviewDummy);
|
||||
_previewDummy = null;
|
||||
_petPreviewDummy = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -343,7 +343,6 @@
|
|||
<PanelContainer
|
||||
Access="Public"
|
||||
HorizontalExpand="True"
|
||||
MinWidth="500"
|
||||
Name="RightPanel"
|
||||
StyleClasses="AngleRect"
|
||||
VerticalAlignment="Stretch"
|
||||
|
|
@ -355,29 +354,41 @@
|
|||
VerticalAlignment="Stretch"
|
||||
VerticalExpand="True">
|
||||
<BoxContainer
|
||||
HorizontalAlignment="Right"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalExpand="True"
|
||||
Margin="3,3,3,3"
|
||||
Orientation="Horizontal"
|
||||
SizeFlagsStretchRatio="1">
|
||||
<Button
|
||||
Access="Public"
|
||||
MinWidth="40"
|
||||
HorizontalExpand="True"
|
||||
Name="AHelpButton"
|
||||
StyleClasses="ButtonBig"
|
||||
Text="{Loc 'ui-lobby-ahelp-button'}" />
|
||||
<Button
|
||||
Access="Public"
|
||||
MinWidth="40"
|
||||
HorizontalExpand="True"
|
||||
Name="MHelpButton"
|
||||
StyleClasses="ButtonBig"
|
||||
Text="{Loc 'ui-lobby-mhelp-button'}" />
|
||||
<vote:VoteCallMenuButton Name="CallVoteButton" StyleClasses="ButtonBig" />
|
||||
<vote:VoteCallMenuButton
|
||||
MinWidth="40"
|
||||
HorizontalExpand="True"
|
||||
Name="CallVoteButton"
|
||||
StyleClasses="ButtonBig" />
|
||||
<Button
|
||||
Access="Public"
|
||||
MinWidth="40"
|
||||
HorizontalExpand="True"
|
||||
Name="OptionsButton"
|
||||
StyleClasses="ButtonBig"
|
||||
Text="{Loc 'ui-lobby-options-button'}" />
|
||||
<Button
|
||||
Access="Public"
|
||||
MinWidth="40"
|
||||
HorizontalExpand="True"
|
||||
Name="LeaveButton"
|
||||
StyleClasses="ButtonBig"
|
||||
Text="{Loc 'ui-lobby-leave-button'}" />
|
||||
|
|
@ -451,21 +462,12 @@
|
|||
<BoxContainer
|
||||
MinHeight="180"
|
||||
Name="CharacterInfoContent"
|
||||
Orientation="Vertical">
|
||||
<BoxContainer
|
||||
HorizontalAlignment="Stretch"
|
||||
Orientation="Vertical"
|
||||
VerticalExpand="True">
|
||||
<lobbyUi:LobbyCharacterPreviewPanel
|
||||
Access="Public"
|
||||
HorizontalExpand="True"
|
||||
Orientation="Horizontal"
|
||||
SizeFlagsStretchRatio="2">
|
||||
<lobbyUi:LobbyCharacterPreviewPanel
|
||||
Access="Public"
|
||||
HorizontalExpand="True"
|
||||
Name="CharacterPreview" />
|
||||
<pets:LobbyPetPreviewPanel
|
||||
Access="Public"
|
||||
HorizontalExpand="True"
|
||||
Name="PetPreview" />
|
||||
</BoxContainer>
|
||||
Name="CharacterPreview" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
<BoxContainer
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ using Content.Client.Parallax.Managers;
|
|||
using Content.Client.Resources;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Shared._Sunrise.SunriseCCVars;
|
||||
using Content.Shared.CCVar;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Utility;
|
||||
|
|
@ -153,6 +155,13 @@ namespace Content.Client.Lobby.UI
|
|||
|
||||
ServerName.Text = Loc.GetString("ui-lobby-welcome", ("name", _serverName));
|
||||
LoadIcons();
|
||||
|
||||
SetupButtonIcon(AHelpButton, "/Textures/Interface/info.svg.192dpi.png", Loc.GetString("ui-lobby-ahelp-button"));
|
||||
SetupButtonIcon(MHelpButton, "/Textures/Interface/mentor.svg.192dpi.png", Loc.GetString("ui-lobby-mhelp-button"));
|
||||
SetupButtonIcon(CallVoteButton, "/Textures/Interface/gavel.svg.192dpi.png", Loc.GetString("ui-vote-menu-button"));
|
||||
SetupButtonIcon(OptionsButton, "/Textures/Interface/VerbIcons/settings.svg.192dpi.png", Loc.GetString("ui-lobby-options-button"));
|
||||
SetupButtonIcon(LeaveButton, "/Textures/Interface/VerbIcons/close.svg.192dpi.png", Loc.GetString("ui-lobby-leave-button"));
|
||||
|
||||
// Sunrise-end
|
||||
}
|
||||
|
||||
|
|
@ -256,7 +265,7 @@ namespace Content.Client.Lobby.UI
|
|||
// ExpandPanel.Visible = !value;
|
||||
//}
|
||||
|
||||
// Sunrise-start
|
||||
// Sunrise-Start
|
||||
protected override void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
if (!ShowParallax)
|
||||
|
|
@ -301,7 +310,27 @@ namespace Content.Client.Lobby.UI
|
|||
}
|
||||
}
|
||||
}
|
||||
// Sunrise-end
|
||||
|
||||
private void SetupButtonIcon(Button button, string iconPath, string tooltip)
|
||||
{
|
||||
button.Text = string.Empty;
|
||||
button.ToolTip = tooltip;
|
||||
|
||||
var iconRect = new TextureRect
|
||||
{
|
||||
Texture = _resourceCache.GetTexture(new ResPath(iconPath)),
|
||||
TextureScale = new Vector2(0.5f, 0.5f),
|
||||
HorizontalAlignment = HAlignment.Center,
|
||||
VerticalAlignment = VAlignment.Center,
|
||||
Stretch = TextureRect.StretchMode.KeepAspectCentered,
|
||||
HorizontalExpand = true,
|
||||
VerticalExpand = true
|
||||
};
|
||||
|
||||
button.RemoveAllChildren();
|
||||
button.AddChild(iconRect);
|
||||
}
|
||||
// Sunrise-End
|
||||
|
||||
public enum LobbyGuiState : byte
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
<Control xmlns="https://spacestation14.io"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
|
||||
<Label Name="Summary" HorizontalAlignment="Center" Margin="0 5 0 0"/>
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
|
||||
<Control Name="ViewBox" HorizontalExpand="True" VerticalExpand="True" MinHeight="100"/>
|
||||
</BoxContainer>
|
||||
<Button Name="ChangePetButton" Text="{Loc 'pet-selection-select-lobby'}" HorizontalAlignment="Center" MinWidth="80" Margin="5 0 0 0"/>
|
||||
</BoxContainer>
|
||||
</Control>
|
||||
|
|
|
|||
|
|
@ -30,8 +30,6 @@ public sealed partial class LobbyPetPreviewPanel : Control
|
|||
IoCManager.InjectDependencies(this);
|
||||
_playerCache.CacheChanged += UpdateSelectedPetFromCache;
|
||||
UpdateSelectedPetFromCache();
|
||||
|
||||
ChangePetButton.OnPressed += _ => OnChangePetRequested?.Invoke();
|
||||
}
|
||||
|
||||
private void UpdateSelectedPetFromCache()
|
||||
|
|
@ -50,7 +48,8 @@ public sealed partial class LobbyPetPreviewPanel : Control
|
|||
|
||||
public void SetSummaryText(string value)
|
||||
{
|
||||
Summary.Text = value;
|
||||
// Sunrise-Edit
|
||||
//Summary.Text = value;
|
||||
}
|
||||
|
||||
public void SetPetSelection(string? petSelection)
|
||||
|
|
@ -71,13 +70,11 @@ public sealed partial class LobbyPetPreviewPanel : Control
|
|||
|
||||
if (string.IsNullOrEmpty(_currentPetSelection))
|
||||
{
|
||||
SetSummaryText(Loc.GetString("pet-selection-summary-no-select"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_prototypeManager.TryIndex<PetSelectionPrototype>(_currentPetSelection, out var petSelectionPrototype))
|
||||
{
|
||||
SetSummaryText(Loc.GetString("pet-selection-summary-invalid"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -93,12 +90,14 @@ public sealed partial class LobbyPetPreviewPanel : Control
|
|||
};
|
||||
spriteView.SetEntity(dummy);
|
||||
ViewBox.AddChild(spriteView);
|
||||
SetSummaryText(Loc.GetString("pet-selection-summary-name", ("name", petSelectionPrototype.LocalizedName)));
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
_playerCache.CacheChanged -= UpdateSelectedPetFromCache;
|
||||
|
||||
if (_previewDummy != null)
|
||||
{
|
||||
_entManager.DeleteEntity(_previewDummy.Value);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue