Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
50 changes: 49 additions & 1 deletion Content.Client/Lobby/UI/HumanoidProfileEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,54 @@
<OptionButton Name="SpawnPriorityButton" HorizontalAlignment="Right" />
</BoxContainer>
</BoxContainer>
<!-- DEN Start -->
<!-- Height -->
<BoxContainer Orientation="Vertical" Margin="10">
<Label Text="{Loc 'humanoid-profile-editor-scale-editor-label'}" />
<PanelContainer StyleClasses="BackgroundPanel" HorizontalExpand="True" >
<BoxContainer Orientation="Horizontal" MinHeight="320">
<!-- Scale Previews -->
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" HorizontalAlignment="Center">
<BoxContainer Orientation="Vertical" VerticalAlignment="Bottom">
<profile:ProfilePreviewSpriteView Name="UristHeightView" Scale="6 6" Margin="4" SizeFlagsStretchRatio="1"/>
<Label Name = "UristHeightDisplay" Align="Center"/>
</BoxContainer>
<BoxContainer Orientation="Vertical" VerticalAlignment="Bottom">
<profile:ProfilePreviewSpriteView Name="CharHeightView" Scale="6 6" Margin="4" SizeFlagsStretchRatio="1"/>
<Label Name = "CharHeightDisplay" Align="Center"/>
</BoxContainer>
</BoxContainer>
<!-- Slider Box -->
<Button HorizontalExpand="True" StyleClasses="BackgroundPanelDark" Disabled="True">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal" Margin="5">
<BoxContainer Orientation="Vertical">
<Label Text = "{Loc 'humanoid-profile-editor-scale-editor-label-height'}" Align="Left" Margin="5 0 5 0"/>
<Label Text = "{Loc 'humanoid-profile-editor-scale-editor-label-width'}" Align="Left" Margin="5 5 5 0"/>
</BoxContainer>
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
<Slider HorizontalExpand="True" Name="Height" />
<Button Name="HeightReset" Text="Reset" />
</BoxContainer>
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
<Slider HorizontalExpand="True" Name="Width" />
<Button Name="WidthReset" Text="Reset" />
</BoxContainer>
</BoxContainer>
</BoxContainer>
<PanelContainer HorizontalExpand="True" StyleClasses="BackgroundPanel">
<BoxContainer Orientation="Vertical" >
<Label Name = "ExactScale" Align="Left"/>
<!--<RichTextLabel Text="{Loc 'humanoid-profile-editor-scale-editor-note'}" Margin="0 5 0 5"/>-->
</BoxContainer>
</PanelContainer>
</BoxContainer>
</Button>
</BoxContainer>
</PanelContainer>
</BoxContainer>
<!-- DEN End -->
<!-- Skin -->
<BoxContainer Margin="10" HorizontalExpand="True" Orientation="Vertical">
<Label Text="{Loc 'humanoid-profile-editor-skin-color-label'}" />
Expand Down Expand Up @@ -134,7 +182,7 @@
</BoxContainer>
<!-- Right side -->
<BoxContainer Orientation="Vertical" VerticalExpand="True" VerticalAlignment="Center">
<profile:ProfilePreviewSpriteView Name="SpriteView" Scale="8 8" Margin="4" SizeFlagsStretchRatio="1" />
<profile:ProfilePreviewSpriteView Name="SpriteView" Scale="8 8" Margin="4" SizeFlagsStretchRatio="1" MaxWidth="256" MinWidth="256" />
<BoxContainer Orientation="Horizontal" HorizontalAlignment="Center" Margin="0 5">
<Button Name="SpriteRotateLeft" Text="◀" StyleClasses="OpenRight" />
<cc:VSeparator Margin="2 0 3 0" />
Expand Down
43 changes: 43 additions & 0 deletions Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public HumanoidProfileEditor(
SpeciesButton.SelectId(args.Id);
SetSpecies(_species[args.Id].ID);
OnSkinColorOnValueChanged();
UpdateScaleSliders(); // DEN
};

#region Skin
Expand Down Expand Up @@ -302,6 +303,37 @@ public HumanoidProfileEditor(
};

#endregion Dummy
// DEN Start, Height Preview and Selector
#region Height

UpdateScaleLabels();

Height.OnValueChanged += _ =>
{
UpdateScale(false, true);
CharHeightView.InvalidateMeasure();
SpriteView.InvalidateMeasure();
};

Width.OnValueChanged += _ =>
{
UpdateScale(true, false);
CharHeightView.InvalidateMeasure();
SpriteView.InvalidateMeasure();
};

HeightReset.OnPressed += _ =>
{
ResetHeight();
};

WidthReset.OnPressed += _ =>
{
ResetWidth();
};

#endregion Height
// DEN End, Height Preview and Selector

#endregion Left

Expand Down Expand Up @@ -342,6 +374,11 @@ private void ReloadPreview()

SpriteView.LoadPreview(Profile, JobOverride, ShowClothes.Pressed);

// DEN Start, height view
UristHeightView.LoadPreview(new HumanoidCharacterProfile(), null, false);
CharHeightView.LoadPreview(Profile, JobOverride, ShowClothes.Pressed);
// DEN End, height view

// Check and set the dirty flag to enable the save/reset buttons as appropriate.
SetDirty();
}
Expand Down Expand Up @@ -376,6 +413,7 @@ public void SetProfile(HumanoidCharacterProfile? profile, int? slot)
UpdateEyePickers();
UpdateSaveButton();
UpdateMarkings();
UpdateScaleSliders(); // DEN

RefreshAntags();
RefreshJobs();
Expand All @@ -401,6 +439,11 @@ private void ReloadProfilePreview()

SpriteView.ReloadProfilePreview(Profile);

// DEN Start, height view
UristHeightView.ReloadProfilePreview(new HumanoidCharacterProfile());
CharHeightView.ReloadProfilePreview(Profile);
// DEN End, height view

// Check and set the dirty flag to enable the save/reset buttons as appropriate.
SetDirty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
using Content.Client.Sprite; // DEN
using System.Numerics; // DEN

namespace Content.Client.Lobby.UI.ProfileEditorControls;

Expand All @@ -28,6 +30,7 @@ private void ReloadHumanoidEntity(HumanoidCharacterProfile humanoid)
return;

EntMan.System<SharedVisualBodySystem>().ApplyProfileTo(PreviewDummy, humanoid);
EntMan.System<ScaleVisualsSystem>().SetSpriteScale(PreviewDummy,new Vector2(humanoid.Width, humanoid.Height)); // DEN
}

/// <summary>
Expand All @@ -53,6 +56,7 @@ private void LoadHumanoidEntity(HumanoidCharacterProfile? humanoid, JobPrototype
var dummy = _prototypeManager.Index(humanoid.Species).DollPrototype;
PreviewDummy = EntMan.SpawnEntity(dummy, MapCoordinates.Nullspace);
EntMan.System<SharedVisualBodySystem>().ApplyProfileTo(PreviewDummy, humanoid);
EntMan.System<ScaleVisualsSystem>().SetSpriteScale(PreviewDummy,new Vector2(humanoid.Width, humanoid.Height)); // DEN
}
else
{
Expand Down
153 changes: 153 additions & 0 deletions Content.Client/_DEN/Lobby/UI/Appearance/HumanoidProfileEditor.Scale.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using System.Numerics;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Preferences;
using Robust.Client.UserInterface.Controls;

namespace Content.Client.Lobby.UI;

public sealed partial class HumanoidProfileEditor
{
private void UpdateScaleSliders()
{
if (Profile == null)
return;

var species = _prototypeManager.Index(Profile.Species);
var height = Profile?.Height ?? species.DefaultHeight;
var width = Profile?.Width ?? species.DefaultWidth;

SetAxisSliderBoundsAndValue(Height, height, species.DefaultHeightBounds);
SetAxisSliderBoundsAndValue(Width, width, species.DefaultWidthBounds);

UpdateScale(true, true);
SetDirty();
}

private static void SetAxisSliderBoundsAndValue(Slider slider, float value, (float min, float max) bounds)
{
slider.MaxValue = bounds.max;
slider.MinValue = bounds.min;
slider.SetValueWithoutEvent(value);
}

private void UpdateScale(bool constrainHeight, bool constrainWidth)
{
if (Profile == null)
return;

var species = _prototypeManager.Index(Profile.Species);

var heightBounds = species.DefaultHeightBounds;
var widthBounds = species.DefaultWidthBounds;

var height = ClampScale(Profile.Height, heightBounds);
var width = ClampScale(Profile.Width, widthBounds);

var constrainedScale = ConstrainedScale(
height,
width,
species,
constrainHeight,
constrainWidth);

height = ClampScale(constrainedScale.height, heightBounds);
width = ClampScale(constrainedScale.width, widthBounds);

Profile = Profile.WithHeight(Height.Value,_prototypeManager);
Profile = Profile.WithWidth(Width.Value,_prototypeManager);

Height.SetValueWithoutEvent(height);
Width.SetValueWithoutEvent(width);

SetDirty();
UpdateScaleLabels();
ReloadProfilePreview();
}

private static (float height, float width) ConstrainedScale(
float height,
float width,
SpeciesPrototype species,
bool constrainHeight,
bool constrainWidth)
{
var ratio = height / width;
var maximumDifference = species.MaximumScaleDifference;
if (ratio < 1 / maximumDifference || ratio > maximumDifference)
{
var targetRatio = ratio < 1 / maximumDifference ? 1 / maximumDifference : maximumDifference;
if (constrainWidth)
width = height / targetRatio;
if (constrainHeight)
height = width * targetRatio;
}

height = ClampScale(height, species.DefaultHeightBounds);
width = ClampScale(width, species.DefaultWidthBounds);

return (height, width);
}

private static float ClampScale(float toClamp, (float min, float max) bounds)
{
return Math.Clamp(toClamp, bounds.min, bounds.max);
}

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

var species = _prototypeManager.Index(Profile.Species);

var height = Profile.Height;
var heightInCm = species.DefaultHeightMetric * height;
var feetAndInches = ConvertMetricHeightToImperial(heightInCm);

UristHeightDisplay.Text = Loc.GetString("humanoid-profile-editor-scale-height-label",
("cm", 176.1), // This is hardcoded because i really really cba.
("feet", 5),
("inches", 9));

CharHeightDisplay.Text = Loc.GetString("humanoid-profile-editor-scale-height-label",
("cm", Math.Round(heightInCm, 1)),
("feet", feetAndInches.feet),
("inches", feetAndInches.inches));

ExactScale.Text = Loc.GetString("humanoid-profile-editor-exact-scale",
("height", Math.Round(Height.Value, 2)),
("width", Math.Round(Width.Value, 2)));
}

public static (int feet, int inches) ConvertMetricHeightToImperial(float heightInCm)
{
var totalInches = heightInCm / 2.54;

var feet = (int)Math.Floor(totalInches / 12);

var inches = (int)totalInches - feet * 12;

return (feet, inches);
}
private void ResetHeight()
{
if (Profile == null)
return;

var species = _prototypeManager.Index(Profile.Species);

Height.Value = species.DefaultHeight;
UpdateScaleSliders();
}

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

var species = _prototypeManager.Index(Profile.Species);

Width.Value = species.DefaultWidth;
UpdateScaleSliders();
}
}
Loading
Loading