using Content.Shared.Mind; using Robust.Shared.Player; using Robust.Shared.Prototypes; namespace Content.Shared._DV.FeedbackOverwatch; public sealed partial class SharedFeedbackOverwatchSystem : EntitySystem { [Dependency] private readonly SharedMindSystem _mind = default!; [Dependency] private readonly IPrototypeManager _proto = default!; [Dependency] private readonly ISharedPlayerManager _player = default!; public List FeedbackPopupProtoIds { get; } = new(); public override void Initialize() { InitializeEvents(); SubscribeLocalEvent(OnPrototypesReloaded); LoadPrototypes(); } private void OnPrototypesReloaded(PrototypesReloadedEventArgs args) { if (!args.WasModified()) return; LoadPrototypes(); } /// /// Load all the prototype IDs into FeedbackPopupProtoIds. /// private void LoadPrototypes() { FeedbackPopupProtoIds.Clear(); var protos = _proto.EnumeratePrototypes(); foreach (var proto in protos) FeedbackPopupProtoIds.Add(proto.ID); FeedbackPopupProtoIds.Sort(); } /// /// Send a popup to the given client controlling the given UID. /// /// UID of the entity the player is controlling. /// Popup to send them. /// If true, if the popup is sent to the same mind again, it will not be displayed. /// Returns true if the popup message was sent to the client successfully. public bool SendPopup(EntityUid? uid, ProtoId popupPrototype, bool sendOnlyOnce = true) { if (uid == null) return false; if (!_mind.TryGetMind(uid.Value, out var mindUid, out _)) return false; return SendPopupMind(mindUid, popupPrototype, sendOnlyOnce); } /// /// Send a popup to the given client controlling the given mind. /// /// UID of the players mind. /// Popup to send them. /// If true, if the popup is sent to the same mind again, it will not be displayed. /// Returns true if the popup message was sent to the client successfully. public bool SendPopupMind(EntityUid? mindId, ProtoId popupPrototype, bool sendOnlyOnce = true) { if (mindId is not {} uid || CompOrNull(mindId)?.UserId is not {} userId) return false; if (sendOnlyOnce) { EnsureComp(uid, out var feedbackInfoComp); // If it's already been seen, don't resend it. if (!feedbackInfoComp.SeenPopups.Add(popupPrototype)) return false; Dirty(uid, feedbackInfoComp); } if (!_player.TryGetSessionById(userId, out var session)) return false; var msg = new FeedbackPopupMessage(popupPrototype); RaiseNetworkEvent(msg, session); return true; } }