Files
tbd-station-14/Content.Server/UserInterface/IntrinsicUISystem.cs
metalgearsloth 5896e68752 Content update for UI prediction (#27214)
* Content update for UI refactor

* Big update

* Sharing

* Remaining content updates

* First big update

* Prototype updates

* AUGH

* Fix UI comp ref

* Cleanup

- Fix predicted message, fix item slots, fix interaction range check.

* Fix regressions

* Make this predictive

idk why it wasn't.

* Fix slime merge

* Merge conflict

* Fix merge
2024-04-26 18:16:24 +10:00

60 lines
1.8 KiB
C#

using Content.Server.Actions;
using Content.Shared.UserInterface;
using Robust.Server.GameObjects;
using Robust.Shared.Player;
namespace Content.Server.UserInterface;
public sealed class IntrinsicUISystem : EntitySystem
{
[Dependency] private readonly ActionsSystem _actionsSystem = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
public override void Initialize()
{
SubscribeLocalEvent<IntrinsicUIComponent, MapInitEvent>(InitActions);
SubscribeLocalEvent<IntrinsicUIComponent, ToggleIntrinsicUIEvent>(OnActionToggle);
}
private void OnActionToggle(EntityUid uid, IntrinsicUIComponent component, ToggleIntrinsicUIEvent args)
{
if (args.Key == null)
return;
args.Handled = InteractUI(uid, args.Key, component);
}
private void InitActions(EntityUid uid, IntrinsicUIComponent component, MapInitEvent args)
{
foreach (var entry in component.UIs.Values)
{
_actionsSystem.AddAction(uid, ref entry.ToggleActionEntity, entry.ToggleAction);
}
}
public bool InteractUI(EntityUid uid, Enum key, IntrinsicUIComponent? iui = null, ActorComponent? actor = null)
{
if (!Resolve(uid, ref iui, ref actor))
return false;
var attempt = new IntrinsicUIOpenAttemptEvent(uid, key);
RaiseLocalEvent(uid, attempt);
if (attempt.Cancelled)
return false;
return _uiSystem.TryToggleUi(uid, key, actor.PlayerSession);
}
}
// Competing with ActivatableUI for horrible event names.
public sealed class IntrinsicUIOpenAttemptEvent : CancellableEntityEventArgs
{
public EntityUid User { get; }
public Enum? Key { get; }
public IntrinsicUIOpenAttemptEvent(EntityUid who, Enum? key)
{
User = who;
Key = key;
}
}