Barber scissors fix (#22895)
* barber! * 5% change to maintenance * some fixes * refactor some * ElectroJR fix merge * aoa * remvoe humanoid * Magic mirror cleanup * Cleanup * Bunch more fixes * Fix nohair + range bugs * Fixes --------- Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -30,6 +30,7 @@ public sealed class MagicMirrorBoundUserInterface : BoundUserInterface
|
|||||||
_window.OnFacialHairSlotAdded += delegate () { AddSlot(MagicMirrorCategory.FacialHair); };
|
_window.OnFacialHairSlotAdded += delegate () { AddSlot(MagicMirrorCategory.FacialHair); };
|
||||||
_window.OnFacialHairSlotRemoved += args => RemoveSlot(MagicMirrorCategory.FacialHair, args);
|
_window.OnFacialHairSlotRemoved += args => RemoveSlot(MagicMirrorCategory.FacialHair, args);
|
||||||
|
|
||||||
|
_window.OnClose += Close;
|
||||||
_window.OpenCentered();
|
_window.OpenCentered();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,17 +54,18 @@ public sealed class MagicMirrorBoundUserInterface : BoundUserInterface
|
|||||||
SendMessage(new MagicMirrorAddSlotMessage(category));
|
SendMessage(new MagicMirrorAddSlotMessage(category));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
|
protected override void UpdateState(BoundUserInterfaceState state)
|
||||||
{
|
{
|
||||||
base.ReceiveMessage(message);
|
base.UpdateState(state);
|
||||||
|
|
||||||
if (message is not MagicMirrorUiData data || _window == null)
|
if (state is not MagicMirrorUiState data || _window == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_window.UpdateState(data);
|
_window.UpdateState(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ public sealed partial class MagicMirrorWindow : DefaultWindow
|
|||||||
public Action<int>? OnFacialHairSlotRemoved;
|
public Action<int>? OnFacialHairSlotRemoved;
|
||||||
public Action? OnFacialHairSlotAdded;
|
public Action? OnFacialHairSlotAdded;
|
||||||
|
|
||||||
private bool _noHair;
|
|
||||||
|
|
||||||
public MagicMirrorWindow()
|
public MagicMirrorWindow()
|
||||||
{
|
{
|
||||||
RobustXamlLoader.Load(this);
|
RobustXamlLoader.Load(this);
|
||||||
@@ -38,15 +36,14 @@ public sealed partial class MagicMirrorWindow : DefaultWindow
|
|||||||
FacialHairPicker.OnSlotAdd += delegate { OnFacialHairSlotAdded!(); };
|
FacialHairPicker.OnSlotAdd += delegate { OnFacialHairSlotAdded!(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateState(MagicMirrorUiData state)
|
public void UpdateState(MagicMirrorUiState state)
|
||||||
{
|
{
|
||||||
HairPicker.UpdateData(state.Hair, state.Species, state.HairSlotTotal);
|
HairPicker.UpdateData(state.Hair, state.Species, state.HairSlotTotal);
|
||||||
FacialHairPicker.UpdateData(state.FacialHair, state.Species, state.FacialHairSlotTotal);
|
FacialHairPicker.UpdateData(state.FacialHair, state.Species, state.FacialHairSlotTotal);
|
||||||
|
|
||||||
if (!HairPicker.Visible && !FacialHairPicker.Visible && !_noHair)
|
if (!HairPicker.Visible && !FacialHairPicker.Visible)
|
||||||
{
|
{
|
||||||
AddChild(new Label { Text = Loc.GetString("magic-mirror-component-activate-user-has-no-hair") });
|
AddChild(new Label { Text = Loc.GetString("magic-mirror-component-activate-user-has-no-hair") });
|
||||||
_noHair = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace Content.Server.Interaction
|
|||||||
|
|
||||||
private void HandleUserInterfaceRangeCheck(ref BoundUserInterfaceCheckRangeEvent ev)
|
private void HandleUserInterfaceRangeCheck(ref BoundUserInterfaceCheckRangeEvent ev)
|
||||||
{
|
{
|
||||||
if (ev.Player.AttachedEntity is not { } user)
|
if (ev.Player.AttachedEntity is not { } user || ev.Result == BoundUserInterfaceRangeResult.Fail)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (InRangeUnobstructed(user, ev.Target, ev.UserInterface.InteractionRange))
|
if (InRangeUnobstructed(user, ev.Target, ev.UserInterface.InteractionRange))
|
||||||
|
|||||||
@@ -3,23 +3,45 @@ using Robust.Shared.Audio;
|
|||||||
|
|
||||||
namespace Content.Server.MagicMirror;
|
namespace Content.Server.MagicMirror;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows humanoids to change their appearance mid-round.
|
||||||
|
/// </summary>
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed partial class MagicMirrorComponent : Component
|
public sealed partial class MagicMirrorComponent : Component
|
||||||
{
|
{
|
||||||
public Entity<HumanoidAppearanceComponent>? Target;
|
/// <summary>
|
||||||
|
/// Magic mirror target, used for validating UI messages.
|
||||||
|
/// </summary>
|
||||||
|
[DataField]
|
||||||
|
public EntityUid? Target;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// doafter time required to add a new slot
|
||||||
|
/// </summary>
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float AddSlotTime = 5f;
|
public TimeSpan AddSlotTime = TimeSpan.FromSeconds(5);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// doafter time required to remove a existing slot
|
||||||
|
/// </summary>
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float RemoveSlotTime = 2f;
|
public TimeSpan RemoveSlotTime = TimeSpan.FromSeconds(2);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// doafter time required to change slot
|
||||||
|
/// </summary>
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float SelectSlotTime = 3f;
|
public TimeSpan SelectSlotTime = TimeSpan.FromSeconds(3);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// doafter time required to recolor slot
|
||||||
|
/// </summary>
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float ChangeSlotTime = 1f;
|
public TimeSpan ChangeSlotTime = TimeSpan.FromSeconds(1);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sound emitted when slots are changed
|
||||||
|
/// </summary>
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public SoundSpecifier ChangeHairSound = new SoundPathSpecifier("/Audio/Items/scissors.ogg");
|
public SoundSpecifier ChangeHairSound = new SoundPathSpecifier("/Audio/Items/scissors.ogg");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,20 +13,23 @@ using Robust.Shared.Player;
|
|||||||
|
|
||||||
namespace Content.Server.MagicMirror;
|
namespace Content.Server.MagicMirror;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows humanoids to change their appearance mid-round.
|
||||||
|
/// </summary>
|
||||||
public sealed class MagicMirrorSystem : EntitySystem
|
public sealed class MagicMirrorSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||||
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
|
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
|
||||||
[Dependency] private readonly MarkingManager _markings = default!;
|
[Dependency] private readonly MarkingManager _markings = default!;
|
||||||
[Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
|
[Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
|
||||||
|
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
|
||||||
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
||||||
|
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<MagicMirrorComponent, ActivatableUIOpenAttemptEvent>(OnOpenUIAttempt);
|
SubscribeLocalEvent<MagicMirrorComponent, ActivatableUIOpenAttemptEvent>(OnOpenUIAttempt);
|
||||||
SubscribeLocalEvent<MagicMirrorComponent, AfterActivatableUIOpenEvent>(AfterUIOpen);
|
SubscribeLocalEvent<MagicMirrorComponent, BoundUIClosedEvent>(OnUIClosed);
|
||||||
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorSelectMessage>(OnMagicMirrorSelect);
|
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorSelectMessage>(OnMagicMirrorSelect);
|
||||||
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorChangeColorMessage>(OnTryMagicMirrorChangeColor);
|
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorChangeColorMessage>(OnTryMagicMirrorChangeColor);
|
||||||
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorAddSlotMessage>(OnTryMagicMirrorAddSlot);
|
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorAddSlotMessage>(OnTryMagicMirrorAddSlot);
|
||||||
@@ -34,21 +37,34 @@ public sealed class MagicMirrorSystem : EntitySystem
|
|||||||
|
|
||||||
SubscribeLocalEvent<MagicMirrorComponent, AfterInteractEvent>(OnMagicMirrorInteract);
|
SubscribeLocalEvent<MagicMirrorComponent, AfterInteractEvent>(OnMagicMirrorInteract);
|
||||||
|
|
||||||
SubscribeLocalEvent<MagicMirrorComponent, SelectDoAfterEvent>(OnSelectSlotDoAfter);
|
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorSelectDoAfterEvent>(OnSelectSlotDoAfter);
|
||||||
SubscribeLocalEvent<MagicMirrorComponent, ChangeColorDoAfterEvent>(OnChangeColorDoAfter);
|
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorChangeColorDoAfterEvent>(OnChangeColorDoAfter);
|
||||||
SubscribeLocalEvent<MagicMirrorComponent, RemoveSlotDoAfterEvent>(OnRemoveSlotDoAfter);
|
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorRemoveSlotDoAfterEvent>(OnRemoveSlotDoAfter);
|
||||||
SubscribeLocalEvent<MagicMirrorComponent, AddSlotDoAfterEvent>(OnAddSlotDoAfter);
|
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorAddSlotDoAfterEvent>(OnAddSlotDoAfter);
|
||||||
|
|
||||||
|
SubscribeLocalEvent<MagicMirrorComponent, BoundUserInterfaceCheckRangeEvent>(OnMirrorRangeCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMirrorRangeCheck(EntityUid uid, MagicMirrorComponent component, ref BoundUserInterfaceCheckRangeEvent args)
|
||||||
|
{
|
||||||
|
if (!Exists(component.Target) || !_interaction.InRangeUnobstructed(uid, component.Target.Value))
|
||||||
|
{
|
||||||
|
args.Result = BoundUserInterfaceRangeResult.Fail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMagicMirrorInteract(Entity<MagicMirrorComponent> mirror, ref AfterInteractEvent args)
|
private void OnMagicMirrorInteract(Entity<MagicMirrorComponent> mirror, ref AfterInteractEvent args)
|
||||||
{
|
{
|
||||||
if (!TryComp<ActorComponent>(args.User, out var actor)) return;
|
if (!args.CanReach || args.Target == null)
|
||||||
if (TryComp<HumanoidAppearanceComponent>(args.Target, out var humanoid))
|
return;
|
||||||
{
|
|
||||||
mirror.Comp.Target = new Entity<HumanoidAppearanceComponent>(args.Target.Value, humanoid);
|
if (!TryComp<ActorComponent>(args.User, out var actor))
|
||||||
UpdateInterface(mirror.Owner, mirror.Comp.Target.Value.Owner, actor.PlayerSession);
|
return;
|
||||||
Log.Debug($"Target {mirror.Comp.Target}!");
|
|
||||||
};
|
if (!_uiSystem.TryOpen(mirror.Owner, MagicMirrorUiKey.Key, actor.PlayerSession))
|
||||||
|
return;
|
||||||
|
|
||||||
|
UpdateInterface(mirror.Owner, args.Target.Value, mirror.Comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnOpenUIAttempt(EntityUid uid, MagicMirrorComponent mirror, ActivatableUIOpenAttemptEvent args)
|
private void OnOpenUIAttempt(EntityUid uid, MagicMirrorComponent mirror, ActivatableUIOpenAttemptEvent args)
|
||||||
@@ -59,12 +75,19 @@ public sealed class MagicMirrorSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnMagicMirrorSelect(EntityUid uid, MagicMirrorComponent component, MagicMirrorSelectMessage message)
|
private void OnMagicMirrorSelect(EntityUid uid, MagicMirrorComponent component, MagicMirrorSelectMessage message)
|
||||||
{
|
{
|
||||||
if (component.Target == null) return;
|
if (component.Target is not { } target || message.Session.AttachedEntity is not { } user)
|
||||||
if (message.Session.AttachedEntity == null) return;
|
return;
|
||||||
|
|
||||||
var doAfter = new SelectDoAfterEvent(message);
|
var doAfter = new MagicMirrorSelectDoAfterEvent()
|
||||||
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, message.Session.AttachedEntity.Value, component.SelectSlotTime, doAfter, uid, target: component.Target.Value.Owner, used: uid)
|
|
||||||
{
|
{
|
||||||
|
Category = message.Category,
|
||||||
|
Slot = message.Slot,
|
||||||
|
Marking = message.Marking,
|
||||||
|
};
|
||||||
|
|
||||||
|
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, user, component.SelectSlotTime, doAfter, uid, target: target, used: uid)
|
||||||
|
{
|
||||||
|
DistanceThreshold = SharedInteractionSystem.InteractionRange,
|
||||||
BreakOnTargetMove = true,
|
BreakOnTargetMove = true,
|
||||||
BreakOnDamage = true,
|
BreakOnDamage = true,
|
||||||
BreakOnHandChange = false,
|
BreakOnHandChange = false,
|
||||||
@@ -75,14 +98,18 @@ public sealed class MagicMirrorSystem : EntitySystem
|
|||||||
|
|
||||||
_audio.PlayPvs(component.ChangeHairSound, uid);
|
_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;
|
private void OnSelectSlotDoAfter(EntityUid uid, MagicMirrorComponent component, MagicMirrorSelectDoAfterEvent args)
|
||||||
switch (args.Message.Category)
|
{
|
||||||
|
if (args.Handled || args.Target == null || args.Cancelled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (component.Target != args.Target)
|
||||||
|
return;
|
||||||
|
|
||||||
|
MarkingCategories category;
|
||||||
|
|
||||||
|
switch (args.Category)
|
||||||
{
|
{
|
||||||
case MagicMirrorCategory.Hair:
|
case MagicMirrorCategory.Hair:
|
||||||
category = MarkingCategories.Hair;
|
category = MarkingCategories.Hair;
|
||||||
@@ -94,18 +121,24 @@ public sealed class MagicMirrorSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_humanoid.SetMarkingId(component.Target.Value.Owner, category, args.Message.Slot, args.Message.Marking);
|
_humanoid.SetMarkingId(component.Target.Value, category, args.Slot, args.Marking);
|
||||||
|
|
||||||
UpdateInterface(uid, component.Target.Value.Owner, args.Message.Session);
|
UpdateInterface(uid, component.Target.Value, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTryMagicMirrorChangeColor(EntityUid uid, MagicMirrorComponent component, MagicMirrorChangeColorMessage message)
|
private void OnTryMagicMirrorChangeColor(EntityUid uid, MagicMirrorComponent component, MagicMirrorChangeColorMessage message)
|
||||||
{
|
{
|
||||||
if (component.Target == null) return;
|
if (component.Target is not { } target || message.Session.AttachedEntity is not { } user)
|
||||||
if (message.Session.AttachedEntity == null) return;
|
return;
|
||||||
|
|
||||||
var doAfter = new ChangeColorDoAfterEvent(message);
|
var doAfter = new MagicMirrorChangeColorDoAfterEvent()
|
||||||
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, message.Session.AttachedEntity.Value, component.ChangeSlotTime, doAfter, uid, target: component.Target.Value.Owner, used: uid)
|
{
|
||||||
|
Category = message.Category,
|
||||||
|
Slot = message.Slot,
|
||||||
|
Colors = message.Colors,
|
||||||
|
};
|
||||||
|
|
||||||
|
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, user, component.ChangeSlotTime, doAfter, uid, target: target, used: uid)
|
||||||
{
|
{
|
||||||
BreakOnTargetMove = true,
|
BreakOnTargetMove = true,
|
||||||
BreakOnDamage = true,
|
BreakOnDamage = true,
|
||||||
@@ -115,14 +148,16 @@ public sealed class MagicMirrorSystem : EntitySystem
|
|||||||
NeedHand = true
|
NeedHand = true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
private void OnChangeColorDoAfter(EntityUid uid, MagicMirrorComponent component, ChangeColorDoAfterEvent args)
|
private void OnChangeColorDoAfter(EntityUid uid, MagicMirrorComponent component, MagicMirrorChangeColorDoAfterEvent args)
|
||||||
{
|
{
|
||||||
if (args.Handled || args.Args.Target == null || args.Cancelled)
|
if (args.Handled || args.Target == null || args.Cancelled)
|
||||||
return;
|
return;
|
||||||
if (component.Target == null) return;
|
|
||||||
|
|
||||||
var category = MarkingCategories.Hair;
|
if (component.Target != args.Target)
|
||||||
switch (args.Message.Category)
|
return;
|
||||||
|
|
||||||
|
MarkingCategories category;
|
||||||
|
switch (args.Category)
|
||||||
{
|
{
|
||||||
case MagicMirrorCategory.Hair:
|
case MagicMirrorCategory.Hair:
|
||||||
category = MarkingCategories.Hair;
|
category = MarkingCategories.Hair;
|
||||||
@@ -134,20 +169,27 @@ public sealed class MagicMirrorSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_humanoid.SetMarkingColor(component.Target.Value.Owner, category, args.Message.Slot, args.Message.Colors);
|
_humanoid.SetMarkingColor(component.Target.Value, category, args.Slot, args.Colors);
|
||||||
|
|
||||||
// using this makes the UI feel like total ass
|
// using this makes the UI feel like total ass
|
||||||
|
// que
|
||||||
// UpdateInterface(uid, component.Target, message.Session);
|
// UpdateInterface(uid, component.Target, message.Session);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTryMagicMirrorRemoveSlot(EntityUid uid, MagicMirrorComponent component, MagicMirrorRemoveSlotMessage message)
|
private void OnTryMagicMirrorRemoveSlot(EntityUid uid, MagicMirrorComponent component, MagicMirrorRemoveSlotMessage message)
|
||||||
{
|
{
|
||||||
if (component.Target == null) return;
|
if (component.Target is not { } target || message.Session.AttachedEntity is not { } user)
|
||||||
if (message.Session.AttachedEntity == null) return;
|
return;
|
||||||
|
|
||||||
var doAfter = new RemoveSlotDoAfterEvent(message);
|
var doAfter = new MagicMirrorRemoveSlotDoAfterEvent()
|
||||||
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, message.Session.AttachedEntity.Value, component.RemoveSlotTime, doAfter, uid, target: component.Target.Value.Owner, used: uid)
|
|
||||||
{
|
{
|
||||||
|
Category = message.Category,
|
||||||
|
Slot = message.Slot,
|
||||||
|
};
|
||||||
|
|
||||||
|
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, user, component.RemoveSlotTime, doAfter, uid, target: target, used: uid)
|
||||||
|
{
|
||||||
|
DistanceThreshold = SharedInteractionSystem.InteractionRange,
|
||||||
BreakOnTargetMove = true,
|
BreakOnTargetMove = true,
|
||||||
BreakOnDamage = true,
|
BreakOnDamage = true,
|
||||||
BreakOnHandChange = false,
|
BreakOnHandChange = false,
|
||||||
@@ -158,15 +200,18 @@ public sealed class MagicMirrorSystem : EntitySystem
|
|||||||
|
|
||||||
_audio.PlayPvs(component.ChangeHairSound, uid);
|
_audio.PlayPvs(component.ChangeHairSound, uid);
|
||||||
}
|
}
|
||||||
private void OnRemoveSlotDoAfter(EntityUid uid, MagicMirrorComponent component, RemoveSlotDoAfterEvent args)
|
|
||||||
|
private void OnRemoveSlotDoAfter(EntityUid uid, MagicMirrorComponent component, MagicMirrorRemoveSlotDoAfterEvent args)
|
||||||
{
|
{
|
||||||
if (args.Handled || args.Args.Target == null || args.Cancelled)
|
if (args.Handled || args.Target == null || args.Cancelled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (component.Target == null) return;
|
if (component.Target != args.Target)
|
||||||
|
return;
|
||||||
|
|
||||||
var category = MarkingCategories.Hair;
|
MarkingCategories category;
|
||||||
switch (args.Message.Category)
|
|
||||||
|
switch (args.Category)
|
||||||
{
|
{
|
||||||
case MagicMirrorCategory.Hair:
|
case MagicMirrorCategory.Hair:
|
||||||
category = MarkingCategories.Hair;
|
category = MarkingCategories.Hair;
|
||||||
@@ -178,18 +223,25 @@ public sealed class MagicMirrorSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_humanoid.RemoveMarking(component.Target.Value.Owner, category, args.Message.Slot);
|
_humanoid.RemoveMarking(component.Target.Value, category, args.Slot);
|
||||||
|
|
||||||
UpdateInterface(uid, component.Target.Value.Owner, args.Message.Session);
|
UpdateInterface(uid, component.Target.Value, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTryMagicMirrorAddSlot(EntityUid uid, MagicMirrorComponent component, MagicMirrorAddSlotMessage message)
|
private void OnTryMagicMirrorAddSlot(EntityUid uid, MagicMirrorComponent component, MagicMirrorAddSlotMessage message)
|
||||||
{
|
{
|
||||||
if (component.Target == null) return;
|
if (component.Target == null)
|
||||||
if (message.Session.AttachedEntity == null) return;
|
return;
|
||||||
|
|
||||||
var doAfter = new AddSlotDoAfterEvent(message);
|
if (message.Session.AttachedEntity == null)
|
||||||
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, message.Session.AttachedEntity.Value, component.AddSlotTime, doAfter, uid, target: component.Target.Value.Owner, used: uid)
|
return;
|
||||||
|
|
||||||
|
var doAfter = new MagicMirrorAddSlotDoAfterEvent()
|
||||||
|
{
|
||||||
|
Category = message.Category,
|
||||||
|
};
|
||||||
|
|
||||||
|
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, message.Session.AttachedEntity.Value, component.AddSlotTime, doAfter, uid, target: component.Target.Value, used: uid)
|
||||||
{
|
{
|
||||||
BreakOnTargetMove = true,
|
BreakOnTargetMove = true,
|
||||||
BreakOnDamage = true,
|
BreakOnDamage = true,
|
||||||
@@ -198,17 +250,17 @@ public sealed class MagicMirrorSystem : EntitySystem
|
|||||||
BreakOnWeightlessMove = false,
|
BreakOnWeightlessMove = false,
|
||||||
NeedHand = true
|
NeedHand = true
|
||||||
});
|
});
|
||||||
|
|
||||||
_audio.PlayPvs(component.ChangeHairSound, uid);
|
_audio.PlayPvs(component.ChangeHairSound, uid);
|
||||||
}
|
}
|
||||||
private void OnAddSlotDoAfter(EntityUid uid, MagicMirrorComponent component, AddSlotDoAfterEvent args)
|
private void OnAddSlotDoAfter(EntityUid uid, MagicMirrorComponent component, MagicMirrorAddSlotDoAfterEvent args)
|
||||||
{
|
{
|
||||||
if (args.Handled || args.Args.Target == null || args.Cancelled)
|
if (args.Handled || args.Target == null || args.Cancelled || !TryComp(component.Target, out HumanoidAppearanceComponent? humanoid))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (component.Target == null) return;
|
MarkingCategories category;
|
||||||
|
|
||||||
var category = MarkingCategories.Hair;
|
switch (args.Category)
|
||||||
switch (args.Message.Category)
|
|
||||||
{
|
{
|
||||||
case MagicMirrorCategory.Hair:
|
case MagicMirrorCategory.Hair:
|
||||||
category = MarkingCategories.Hair;
|
category = MarkingCategories.Hair;
|
||||||
@@ -220,21 +272,21 @@ public sealed class MagicMirrorSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var marking = _markings.MarkingsByCategoryAndSpecies(category, component.Target.Value.Comp.Species).Keys.FirstOrDefault();
|
var marking = _markings.MarkingsByCategoryAndSpecies(category, humanoid.Species).Keys.FirstOrDefault();
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(marking))
|
if (string.IsNullOrEmpty(marking))
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
_humanoid.AddMarking(component.Target.Value, marking, Color.Black);
|
||||||
|
|
||||||
|
UpdateInterface(uid, component.Target.Value, component);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_humanoid.AddMarking(component.Target.Value.Owner, marking, Color.Black);
|
private void UpdateInterface(EntityUid mirrorUid, EntityUid targetUid, MagicMirrorComponent component)
|
||||||
|
|
||||||
UpdateInterface(uid, component.Target.Value.Owner, args.Message.Session);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateInterface(EntityUid uid, EntityUid playerUid, ICommonSession session)
|
|
||||||
{
|
{
|
||||||
if (!TryComp<HumanoidAppearanceComponent>(playerUid, out var humanoid)) return;
|
if (!TryComp<HumanoidAppearanceComponent>(targetUid, out var humanoid))
|
||||||
if (session is not { } player) return;
|
return;
|
||||||
|
|
||||||
var hair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.Hair, out var hairMarkings)
|
var hair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.Hair, out var hairMarkings)
|
||||||
? new List<Marking>(hairMarkings)
|
? new List<Marking>(hairMarkings)
|
||||||
@@ -244,21 +296,19 @@ public sealed class MagicMirrorSystem : EntitySystem
|
|||||||
? new List<Marking>(facialHairMarkings)
|
? new List<Marking>(facialHairMarkings)
|
||||||
: new();
|
: new();
|
||||||
|
|
||||||
var msg = new MagicMirrorUiData(
|
var state = new MagicMirrorUiState(
|
||||||
humanoid.Species,
|
humanoid.Species,
|
||||||
hair,
|
hair,
|
||||||
humanoid.MarkingSet.PointsLeft(MarkingCategories.Hair) + hair.Count,
|
humanoid.MarkingSet.PointsLeft(MarkingCategories.Hair) + hair.Count,
|
||||||
facialHair,
|
facialHair,
|
||||||
humanoid.MarkingSet.PointsLeft(MarkingCategories.FacialHair) + facialHair.Count);
|
humanoid.MarkingSet.PointsLeft(MarkingCategories.FacialHair) + facialHair.Count);
|
||||||
|
|
||||||
_uiSystem.TrySendUiMessage(uid, MagicMirrorUiKey.Key, msg, player);
|
component.Target = targetUid;
|
||||||
|
_uiSystem.TrySetUiState(mirrorUid, MagicMirrorUiKey.Key, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AfterUIOpen(EntityUid uid, MagicMirrorComponent component, AfterActivatableUIOpenEvent args)
|
private void OnUIClosed(Entity<MagicMirrorComponent> ent, ref BoundUIClosedEvent args)
|
||||||
{
|
{
|
||||||
if (!TryComp<HumanoidAppearanceComponent>(args.User, out var humanoid)) return;
|
ent.Comp.Target = null;
|
||||||
component.Target = new Entity<HumanoidAppearanceComponent>(args.User, humanoid);
|
|
||||||
|
|
||||||
UpdateInterface(uid, args.User, args.Session);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
using Content.Shared.DoAfter;
|
using Content.Shared.DoAfter;
|
||||||
using Content.Shared.Humanoid.Markings;
|
using Content.Shared.Humanoid.Markings;
|
||||||
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.MagicMirror;
|
namespace Content.Shared.MagicMirror;
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public enum MagicMirrorUiKey
|
public enum MagicMirrorUiKey : byte
|
||||||
{
|
{
|
||||||
Key
|
Key
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public enum MagicMirrorCategory
|
public enum MagicMirrorCategory : byte
|
||||||
{
|
{
|
||||||
Hair,
|
Hair,
|
||||||
FacialHair
|
FacialHair
|
||||||
@@ -85,9 +86,9 @@ public sealed class MagicMirrorAddSlotMessage : BoundUserInterfaceMessage
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class MagicMirrorUiData : BoundUserInterfaceMessage
|
public sealed class MagicMirrorUiState : BoundUserInterfaceState
|
||||||
{
|
{
|
||||||
public MagicMirrorUiData(string species, List<Marking> hair, int hairSlotTotal, List<Marking> facialHair, int facialHairSlotTotal)
|
public MagicMirrorUiState(string species, List<Marking> hair, int hairSlotTotal, List<Marking> facialHair, int facialHairSlotTotal)
|
||||||
{
|
{
|
||||||
Species = species;
|
Species = species;
|
||||||
Hair = hair;
|
Hair = hair;
|
||||||
@@ -96,60 +97,47 @@ public sealed class MagicMirrorUiData : BoundUserInterfaceMessage
|
|||||||
FacialHairSlotTotal = facialHairSlotTotal;
|
FacialHairSlotTotal = facialHairSlotTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Species { get; }
|
public NetEntity Target;
|
||||||
|
|
||||||
public List<Marking> Hair { get; }
|
public string Species;
|
||||||
public int HairSlotTotal { get; }
|
|
||||||
|
|
||||||
public List<Marking> FacialHair { get; }
|
public List<Marking> Hair;
|
||||||
public int FacialHairSlotTotal { get; }
|
public int HairSlotTotal;
|
||||||
|
|
||||||
|
public List<Marking> FacialHair;
|
||||||
|
public int FacialHairSlotTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed partial class RemoveSlotDoAfterEvent : DoAfterEvent
|
public sealed partial class MagicMirrorRemoveSlotDoAfterEvent : DoAfterEvent
|
||||||
{
|
{
|
||||||
public MagicMirrorRemoveSlotMessage Message;
|
public override DoAfterEvent Clone() => this;
|
||||||
|
public MagicMirrorCategory Category;
|
||||||
public RemoveSlotDoAfterEvent(MagicMirrorRemoveSlotMessage message)
|
public int Slot;
|
||||||
{
|
|
||||||
Message = message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public sealed partial class MagicMirrorAddSlotDoAfterEvent : DoAfterEvent
|
||||||
|
{
|
||||||
|
public override DoAfterEvent Clone() => this;
|
||||||
|
public MagicMirrorCategory Category;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public sealed partial class MagicMirrorSelectDoAfterEvent : DoAfterEvent
|
||||||
|
{
|
||||||
|
public MagicMirrorCategory Category;
|
||||||
|
public int Slot;
|
||||||
|
public string Marking = string.Empty;
|
||||||
|
|
||||||
public override DoAfterEvent Clone() => this;
|
public override DoAfterEvent Clone() => this;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed partial class AddSlotDoAfterEvent : DoAfterEvent
|
public sealed partial class MagicMirrorChangeColorDoAfterEvent : 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;
|
public override DoAfterEvent Clone() => this;
|
||||||
|
public MagicMirrorCategory Category;
|
||||||
|
public int Slot;
|
||||||
|
public List<Color> Colors = new List<Color>();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user