Cleaner BoundUserInterfaces (#17736)

This commit is contained in:
TemporalOroboros
2023-07-08 09:02:17 -07:00
committed by GitHub
parent 55b4fb1649
commit 3ac4cf85db
137 changed files with 1069 additions and 972 deletions

View File

@@ -23,7 +23,6 @@ using Content.Shared.Storage;
using Content.Shared.Storage.Components;
using Content.Shared.Timing;
using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Server.Player;
@@ -33,7 +32,6 @@ using Robust.Shared.Map;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using static Content.Shared.Storage.SharedStorageComponent;
@@ -43,6 +41,7 @@ namespace Content.Server.Storage.EntitySystems
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IAdminManager _admin = default!;
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly ContainerSystem _containerSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly EntityLookupSystem _entityLookupSystem = default!;
@@ -68,7 +67,7 @@ namespace Content.Server.Storage.EntitySystems
SubscribeLocalEvent<ServerStorageComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<ServerStorageComponent, GetVerbsEvent<ActivationVerb>>(AddOpenUiVerb);
SubscribeLocalEvent<ServerStorageComponent, GetVerbsEvent<UtilityVerb>>(AddTransferVerbs);
SubscribeLocalEvent<ServerStorageComponent, InteractUsingEvent>(OnInteractUsing, after: new []{ typeof(ItemSlotsSystem)} );
SubscribeLocalEvent<ServerStorageComponent, InteractUsingEvent>(OnInteractUsing, after: new[] { typeof(ItemSlotsSystem) });
SubscribeLocalEvent<ServerStorageComponent, ActivateInWorldEvent>(OnActivate);
SubscribeLocalEvent<ServerStorageComponent, OpenStorageImplantEvent>(OnImplantActivate);
SubscribeLocalEvent<ServerStorageComponent, AfterInteractEvent>(AfterInteract);
@@ -98,7 +97,7 @@ namespace Content.Server.Storage.EntitySystems
private void AddOpenUiVerb(EntityUid uid, ServerStorageComponent component, GetVerbsEvent<ActivationVerb> args)
{
bool silent = false;
var silent = false;
if (!args.CanAccess || !args.CanInteract || TryComp<LockComponent>(uid, out var lockComponent) && lockComponent.Locked)
{
// we allow admins to open the storage anyways
@@ -115,7 +114,7 @@ namespace Content.Server.Storage.EntitySystems
return;
// Does this player currently have the storage UI open?
bool uiOpen = _uiSystem.SessionHasOpenUi(uid, StorageUiKey.Key, actor.PlayerSession);
var uiOpen = _uiSystem.SessionHasOpenUi(uid, StorageUiKey.Key, actor.PlayerSession);
ActivationVerb verb = new()
{
@@ -125,13 +124,13 @@ namespace Content.Server.Storage.EntitySystems
{
verb.Text = Loc.GetString("verb-common-close-ui");
verb.Icon = new SpriteSpecifier.Texture(
new ("/Textures/Interface/VerbIcons/close.svg.192dpi.png"));
new("/Textures/Interface/VerbIcons/close.svg.192dpi.png"));
}
else
{
verb.Text = Loc.GetString("verb-common-open-ui");
verb.Icon = new SpriteSpecifier.Texture(
new ("/Textures/Interface/VerbIcons/open.svg.192dpi.png"));
new("/Textures/Interface/VerbIcons/open.svg.192dpi.png"));
}
args.Verbs.Add(verb);
}
@@ -169,7 +168,8 @@ namespace Content.Server.Storage.EntitySystems
if (args.Handled || !storageComp.ClickInsert || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked)
return;
Logger.DebugS(storageComp.LoggerName, $"Storage (UID {uid}) attacked by user (UID {args.User}) with entity (UID {args.Used}).");
_logManager.GetSawmill(storageComp.LoggerName)
.Debug($"Storage (UID {uid}) attacked by user (UID {args.User}) with entity (UID {args.Used}).");
if (HasComp<PlaceableSurfaceComponent>(uid))
return;
@@ -253,7 +253,7 @@ namespace Content.Server.Storage.EntitySystems
// Pick up the clicked entity
if (storageComp.QuickInsert)
{
if (args.Target is not {Valid: true} target)
if (args.Target is not { Valid: true } target)
return;
if (_containerSystem.IsEntityInContainer(target)
@@ -267,7 +267,9 @@ namespace Content.Server.Storage.EntitySystems
var position = EntityCoordinates.FromMap(
parent.IsValid() ? parent : uid,
transformEnt.MapPosition);
transformEnt.MapPosition,
_transform
);
if (PlayerInsertEntityInWorld(uid, args.User, target, storageComp))
{
@@ -307,8 +309,9 @@ namespace Content.Server.Storage.EntitySystems
var position = EntityCoordinates.FromMap(
xform.ParentUid.IsValid() ? xform.ParentUid : uid,
new MapCoordinates(_transform.GetWorldPosition(targetXform, xformQuery),
targetXform.MapID), EntityManager);
new MapCoordinates(_transform.GetWorldPosition(targetXform, xformQuery), targetXform.MapID),
_transform
);
if (PlayerInsertEntityInWorld(uid, args.Args.User, entity, component))
{
@@ -353,7 +356,7 @@ namespace Content.Server.Storage.EntitySystems
if (!Exists(args.InteractedItemUID))
{
Logger.Error($"Player {args.Session} interacted with non-existent item {args.InteractedItemUID} stored in {ToPrettyString(uid)}");
Log.Error($"Player {args.Session} interacted with non-existent item {args.InteractedItemUID} stored in {ToPrettyString(uid)}");
return;
}
@@ -605,29 +608,6 @@ namespace Content.Server.Storage.EntitySystems
return true;
}
private bool CanCombineStacks(
ServerStorageComponent storageComp,
StackComponent stack)
{
if (storageComp.Storage == null)
return false;
var stackQuery = GetEntityQuery<StackComponent>();
var countLeft = stack.Count;
foreach (var ent in storageComp.Storage.ContainedEntities)
{
if (!stackQuery.TryGetComponent(ent, out var destStack))
continue;
if (destStack.StackTypeId != stack.StackTypeId)
continue;
countLeft -= _stack.GetAvailableSpace(stack);
}
return countLeft <= 0;
}
// REMOVE: remove and drop on the ground
public bool RemoveAndDrop(EntityUid uid, EntityUid removeEnt, ServerStorageComponent? storageComp = null)
{
@@ -705,7 +685,8 @@ namespace Content.Server.Storage.EntitySystems
_useDelay.BeginDelay(uid, useDelay);
}
Logger.DebugS(storageComp.LoggerName, $"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity}).");
_logManager.GetSawmill(storageComp.LoggerName)
.Debug($"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity}).");
var bui = _uiSystem.GetUiOrNull(uid, StorageUiKey.Key);
if (bui != null)
@@ -750,10 +731,10 @@ namespace Content.Server.Storage.EntitySystems
var bui = _uiSystem.GetUiOrNull(uid, StorageUiKey.Key);
if (bui != null)
_uiSystem.SetUiState(bui, state);
UserInterfaceSystem.SetUiState(bui, state);
}
private void Popup(EntityUid uid, EntityUid player, string message, ServerStorageComponent storageComp)
private void Popup(EntityUid _, EntityUid player, string message, ServerStorageComponent storageComp)
{
if (!storageComp.ShowPopup)
return;
@@ -761,8 +742,7 @@ namespace Content.Server.Storage.EntitySystems
_popupSystem.PopupEntity(Loc.GetString(message), player, player);
}
private void PopupEnt(EntityUid uid, EntityUid player, string message, EntityUid entityUid,
ServerStorageComponent storageComp)
private void PopupEnt(EntityUid _, EntityUid player, string message, EntityUid entityUid, ServerStorageComponent storageComp)
{
if (!storageComp.ShowPopup)
return;