diff --git a/Content.Server/MagicMirror/MagicMirrorSystem.cs b/Content.Server/MagicMirror/MagicMirrorSystem.cs index 84f1f1c3e5..fc1bff9756 100644 --- a/Content.Server/MagicMirror/MagicMirrorSystem.cs +++ b/Content.Server/MagicMirror/MagicMirrorSystem.cs @@ -7,9 +7,7 @@ using Content.Shared.Humanoid; using Content.Shared.Humanoid.Markings; using Content.Shared.Interaction; using Content.Shared.MagicMirror; -using Robust.Server.GameObjects; using Robust.Shared.Audio.Systems; -using Robust.Shared.Player; namespace Content.Server.MagicMirror; @@ -22,14 +20,14 @@ public sealed class MagicMirrorSystem : SharedMagicMirrorSystem [Dependency] private readonly DoAfterSystem _doAfterSystem = default!; [Dependency] private readonly MarkingManager _markings = default!; [Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!; - [Dependency] private readonly UserInterfaceSystem _uiSystem = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnOpenUIAttempt); - Subs.BuiEvents(MagicMirrorUiKey.Key, subs => + Subs.BuiEvents(MagicMirrorUiKey.Key, + subs => { subs.Event(OnUiClosed); subs.Event(OnMagicMirrorSelect); @@ -278,32 +276,6 @@ public sealed class MagicMirrorSystem : SharedMagicMirrorSystem } - private void UpdateInterface(EntityUid mirrorUid, EntityUid targetUid, MagicMirrorComponent component) - { - if (!TryComp(targetUid, out var humanoid)) - return; - - var hair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.Hair, out var hairMarkings) - ? new List(hairMarkings) - : new(); - - var facialHair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.FacialHair, out var facialHairMarkings) - ? new List(facialHairMarkings) - : new(); - - var state = new MagicMirrorUiState( - humanoid.Species, - hair, - humanoid.MarkingSet.PointsLeft(MarkingCategories.Hair) + hair.Count, - facialHair, - humanoid.MarkingSet.PointsLeft(MarkingCategories.FacialHair) + facialHair.Count); - - // TODO: Component states - component.Target = targetUid; - _uiSystem.SetUiState(mirrorUid, MagicMirrorUiKey.Key, state); - Dirty(mirrorUid, component); - } - private void OnUiClosed(Entity ent, ref BoundUIClosedEvent args) { ent.Comp.Target = null; diff --git a/Content.Shared/MagicMirror/MagicMirrorComponent.cs b/Content.Shared/MagicMirror/MagicMirrorComponent.cs index 6357543905..95b1736979 100644 --- a/Content.Shared/MagicMirror/MagicMirrorComponent.cs +++ b/Content.Shared/MagicMirror/MagicMirrorComponent.cs @@ -47,5 +47,5 @@ public sealed partial class MagicMirrorComponent : Component /// Sound emitted when slots are changed /// [DataField, ViewVariables(VVAccess.ReadWrite)] - public SoundSpecifier ChangeHairSound = new SoundPathSpecifier("/Audio/Items/scissors.ogg"); + public SoundSpecifier? ChangeHairSound = new SoundPathSpecifier("/Audio/Items/scissors.ogg"); } diff --git a/Content.Shared/MagicMirror/SharedMagicMirrorSystem.cs b/Content.Shared/MagicMirror/SharedMagicMirrorSystem.cs index f9c941ffe3..91059d60bf 100644 --- a/Content.Shared/MagicMirror/SharedMagicMirrorSystem.cs +++ b/Content.Shared/MagicMirror/SharedMagicMirrorSystem.cs @@ -1,6 +1,8 @@ using Content.Shared.DoAfter; +using Content.Shared.Humanoid; using Content.Shared.Humanoid.Markings; using Content.Shared.Interaction; +using Content.Shared.UserInterface; using Robust.Shared.Serialization; namespace Content.Shared.MagicMirror; @@ -8,10 +10,12 @@ namespace Content.Shared.MagicMirror; public abstract class SharedMagicMirrorSystem : EntitySystem { [Dependency] private readonly SharedInteractionSystem _interaction = default!; + [Dependency] protected readonly SharedUserInterfaceSystem _uiSystem = default!; public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(OnBeforeUIOpen); SubscribeLocalEvent(OnMirrorRangeCheck); } @@ -22,6 +26,38 @@ public abstract class SharedMagicMirrorSystem : EntitySystem args.Result = BoundUserInterfaceRangeResult.Fail; } } + + private void OnBeforeUIOpen(Entity ent, ref BeforeActivatableUIOpenEvent args) + { + ent.Comp.Target ??= args.User; + UpdateInterface(ent, args.User, ent); + } + + protected void UpdateInterface(EntityUid mirrorUid, EntityUid targetUid, MagicMirrorComponent component) + { + if (!TryComp(targetUid, out var humanoid)) + return; + + var hair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.Hair, out var hairMarkings) + ? new List(hairMarkings) + : new(); + + var facialHair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.FacialHair, out var facialHairMarkings) + ? new List(facialHairMarkings) + : new(); + + var state = new MagicMirrorUiState( + humanoid.Species, + hair, + humanoid.MarkingSet.PointsLeft(MarkingCategories.Hair) + hair.Count, + facialHair, + humanoid.MarkingSet.PointsLeft(MarkingCategories.FacialHair) + facialHair.Count); + + // TODO: Component states + component.Target = targetUid; + _uiSystem.SetUiState(mirrorUid, MagicMirrorUiKey.Key, state); + Dirty(mirrorUid, component); + } } [Serializable, NetSerializable] diff --git a/Resources/Prototypes/Entities/Structures/Wallmounts/mirror.yml b/Resources/Prototypes/Entities/Structures/Wallmounts/mirror.yml index d02bce020d..1fe3318ef5 100644 --- a/Resources/Prototypes/Entities/Structures/Wallmounts/mirror.yml +++ b/Resources/Prototypes/Entities/Structures/Wallmounts/mirror.yml @@ -11,7 +11,12 @@ - type: Clickable - type: Transform anchored: true - - type: MagicMirror + - type: MagicMirror #instant and silent + changeHairSound: null + addSlotTime: 0 + removeSlotTime: 0 + selectSlotTime: 0 + changeSlotTime: 0 - type: ActivatableUI key: enum.MagicMirrorUiKey.Key - type: UserInterface