Humanoid appearance fixes (#7020)
This commit is contained in:
@@ -1,13 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using Content.Client.Cuffs.Components;
|
using Content.Client.Cuffs.Components;
|
||||||
using Content.Shared.Body.Components;
|
using Content.Shared.Body.Components;
|
||||||
using Content.Shared.CharacterAppearance;
|
using Content.Shared.CharacterAppearance;
|
||||||
using Content.Shared.CharacterAppearance.Components;
|
using Content.Shared.CharacterAppearance.Components;
|
||||||
using Content.Shared.CharacterAppearance.Systems;
|
using Content.Shared.CharacterAppearance.Systems;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.IoC;
|
|
||||||
using Robust.Shared.Maths;
|
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
namespace Content.Client.CharacterAppearance.Systems
|
namespace Content.Client.CharacterAppearance.Systems
|
||||||
@@ -26,8 +22,7 @@ namespace Content.Client.CharacterAppearance.Systems
|
|||||||
SubscribeLocalEvent<HumanoidAppearanceBodyPartRemovedEvent>(BodyPartRemoved);
|
SubscribeLocalEvent<HumanoidAppearanceBodyPartRemovedEvent>(BodyPartRemoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<HumanoidVisualLayers> _bodyPartLayers = new List<HumanoidVisualLayers>
|
private readonly HumanoidVisualLayers[] _bodyPartLayers = {
|
||||||
{
|
|
||||||
HumanoidVisualLayers.Chest,
|
HumanoidVisualLayers.Chest,
|
||||||
HumanoidVisualLayers.Head,
|
HumanoidVisualLayers.Head,
|
||||||
HumanoidVisualLayers.Eyes,
|
HumanoidVisualLayers.Eyes,
|
||||||
@@ -44,32 +39,63 @@ namespace Content.Client.CharacterAppearance.Systems
|
|||||||
private void UpdateLooks(EntityUid uid, HumanoidAppearanceComponent component,
|
private void UpdateLooks(EntityUid uid, HumanoidAppearanceComponent component,
|
||||||
ChangedHumanoidAppearanceEvent args)
|
ChangedHumanoidAppearanceEvent args)
|
||||||
{
|
{
|
||||||
if (!EntityManager.TryGetComponent(uid, out SpriteComponent? sprite))
|
var spriteQuery = EntityManager.GetEntityQuery<SpriteComponent>();
|
||||||
|
|
||||||
|
if (!spriteQuery.TryGetComponent(uid, out var sprite))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (EntityManager.TryGetComponent(uid, out SharedBodyComponent? body))
|
if (EntityManager.TryGetComponent(uid, out SharedBodyComponent? body))
|
||||||
{
|
{
|
||||||
foreach (var (part, _) in body.Parts)
|
foreach (var (part, _) in body.Parts)
|
||||||
{
|
{
|
||||||
if (EntityManager.TryGetComponent(part.Owner, out SpriteComponent? partSprite))
|
if (spriteQuery.TryGetComponent(part.Owner, out var partSprite))
|
||||||
{
|
{
|
||||||
partSprite!.Color = component.Appearance.SkinColor;
|
partSprite.Color = component.Appearance.SkinColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var hairColor = component.CanColorHair ? component.Appearance.HairColor : Color.White;
|
// Like body parts some stuff may not have hair.
|
||||||
hairColor = component.HairMatchesSkin ? component.Appearance.SkinColor : hairColor;
|
if (sprite.LayerMapTryGet(HumanoidVisualLayers.Hair, out var hairLayer))
|
||||||
sprite.LayerSetColor(HumanoidVisualLayers.Hair, hairColor.WithAlpha(component.HairAlpha));
|
{
|
||||||
|
var hairColor = component.CanColorHair ? component.Appearance.HairColor : Color.White;
|
||||||
|
hairColor = component.HairMatchesSkin ? component.Appearance.SkinColor : hairColor;
|
||||||
|
sprite.LayerSetColor(hairLayer, hairColor.WithAlpha(component.HairAlpha));
|
||||||
|
|
||||||
var facialHairColor = component.CanColorHair ? component.Appearance.FacialHairColor : Color.White;
|
var hairStyle = component.Appearance.HairStyleId;
|
||||||
facialHairColor = component.HairMatchesSkin ? component.Appearance.SkinColor : facialHairColor;
|
if (string.IsNullOrWhiteSpace(hairStyle) ||
|
||||||
sprite.LayerSetColor(HumanoidVisualLayers.FacialHair, facialHairColor.WithAlpha(component.HairAlpha));
|
!_accessoryManager.IsValidAccessoryInCategory(hairStyle, component.CategoriesHair))
|
||||||
|
{
|
||||||
|
hairStyle = HairStyles.DefaultHairStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
var hairPrototype = _prototypeManager.Index<SpriteAccessoryPrototype>(hairStyle);
|
||||||
|
sprite.LayerSetSprite(hairLayer, hairPrototype.Sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sprite.LayerMapTryGet(HumanoidVisualLayers.FacialHair, out var facialLayer))
|
||||||
|
{
|
||||||
|
var facialHairColor = component.CanColorHair ? component.Appearance.FacialHairColor : Color.White;
|
||||||
|
facialHairColor = component.HairMatchesSkin ? component.Appearance.SkinColor : facialHairColor;
|
||||||
|
sprite.LayerSetColor(facialLayer, facialHairColor.WithAlpha(component.HairAlpha));
|
||||||
|
|
||||||
|
var facialHairStyle = component.Appearance.FacialHairStyleId;
|
||||||
|
if (string.IsNullOrWhiteSpace(facialHairStyle) ||
|
||||||
|
!_accessoryManager.IsValidAccessoryInCategory(facialHairStyle, component.CategoriesFacialHair))
|
||||||
|
{
|
||||||
|
facialHairStyle = HairStyles.DefaultFacialHairStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
var facialHairPrototype = _prototypeManager.Index<SpriteAccessoryPrototype>(facialHairStyle);
|
||||||
|
sprite.LayerSetSprite(facialLayer, facialHairPrototype.Sprite);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var layer in _bodyPartLayers)
|
foreach (var layer in _bodyPartLayers)
|
||||||
{
|
{
|
||||||
sprite.LayerSetColor(layer, component.Appearance.SkinColor);
|
// Not every mob may have the furry layers hence we just skip it.
|
||||||
|
if (!sprite.LayerMapTryGet(layer, out var actualLayer)) continue;
|
||||||
|
|
||||||
|
sprite.LayerSetColor(actualLayer, component.Appearance.SkinColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprite.LayerSetColor(HumanoidVisualLayers.Eyes, component.Appearance.EyeColor);
|
sprite.LayerSetColor(HumanoidVisualLayers.Eyes, component.Appearance.EyeColor);
|
||||||
@@ -88,26 +114,6 @@ namespace Content.Client.CharacterAppearance.Systems
|
|||||||
{
|
{
|
||||||
sprite.LayerSetVisible(HumanoidVisualLayers.Handcuffs, false);
|
sprite.LayerSetVisible(HumanoidVisualLayers.Handcuffs, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var hairStyle = component.Appearance.HairStyleId;
|
|
||||||
if (string.IsNullOrWhiteSpace(hairStyle) ||
|
|
||||||
!_accessoryManager.IsValidAccessoryInCategory(hairStyle, component.CategoriesHair))
|
|
||||||
{
|
|
||||||
hairStyle = HairStyles.DefaultHairStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
var facialHairStyle = component.Appearance.FacialHairStyleId;
|
|
||||||
if (string.IsNullOrWhiteSpace(facialHairStyle) ||
|
|
||||||
!_accessoryManager.IsValidAccessoryInCategory(facialHairStyle, component.CategoriesFacialHair))
|
|
||||||
{
|
|
||||||
facialHairStyle = HairStyles.DefaultFacialHairStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
var hairPrototype = _prototypeManager.Index<SpriteAccessoryPrototype>(hairStyle);
|
|
||||||
var facialHairPrototype = _prototypeManager.Index<SpriteAccessoryPrototype>(facialHairStyle);
|
|
||||||
|
|
||||||
sprite.LayerSetSprite(HumanoidVisualLayers.Hair, hairPrototype.Sprite);
|
|
||||||
sprite.LayerSetSprite(HumanoidVisualLayers.FacialHair, facialHairPrototype.Sprite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scaffolding until Body is moved to ECS.
|
// Scaffolding until Body is moved to ECS.
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using System;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.IoC;
|
|
||||||
using Robust.Shared.Maths;
|
|
||||||
using Robust.Shared.Random;
|
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.CharacterAppearance
|
namespace Content.Shared.CharacterAppearance
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
using System;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.Serialization;
|
|
||||||
|
|
||||||
namespace Content.Shared.CharacterAppearance
|
namespace Content.Shared.CharacterAppearance
|
||||||
{
|
{
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public enum HumanoidVisualLayers
|
public enum HumanoidVisualLayers : byte
|
||||||
{
|
{
|
||||||
Hair,
|
Hair,
|
||||||
FacialHair,
|
FacialHair,
|
||||||
|
|||||||
Reference in New Issue
Block a user