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

Port Height Sliders #458

Merged
merged 28 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
83e9a88
Start port
VMSolidus Jun 13, 2024
15b9a75
next
VMSolidus Jun 13, 2024
b080e93
adjust fixutre size and zoom and changed default scales
DEATHB4DEFEAT Jan 28, 2024
899ede9
Merge remote-tracking branch 'Parkstation-new/height-slider' into por…
DEATHB4DEFEAT Jan 28, 2024
166c282
remove datafields that don't exist anymore
DEATHB4DEFEAT Jan 28, 2024
bb6b29b
use string manipulation instead of Regex
DEATHB4DEFEAT Feb 5, 2024
8264ea7
fix height label and default species heights
DEATHB4DEFEAT Feb 5, 2024
b2fbfae
review changes
DEATHB4DEFEAT Feb 10, 2024
7c68d37
width
DEATHB4DEFEAT Feb 10, 2024
4df4a5a
allow scaling by a Vector2 instead of general average scale
DEATHB4DEFEAT Feb 10, 2024
73da808
update width/height sliders when changing species
DEATHB4DEFEAT Feb 12, 2024
0b02013
Update HumanoidCharacterProfile.cs
VMSolidus Jun 13, 2024
a66562f
Oh right
VMSolidus Jun 14, 2024
225da44
Clamp fixtures to prevent door stuck
VMSolidus Jun 16, 2024
0acbf82
Update HeightAdjustSystem.cs
VMSolidus Jun 16, 2024
ae6bc7e
Update HeightAdjustSystem.cs
VMSolidus Jun 16, 2024
2598317
Moving namespace to EE
VMSolidus Jun 16, 2024
133f889
Magnitude is needed here because negative numbers are valid inputs, t…
VMSolidus Jun 16, 2024
5310408
Returning Oni their higher mass, now that fixtures are clamped
VMSolidus Jun 16, 2024
af8bfde
Merge branch 'master' into port-of-height-sliders
VMSolidus Jun 17, 2024
0673211
Two new CVars and height slider now shows actual height in CM
VMSolidus Jun 19, 2024
fabcdfa
Merge branch 'master' into port-of-height-sliders
VMSolidus Jun 19, 2024
639a17e
Height sliders now include weight
VMSolidus Jun 19, 2024
2545218
UI now automatically resizes the preview
VMSolidus Jun 19, 2024
282b207
Apply suggestions from code review
VMSolidus Jun 20, 2024
4b4dbea
Merge branch 'master' into port-of-height-sliders
VMSolidus Jun 20, 2024
57206e7
Apply suggestions from code review
VMSolidus Jun 25, 2024
290d1db
Apply suggestions from code review
VMSolidus Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 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,15 @@ private void UpdateSprite(HumanoidAppearanceComponent component, SpriteComponent
UpdateLayers(component, sprite);
ApplyMarkingSet(component, sprite);

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);

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

Expand Down Expand Up @@ -194,6 +204,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;
humanoid.Width = profile.Width;

UpdateSprite(humanoid, Comp<SpriteComponent>(uid));
}
Expand Down
16 changes: 16 additions & 0 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@
<Label Text="{Loc 'humanoid-profile-editor-spawn-priority-label'}" />
<Control HorizontalExpand="True"/>
<OptionButton Name="CSpawnPriorityButton" 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>
<!--Weight -->
<BoxContainer HorizontalExpand="True">
<Label Name="CWeightLabel" />
</BoxContainer>
</BoxContainer>
<!-- Skin -->
Expand Down
148 changes: 148 additions & 0 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
Expand Down Expand Up @@ -81,6 +82,8 @@ public sealed partial class HumanoidProfileEditor : Control
private SingleMarkingPicker _hairPicker => CHairStylePicker;
private SingleMarkingPicker _facialHairPicker => CFacialHairPicker;
private EyeColorPicker _eyesPicker => CEyeColorPicker;
private Slider _heightSlider => CHeightSlider;
private Slider _widthSlider => CWidthSlider;

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

#endregion Species

#region Height

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

VMSolidus marked this conversation as resolved.
Show resolved Hide resolved

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

_heightSlider.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.MinHeight, prototype.MaxHeight);
var height = MathF.Round(prototype.AverageHeight * value);
CHeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", (int) height));
SetProfileHeight(value);
UpdateWeight();
};

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


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

_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 = MathF.Round(prototype.AverageWidth * value);
CWidthLabel.Text = Loc.GetString("humanoid-profile-editor-width-label", ("width", width));
SetProfileWidth(value);
UpdateWeight();
};

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

prototypeManager.Index(prototype.Prototype).TryGetComponent<FixturesComponent>(out var fixture);
if (fixture != null)
{
var radius = fixture.Fixtures["fix1"].Shape.Radius;
var density = fixture.Fixtures["fix1"].Density;
var avg = (_widthSlider.Value + _heightSlider.Value) / 2;
var weight = MathF.Round(MathF.PI * MathF.Pow(radius * avg, 2) * density);
CWeightLabel.Text = Loc.GetString("humanoid-profile-editor-weight-label", ("weight", (int) weight));
}
else
{
//Whelp, the fixture doesn't exist, guesstimate it instead
VMSolidus marked this conversation as resolved.
Show resolved Hide resolved
CWeightLabel.Text = Loc.GetString("humanoid-profile-editor-weight-label", ("weight", (int) 71));
}



VMSolidus marked this conversation as resolved.
Show resolved Hide resolved

#endregion Height

#region Skin


Expand Down Expand Up @@ -877,6 +960,9 @@ 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();// - Changing species provides inaccurate sliders
UpdateWidthControls();// - Changing species provides inaccurate sliders
VMSolidus marked this conversation as resolved.
Show resolved Hide resolved
UpdateWeight();
RebuildSpriteView(); // they might have different inv so we need a new dummy
UpdateSpeciesGuidebookIcon();
IsDirty = true;
Expand Down Expand Up @@ -907,6 +993,18 @@ private void SetSpawnPriority(SpawnPriorityPreference newSpawnPriority)
IsDirty = true;
}

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

private void SetProfileWidth(float width)
{
Profile = Profile?.WithWidth(width);
IsDirty = true;
}

public void Save()
{
IsDirty = false;
Expand Down Expand Up @@ -1111,6 +1209,53 @@ private void UpdateSpawnPriorityControls()
_spawnPriorityButton.SelectId((int) Profile.SpawnPriority);
}

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 = MathF.Round(species.AverageHeight * _heightSlider.Value);
CHeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", (int) 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 = MathF.Round(species.AverageWidth * _widthSlider.Value);
CWidthLabel.Text = Loc.GetString("humanoid-profile-editor-width-label", ("width", (int) width));
}

private void UpdateWeight()
{
if (Profile == null)
return;
VMSolidus marked this conversation as resolved.
Show resolved Hide resolved
var species = _speciesList.Find(x => x.ID == Profile.Species) ?? _speciesList.First();
_prototypeManager.Index(species.Prototype).TryGetComponent<FixturesComponent>(out var fixture);
if (fixture != null)
{
var radius = fixture.Fixtures["fix1"].Shape.Radius;
var density = fixture.Fixtures["fix1"].Density;
var avg = (Profile.Width + Profile.Height) / 2;
var weight = MathF.Round(MathF.PI * MathF.Pow(radius * avg, 2) * density);
CWeightLabel.Text = Loc.GetString("humanoid-profile-editor-weight-label", ("weight", (int) weight));
}
VMSolidus marked this conversation as resolved.
Show resolved Hide resolved
_previewSpriteView.InvalidateMeasure();
}

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

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