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