2021-10-16 15:28:02 -07:00
|
|
|
using Content.Server.CharacterAppearance.Systems;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.UserInterface;
|
|
|
|
|
using Content.Shared.CharacterAppearance;
|
|
|
|
|
using Content.Shared.CharacterAppearance.Components;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.GameObjects;
|
2019-11-23 21:55:46 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.CharacterAppearance.Components
|
2019-11-23 21:55:46 +01:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2022-03-12 13:26:06 -05:00
|
|
|
public sealed class MagicMirrorComponent : SharedMagicMirrorComponent
|
2019-11-23 21:55:46 +01:00
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entities = default!;
|
2021-03-28 08:26:32 +02:00
|
|
|
[Dependency] private readonly SpriteAccessoryManager _spriteAccessoryManager = default!;
|
|
|
|
|
|
2022-03-12 13:26:06 -05:00
|
|
|
[ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(MagicMirrorUiKey.Key);
|
2019-11-23 21:55:46 +01:00
|
|
|
|
2021-06-19 19:41:26 -07:00
|
|
|
protected override void Initialize()
|
2019-11-23 21:55:46 +01:00
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2020-08-22 22:29:20 +02:00
|
|
|
|
|
|
|
|
if (UserInterface != null)
|
|
|
|
|
{
|
|
|
|
|
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-19 19:41:26 -07:00
|
|
|
protected override void OnRemove()
|
2020-08-22 22:29:20 +02:00
|
|
|
{
|
|
|
|
|
if (UserInterface != null)
|
|
|
|
|
{
|
|
|
|
|
UserInterface.OnReceiveMessage -= OnUiReceiveMessage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.OnRemove();
|
2019-11-23 21:55:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-28 08:26:32 +02:00
|
|
|
private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
|
2019-11-23 21:55:46 +01:00
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
if (obj.Session.AttachedEntity is not {Valid: true} player)
|
2020-08-22 22:29:20 +02:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
if (!_entities.TryGetComponent(player, out HumanoidAppearanceComponent? looks))
|
2020-01-15 14:28:46 +01:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-23 21:55:46 +01:00
|
|
|
switch (obj.Message)
|
|
|
|
|
{
|
|
|
|
|
case HairSelectedMessage msg:
|
2021-03-28 08:26:32 +02:00
|
|
|
var cat = msg.IsFacialHair
|
|
|
|
|
? looks.CategoriesFacialHair
|
|
|
|
|
: looks.CategoriesHair;
|
|
|
|
|
|
|
|
|
|
if (!_spriteAccessoryManager.IsValidAccessoryInCategory(msg.HairId, cat))
|
2019-11-23 21:55:46 +01:00
|
|
|
return;
|
|
|
|
|
|
2021-03-16 15:50:20 +01:00
|
|
|
looks.Appearance = msg.IsFacialHair
|
2021-03-28 08:26:32 +02:00
|
|
|
? looks.Appearance.WithFacialHairStyleName(msg.HairId)
|
|
|
|
|
: looks.Appearance.WithHairStyleName(msg.HairId);
|
2019-11-23 21:55:46 +01:00
|
|
|
|
|
|
|
|
break;
|
2020-01-15 14:28:46 +01:00
|
|
|
|
2019-11-23 21:55:46 +01:00
|
|
|
case HairColorSelectedMessage msg:
|
2021-03-28 08:26:32 +02:00
|
|
|
if (msg.IsFacialHair ? !looks.CanColorFacialHair : !looks.CanColorHair)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-01-15 14:28:46 +01:00
|
|
|
var (r, g, b) = msg.HairColor;
|
|
|
|
|
var color = new Color(r, g, b);
|
|
|
|
|
|
2021-03-16 15:50:20 +01:00
|
|
|
looks.Appearance = msg.IsFacialHair
|
|
|
|
|
? looks.Appearance.WithFacialHairColor(color)
|
|
|
|
|
: looks.Appearance.WithHairColor(color);
|
2019-11-23 21:55:46 +01:00
|
|
|
|
2021-03-07 20:48:24 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EyeColorSelectedMessage msg:
|
|
|
|
|
var (eyeR, eyeG, eyeB) = msg.EyeColor;
|
|
|
|
|
var eyeColor = new Color(eyeR, eyeG, eyeB);
|
|
|
|
|
|
|
|
|
|
looks.Appearance = looks.Appearance.WithEyeColor(eyeColor);
|
|
|
|
|
|
2019-11-23 21:55:46 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2021-10-16 15:28:02 -07:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
EntitySystem.Get<HumanoidAppearanceSystem>().ForceAppearanceUpdate(player);
|
2019-11-23 21:55:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|