private void OnActionPerform(EntityUid uid, ServerUserInterfaceComponent component, OpenUiActionEvent args) { if (args.Handled || args.Key == null) { return; } if (!TryComp(args.Performer, out ActorComponent? actor)) { return; } if (!component.TryGetBoundUserInterface(args.Key, out var bui)) { return; } bui.Toggle(actor.PlayerSession); args.Handled = true; }
/// <summary> /// Verify that the subscribed clients are still in range of the entity. /// </summary> /// <param name="transformComp">Transform Component of the entity being checked.</param> /// <param name="uiComp">UserInterface Component of entity being checked.</param> private void CheckRange(ITransformComponent transformComp, ServerUserInterfaceComponent uiComp) { foreach (var ui in uiComp.Interfaces) { // We have to cache the set of sessions because Unsubscribe modifies the original. _sessionCache.Clear(); _sessionCache.AddRange(ui.SubscribedSessions); if (_sessionCache.Count == 0) { continue; } var uiPos = transformComp.WorldPosition; var uiMap = transformComp.MapID; foreach (var session in _sessionCache) { var attachedEntity = session.AttachedEntity; // The component manages the set of sessions, so this invalid session should be removed soon. if (attachedEntity == null || !attachedEntity.IsValid()) { continue; } if (uiMap != attachedEntity.Transform.MapID) { ui.Close(session); continue; } var distanceSquared = (uiPos - attachedEntity.Transform.WorldPosition).LengthSquared; if (distanceSquared > MaxWindowRangeSquared) { ui.Close(session); } } } }