Files
RobustToolbox/Robust.Shared/GameObjects/Components/UserInterface/BoundUserInterface.cs
metalgearsloth d72de032fa Predicted BUIs (#5059)
* Add TryGetOpenBUI

Avoids having to get the component and openinterfaces separately.

* Couple more helpers

* entityquery

* reviews

* Shared BUIs

* zawehdo

* More boilerplate

* Bunch more work

* Building

* Stuff

* More state handling

* API cleanup

* Slight tweak

* Tweaks

* gabriel

* Disposies

* Active UI support

* Lots of fixes

- Fix states not applying properly, fix predicted messages, remove redundant message type, add RaiseUiMessage for an easy way to do it from shared, add the old BUI state change events back.

* Fix test failures

* weh

* Remove unncessary closes.

* release note
2024-04-26 18:12:55 +10:00

92 lines
2.6 KiB
C#

using System;
using Robust.Shared.IoC;
using Robust.Shared.Player;
namespace Robust.Shared.GameObjects
{
/// <summary>
/// An abstract class to override to implement bound user interfaces.
/// </summary>
public abstract class BoundUserInterface : IDisposable
{
[Dependency] protected readonly IEntityManager EntMan = default!;
[Dependency] private readonly ISharedPlayerManager _playerManager = default!;
protected readonly SharedUserInterfaceSystem UiSystem;
public readonly Enum UiKey;
public EntityUid Owner { get; }
/// <summary>
/// The last received state object sent from the server.
/// </summary>
protected BoundUserInterfaceState? State { get; private set; }
protected BoundUserInterface(EntityUid owner, Enum uiKey)
{
IoCManager.InjectDependencies(this);
UiSystem = EntMan.System<SharedUserInterfaceSystem>();
Owner = owner;
UiKey = uiKey;
}
/// <summary>
/// Invoked when the UI is opened.
/// Do all creation and opening of things like windows in here.
/// </summary>
protected internal virtual void Open()
{
}
/// <summary>
/// Invoked when the server uses <c>SetState</c>.
/// </summary>
protected internal virtual void UpdateState(BoundUserInterfaceState state)
{
}
/// <summary>
/// Invoked when the server sends an arbitrary message.
/// </summary>
protected internal virtual void ReceiveMessage(BoundUserInterfaceMessage message)
{
}
/// <summary>
/// Invoked to close the UI.
/// </summary>
public void Close()
{
UiSystem.CloseUi(Owner, UiKey, _playerManager.LocalEntity, predicted: true);
}
/// <summary>
/// Sends a message to the server-side UI.
/// </summary>
public void SendMessage(BoundUserInterfaceMessage message)
{
UiSystem.ClientSendUiMessage(Owner, UiKey, message);
}
public void SendPredictedMessage(BoundUserInterfaceMessage message)
{
UiSystem.SendPredictedUiMessage(this, message);
}
~BoundUserInterface()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
}
}
}