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
3 changes: 0 additions & 3 deletions Content.Client/Humanoid/HumanoidAppearanceSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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 @@ -14,8 +13,6 @@ 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 Down
9 changes: 5 additions & 4 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IProt
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 stringValue = Regex.Replace(value.ToString(CultureInfo.InvariantCulture), @"\.([0-9][0-9]).*", ".$1"); // Hide the extra decimals
CHeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", stringValue));
var height = value.ToString(CultureInfo.InvariantCulture);
CHeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", height.Length > 4 ? height[..4] : height));
SetProfileHeight(value);
};

Expand Down Expand Up @@ -1060,8 +1060,9 @@ private void UpdateHeightControls()
_heightSlider.MinValue = species.MinHeight;
_heightSlider.Value = Profile.Height;
_heightSlider.MaxValue = species.MaxHeight;
var stringValue = Regex.Replace(Profile.Height.ToString(CultureInfo.InvariantCulture), @"\.([0-9][0-9]).*", ".$1"); // Hide the extra decimals
CHeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", stringValue));

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

Expand Down
25 changes: 21 additions & 4 deletions Content.Shared/Humanoid/SharedHumanoidAppearanceSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,26 @@ public void SetSex(EntityUid uid, Sex sex, bool sync = true, HumanoidAppearanceC
}
}

// Parkstation-HeightSlider Start
/// <summary>
/// Set a humanoid mob's sex. This will not change their gender.
DEATHB4DEFEAT marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <param name="uid">The humanoid mob's UID.</param>
/// <param name="height">The height to set the mob to.</param>
/// <param name="sync">Whether to immediately synchronize this to the humanoid mob, or not.</param>
/// <param name="humanoid">Humanoid component of the entity</param>
public void SetHeight(EntityUid uid, float height, bool sync = true, HumanoidAppearanceComponent? humanoid = null)
{
if (!Resolve(uid, ref humanoid) || Math.Abs(humanoid.Height - height) < 0.01f)
DEATHB4DEFEAT marked this conversation as resolved.
Show resolved Hide resolved
return;

humanoid.Height = height;

if (sync)
Dirty(humanoid);
}
// Parkstation-HeightSlider End

/// <summary>
/// Loads a humanoid character profile directly onto this humanoid mob.
/// </summary>
Expand Down Expand Up @@ -330,10 +350,7 @@ public virtual void LoadProfile(EntityUid uid, HumanoidCharacterProfile profile,
}

humanoid.Age = profile.Age;
// Parkstation-HeightSlider Start
humanoid.Height = profile.Height;
_heightAdjust.SetScale(uid, profile.Height);
// Parkstation-HeightSlider End
_heightAdjust.SetScale(uid, profile.Height); // Parkstation-HeightSlider

Dirty(humanoid);
}
Expand Down
1 change: 1 addition & 0 deletions Content.Shared/Preferences/HumanoidCharacterProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public static HumanoidCharacterProfile RandomWithSpecies(string species = Shared

public string Name { get; private set; }
public string FlavorText { get; private set; }
[DataField("species")] // Parkstation-HeightSlider // :)
public string Species { get; private set; }

[DataField("height")]
Expand Down
DEATHB4DEFEAT marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.Humanoid;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Systems;
using Robust.Shared.Physics;
Expand All @@ -9,14 +10,15 @@ public sealed class HeightAdjustSystem : EntitySystem
{
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedContentEyeSystem _eye = default!;
[Dependency] private readonly SharedHumanoidAppearanceSystem _appearance = default!;


/// <summary>
/// Changes the density of fixtures and zoom of eyes based on a provided float scale
/// </summary>
/// <param name="uid">The entity to modify values for</param>
/// <param name="scale">The scale to multiply values by</param>
/// <returns>True if both operations succeeded</returns>
/// <returns>True if all operations succeeded</returns>
public bool SetScale(EntityUid uid, float scale)
{
var succeeded = true;
Expand All @@ -26,9 +28,18 @@ public bool SetScale(EntityUid uid, float scale)
succeeded = false;

if (EntityManager.TryGetComponent<FixturesComponent>(uid, out var fixtures))
{
foreach (var fixture in fixtures.Fixtures)
// _physics.SetDensity(uid, fixture.Key, fixture.Value, fixture.Value.Density * scale); // If you want to do the same thing without changing size
{
// _physics.SetDensity(uid, fixture.Key, fixture.Value, fixture.Value.Density * scale); // This does the same thing as below, just without modifying the fixture size
_physics.SetRadius(uid, fixture.Key, fixture.Value, fixture.Value.Shape, fixture.Value.Shape.Radius * scale);
}
}
else
succeeded = false;

if (EntityManager.HasComponent<HumanoidAppearanceComponent>(uid))
_appearance.SetHeight(uid, scale);
else
succeeded = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
components:
- type: HumanoidAppearance
species: Felinid
initial: Felinid
- type: Fixtures
fixtures: # TODO: This needs a second fixture just for mob collisions.
fix1:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- type: humanoidProfile
id: Felinid
profile:
species: Felinid
height: 0.8
Loading