2022-03-10 23:37:35 -06:00
|
|
|
|
using Content.Server.Actions;
|
2023-09-08 18:16:05 -07:00
|
|
|
|
using Content.Shared.UserInterface;
|
2022-03-10 23:37:35 -06:00
|
|
|
|
using Robust.Server.GameObjects;
|
2023-10-29 04:21:02 +11:00
|
|
|
|
using Robust.Shared.Player;
|
2022-03-10 23:37:35 -06:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.UserInterface;
|
|
|
|
|
|
|
|
|
|
|
|
public sealed class IntrinsicUISystem : EntitySystem
|
|
|
|
|
|
{
|
|
|
|
|
|
[Dependency] private readonly ActionsSystem _actionsSystem = default!;
|
2023-07-08 09:02:17 -07:00
|
|
|
|
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
2022-03-10 23:37:35 -06:00
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
2023-09-23 04:49:39 -04:00
|
|
|
|
SubscribeLocalEvent<IntrinsicUIComponent, MapInitEvent>(InitActions);
|
2022-03-10 23:37:35 -06:00
|
|
|
|
SubscribeLocalEvent<IntrinsicUIComponent, ToggleIntrinsicUIEvent>(OnActionToggle);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnActionToggle(EntityUid uid, IntrinsicUIComponent component, ToggleIntrinsicUIEvent args)
|
|
|
|
|
|
{
|
2024-04-26 18:16:24 +10:00
|
|
|
|
if (args.Key == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2022-03-10 23:37:35 -06:00
|
|
|
|
args.Handled = InteractUI(uid, args.Key, component);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-23 04:49:39 -04:00
|
|
|
|
private void InitActions(EntityUid uid, IntrinsicUIComponent component, MapInitEvent args)
|
2022-03-10 23:37:35 -06:00
|
|
|
|
{
|
2024-04-26 18:16:24 +10:00
|
|
|
|
foreach (var entry in component.UIs.Values)
|
2022-03-10 23:37:35 -06:00
|
|
|
|
{
|
2023-09-23 04:49:39 -04:00
|
|
|
|
_actionsSystem.AddAction(uid, ref entry.ToggleActionEntity, entry.ToggleAction);
|
2022-03-10 23:37:35 -06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-26 18:16:24 +10:00
|
|
|
|
public bool InteractUI(EntityUid uid, Enum key, IntrinsicUIComponent? iui = null, ActorComponent? actor = null)
|
2022-03-10 23:37:35 -06:00
|
|
|
|
{
|
|
|
|
|
|
if (!Resolve(uid, ref iui, ref actor))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
var attempt = new IntrinsicUIOpenAttemptEvent(uid, key);
|
2023-10-11 02:17:59 -07:00
|
|
|
|
RaiseLocalEvent(uid, attempt);
|
2022-10-17 02:44:23 +11:00
|
|
|
|
if (attempt.Cancelled)
|
|
|
|
|
|
return false;
|
2022-03-10 23:37:35 -06:00
|
|
|
|
|
2024-04-26 18:16:24 +10:00
|
|
|
|
return _uiSystem.TryToggleUi(uid, key, actor.PlayerSession);
|
2022-03-10 23:37:35 -06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|