diff --git a/Content.Client/MagicMirror/MagicMirrorBoundUserInterface.cs b/Content.Client/MagicMirror/MagicMirrorBoundUserInterface.cs index ba4362a472..ebb6780853 100644 --- a/Content.Client/MagicMirror/MagicMirrorBoundUserInterface.cs +++ b/Content.Client/MagicMirror/MagicMirrorBoundUserInterface.cs @@ -64,5 +64,16 @@ public sealed class MagicMirrorBoundUserInterface : BoundUserInterface _window.UpdateState(data); } + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (!disposing) + return; + + if (_window != null) + _window.OnClose -= Close; + + _window?.Dispose(); + } } diff --git a/Content.Server/MagicMirror/MagicMirrorComponent.cs b/Content.Server/MagicMirror/MagicMirrorComponent.cs index d9c2fff6da..b974b513cd 100644 --- a/Content.Server/MagicMirror/MagicMirrorComponent.cs +++ b/Content.Server/MagicMirror/MagicMirrorComponent.cs @@ -1,6 +1,25 @@ +using Content.Shared.Humanoid; +using Robust.Shared.Audio; + namespace Content.Server.MagicMirror; [RegisterComponent] public sealed partial class MagicMirrorComponent : Component { + public Entity? Target; + + [DataField, ViewVariables(VVAccess.ReadWrite)] + public float AddSlotTime = 5f; + + [DataField, ViewVariables(VVAccess.ReadWrite)] + public float RemoveSlotTime = 2f; + + [DataField, ViewVariables(VVAccess.ReadWrite)] + public float SelectSlotTime = 3f; + + [DataField, ViewVariables(VVAccess.ReadWrite)] + public float ChangeSlotTime = 1f; + + [DataField, ViewVariables(VVAccess.ReadWrite)] + public SoundSpecifier ChangeHairSound = new SoundPathSpecifier("/Audio/Items/scissors.ogg"); } diff --git a/Content.Server/MagicMirror/MagicMirrorSystem.cs b/Content.Server/MagicMirror/MagicMirrorSystem.cs index a599a2c868..eb989eafd6 100644 --- a/Content.Server/MagicMirror/MagicMirrorSystem.cs +++ b/Content.Server/MagicMirror/MagicMirrorSystem.cs @@ -1,16 +1,22 @@ using System.Linq; +using Content.Server.DoAfter; using Content.Server.Humanoid; using Content.Server.UserInterface; +using Content.Shared.DoAfter; 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; public sealed class MagicMirrorSystem : EntitySystem { + [Dependency] private readonly SharedAudioSystem _audio = default!; + [Dependency] private readonly DoAfterSystem _doAfterSystem = default!; [Dependency] private readonly MarkingManager _markings = default!; [Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!; [Dependency] private readonly UserInterfaceSystem _uiSystem = default!; @@ -22,9 +28,27 @@ public sealed class MagicMirrorSystem : EntitySystem SubscribeLocalEvent(OnOpenUIAttempt); SubscribeLocalEvent(AfterUIOpen); SubscribeLocalEvent(OnMagicMirrorSelect); - SubscribeLocalEvent(OnMagicMirrorChangeColor); - SubscribeLocalEvent(OnMagicMirrorAddSlot); - SubscribeLocalEvent(OnMagicMirrorRemoveSlot); + SubscribeLocalEvent(OnTryMagicMirrorChangeColor); + SubscribeLocalEvent(OnTryMagicMirrorAddSlot); + SubscribeLocalEvent(OnTryMagicMirrorRemoveSlot); + + SubscribeLocalEvent(OnMagicMirrorInteract); + + SubscribeLocalEvent(OnSelectSlotDoAfter); + SubscribeLocalEvent(OnChangeColorDoAfter); + SubscribeLocalEvent(OnRemoveSlotDoAfter); + SubscribeLocalEvent(OnAddSlotDoAfter); + } + + private void OnMagicMirrorInteract(Entity mirror, ref AfterInteractEvent args) + { + if (!TryComp(args.User, out var actor)) return; + if (TryComp(args.Target, out var humanoid)) + { + mirror.Comp.Target = new Entity(args.Target.Value, humanoid); + UpdateInterface(mirror.Owner, mirror.Comp.Target.Value.Owner, actor.PlayerSession); + Log.Debug($"Target {mirror.Comp.Target}!"); + }; } private void OnOpenUIAttempt(EntityUid uid, MagicMirrorComponent mirror, ActivatableUIOpenAttemptEvent args) @@ -33,16 +57,32 @@ public sealed class MagicMirrorSystem : EntitySystem args.Cancel(); } - private void OnMagicMirrorSelect(EntityUid uid, MagicMirrorComponent component, - MagicMirrorSelectMessage message) + private void OnMagicMirrorSelect(EntityUid uid, MagicMirrorComponent component, MagicMirrorSelectMessage message) { - if (message.Session.AttachedEntity == null || !TryComp(message.Session.AttachedEntity.Value, out var humanoid)) + if (component.Target == null) return; + if (message.Session.AttachedEntity == null) return; + + var doAfter = new SelectDoAfterEvent(message); + _doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, message.Session.AttachedEntity.Value, component.SelectSlotTime, doAfter, uid, target: component.Target.Value.Owner, used: uid) { + BreakOnTargetMove = true, + BreakOnDamage = true, + BreakOnHandChange = false, + BreakOnUserMove = true, + BreakOnWeightlessMove = false, + NeedHand = true + }); + + _audio.PlayPvs(component.ChangeHairSound, uid); + } + private void OnSelectSlotDoAfter(EntityUid uid, MagicMirrorComponent component, SelectDoAfterEvent args) + { + if (args.Handled || args.Args.Target == null || args.Cancelled) return; - } + if (component.Target == null) return; var category = MarkingCategories.Hair; - switch (message.Category) + switch (args.Message.Category) { case MagicMirrorCategory.Hair: category = MarkingCategories.Hair; @@ -54,21 +94,35 @@ public sealed class MagicMirrorSystem : EntitySystem return; } - _humanoid.SetMarkingId(message.Session.AttachedEntity.Value, category, message.Slot, message.Marking); + _humanoid.SetMarkingId(component.Target.Value.Owner, category, args.Message.Slot, args.Message.Marking); - UpdateInterface(uid, message.Session.AttachedEntity.Value, message.Session); + UpdateInterface(uid, component.Target.Value.Owner, args.Message.Session); } - private void OnMagicMirrorChangeColor(EntityUid uid, MagicMirrorComponent component, - MagicMirrorChangeColorMessage message) + private void OnTryMagicMirrorChangeColor(EntityUid uid, MagicMirrorComponent component, MagicMirrorChangeColorMessage message) { - if (message.Session.AttachedEntity == null || !TryComp(message.Session.AttachedEntity.Value, out var humanoid)) + if (component.Target == null) return; + if (message.Session.AttachedEntity == null) return; + + var doAfter = new ChangeColorDoAfterEvent(message); + _doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, message.Session.AttachedEntity.Value, component.ChangeSlotTime, doAfter, uid, target: component.Target.Value.Owner, used: uid) { + BreakOnTargetMove = true, + BreakOnDamage = true, + BreakOnHandChange = false, + BreakOnUserMove = true, + BreakOnWeightlessMove = false, + NeedHand = true + }); + } + private void OnChangeColorDoAfter(EntityUid uid, MagicMirrorComponent component, ChangeColorDoAfterEvent args) + { + if (args.Handled || args.Args.Target == null || args.Cancelled) return; - } + if (component.Target == null) return; var category = MarkingCategories.Hair; - switch (message.Category) + switch (args.Message.Category) { case MagicMirrorCategory.Hair: category = MarkingCategories.Hair; @@ -80,22 +134,39 @@ public sealed class MagicMirrorSystem : EntitySystem return; } - _humanoid.SetMarkingColor(message.Session.AttachedEntity.Value, category, message.Slot, message.Colors); + _humanoid.SetMarkingColor(component.Target.Value.Owner, category, args.Message.Slot, args.Message.Colors); // using this makes the UI feel like total ass - // UpdateInterface(uid, message.Session.AttachedEntity.Value, message.Session); + // UpdateInterface(uid, component.Target, message.Session); } - private void OnMagicMirrorRemoveSlot(EntityUid uid, MagicMirrorComponent component, - MagicMirrorRemoveSlotMessage message) + private void OnTryMagicMirrorRemoveSlot(EntityUid uid, MagicMirrorComponent component, MagicMirrorRemoveSlotMessage message) { - if (message.Session.AttachedEntity == null || !TryComp(message.Session.AttachedEntity.Value, out var humanoid)) + if (component.Target == null) return; + if (message.Session.AttachedEntity == null) return; + + var doAfter = new RemoveSlotDoAfterEvent(message); + _doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, message.Session.AttachedEntity.Value, component.RemoveSlotTime, doAfter, uid, target: component.Target.Value.Owner, used: uid) { + BreakOnTargetMove = true, + BreakOnDamage = true, + BreakOnHandChange = false, + BreakOnUserMove = true, + BreakOnWeightlessMove = false, + NeedHand = true + }); + + _audio.PlayPvs(component.ChangeHairSound, uid); + } + private void OnRemoveSlotDoAfter(EntityUid uid, MagicMirrorComponent component, RemoveSlotDoAfterEvent args) + { + if (args.Handled || args.Args.Target == null || args.Cancelled) return; - } + + if (component.Target == null) return; var category = MarkingCategories.Hair; - switch (message.Category) + switch (args.Message.Category) { case MagicMirrorCategory.Hair: category = MarkingCategories.Hair; @@ -107,21 +178,37 @@ public sealed class MagicMirrorSystem : EntitySystem return; } - _humanoid.RemoveMarking(message.Session.AttachedEntity.Value, category, message.Slot); + _humanoid.RemoveMarking(component.Target.Value.Owner, category, args.Message.Slot); - UpdateInterface(uid, message.Session.AttachedEntity.Value, message.Session); + UpdateInterface(uid, component.Target.Value.Owner, args.Message.Session); } - private void OnMagicMirrorAddSlot(EntityUid uid, MagicMirrorComponent component, - MagicMirrorAddSlotMessage message) + private void OnTryMagicMirrorAddSlot(EntityUid uid, MagicMirrorComponent component, MagicMirrorAddSlotMessage message) { - if (message.Session.AttachedEntity == null || !TryComp(message.Session.AttachedEntity.Value, out var humanoid)) + if (component.Target == null) return; + if (message.Session.AttachedEntity == null) return; + + var doAfter = new AddSlotDoAfterEvent(message); + _doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, message.Session.AttachedEntity.Value, component.AddSlotTime, doAfter, uid, target: component.Target.Value.Owner, used: uid) { + BreakOnTargetMove = true, + BreakOnDamage = true, + BreakOnHandChange = false, + BreakOnUserMove = true, + BreakOnWeightlessMove = false, + NeedHand = true + }); + _audio.PlayPvs(component.ChangeHairSound, uid); + } + private void OnAddSlotDoAfter(EntityUid uid, MagicMirrorComponent component, AddSlotDoAfterEvent args) + { + if (args.Handled || args.Args.Target == null || args.Cancelled) return; - } + + if (component.Target == null) return; var category = MarkingCategories.Hair; - switch (message.Category) + switch (args.Message.Category) { case MagicMirrorCategory.Hair: category = MarkingCategories.Hair; @@ -133,23 +220,21 @@ public sealed class MagicMirrorSystem : EntitySystem return; } - var marking = _markings.MarkingsByCategoryAndSpecies(category, humanoid.Species).Keys.FirstOrDefault(); + var marking = _markings.MarkingsByCategoryAndSpecies(category, component.Target.Value.Comp.Species).Keys.FirstOrDefault(); if (string.IsNullOrEmpty(marking)) { return; } - _humanoid.AddMarking(message.Session.AttachedEntity.Value, marking, Color.Black); + _humanoid.AddMarking(component.Target.Value.Owner, marking, Color.Black); - UpdateInterface(uid, message.Session.AttachedEntity.Value, message.Session); + UpdateInterface(uid, component.Target.Value.Owner, args.Message.Session); } - private void UpdateInterface(EntityUid uid, EntityUid playerUid, ICommonSession session, HumanoidAppearanceComponent? humanoid = null) + private void UpdateInterface(EntityUid uid, EntityUid playerUid, ICommonSession session) { - if (!Resolve(playerUid, ref humanoid) || session is not { } player) - { - return; - } + if (!TryComp(playerUid, out var humanoid)) return; + if (session is not { } player) return; var hair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.Hair, out var hairMarkings) ? new List(hairMarkings) @@ -171,9 +256,9 @@ public sealed class MagicMirrorSystem : EntitySystem private void AfterUIOpen(EntityUid uid, MagicMirrorComponent component, AfterActivatableUIOpenEvent args) { - var looks = Comp(args.User); - var actor = Comp(args.User); + if (!TryComp(args.User, out var humanoid)) return; + component.Target = new Entity(args.User, humanoid); UpdateInterface(uid, args.User, args.Session); } -} \ No newline at end of file +} diff --git a/Content.Shared/MagicMirror/SharedMagicMirrorSystem.cs b/Content.Shared/MagicMirror/SharedMagicMirrorSystem.cs index 831beb06d6..7d389c90e0 100644 --- a/Content.Shared/MagicMirror/SharedMagicMirrorSystem.cs +++ b/Content.Shared/MagicMirror/SharedMagicMirrorSystem.cs @@ -1,3 +1,4 @@ +using Content.Shared.DoAfter; using Content.Shared.Humanoid.Markings; using Robust.Shared.Serialization; @@ -104,3 +105,51 @@ public sealed class MagicMirrorUiData : BoundUserInterfaceMessage public int FacialHairSlotTotal { get; } } + +[Serializable, NetSerializable] +public sealed partial class RemoveSlotDoAfterEvent : DoAfterEvent +{ + public MagicMirrorRemoveSlotMessage Message; + + public RemoveSlotDoAfterEvent(MagicMirrorRemoveSlotMessage message) + { + Message = message; + } + public override DoAfterEvent Clone() => this; +} + +[Serializable, NetSerializable] +public sealed partial class AddSlotDoAfterEvent : DoAfterEvent +{ + public MagicMirrorAddSlotMessage Message; + + public AddSlotDoAfterEvent(MagicMirrorAddSlotMessage message) + { + Message = message; + } + public override DoAfterEvent Clone() => this; +} + +[Serializable, NetSerializable] +public sealed partial class SelectDoAfterEvent : DoAfterEvent +{ + public MagicMirrorSelectMessage Message; + + public SelectDoAfterEvent(MagicMirrorSelectMessage message) + { + Message = message; + } + public override DoAfterEvent Clone() => this; +} + +[Serializable, NetSerializable] +public sealed partial class ChangeColorDoAfterEvent : DoAfterEvent +{ + public MagicMirrorChangeColorMessage Message; + + public ChangeColorDoAfterEvent(MagicMirrorChangeColorMessage message) + { + Message = message; + } + public override DoAfterEvent Clone() => this; +} diff --git a/Resources/Audio/Items/attributions.yml b/Resources/Audio/Items/attributions.yml index 7822272424..7e186cc076 100644 --- a/Resources/Audio/Items/attributions.yml +++ b/Resources/Audio/Items/attributions.yml @@ -81,4 +81,9 @@ - files: ["ring.ogg"] license: "CC-BY-SA-3.0" copyright: "Taken from /tg/station" - source: "https://github.com/tgstation/tgstation/commit/c61c452d78425d89920b41ed5f95fd190e733a3c" \ No newline at end of file + source: "https://github.com/tgstation/tgstation/commit/c61c452d78425d89920b41ed5f95fd190e733a3c" + +- files: ["scissors.ogg"] + license: "CC0-1.0" + copyright: "User Hanbaal on freesound.org. Converted to ogg by TheShuEd" + source: "https://freesound.org/people/Hanbaal/sounds/178669/" \ No newline at end of file diff --git a/Resources/Audio/Items/scissors.ogg b/Resources/Audio/Items/scissors.ogg new file mode 100644 index 0000000000..1031c426ac Binary files /dev/null and b/Resources/Audio/Items/scissors.ogg differ diff --git a/Resources/Locale/en-US/prototypes/catalog/fills/crates/service-crates.ftl b/Resources/Locale/en-US/prototypes/catalog/fills/crates/service-crates.ftl index 2bed24a4ef..d44be5e979 100644 --- a/Resources/Locale/en-US/prototypes/catalog/fills/crates/service-crates.ftl +++ b/Resources/Locale/en-US/prototypes/catalog/fills/crates/service-crates.ftl @@ -32,7 +32,7 @@ ent-CrateJanitorBiosuit = Janitor bio suit crate .desc = Contains 2 biohazard suits to ensure that no disease will distract you from cleaning. ent-CrateServiceTheatre = Theatrical performances crate - .desc = Contains a moth cloak, maid uniform, clown and mime attributes, and other performance charms. + .desc = Contains a moth cloak, barber scissors, maid uniform, clown and mime attributes, and other performance charms. ent-CrateJanitorExplosive = Janitorial bomb suit crate .desc = Supplies a bomb suit for cleaning up any explosive compounds, buy one today! diff --git a/Resources/Prototypes/Catalog/Fills/Crates/service.yml b/Resources/Prototypes/Catalog/Fills/Crates/service.yml index df789208e7..a1cb914a1a 100644 --- a/Resources/Prototypes/Catalog/Fills/Crates/service.yml +++ b/Resources/Prototypes/Catalog/Fills/Crates/service.yml @@ -76,6 +76,7 @@ - id: ClothingUniformJumpskirtJanimaid - id: ClothingNeckCloakVoid - id: RevolverCapGun + - id: BarberScissors - type: entity id: CrateServiceCustomSmokable diff --git a/Resources/Prototypes/Catalog/Fills/Lockers/misc.yml b/Resources/Prototypes/Catalog/Fills/Lockers/misc.yml index 171546052a..6acbe12af2 100644 --- a/Resources/Prototypes/Catalog/Fills/Lockers/misc.yml +++ b/Resources/Prototypes/Catalog/Fills/Lockers/misc.yml @@ -152,6 +152,8 @@ prob: 0.20 - id: DrinkSpaceLube prob: 0.20 + - id: BarberScissors + prob: 0.05 # Syndicate loot - id: null prob: 0.95 diff --git a/Resources/Prototypes/Entities/Objects/Specific/Service/barber.yml b/Resources/Prototypes/Entities/Objects/Specific/Service/barber.yml new file mode 100644 index 0000000000..e8cb94c524 --- /dev/null +++ b/Resources/Prototypes/Entities/Objects/Specific/Service/barber.yml @@ -0,0 +1,25 @@ +- type: entity + id: BarberScissors + name: barber scissors + description: is able to reshape the hairstyle of any crew cut to your liking. + parent: BaseItem + components: + - type: Sprite + sprite: Objects/Tools/scissors.rsi + state: icon + - type: MagicMirror + - type: ActivatableUI + key: enum.MagicMirrorUiKey.Key + closeOnHandDeselect: true + - type: UserInterface + interfaces: + - key: enum.MagicMirrorUiKey.Key + type: MagicMirrorBoundUserInterface + - type: MeleeWeapon + wideAnimationRotation: -90 + attackRate: 1 + damage: + types: + Piercing: 6 + soundHit: + path: "/Audio/Weapons/bladeslice.ogg" \ No newline at end of file diff --git a/Resources/Textures/Objects/Tools/scissors.rsi/icon.png b/Resources/Textures/Objects/Tools/scissors.rsi/icon.png new file mode 100644 index 0000000000..b92e522676 Binary files /dev/null and b/Resources/Textures/Objects/Tools/scissors.rsi/icon.png differ diff --git a/Resources/Textures/Objects/Tools/scissors.rsi/meta.json b/Resources/Textures/Objects/Tools/scissors.rsi/meta.json new file mode 100644 index 0000000000..b544b3bc15 --- /dev/null +++ b/Resources/Textures/Objects/Tools/scissors.rsi/meta.json @@ -0,0 +1,14 @@ +{ + "version": 1, + "license": "CC0-1.0", + "copyright": "Created by TheShuEd(github) for Space Station 14", + "size": { + "x": 32, + "y": 32 + }, + "states": [ + { + "name": "icon" + } + ] +}