Adds a live preview to the character customizer (#2523)
* Preview * -Dispose Dummy -Unsubscribe from OnServerDataLoaded
This commit is contained in:
@@ -1,22 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Client.GameObjects.Components;
|
||||
using Content.Client.GameObjects.Components;
|
||||
using Content.Client.GameObjects.Components.Mobs;
|
||||
using Content.Client.Interfaces;
|
||||
using Content.Shared;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Preferences;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics.Drawing;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Client.UserInterface
|
||||
{
|
||||
@@ -43,17 +46,25 @@ namespace Content.Client.UserInterface
|
||||
private readonly OptionButton _preferenceUnavailableButton;
|
||||
private readonly List<AntagPreferenceSelector> _antagPreferences;
|
||||
|
||||
private readonly IEntity _previewDummy;
|
||||
private readonly SpriteView _previewSprite;
|
||||
private readonly SpriteView _previewSpriteSide;
|
||||
|
||||
private bool _isDirty;
|
||||
public int CharacterSlot;
|
||||
public HumanoidCharacterProfile Profile;
|
||||
public event Action<HumanoidCharacterProfile> OnProfileChanged;
|
||||
|
||||
public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IPrototypeManager prototypeManager)
|
||||
public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IPrototypeManager prototypeManager, IEntityManager entityManager)
|
||||
{
|
||||
_random = IoCManager.Resolve<IRobustRandom>();
|
||||
|
||||
_preferencesManager = preferencesManager;
|
||||
|
||||
var hbox = new HBoxContainer();
|
||||
AddChild(hbox);
|
||||
|
||||
#region Left
|
||||
var margin = new MarginContainer
|
||||
{
|
||||
MarginTopOverride = 10,
|
||||
@@ -61,7 +72,7 @@ namespace Content.Client.UserInterface
|
||||
MarginLeftOverride = 10,
|
||||
MarginRightOverride = 10
|
||||
};
|
||||
AddChild(margin);
|
||||
hbox.AddChild(margin);
|
||||
|
||||
var vBox = new VBoxContainer();
|
||||
margin.AddChild(vBox);
|
||||
@@ -98,7 +109,7 @@ namespace Content.Client.UserInterface
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand
|
||||
};
|
||||
var nameLabel = new Label {Text = Loc.GetString("Name:")};
|
||||
var nameLabel = new Label { Text = Loc.GetString("Name:") };
|
||||
_nameEdit = new LineEdit
|
||||
{
|
||||
CustomMinimumSize = (270, 0),
|
||||
@@ -119,7 +130,7 @@ namespace Content.Client.UserInterface
|
||||
|
||||
#endregion Name
|
||||
|
||||
var tabContainer = new TabContainer {SizeFlagsVertical = SizeFlags.FillExpand};
|
||||
var tabContainer = new TabContainer { SizeFlagsVertical = SizeFlags.FillExpand };
|
||||
vBox.AddChild(tabContainer);
|
||||
|
||||
#region Appearance
|
||||
@@ -141,7 +152,7 @@ namespace Content.Client.UserInterface
|
||||
{
|
||||
var panel = HighlightedContainer();
|
||||
var hBox = new HBoxContainer();
|
||||
var sexLabel = new Label {Text = Loc.GetString("Sex:")};
|
||||
var sexLabel = new Label { Text = Loc.GetString("Sex:") };
|
||||
|
||||
var sexButtonGroup = new ButtonGroup();
|
||||
|
||||
@@ -171,8 +182,8 @@ namespace Content.Client.UserInterface
|
||||
{
|
||||
var panel = HighlightedContainer();
|
||||
var hBox = new HBoxContainer();
|
||||
var ageLabel = new Label {Text = Loc.GetString("Age:")};
|
||||
_ageEdit = new LineEdit {CustomMinimumSize = (40, 0)};
|
||||
var ageLabel = new Label { Text = Loc.GetString("Age:") };
|
||||
_ageEdit = new LineEdit { CustomMinimumSize = (40, 0) };
|
||||
_ageEdit.OnTextChanged += args =>
|
||||
{
|
||||
if (!int.TryParse(args.Text, out var newAge))
|
||||
@@ -348,7 +359,7 @@ namespace Content.Client.UserInterface
|
||||
|
||||
foreach (var antag in prototypeManager.EnumeratePrototypes<AntagPrototype>().OrderBy(a => a.Name))
|
||||
{
|
||||
if(!antag.SetPreference)
|
||||
if (!antag.SetPreference)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -410,6 +421,71 @@ namespace Content.Client.UserInterface
|
||||
|
||||
#endregion Save
|
||||
|
||||
#endregion
|
||||
|
||||
#region Right
|
||||
|
||||
margin = new MarginContainer
|
||||
{
|
||||
MarginTopOverride = 10,
|
||||
MarginBottomOverride = 10,
|
||||
MarginLeftOverride = 10,
|
||||
MarginRightOverride = 10
|
||||
};
|
||||
hbox.AddChild(margin);
|
||||
|
||||
vBox = new VBoxContainer()
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
};
|
||||
hbox.AddChild(vBox);
|
||||
|
||||
#region Preview
|
||||
|
||||
_previewDummy = entityManager.SpawnEntity("HumanMob_Dummy", MapCoordinates.Nullspace);
|
||||
var sprite = _previewDummy.GetComponent<SpriteComponent>();
|
||||
|
||||
// Front
|
||||
var box = new Control()
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.Fill,
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
SizeFlagsStretchRatio = 1f,
|
||||
};
|
||||
vBox.AddChild(box);
|
||||
_previewSprite = new SpriteView
|
||||
{
|
||||
Sprite = sprite,
|
||||
Scale = (6, 6),
|
||||
OverrideDirection = Direction.South,
|
||||
SizeFlagsVertical = SizeFlags.ShrinkCenter,
|
||||
SizeFlagsStretchRatio = 1
|
||||
};
|
||||
box.AddChild(_previewSprite);
|
||||
|
||||
// Side
|
||||
box = new Control()
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.Fill,
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
SizeFlagsStretchRatio = 1f,
|
||||
};
|
||||
vBox.AddChild(box);
|
||||
_previewSpriteSide = new SpriteView
|
||||
{
|
||||
Sprite = sprite,
|
||||
Scale = (6, 6),
|
||||
OverrideDirection = Direction.East,
|
||||
SizeFlagsVertical = SizeFlags.ShrinkCenter,
|
||||
SizeFlagsStretchRatio = 1
|
||||
};
|
||||
box.AddChild(_previewSpriteSide);
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
if (preferencesManager.ServerDataLoaded)
|
||||
{
|
||||
LoadServerData();
|
||||
@@ -420,6 +496,16 @@ namespace Content.Client.UserInterface
|
||||
IsDirty = false;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing)
|
||||
return;
|
||||
|
||||
_previewDummy.Delete();
|
||||
_preferencesManager.OnServerDataLoaded -= LoadServerData;
|
||||
}
|
||||
|
||||
private void LoadServerData()
|
||||
{
|
||||
Profile = (HumanoidCharacterProfile) _preferencesManager.Preferences.SelectedCharacter;
|
||||
@@ -458,6 +544,7 @@ namespace Content.Client.UserInterface
|
||||
set
|
||||
{
|
||||
_isDirty = value;
|
||||
UpdatePreview();
|
||||
UpdateSaveButton();
|
||||
}
|
||||
}
|
||||
@@ -503,6 +590,12 @@ namespace Content.Client.UserInterface
|
||||
_saveButton.Disabled = Profile is null || !IsDirty;
|
||||
}
|
||||
|
||||
private void UpdatePreview()
|
||||
{
|
||||
_previewDummy.GetComponent<HumanoidAppearanceComponent>().UpdateFromProfile(Profile);
|
||||
LobbyCharacterPreviewPanel.GiveDummyJobClothes(_previewDummy, Profile);
|
||||
}
|
||||
|
||||
public void UpdateControls()
|
||||
{
|
||||
if (Profile is null) return;
|
||||
@@ -514,6 +607,8 @@ namespace Content.Client.UserInterface
|
||||
UpdateJobPriorities();
|
||||
UpdateAntagPreferences();
|
||||
|
||||
UpdatePreview();
|
||||
|
||||
_preferenceUnavailableButton.SelectId((int) Profile.PreferenceUnavailable);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user