* A lot of unfinished work, trying to figure stuff out but it ain't really working * The eye colors finally work on the sprite! * Big refactor for HumanoidProfileEditor, crashes upon making a lobby * Fixed Lobby crashing * Moves the eye selection box to a new tab, which fixes selection the box from going off-screen and not expanding the bars * uncommented something I shouldn't have commented out * Moved eye colors back to the appearance tab, still some ui glitches * Made it possible to scroll in the appearance tab * Added "Eye color:" label * Migrating some deprecated functions into their replacements * Merged two private sealed classes into one public class, removing duplication
120 lines
3.8 KiB
C#
120 lines
3.8 KiB
C#
#nullable enable
|
|
using Content.Server.GameObjects.Components.Mobs;
|
|
using Content.Server.Utility;
|
|
using Content.Shared.GameObjects.Components;
|
|
using Content.Shared.Interfaces;
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
|
using Content.Shared.Preferences.Appearance;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Content.Server.GameObjects.Components
|
|
{
|
|
[RegisterComponent]
|
|
[ComponentReference(typeof(IActivate))]
|
|
public class MagicMirrorComponent : SharedMagicMirrorComponent, IActivate
|
|
{
|
|
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(MagicMirrorUiKey.Key);
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
if (UserInterface != null)
|
|
{
|
|
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
|
|
}
|
|
}
|
|
|
|
public override void OnRemove()
|
|
{
|
|
if (UserInterface != null)
|
|
{
|
|
UserInterface.OnReceiveMessage -= OnUiReceiveMessage;
|
|
}
|
|
|
|
base.OnRemove();
|
|
}
|
|
|
|
private static void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
|
|
{
|
|
if (obj.Session.AttachedEntity == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!obj.Session.AttachedEntity.TryGetComponent(out HumanoidAppearanceComponent? looks))
|
|
{
|
|
return;
|
|
}
|
|
|
|
switch (obj.Message)
|
|
{
|
|
case HairSelectedMessage msg:
|
|
var map =
|
|
msg.IsFacialHair ? HairStyles.FacialHairStylesMap : HairStyles.HairStylesMap;
|
|
if (!map.ContainsKey(msg.HairName))
|
|
return;
|
|
|
|
if (msg.IsFacialHair)
|
|
{
|
|
looks.Appearance = looks.Appearance.WithFacialHairStyleName(msg.HairName);
|
|
}
|
|
else
|
|
{
|
|
looks.Appearance = looks.Appearance.WithHairStyleName(msg.HairName);
|
|
}
|
|
|
|
break;
|
|
|
|
case HairColorSelectedMessage msg:
|
|
var (r, g, b) = msg.HairColor;
|
|
var color = new Color(r, g, b);
|
|
|
|
if (msg.IsFacialHair)
|
|
{
|
|
looks.Appearance = looks.Appearance.WithFacialHairColor(color);
|
|
}
|
|
else
|
|
{
|
|
looks.Appearance = looks.Appearance.WithHairColor(color);
|
|
}
|
|
|
|
break;
|
|
|
|
case EyeColorSelectedMessage msg:
|
|
var (eyeR, eyeG, eyeB) = msg.EyeColor;
|
|
var eyeColor = new Color(eyeR, eyeG, eyeB);
|
|
|
|
looks.Appearance = looks.Appearance.WithEyeColor(eyeColor);
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
void IActivate.Activate(ActivateEventArgs eventArgs)
|
|
{
|
|
if (!eventArgs.User.TryGetComponent(out IActorComponent? actor))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!eventArgs.User.TryGetComponent(out HumanoidAppearanceComponent? looks))
|
|
{
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("You can't have any hair!"));
|
|
return;
|
|
}
|
|
|
|
UserInterface?.Toggle(actor.playerSession);
|
|
|
|
var msg = new MagicMirrorInitialDataMessage(looks.Appearance.HairColor, looks.Appearance.FacialHairColor, looks.Appearance.HairStyleName,
|
|
looks.Appearance.FacialHairStyleName, looks.Appearance.EyeColor);
|
|
|
|
UserInterface?.SendMessage(msg, actor.playerSession);
|
|
}
|
|
}
|
|
}
|