Predict StorageComponent (#19682)
This commit is contained in:
@@ -4,12 +4,13 @@ using Content.Client.UserInterface.Controls;
|
||||
using Content.Client.Verbs.UI;
|
||||
using Content.Shared.Input;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Storage;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Input;
|
||||
using static Content.Shared.Storage.SharedStorageComponent;
|
||||
using static Content.Shared.Storage.StorageComponent;
|
||||
|
||||
namespace Content.Client.Storage
|
||||
{
|
||||
@@ -19,8 +20,11 @@ namespace Content.Client.Storage
|
||||
[ViewVariables]
|
||||
private StorageWindow? _window;
|
||||
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
|
||||
public StorageBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
@@ -29,17 +33,22 @@ namespace Content.Client.Storage
|
||||
|
||||
if (_window == null)
|
||||
{
|
||||
_window = new StorageWindow(EntMan)
|
||||
{
|
||||
Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName
|
||||
};
|
||||
// TODO: This is a bit of a mess but storagecomponent got moved to shared and cleaned up a bit.
|
||||
var controller = IoCManager.Resolve<IUserInterfaceManager>().GetUIController<StorageUIController>();
|
||||
_window = controller.EnsureStorageWindow(Owner);
|
||||
_window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
|
||||
|
||||
_window.EntityList.GenerateItem += _window.GenerateButton;
|
||||
_window.EntityList.ItemPressed += InteractWithItem;
|
||||
_window.StorageContainerButton.OnPressed += TouchedContainerButton;
|
||||
|
||||
_window.OnClose += Close;
|
||||
_window.OpenCenteredLeft();
|
||||
|
||||
if (EntMan.TryGetComponent<StorageComponent>(Owner, out var storageComp))
|
||||
{
|
||||
BuildEntityList(Owner, storageComp);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -47,6 +56,11 @@ namespace Content.Client.Storage
|
||||
}
|
||||
}
|
||||
|
||||
public void BuildEntityList(EntityUid uid, StorageComponent component)
|
||||
{
|
||||
_window?.BuildEntityList(uid, component);
|
||||
}
|
||||
|
||||
public void InteractWithItem(BaseButton.ButtonEventArgs args, ListData cData)
|
||||
{
|
||||
if (cData is not EntityListData { Uid: var entity })
|
||||
@@ -54,7 +68,7 @@ namespace Content.Client.Storage
|
||||
|
||||
if (args.Event.Function == EngineKeyFunctions.UIClick)
|
||||
{
|
||||
SendMessage(new StorageInteractWithItemEvent(EntMan.GetNetEntity(entity)));
|
||||
SendPredictedMessage(new StorageInteractWithItemEvent(_entManager.GetNetEntity(entity)));
|
||||
}
|
||||
else if (EntMan.EntityExists(entity))
|
||||
{
|
||||
@@ -92,17 +106,7 @@ namespace Content.Client.Storage
|
||||
|
||||
public void TouchedContainerButton(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
SendMessage(new StorageInsertItemMessage());
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
if (_window == null || state is not StorageBoundUserInterfaceState cast)
|
||||
return;
|
||||
|
||||
_window?.BuildEntityList(cast);
|
||||
SendPredictedMessage(new StorageInsertItemMessage());
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
@@ -113,14 +117,13 @@ namespace Content.Client.Storage
|
||||
|
||||
if (_window != null)
|
||||
{
|
||||
_window.Orphan();
|
||||
_window.EntityList.GenerateItem -= _window.GenerateButton;
|
||||
_window.EntityList.ItemPressed -= InteractWithItem;
|
||||
_window.StorageContainerButton.OnPressed -= TouchedContainerButton;
|
||||
_window.OnClose -= Close;
|
||||
_window = null;
|
||||
}
|
||||
|
||||
_window?.Dispose();
|
||||
_window = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user