actually fix magic mirrors (#28282)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System.Linq;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Humanoid;
|
||||
using Content.Shared.UserInterface;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Humanoid;
|
||||
using Content.Shared.Humanoid.Markings;
|
||||
@@ -24,7 +23,6 @@ public sealed class MagicMirrorSystem : SharedMagicMirrorSystem
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<MagicMirrorComponent, ActivatableUIOpenAttemptEvent>(OnOpenUIAttempt);
|
||||
|
||||
Subs.BuiEvents<MagicMirrorComponent>(MagicMirrorUiKey.Key,
|
||||
subs =>
|
||||
@@ -36,7 +34,6 @@ public sealed class MagicMirrorSystem : SharedMagicMirrorSystem
|
||||
subs.Event<MagicMirrorRemoveSlotMessage>(OnTryMagicMirrorRemoveSlot);
|
||||
});
|
||||
|
||||
SubscribeLocalEvent<MagicMirrorComponent, AfterInteractEvent>(OnMagicMirrorInteract);
|
||||
|
||||
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorSelectDoAfterEvent>(OnSelectSlotDoAfter);
|
||||
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorChangeColorDoAfterEvent>(OnChangeColorDoAfter);
|
||||
@@ -44,23 +41,6 @@ public sealed class MagicMirrorSystem : SharedMagicMirrorSystem
|
||||
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorAddSlotDoAfterEvent>(OnAddSlotDoAfter);
|
||||
}
|
||||
|
||||
private void OnMagicMirrorInteract(Entity<MagicMirrorComponent> mirror, ref AfterInteractEvent args)
|
||||
{
|
||||
if (!args.CanReach || args.Target == null)
|
||||
return;
|
||||
|
||||
if (!_uiSystem.TryOpenUi(mirror.Owner, MagicMirrorUiKey.Key, args.User))
|
||||
return;
|
||||
|
||||
UpdateInterface(mirror.Owner, args.Target.Value, mirror.Comp);
|
||||
}
|
||||
|
||||
private void OnOpenUIAttempt(EntityUid uid, MagicMirrorComponent mirror, ActivatableUIOpenAttemptEvent args)
|
||||
{
|
||||
if (!HasComp<HumanoidAppearanceComponent>(args.User))
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
private void OnMagicMirrorSelect(EntityUid uid, MagicMirrorComponent component, MagicMirrorSelectMessage message)
|
||||
{
|
||||
if (component.Target is not { } target)
|
||||
@@ -83,7 +63,8 @@ public sealed class MagicMirrorSystem : SharedMagicMirrorSystem
|
||||
BreakOnMove = true,
|
||||
BreakOnHandChange = false,
|
||||
NeedHand = true
|
||||
}, out var doAfterId);
|
||||
},
|
||||
out var doAfterId);
|
||||
|
||||
component.DoAfter = doAfterId;
|
||||
_audio.PlayPvs(component.ChangeHairSound, uid);
|
||||
@@ -137,7 +118,8 @@ public sealed class MagicMirrorSystem : SharedMagicMirrorSystem
|
||||
BreakOnMove = true,
|
||||
BreakOnHandChange = false,
|
||||
NeedHand = true
|
||||
}, out var doAfterId);
|
||||
},
|
||||
out var doAfterId);
|
||||
|
||||
component.DoAfter = doAfterId;
|
||||
}
|
||||
@@ -189,7 +171,8 @@ public sealed class MagicMirrorSystem : SharedMagicMirrorSystem
|
||||
BreakOnDamage = true,
|
||||
BreakOnHandChange = false,
|
||||
NeedHand = true
|
||||
}, out var doAfterId);
|
||||
},
|
||||
out var doAfterId);
|
||||
|
||||
component.DoAfter = doAfterId;
|
||||
_audio.PlayPvs(component.ChangeHairSound, uid);
|
||||
@@ -241,7 +224,8 @@ public sealed class MagicMirrorSystem : SharedMagicMirrorSystem
|
||||
BreakOnMove = true,
|
||||
BreakOnHandChange = false,
|
||||
NeedHand = true
|
||||
}, out var doAfterId);
|
||||
},
|
||||
out var doAfterId);
|
||||
|
||||
component.DoAfter = doAfterId;
|
||||
_audio.PlayPvs(component.ChangeHairSound, uid);
|
||||
|
||||
@@ -11,15 +11,27 @@ namespace Content.Shared.MagicMirror;
|
||||
public abstract class SharedMagicMirrorSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
|
||||
[Dependency] protected readonly SharedUserInterfaceSystem _uiSystem = default!;
|
||||
[Dependency] protected readonly SharedUserInterfaceSystem UISystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<MagicMirrorComponent, AfterInteractEvent>(OnMagicMirrorInteract);
|
||||
SubscribeLocalEvent<MagicMirrorComponent, BeforeActivatableUIOpenEvent>(OnBeforeUIOpen);
|
||||
SubscribeLocalEvent<MagicMirrorComponent, BoundUserInterfaceCheckRangeEvent>(OnMirrorRangeCheck);
|
||||
}
|
||||
|
||||
private void OnMagicMirrorInteract(Entity<MagicMirrorComponent> mirror, ref AfterInteractEvent args)
|
||||
{
|
||||
if (!args.CanReach || args.Target == null)
|
||||
return;
|
||||
|
||||
if (!UISystem.TryOpenUi(mirror.Owner, MagicMirrorUiKey.Key, args.User))
|
||||
return;
|
||||
|
||||
UpdateInterface(mirror, args.Target.Value, mirror);
|
||||
}
|
||||
|
||||
private void OnMirrorRangeCheck(EntityUid uid, MagicMirrorComponent component, ref BoundUserInterfaceCheckRangeEvent args)
|
||||
{
|
||||
if (args.Result == BoundUserInterfaceRangeResult.Fail)
|
||||
@@ -33,7 +45,9 @@ public abstract class SharedMagicMirrorSystem : EntitySystem
|
||||
|
||||
private void OnBeforeUIOpen(Entity<MagicMirrorComponent> ent, ref BeforeActivatableUIOpenEvent args)
|
||||
{
|
||||
ent.Comp.Target ??= args.User;
|
||||
if (args.User != ent.Comp.Target && ent.Comp.Target != null)
|
||||
return;
|
||||
|
||||
UpdateInterface(ent, args.User, ent);
|
||||
}
|
||||
|
||||
@@ -41,6 +55,7 @@ public abstract class SharedMagicMirrorSystem : EntitySystem
|
||||
{
|
||||
if (!TryComp<HumanoidAppearanceComponent>(targetUid, out var humanoid))
|
||||
return;
|
||||
component.Target ??= targetUid;
|
||||
|
||||
var hair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.Hair, out var hairMarkings)
|
||||
? new List<Marking>(hairMarkings)
|
||||
@@ -59,7 +74,7 @@ public abstract class SharedMagicMirrorSystem : EntitySystem
|
||||
|
||||
// TODO: Component states
|
||||
component.Target = targetUid;
|
||||
_uiSystem.SetUiState(mirrorUid, MagicMirrorUiKey.Key, state);
|
||||
UISystem.SetUiState(mirrorUid, MagicMirrorUiKey.Key, state);
|
||||
Dirty(mirrorUid, component);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user