Rotating character preview & lobby preview change (#19741)

This commit is contained in:
Morb
2023-09-13 04:57:38 +03:00
committed by GitHub
parent 486bba4565
commit 80543c322d
3 changed files with 47 additions and 88 deletions

View File

@@ -43,10 +43,15 @@ namespace Content.Client.Lobby.UI
CharacterSetupButton = new Button
{
Text = Loc.GetString("lobby-character-preview-panel-character-setup-button"),
HorizontalAlignment = HAlignment.Left
HorizontalAlignment = HAlignment.Center,
Margin = new Thickness(0, 5, 0, 0),
};
_summaryLabel = new Label();
_summaryLabel = new Label
{
HorizontalAlignment = HAlignment.Center,
Margin = new Thickness(3, 3),
};
var vBox = new BoxContainer
{
@@ -61,7 +66,8 @@ namespace Content.Client.Lobby.UI
};
_viewBox = new BoxContainer
{
Orientation = LayoutOrientation.Horizontal
Orientation = LayoutOrientation.Horizontal,
HorizontalAlignment = HAlignment.Center,
};
var _vSpacer = new VSpacer();
@@ -89,18 +95,6 @@ namespace Content.Client.Lobby.UI
_previewDummy = default;
}
private SpriteView MakeSpriteView(EntityUid entity, Direction direction)
{
var spriteView = new SpriteView
{
OverrideDirection = direction,
Scale = new Vector2(2, 2),
};
spriteView.SetEntity(entity);
return spriteView;
}
public void UpdateUI()
{
if (!_preferencesManager.ServerDataLoaded)
@@ -119,15 +113,16 @@ namespace Content.Client.Lobby.UI
else
{
_previewDummy = _entityManager.SpawnEntity(_prototypeManager.Index<SpeciesPrototype>(selectedCharacter.Species).DollPrototype, MapCoordinates.Nullspace);
var viewSouth = MakeSpriteView(_previewDummy.Value, Direction.South);
var viewNorth = MakeSpriteView(_previewDummy.Value, Direction.North);
var viewWest = MakeSpriteView(_previewDummy.Value, Direction.West);
var viewEast = MakeSpriteView(_previewDummy.Value, Direction.East);
_viewBox.DisposeAllChildren();
_viewBox.AddChild(viewSouth);
_viewBox.AddChild(viewNorth);
_viewBox.AddChild(viewWest);
_viewBox.AddChild(viewEast);
var spriteView = new SpriteView
{
OverrideDirection = Direction.South,
Scale = new Vector2(4f, 4f),
MaxSize = new Vector2(112, 112),
Stretch = SpriteView.StretchMode.None,
};
spriteView.SetEntity(_previewDummy.Value);
_viewBox.AddChild(spriteView);
_summaryLabel.Text = selectedCharacter.Summary;
_entityManager.System<HumanoidAppearanceSystem>().LoadProfile(_previewDummy.Value, selectedCharacter);
GiveDummyJobClothes(_previewDummy.Value, selectedCharacter);

View File

@@ -1,7 +1,8 @@
<Control xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prefUi="clr-namespace:Content.Client.Preferences.UI"
xmlns:humanoid="clr-namespace:Content.Client.Humanoid">
xmlns:humanoid="clr-namespace:Content.Client.Humanoid"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls">
<BoxContainer Orientation="Horizontal">
<!-- Left side -->
<BoxContainer Orientation="Vertical" Margin="10 10 10 10">
@@ -143,9 +144,13 @@
</TabContainer>
</BoxContainer>
<!-- Right side -->
<BoxContainer Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True">
<Control Name="CSpriteViewFront" VerticalExpand="True" SizeFlagsStretchRatio="1" />
<Control Name="CSpriteViewSide" VerticalExpand="True" SizeFlagsStretchRatio="1" />
<BoxContainer Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True" VerticalAlignment="Center">
<SpriteView Name="CSpriteView" Scale="8 8" SizeFlagsStretchRatio="1" />
<BoxContainer Orientation="Horizontal" HorizontalAlignment="Center" Margin="0 5">
<Button Name="CSpriteRotateLeft" Text="◀" StyleClasses="OpenRight" />
<cc:VSeparator Margin="2 0 3 0" />
<Button Name="CSpriteRotateRight" Text="▶" StyleClasses="OpenLeft" />
</BoxContainer>
</BoxContainer>
</BoxContainer>
</Control>

View File

@@ -88,18 +88,12 @@ namespace Content.Client.Preferences.UI
private readonly List<AntagPreferenceSelector> _antagPreferences;
private readonly List<TraitPreferenceSelector> _traitPreferences;
private Control _previewSpriteControl => CSpriteViewFront;
private Control _previewSpriteSideControl => CSpriteViewSide;
private SpriteView _previewSpriteView => CSpriteView;
private Button _previewRotateLeftButton => CSpriteRotateLeft;
private Button _previewRotateRightButton => CSpriteRotateRight;
private Direction _previewRotation = Direction.North;
private EntityUid? _previewDummy;
/// <summary>
/// Used to avoid unnecessarily re-creating the entity.
/// </summary>
private string? _lastSpecies;
private SpriteView? _previewSprite;
private SpriteView? _previewSpriteSide;
private BoxContainer _rgbSkinColorContainer => CRgbSkinColorContainer;
private ColorSelectorSliders _rgbSkinColorSelector;
@@ -479,6 +473,18 @@ namespace Content.Client.Preferences.UI
#endregion FlavorText
#region Dummy
_previewRotateLeftButton.OnPressed += _ =>
{
_previewRotation = _previewRotation.TurnCw();
_needUpdatePreview = true;
};
_previewRotateRightButton.OnPressed += _ =>
{
_previewRotation = _previewRotation.TurnCcw();
_needUpdatePreview = true;
};
var species = Profile?.Species ?? SharedHumanoidAppearanceSystem.DefaultSpecies;
var dollProto = _prototypeManager.Index<SpeciesPrototype>(species).DollPrototype;
@@ -486,27 +492,7 @@ namespace Content.Client.Preferences.UI
_entMan.DeleteEntity(_previewDummy!.Value);
_previewDummy = _entMan.SpawnEntity(dollProto, MapCoordinates.Nullspace);
_lastSpecies = species;
_previewSprite = new SpriteView
{
Scale = new Vector2(6, 6),
OverrideDirection = Direction.South,
VerticalAlignment = VAlignment.Center,
SizeFlagsStretchRatio = 1
};
_previewSprite.SetEntity(_previewDummy.Value);
_previewSpriteControl.AddChild(_previewSprite);
_previewSpriteSide = new SpriteView
{
Scale = new Vector2(6, 6),
OverrideDirection = Direction.East,
VerticalAlignment = VAlignment.Center,
SizeFlagsStretchRatio = 1
};
_previewSpriteSide.SetEntity(_previewDummy.Value);
_previewSpriteSideControl.AddChild(_previewSpriteSide);
_previewSpriteView.SetEntity(_previewDummy);
#endregion Dummy
#endregion Left
@@ -726,35 +712,7 @@ namespace Content.Client.Preferences.UI
_entMan.DeleteEntity(_previewDummy!.Value);
_previewDummy = _entMan.SpawnEntity(dollProto, MapCoordinates.Nullspace);
_lastSpecies = species;
if (_previewSprite == null)
{
// Front
_previewSprite = new SpriteView
{
Scale = new Vector2(6, 6),
OverrideDirection = Direction.South,
VerticalAlignment = VAlignment.Center,
SizeFlagsStretchRatio = 1
};
_previewSpriteControl.AddChild(_previewSprite);
}
_previewSprite.SetEntity(_previewDummy.Value);
if (_previewSpriteSide == null)
{
_previewSpriteSide = new SpriteView
{
Scale = new Vector2(6, 6),
OverrideDirection = Direction.East,
VerticalAlignment = VAlignment.Center,
SizeFlagsStretchRatio = 1
};
_previewSpriteSideControl.AddChild(_previewSpriteSide);
}
_previewSpriteSide.SetEntity(_previewDummy.Value);
_previewSpriteView.SetEntity(_previewDummy);
_needUpdatePreview = true;
}
@@ -1127,6 +1085,8 @@ namespace Content.Client.Preferences.UI
if (ShowClothes.Pressed)
LobbyCharacterPreviewPanel.GiveDummyJobClothes(_previewDummy!.Value, Profile);
_previewSpriteView.OverrideDirection = (Direction) ((int) _previewRotation % 4 * 2);
}
public void UpdateControls()
@@ -1162,7 +1122,6 @@ namespace Content.Client.Preferences.UI
if (_needUpdatePreview)
{
UpdatePreview();
_needUpdatePreview = false;
}
}