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
8 changes: 8 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,12 @@ 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);
sprite.Scale = new Vector2(height, height);
// Parkstation-HeightSlider End

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

Expand Down Expand Up @@ -194,6 +201,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
6 changes: 6 additions & 0 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml
DEATHB4DEFEAT marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@
<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="100" />
<Slider Name="CHeightSlider" MinValue="0.5" Value="1" MaxValue="1.5" HorizontalExpand="True" Margin="5 0 5 0" />
<Button Name="CHeightReset" Text="{Loc 'humanoid-profile-editor-reset-height-button'}" />
</BoxContainer>
</BoxContainer>
<!-- Skin -->
Expand Down
61 changes: 61 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,7 @@ 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 TabContainer _tabContainer => CTabContainer;
private BoxContainer _jobList => CJobList;
Expand Down Expand Up @@ -191,6 +194,38 @@ 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);
};

#endregion Height
// Parkstation-HeightSlider End

#region Skin


Expand Down Expand Up @@ -831,6 +866,14 @@ private void SetBackpack(BackpackPreference newBackpack)
IsDirty = true;
}

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

public void Save()
{
IsDirty = false;
Expand Down Expand Up @@ -1006,6 +1049,23 @@ 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));
}
// Parkstation-HeightSlider End

private void UpdateHairPickers()
{
if (Profile == null)
Expand Down Expand Up @@ -1156,6 +1216,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 @@ -42,6 +42,7 @@ private static HumanoidCharacterProfile CharlieCharlieson()
"Charlie Charlieson",
"The biggest boy around.",
"Human",
1,
21,
Sex.Male,
Gender.Epicene,
Expand Down
Loading
Loading