Kill UserInterfaceHelpers (#20912)
This commit is contained in:
@@ -76,7 +76,7 @@ public sealed partial class ActivatableUISystem : EntitySystem
|
||||
return;
|
||||
|
||||
ActivationVerb verb = new();
|
||||
verb.Act = () => InteractUI(args.User, component);
|
||||
verb.Act = () => InteractUI(args.User, uid, component);
|
||||
verb.Text = Loc.GetString(component.VerbText);
|
||||
// TODO VERBS add "open UI" icon?
|
||||
args.Verbs.Add(verb);
|
||||
@@ -84,16 +84,24 @@ public sealed partial class ActivatableUISystem : EntitySystem
|
||||
|
||||
private void OnActivate(EntityUid uid, ActivatableUIComponent component, ActivateInWorldEvent args)
|
||||
{
|
||||
if (args.Handled) return;
|
||||
if (component.InHandsOnly) return;
|
||||
args.Handled = InteractUI(args.User, component);
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (component.InHandsOnly)
|
||||
return;
|
||||
|
||||
args.Handled = InteractUI(args.User, uid, component);
|
||||
}
|
||||
|
||||
private void OnUseInHand(EntityUid uid, ActivatableUIComponent component, UseInHandEvent args)
|
||||
{
|
||||
if (args.Handled) return;
|
||||
if (component.rightClickOnly) return;
|
||||
args.Handled = InteractUI(args.User, component);
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (component.rightClickOnly)
|
||||
return;
|
||||
|
||||
args.Handled = InteractUI(args.User, uid, component);
|
||||
}
|
||||
|
||||
private void OnParentChanged(EntityUid uid, ActivatableUIComponent aui, ref EntParentChangedMessage args)
|
||||
@@ -103,53 +111,64 @@ public sealed partial class ActivatableUISystem : EntitySystem
|
||||
|
||||
private void OnUIClose(EntityUid uid, ActivatableUIComponent component, BoundUIClosedEvent args)
|
||||
{
|
||||
if (args.Session != component.CurrentSingleUser) return;
|
||||
if (args.UiKey != component.Key) return;
|
||||
if (args.Session != component.CurrentSingleUser)
|
||||
return;
|
||||
|
||||
if (!Equals(args.UiKey, component.Key))
|
||||
return;
|
||||
|
||||
SetCurrentSingleUser(uid, null, component);
|
||||
}
|
||||
|
||||
private bool InteractUI(EntityUid user, ActivatableUIComponent aui)
|
||||
private bool InteractUI(EntityUid user, EntityUid uiEntity, ActivatableUIComponent aui)
|
||||
{
|
||||
if (!_blockerSystem.CanInteract(user, aui.Owner) && (!aui.AllowSpectator || !HasComp<GhostComponent>(user)))
|
||||
if (!_blockerSystem.CanInteract(user, uiEntity) && (!aui.AllowSpectator || !HasComp<GhostComponent>(user)))
|
||||
return false;
|
||||
|
||||
if (aui.RequireHands && !HasComp<HandsComponent>(user))
|
||||
return false;
|
||||
|
||||
if (!EntityManager.TryGetComponent(user, out ActorComponent? actor)) return false;
|
||||
if (!EntityManager.TryGetComponent(user, out ActorComponent? actor))
|
||||
return false;
|
||||
|
||||
if (aui.AdminOnly && !_adminManager.IsAdmin(actor.PlayerSession)) return false;
|
||||
if (aui.AdminOnly && !_adminManager.IsAdmin(actor.PlayerSession))
|
||||
return false;
|
||||
|
||||
var ui = aui.UserInterface;
|
||||
if (ui == null) return false;
|
||||
if (aui.Key == null)
|
||||
return false;
|
||||
|
||||
if (!_uiSystem.TryGetUi(uiEntity, aui.Key, out var ui))
|
||||
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 (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;
|
||||
var uae = new UserOpenActivatableUIAttemptEvent(user, uiEntity);
|
||||
RaiseLocalEvent(user, uae);
|
||||
RaiseLocalEvent(uiEntity, oae);
|
||||
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);
|
||||
RaiseLocalEvent(uiEntity, bae);
|
||||
|
||||
SetCurrentSingleUser((aui).Owner, actor.PlayerSession, aui);
|
||||
SetCurrentSingleUser(uiEntity, actor.PlayerSession, aui);
|
||||
_uiSystem.ToggleUi(ui, actor.PlayerSession);
|
||||
|
||||
//Let the component know a user opened it so it can do whatever it needs to do
|
||||
var aae = new AfterActivatableUIOpenEvent(user, actor.PlayerSession);
|
||||
RaiseLocalEvent((aui).Owner, aae, false);
|
||||
RaiseLocalEvent(uiEntity, aae);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -163,24 +182,28 @@ public sealed partial class ActivatableUISystem : EntitySystem
|
||||
|
||||
aui.CurrentSingleUser = v;
|
||||
|
||||
RaiseLocalEvent(uid, new ActivatableUIPlayerChangedEvent(), false);
|
||||
RaiseLocalEvent(uid, new ActivatableUIPlayerChangedEvent());
|
||||
}
|
||||
|
||||
public void CloseAll(EntityUid uid, ActivatableUIComponent? aui = null)
|
||||
{
|
||||
if (!Resolve(uid, ref aui, false))
|
||||
return;
|
||||
if (aui.UserInterface is null)
|
||||
|
||||
if (aui.Key == null || !_uiSystem.TryGetUi(uid, aui.Key, out var ui))
|
||||
return;
|
||||
|
||||
_uiSystem.CloseAll(aui.UserInterface);
|
||||
_uiSystem.CloseAll(ui);
|
||||
}
|
||||
|
||||
private void OnHandDeselected(EntityUid uid, ActivatableUIComponent? aui, HandDeselectedEvent args)
|
||||
{
|
||||
if (!Resolve(uid, ref aui, false)) return;
|
||||
if (!Resolve(uid, ref aui, false))
|
||||
return;
|
||||
|
||||
if (!aui.CloseOnHandDeselect)
|
||||
return;
|
||||
|
||||
CloseAll(uid, aui);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user