private void AddOpenUiVerb(EntityUid uid, ActivatableUIComponent component, GetVerbsEvent <ActivationVerb> args) { if (!args.CanAccess) { return; } if (component.RequireHands && args.Hands == null) { return; } if (component.InHandsOnly && args.Using != uid) { return; } if (!args.CanInteract && (!component.AllowSpectator || !HasComp <GhostComponent>(args.User))) { return; } ActivationVerb verb = new(); verb.Act = () => InteractUI(args.User, component); verb.Text = Loc.GetString(component.VerbText); // TODO VERBS add "open UI" icon? args.Verbs.Add(verb); }
private void OnUseInHand(EntityUid uid, ActivatableUIComponent component, UseInHandEvent args) { if (args.Handled) { return; } args.Handled = InteractUI(args.User, component); }
private bool InteractUI(EntityUid user, ActivatableUIComponent aui) { if (!EntityManager.TryGetComponent(user, out ActorComponent? actor)) { return(false); } if (aui.AdminOnly && !_adminManager.IsAdmin(actor.PlayerSession)) { return(false); } var ui = aui.UserInterface; if (ui == null) { return(false); } if (aui.SingleUser && (aui.CurrentSingleUser != null) && (actor.PlayerSession != aui.CurrentSingleUser)) { // If we get here, supposedly, the object is in use. // Check with BUI that it's ACTUALLY in use just in case. // Since this could brick the object if it goes wrong. if (ui.SubscribedSessions.Count != 0) { return(false); } } // If we've gotten this far, fire a cancellable event that indicates someone is about to activate this. // This is so that stuff can require further conditions (like power). var oae = new ActivatableUIOpenAttemptEvent(user); var uae = new UserOpenActivatableUIAttemptEvent(user, aui.Owner); RaiseLocalEvent(user, uae, false); RaiseLocalEvent((aui).Owner, oae, false); if (oae.Cancelled || uae.Cancelled) { return(false); } // Give the UI an opportunity to prepare itself if it needs to do anything // before opening var bae = new BeforeActivatableUIOpenEvent(user); RaiseLocalEvent((aui).Owner, bae, false); SetCurrentSingleUser((aui).Owner, actor.PlayerSession, aui); ui.Toggle(actor.PlayerSession); //Let the component know a user opened it so it can do whatever it needs to do var aae = new AfterActivatableUIOpenEvent(user); RaiseLocalEvent((aui).Owner, aae, false); return(true); }
private void OnActivate(EntityUid uid, ActivatableUIComponent component, ActivateInWorldEvent args) { if (args.Handled) { return; } if (component.InHandsOnly) { return; } args.Handled = InteractUI(args.User, component); }
private void OnUIClose(EntityUid uid, ActivatableUIComponent component, BoundUIClosedEvent args) { if (args.Session != component.CurrentSingleUser) { return; } if (args.UiKey != component.Key) { return; } SetCurrentSingleUser(uid, null, component); }
private bool InteractUI(EntityUid user, ActivatableUIComponent aui) { if (!EntityManager.TryGetComponent(user, out ActorComponent? actor)) { return(false); } if (aui.AdminOnly && !_adminManager.IsAdmin(actor.PlayerSession)) { return(false); } if (!_actionBlockerSystem.CanInteract(user)) { user.PopupMessageCursor(Loc.GetString("base-computer-ui-component-cannot-interact")); return(true); } var ui = aui.UserInterface; if (ui == null) { return(false); } if (aui.SingleUser && (aui.CurrentSingleUser != null) && (actor.PlayerSession != aui.CurrentSingleUser)) { // If we get here, supposedly, the object is in use. // Check with BUI that it's ACTUALLY in use just in case. // Since this could brick the object if it goes wrong. if (ui.SubscribedSessions.Count != 0) { return(false); } } // If we've gotten this far, fire a cancellable event that indicates someone is about to activate this. // This is so that stuff can require further conditions (like power). var oae = new ActivatableUIOpenAttemptEvent(user); RaiseLocalEvent((aui).Owner, oae, false); if (oae.Cancelled) { return(false); } SetCurrentSingleUser((aui).Owner, actor.PlayerSession, aui); ui.Toggle(actor.PlayerSession); return(true); }
private void OnParentChanged(EntityUid uid, ActivatableUIComponent aui, ref EntParentChangedMessage args) { CloseAll(uid, aui); }