Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Character Height Slider #45

Closed
wants to merge 12 commits into from
14 changes: 14 additions & 0 deletions Content.Client/Humanoid/HumanoidAppearanceSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
using Content.Shared.Humanoid.Prototypes;
Expand Down Expand Up @@ -30,6 +31,17 @@ private void UpdateSprite(HumanoidAppearanceComponent component, SpriteComponent
UpdateLayers(component, sprite);
ApplyMarkingSet(component, sprite);

// Parkstation-HeightSlider Start
var speciesPrototype = _prototypeManager.Index(component.Species);

var height = Math.Clamp(component.Height, speciesPrototype.MinHeight, speciesPrototype.MaxHeight);
var width = Math.Clamp(component.Width, speciesPrototype.MinWidth, speciesPrototype.MaxWidth);
component.Height = height;
component.Width = width;

sprite.Scale = new Vector2(width, height);
// Parkstation-HeightSlider End

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

Expand Down Expand Up @@ -194,6 +206,8 @@ 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; // Parkstation-HeightSlider
humanoid.Width = profile.Width; // Parkstation-HeightSlider

UpdateSprite(humanoid, Comp<SpriteComponent>(uid));
}
Expand Down
12 changes: 12 additions & 0 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@
<Label Text="{Loc 'humanoid-profile-editor-backpack-label'}" />
<Control HorizontalExpand="True"/>
<OptionButton Name="CBackpackButton" HorizontalAlignment="Right" />
</BoxContainer>
<!-- Height -->
<BoxContainer HorizontalExpand="True">
<Label Name="CHeightLabel" MinWidth="110" />
<Slider Name="CHeightSlider" MinValue="0.5" Value="1" MaxValue="1.5" HorizontalExpand="True" Margin="5 0 5 0" />
<Button Name="CHeightReset" Text="{Loc 'ui-options-bind-reset'}" />
</BoxContainer>
<!-- Width -->
<BoxContainer HorizontalExpand="True">
<Label Name="CWidthLabel" MinWidth="110" />
<Slider Name="CWidthSlider" MinValue="0.5" Value="1" MaxValue="1.5" HorizontalExpand="True" Margin="5 0 5 0" />
<Button Name="CWidthReset" Text="{Loc 'ui-options-bind-reset'}" />
</BoxContainer>
</BoxContainer>
<!-- Skin -->
Expand Down
112 changes: 112 additions & 0 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text.RegularExpressions;
using Content.Client.Humanoid;
using Content.Client.Lobby.UI;
using Content.Client.Message;
Expand Down Expand Up @@ -75,6 +77,8 @@ public sealed partial class HumanoidProfileEditor : Control
private SingleMarkingPicker _hairPicker => CHairStylePicker;
private SingleMarkingPicker _facialHairPicker => CFacialHairPicker;
private EyeColorPicker _eyesPicker => CEyeColorPicker;
private Slider _heightSlider => CHeightSlider; // Parkstation-HeightSlider
private Slider _widthSlider => CWidthSlider; // Parkstation-HeightSlider

private TabContainer _tabContainer => CTabContainer;
private BoxContainer _jobList => CJobList;
Expand Down Expand Up @@ -191,6 +195,64 @@ public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IProt

#endregion Species

// Parkstation-HeightSlider Start
#region Height

var prototype = _speciesList.Find(x => x.ID == Profile?.Species) ?? _speciesList.First();


_heightSlider.MinValue = prototype.MinHeight;
_heightSlider.MaxValue = prototype.MaxHeight;
_heightSlider.Value = Profile?.Height ?? prototype.DefaultHeight;
CHeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", _heightSlider.Value));

_heightSlider.OnValueChanged += args =>
{
if (Profile is null)
return;

prototype = _speciesList.Find(x => x.ID == Profile.Species) ?? _speciesList.First(); // Just in case
DEATHB4DEFEAT marked this conversation as resolved.
Show resolved Hide resolved

var value = Math.Clamp(args.Value, prototype.MinHeight, prototype.MaxHeight);
var height = value.ToString(CultureInfo.InvariantCulture);
CHeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", height.Length > 4 ? height[..4] : height));
SetProfileHeight(value);
};

CHeightReset.OnPressed += _ =>
{
_heightSlider.Value = prototype.DefaultHeight;
SetProfileHeight(prototype.DefaultHeight);
};


_widthSlider.MinValue = prototype.MinWidth;
_widthSlider.MaxValue = prototype.MaxWidth;
_widthSlider.Value = Profile?.Width ?? prototype.DefaultWidth;
CWidthLabel.Text = Loc.GetString("humanoid-profile-editor-width-label", ("width", _widthSlider.Value));

_widthSlider.OnValueChanged += args =>
{
if (Profile is null)
return;

prototype = _speciesList.Find(x => x.ID == Profile.Species) ?? _speciesList.First(); // Just in case

var value = Math.Clamp(args.Value, prototype.MinWidth, prototype.MaxWidth);
var width = value.ToString(CultureInfo.InvariantCulture);
CWidthLabel.Text = Loc.GetString("humanoid-profile-editor-width-label", ("width", width.Length > 4 ? width[..4] : width));
SetProfileWidth(value);
};

CWidthReset.OnPressed += _ =>
{
_widthSlider.Value = prototype.DefaultWidth;
SetProfileWidth(prototype.DefaultWidth);
};

#endregion Height
// Parkstation-HeightSlider End

#region Skin


Expand Down Expand Up @@ -808,6 +870,8 @@ private void SetSpecies(string newSpecies)
OnSkinColorOnValueChanged(); // Species may have special color prefs, make sure to update it.
CMarkings.SetSpecies(newSpecies); // Repopulate the markings tab as well.
UpdateSexControls(); // update sex for new species
UpdateHeightControls(); // Parkstation-HeightSlider - Changing species provides inaccurate sliders
UpdateWidthControls(); // Parkstation-HeightSlider - Changing species provides inaccurate sliders
RebuildSpriteView(); // they might have different inv so we need a new dummy
IsDirty = true;
_needUpdatePreview = true;
Expand All @@ -831,6 +895,20 @@ private void SetBackpack(BackpackPreference newBackpack)
IsDirty = true;
}

// Parkstation-HeightSlider Start
private void SetProfileHeight(float height)
{
Profile = Profile?.WithHeight(height);
IsDirty = true;
}

private void SetProfileWidth(float width)
{
Profile = Profile?.WithWidth(width);
IsDirty = true;
}
// Parkstation-HeightSlider End

public void Save()
{
IsDirty = false;
Expand Down Expand Up @@ -1006,6 +1084,38 @@ private void UpdateBackpackControls()
_backpackButton.SelectId((int) Profile.Backpack);
}

// Parkstation-HeightSlider Start
private void UpdateHeightControls()
{
if (Profile == null)
return;

var species = _speciesList.Find(x => x.ID == Profile.Species) ?? _speciesList.First();

_heightSlider.MinValue = species.MinHeight;
_heightSlider.Value = Profile.Height;
_heightSlider.MaxValue = species.MaxHeight;

var height = Profile.Height.ToString(CultureInfo.InvariantCulture);
CHeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", height.Length > 4 ? height[..4] : height));
}

private void UpdateWidthControls()
{
if (Profile == null)
return;

var species = _speciesList.Find(x => x.ID == Profile.Species) ?? _speciesList.First();

_widthSlider.MinValue = species.MinWidth;
_widthSlider.Value = Profile.Width;
_widthSlider.MaxValue = species.MaxWidth;

var width = Profile.Width.ToString(CultureInfo.InvariantCulture);
CWidthLabel.Text = Loc.GetString("humanoid-profile-editor-width-label", ("width", width.Length > 4 ? width[..4] : width));
}
// Parkstation-HeightSlider End

private void UpdateHairPickers()
{
if (Profile == null)
Expand Down Expand Up @@ -1156,6 +1266,8 @@ public void UpdateControls()
UpdateHairPickers();
UpdateCMarkingsHair();
UpdateCMarkingsFacialHair();
UpdateHeightControls();
UpdateWidthControls();

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