using JetBrains.Annotations; using Robust.Client.Player; using Robust.Shared.GameObjects; using Robust.Shared.IoC; namespace Robust.Client.GameObjects { [UsedImplicitly] public sealed class UserInterfaceSystem : SharedUserInterfaceSystem { [Dependency] private readonly IPlayerManager _playerManager = default!; public override void Initialize() { base.Initialize(); SubscribeNetworkEvent(MessageReceived); SubscribeLocalEvent(OnUserInterfaceShutdown); } private void OnUserInterfaceShutdown(EntityUid uid, ClientUserInterfaceComponent component, ComponentShutdown args) { foreach (var bui in component.Interfaces) { bui.Dispose(); } } private void MessageReceived(BoundUIWrapMessage ev) { var uid = ev.Entity; var cmp = ComponentManager.GetComponent(uid); var message = ev.Message; // This should probably not happen at this point, but better make extra sure! if(_playerManager.LocalPlayer != null) message.Session = _playerManager.LocalPlayer.Session; message.Entity = uid; message.UiKey = ev.UiKey; // Raise as object so the correct type is used. RaiseLocalEvent(uid, (object)message); cmp.MessageReceived(ev); } internal void Send(BoundUIWrapMessage msg) { RaiseNetworkEvent(msg); } } }