Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
LankLTE authored and revsys413 committed Apr 3, 2024
1 parent 4fe623a commit 8c10ac9
Show file tree
Hide file tree
Showing 20 changed files with 2,886 additions and 7 deletions.
10 changes: 10 additions & 0 deletions Content.Client/Humanoid/HumanoidAppearanceSystem.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Numerics;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Preferences;
using Robust.Client.GameObjects;
using Robust.Client.Console;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

Expand All @@ -12,6 +14,8 @@ public sealed class HumanoidAppearanceSystem : SharedHumanoidAppearanceSystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly MarkingManager _markingManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;

public override void Initialize()
{
Expand All @@ -30,6 +34,11 @@ private void UpdateSprite(HumanoidAppearanceComponent component, SpriteComponent
UpdateLayers(component, sprite);
ApplyMarkingSet(component, sprite);

var speciesPrototype = _prototypeManager.Index<SpeciesPrototype>(component.Species);
var height = Math.Clamp(MathF.Round(component.Height, 1), speciesPrototype.MinHeight, speciesPrototype.MaxHeight); // should NOT be locked, at all

sprite.Scale = new Vector2(speciesPrototype.ScaleHeight ? height : 1f, height);

sprite[sprite.LayerMapReserveBlank(HumanoidVisualLayers.Eyes)].Color = component.EyeColor;
}

Expand Down Expand Up @@ -194,6 +203,7 @@ public override void LoadProfile(EntityUid uid, HumanoidCharacterProfile profile
humanoid.Species = profile.Species;
humanoid.SkinColor = profile.Appearance.SkinColor;
humanoid.EyeColor = profile.Appearance.EyeColor;
humanoid.Height = profile.Height;

UpdateSprite(humanoid, Comp<SpriteComponent>(uid));
}
Expand Down
7 changes: 7 additions & 0 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@
<Label Text="{Loc 'humanoid-profile-editor-spawn-priority-label'}" />
<Control HorizontalExpand="True"/>
<OptionButton Name="CSpawnPriorityButton" HorizontalAlignment="Right" />
</BoxContainer>
<!-- Height -->
<BoxContainer HorizontalExpand="True">
<Label Text="{Loc 'humanoid-profile-editor-height-label'}" />
<Label Name="CHeightLabel" Text="1" />
<Button Name="CHeightReset" Text="{Loc 'humanoid-profile-editor-reset-height-button'}"/>
<LineEdit HorizontalAlignment="Right" HorizontalExpand="True" Name="CHeight" MinSize="40 0" Text="1.0" />
</BoxContainer>
</BoxContainer>
<!-- Skin -->
Expand Down
55 changes: 55 additions & 0 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using System.Linq;
using System.Numerics;
using Content.Client.Guidebook;
Expand Down Expand Up @@ -78,6 +79,7 @@ public sealed partial class HumanoidProfileEditor : Control
private SingleMarkingPicker _hairPicker => CHairStylePicker;
private SingleMarkingPicker _facialHairPicker => CFacialHairPicker;
private EyeColorPicker _eyesPicker => CEyeColorPicker;
private LineEdit _heightPicker => CHeight;

private TabContainer _tabContainer => CTabContainer;
private BoxContainer _jobList => CJobList;
Expand Down Expand Up @@ -108,6 +110,8 @@ public sealed partial class HumanoidProfileEditor : Control

public event Action<HumanoidCharacterProfile, int>? OnProfileChanged;

private float _defaultHeight = 1f;

public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IPrototypeManager prototypeManager,
IEntityManager entityManager, IConfigurationManager configurationManager)
{
Expand Down Expand Up @@ -196,6 +200,35 @@ public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IProt

#endregion Species

#region Height


_heightPicker.OnTextChanged += args =>
{
if (Profile is null || !float.TryParse(args.Text, out var newHeight))
return;
var prototype = _prototypeManager.Index<SpeciesPrototype>(Profile.Species);
if (newHeight < prototype.MinHeight)
newHeight = prototype.MinHeight;
if (newHeight > prototype.MaxHeight)
newHeight = prototype.MaxHeight;
CHeightLabel.Text = MathF.Round(newHeight, 1).ToString("G");
SetProfileHeight(MathF.Round(newHeight, 1));
};

CHeightReset.OnPressed += _ =>
{
_heightPicker.Text = _defaultHeight.ToString(CultureInfo.InvariantCulture);
CHeightLabel.Text = _defaultHeight.ToString(CultureInfo.InvariantCulture);
SetProfileHeight(_defaultHeight);
};

#endregion Height

#region Skin


Expand Down Expand Up @@ -869,6 +902,12 @@ private void SetBackpack(BackpackPreference newBackpack)
IsDirty = true;
}

private void SetProfileHeight(float height)
{
Profile = Profile?.WithHeight(height);
IsDirty = true;
}

private void SetSpawnPriority(SpawnPriorityPreference newSpawnPriority)
{
Profile = Profile?.WithSpawnPriorityPreference(newSpawnPriority);
Expand Down Expand Up @@ -1069,6 +1108,21 @@ private void UpdateBackpackControls()
_backpackButton.SelectId((int) Profile.Backpack);
}

private void UpdateHeightControls()
{
if (Profile == null)
{
return;
}

var species = _speciesList.Find(x => x.ID == Profile.Species);
if (species != null)
_defaultHeight = species.DefaultHeight;

_heightPicker.Text = Profile.Height.ToString();
CHeightLabel.Text = Profile.Height.ToString();
}

private void UpdateSpawnPriorityControls()
{
if (Profile == null)
Expand Down Expand Up @@ -1230,6 +1284,7 @@ public void UpdateControls()
UpdateHairPickers();
UpdateCMarkingsHair();
UpdateCMarkingsFacialHair();
UpdateHeightControls();

_preferenceUnavailableButton.SelectId((int) Profile.PreferenceUnavailable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private static HumanoidCharacterProfile CharlieCharlieson()
"Charlie Charlieson",
"The biggest boy around.",
"Human",
1,
21,
Sex.Male,
Gender.Epicene,
Expand Down
Loading

0 comments on commit 8c10ac9

Please sign in to comment.