Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ngines into upstreammerge
  • Loading branch information
Aidenkrz committed Oct 16, 2024
2 parents a6c1cb8 + 1d9c7a8 commit 456473c
Show file tree
Hide file tree
Showing 33 changed files with 352 additions and 341 deletions.
135 changes: 59 additions & 76 deletions Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public HumanoidProfileEditor(
UpdateHairPickers();
OnSkinColorOnValueChanged();
UpdateCustomSpecieNameEdit();
UpdateHeightWidthSliders();
};

#endregion Species
Expand All @@ -195,76 +196,24 @@ public HumanoidProfileEditor(

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

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

HeightSlider.OnValueChanged += args =>
{
if (Profile is null)
return;
prototype = _species.Find(x => x.ID == Profile.Species) ?? _species.First(); // Just in case
UpdateHeightWidthSliders();
UpdateDimensions(SliderUpdate.Both);

var value = Math.Clamp(args.Value, prototype.MinHeight, prototype.MaxHeight);
var height = MathF.Round(prototype.AverageHeight * value);
HeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", (int) height));
SetProfileHeight(value);
UpdateWeight();
};
HeightSlider.OnValueChanged += _ => UpdateDimensions(SliderUpdate.Height);
WidthSlider.OnValueChanged += _ => UpdateDimensions(SliderUpdate.Width);

HeightReset.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);
WidthLabel.Text = Loc.GetString("humanoid-profile-editor-width-label", ("width", width));

WidthSlider.OnValueChanged += args =>
{
if (Profile is null)
return;
prototype = _species.Find(x => x.ID == Profile.Species) ?? _species.First(); // Just in case
var value = Math.Clamp(args.Value, prototype.MinWidth, prototype.MaxWidth);
var width = MathF.Round(prototype.AverageWidth * value);
WidthLabel.Text = Loc.GetString("humanoid-profile-editor-width-label", ("width", width));
SetProfileWidth(value);
UpdateWeight();
UpdateDimensions(SliderUpdate.Height);
};

WidthReset.OnPressed += _ =>
{
WidthSlider.Value = prototype.DefaultWidth;
SetProfileWidth(prototype.DefaultWidth);
UpdateWeight();
UpdateDimensions(SliderUpdate.Width);
};

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);
WeightLabel.Text = Loc.GetString("humanoid-profile-editor-weight-label", ("weight", (int) weight));
}
else
{
// Whelp, the fixture doesn't exist, guesstimate it instead
WeightLabel.Text = Loc.GetString("humanoid-profile-editor-weight-label", ("weight", (int) 71));
}

#endregion Height

#region Skin
Expand Down Expand Up @@ -697,8 +646,7 @@ public void SetProfile(HumanoidCharacterProfile? profile, int? slot)
UpdateHairPickers();
UpdateCMarkingsHair();
UpdateCMarkingsFacialHair();
UpdateHeightControls();
UpdateWidthControls();
UpdateHeightWidthSliders();
UpdateWeight();
UpdateCharacterRequired();

Expand Down Expand Up @@ -1193,8 +1141,7 @@ private void SetSpecies(string newSpecies)
UpdateSexControls(); // Update sex for new species
UpdateCharacterRequired();
// Changing species provides inaccurate sliders without these
UpdateHeightControls();
UpdateWidthControls();
UpdateHeightWidthSliders();
UpdateWeight();
UpdateSpeciesGuidebookIcon();
IsDirty = true;
Expand Down Expand Up @@ -1411,34 +1358,68 @@ private void UpdateSpawnPriorityControls()
SpawnPriorityButton.SelectId((int) Profile.SpawnPriority);
}

private void UpdateHeightControls()
private void UpdateHeightWidthSliders()
{
if (Profile == null)
return;

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

HeightSlider.MinValue = species.MinHeight;
HeightSlider.Value = Profile.Height;
HeightSlider.MaxValue = species.MaxHeight;
HeightSlider.Value = Profile?.Height ?? species.DefaultHeight;

WidthSlider.MinValue = species.MinWidth;
WidthSlider.MaxValue = species.MaxWidth;
WidthSlider.Value = Profile?.Width ?? species.DefaultWidth;

var height = MathF.Round(species.AverageHeight * HeightSlider.Value);
HeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", (int) height));

var width = MathF.Round(species.AverageWidth * WidthSlider.Value);
WidthLabel.Text = Loc.GetString("humanoid-profile-editor-width-label", ("width", (int) width));
}

private void UpdateWidthControls()
private enum SliderUpdate
{
if (Profile == null)
return;
Height,
Width,
Both
}

var species = _species.Find(x => x.ID == Profile.Species) ?? _species.First();
private void UpdateDimensions(SliderUpdate updateType)
{
var species = _species.Find(x => x.ID == Profile?.Species) ?? _species.First();

WidthSlider.MinValue = species.MinWidth;
WidthSlider.Value = Profile.Width;
WidthSlider.MaxValue = species.MaxWidth;
if (Profile == null) return;

var heightValue = Math.Clamp(HeightSlider.Value, species.MinHeight, species.MaxHeight);
var widthValue = Math.Clamp(WidthSlider.Value, species.MinWidth, species.MaxWidth);
var sizeRatio = species.SizeRatio;
var ratio = heightValue / widthValue;

if (updateType == SliderUpdate.Height || updateType == SliderUpdate.Both)
if (ratio < 1 / sizeRatio || ratio > sizeRatio)
widthValue = heightValue / (ratio < 1 / sizeRatio ? (1 / sizeRatio) : sizeRatio);

if (updateType == SliderUpdate.Width || updateType == SliderUpdate.Both)
if (ratio < 1 / sizeRatio || ratio > sizeRatio)
heightValue = widthValue * (ratio < 1 / sizeRatio ? (1 / sizeRatio) : sizeRatio);


heightValue = Math.Clamp(heightValue, species.MinHeight, species.MaxHeight);
widthValue = Math.Clamp(widthValue, species.MinWidth, species.MaxWidth);

HeightSlider.Value = heightValue;
WidthSlider.Value = widthValue;

SetProfileHeight(heightValue);
SetProfileWidth(widthValue);

var height = MathF.Round(species.AverageHeight * HeightSlider.Value);
HeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", (int) height));

var width = MathF.Round(species.AverageWidth * WidthSlider.Value);
WidthLabel.Text = Loc.GetString("humanoid-profile-editor-width-label", ("width", (int) width));

UpdateWeight();
}

private void UpdateWeight()
Expand All @@ -1456,7 +1437,9 @@ private void UpdateWeight()
var avg = (Profile.Width + Profile.Height) / 2;
var weight = MathF.Round(MathF.PI * MathF.Pow(radius * avg, 2) * density);
WeightLabel.Text = Loc.GetString("humanoid-profile-editor-weight-label", ("weight", (int) weight));
}
}
else // Whelp, the fixture doesn't exist, guesstimate it instead
WeightLabel.Text = Loc.GetString("humanoid-profile-editor-weight-label", ("weight", (int) 71));

SpriteView.InvalidateMeasure();
}
Expand Down
5 changes: 5 additions & 0 deletions Content.Shared/Climbing/Systems/ClimbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,11 @@ public void ForciblySetClimbing(EntityUid uid, EntityUid climbable, ClimbingComp
Climb(uid, uid, climbable, true, component);
}

public void ForciblyStopClimbing(EntityUid uid, ClimbingComponent? climbing = null, FixturesComponent? fixtures = null)
{
StopClimb(uid, climbing, fixtures);
}

private void OnBuckleChange(EntityUid uid, ClimbingComponent component, ref BuckleChangeEvent args)
{
if (!args.Buckling)
Expand Down
6 changes: 6 additions & 0 deletions Content.Shared/Humanoid/Prototypes/SpeciesPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ public sealed partial class SpeciesPrototype : IPrototype
[DataField]
public int MaxAge = 120;

/// <summary>
/// The minimum height and width ratio for this species
/// </summary>
[DataField]
public float SizeRatio = 1.2f;

/// <summary>
/// The minimum height for this species
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion Content.Shared/Humanoid/SharedHumanoidAppearanceSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,14 @@ public virtual void LoadProfile(EntityUid uid, HumanoidCharacterProfile profile,

humanoid.CustomSpecieName = profile.Customspeciename;

_heightAdjust.SetScale(uid, new Vector2(profile.Width, profile.Height));
var species = _proto.Index(humanoid.Species);

if (profile.Height <= 0 || profile.Width <= 0)
SetScale(uid, new Vector2(species.DefaultWidth, species.DefaultHeight), true, humanoid);
else
SetScale(uid, new Vector2(profile.Width, profile.Height), true, humanoid);

_heightAdjust.SetScale(uid, new Vector2(humanoid.Width, humanoid.Height));

humanoid.LastProfileLoaded = profile; // DeltaV - let paradox anomaly be cloned

Expand Down
30 changes: 28 additions & 2 deletions Content.Shared/Standing/StandingStateSystem.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Content.Shared.Buckle;
using Content.Shared.Buckle.Components;
using Content.Shared.Climbing.Systems;
using Content.Shared.Climbing.Components;
using Content.Shared.Hands.Components;
using Content.Shared.Movement.Systems;
using Content.Shared.Physics;
using Content.Shared.Rotation;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Systems;
using System.Linq;

namespace Content.Shared.Standing;

Expand All @@ -17,9 +20,11 @@ public sealed class StandingStateSystem : EntitySystem
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
[Dependency] private readonly SharedBuckleSystem _buckle = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly ClimbSystem _climb = default!;

// If StandingCollisionLayer value is ever changed to more than one layer, the logic needs to be edited.
private const int StandingCollisionLayer = (int) CollisionGroup.MidImpassable;
private const int StandingCollisionLayer = (int)CollisionGroup.MidImpassable;

public bool IsDown(EntityUid uid, StandingStateComponent? standingState = null)
{
Expand Down Expand Up @@ -88,6 +93,9 @@ public bool Down(EntityUid uid, bool playSound = true, bool dropHeldItems = true
_audio.PlayPredicted(standingState.DownSound, uid, null);

_movement.RefreshMovementSpeedModifiers(uid);

Climb(uid);

return true;
}

Expand Down Expand Up @@ -118,6 +126,7 @@ public bool Stand(EntityUid uid,
}

standingState.CurrentState = StandingState.Standing;

Dirty(uid, standingState);
RaiseLocalEvent(uid, new StoodEvent(), false);

Expand All @@ -134,10 +143,27 @@ public bool Stand(EntityUid uid,
standingState.ChangedFixtures.Clear();
_movement.RefreshMovementSpeedModifiers(uid);

Climb(uid);

return true;
}

private void Climb(EntityUid uid)
{
_climb.ForciblyStopClimbing(uid);

var entityDistances = new Dictionary<EntityUid, float>();

foreach (var entity in _lookup.GetEntitiesInRange(uid, 0.3f))
if (HasComp<ClimbableComponent>(entity))
entityDistances[entity] = (Transform(uid).Coordinates.Position - Transform(entity).Coordinates.Position).LengthSquared();

if (entityDistances.Count > 0)
_climb.ForciblySetClimbing(uid, entityDistances.OrderBy(e => e.Value).First().Key);
}
}


public sealed class DropHandItemsEvent : EventArgs { }

/// <summary>
Expand All @@ -158,4 +184,4 @@ public sealed class StoodEvent : EntityEventArgs { }
/// <summary>
/// Raised when an entity is not standing
/// </summary>
public sealed class DownedEvent : EntityEventArgs { }
public sealed class DownedEvent : EntityEventArgs { }
25 changes: 25 additions & 0 deletions Resources/Changelog/Changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7290,3 +7290,28 @@ Entries:
id: 6453
time: '2024-10-15T23:13:13.0000000+00:00'
url: https://github.com/Simple-Station/Einstein-Engines/pull/1047
- author: Aidenkrz
changes:
- type: Fix
message: You can properly lay down and stand up on tables now.
id: 6454
time: '2024-10-16T03:08:07.0000000+00:00'
url: https://github.com/Simple-Station/Einstein-Engines/pull/1057
- author: Aidenkrz
changes:
- type: Tweak
message: Height and width are now constrained by each other.
- type: Fix
message: Humanoids can no longer phase through walls.
id: 6455
time: '2024-10-16T12:54:15.0000000+00:00'
url: https://github.com/Simple-Station/Einstein-Engines/pull/1049
- author: Aidenkrz
changes:
- type: Fix
message: Bluespace crystals now properly eject from lathes.
- type: Fix
message: Bluespace parts can be reverse engineered.
id: 6456
time: '2024-10-16T12:55:19.0000000+00:00'
url: https://github.com/Simple-Station/Einstein-Engines/pull/1052
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/materials/materials.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ materials-meat = meat
materials-web = silk
materials-bones = bone
materials-coal = coal
materials-bluespace = bluespace
materials-normality = normality
# Ores
materials-raw-iron = raw iron
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
state: super_matter_bin
- type: RandomSpawner
rarePrototypes:
- QuadraticCapacitorStockPart
- FemtoManipulatorStockPart
- BluespaceCapacitorStockPart
- BluespaceManipulatorStockPart
- BluespaceMatterBinStockPart
rareChance: 0.05
prototypes:
Expand Down Expand Up @@ -130,7 +130,7 @@
state: bluespace_matter_bin
- type: RandomSpawner
prototypes:
- QuadraticCapacitorStockPart
- BluespaceCapacitorStockPart
- PicoManipulatorStockPart
- BluespaceMatterBinStockPart
offset: 0.0
Expand Down
Loading

0 comments on commit 456473c

Please sign in to comment.