action refactor proper ecs edition (#27422)

This commit is contained in:
deltanedas
2025-05-28 19:52:11 +00:00
committed by GitHub
parent a9f7cfbcb6
commit b3825dce97
111 changed files with 1995 additions and 2901 deletions

View File

@@ -1,3 +1,6 @@
using Content.Shared.Actions.Components;
using static Robust.Shared.Input.Binding.PointerInputCmdHandler;
namespace Content.Client.Actions;
/// <summary>
@@ -7,3 +10,17 @@ public sealed class FillActionSlotEvent : EntityEventArgs
{
public EntityUid? Action;
}
/// <summary>
/// Client-side event used to attempt to trigger a targeted action.
/// This only gets raised if the has <see cref="TargetActionComponent">.
/// Handlers must set <c>Handled</c> to true, then if the action has been performed,
/// i.e. a target is found, then FoundTarget must be set to true.
/// </summary>
[ByRefEvent]
public record struct ActionTargetAttemptEvent(
PointerInputCmdArgs Input,
Entity<ActionsComponent> User,
ActionComponent Action,
bool Handled = false,
bool FoundTarget = false);

View File

@@ -1,18 +1,23 @@
using System.IO;
using System.Linq;
using Content.Shared.Actions;
using Content.Shared.Actions.Components;
using Content.Shared.Charges.Systems;
using Content.Shared.Mapping;
using Content.Shared.Maps;
using JetBrains.Annotations;
using Robust.Client.Player;
using Robust.Shared.ContentPack;
using Robust.Shared.GameStates;
using Robust.Shared.Input.Binding;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager;
using Robust.Shared.Serialization.Markdown;
using Robust.Shared.Serialization.Markdown.Mapping;
using Robust.Shared.Serialization.Markdown.Sequence;
using Robust.Shared.Serialization.Markdown.Value;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using YamlDotNet.RepresentationModel;
@@ -25,6 +30,7 @@ namespace Content.Client.Actions
[Dependency] private readonly SharedChargesSystem _sharedCharges = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IResourceManager _resources = default!;
[Dependency] private readonly ISerializationManager _serialization = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
@@ -38,131 +44,67 @@ namespace Content.Client.Actions
public event Action<List<SlotAssignment>>? AssignSlot;
private readonly List<EntityUid> _removed = new();
private readonly List<(EntityUid, BaseActionComponent?)> _added = new();
private readonly List<Entity<ActionComponent>> _added = new();
public static readonly EntProtoId MappingEntityAction = "BaseMappingEntityAction";
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ActionsComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<ActionsComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
SubscribeLocalEvent<ActionsComponent, ComponentHandleState>(HandleComponentState);
SubscribeLocalEvent<ActionsComponent, ComponentHandleState>(OnHandleState);
SubscribeLocalEvent<InstantActionComponent, ComponentHandleState>(OnInstantHandleState);
SubscribeLocalEvent<EntityTargetActionComponent, ComponentHandleState>(OnEntityTargetHandleState);
SubscribeLocalEvent<WorldTargetActionComponent, ComponentHandleState>(OnWorldTargetHandleState);
SubscribeLocalEvent<EntityWorldTargetActionComponent, ComponentHandleState>(OnEntityWorldTargetHandleState);
SubscribeLocalEvent<ActionComponent, AfterAutoHandleStateEvent>(OnActionAutoHandleState);
SubscribeLocalEvent<EntityTargetActionComponent, ActionTargetAttemptEvent>(OnEntityTargetAttempt);
SubscribeLocalEvent<WorldTargetActionComponent, ActionTargetAttemptEvent>(OnWorldTargetAttempt);
}
private void OnInstantHandleState(EntityUid uid, InstantActionComponent component, ref ComponentHandleState args)
{
if (args.Current is not InstantActionComponentState state)
return;
BaseHandleState<InstantActionComponent>(uid, component, state);
private void OnActionAutoHandleState(Entity<ActionComponent> ent, ref AfterAutoHandleStateEvent args)
{
UpdateAction(ent);
}
private void OnEntityTargetHandleState(EntityUid uid, EntityTargetActionComponent component, ref ComponentHandleState args)
public override void UpdateAction(Entity<ActionComponent> ent)
{
if (args.Current is not EntityTargetActionComponentState state)
return;
component.Whitelist = state.Whitelist;
component.Blacklist = state.Blacklist;
component.CanTargetSelf = state.CanTargetSelf;
BaseHandleState<EntityTargetActionComponent>(uid, component, state);
}
private void OnWorldTargetHandleState(EntityUid uid, WorldTargetActionComponent component, ref ComponentHandleState args)
{
if (args.Current is not WorldTargetActionComponentState state)
return;
BaseHandleState<WorldTargetActionComponent>(uid, component, state);
}
private void OnEntityWorldTargetHandleState(EntityUid uid,
EntityWorldTargetActionComponent component,
ref ComponentHandleState args)
{
if (args.Current is not EntityWorldTargetActionComponentState state)
return;
component.Whitelist = state.Whitelist;
component.CanTargetSelf = state.CanTargetSelf;
BaseHandleState<EntityWorldTargetActionComponent>(uid, component, state);
}
private void BaseHandleState<T>(EntityUid uid, BaseActionComponent component, BaseActionComponentState state) where T : BaseActionComponent
{
// TODO ACTIONS use auto comp states
component.Icon = state.Icon;
component.IconOn = state.IconOn;
component.IconColor = state.IconColor;
component.OriginalIconColor = state.OriginalIconColor;
component.DisabledIconColor = state.DisabledIconColor;
component.Keywords.Clear();
component.Keywords.UnionWith(state.Keywords);
component.Enabled = state.Enabled;
component.Toggled = state.Toggled;
component.Cooldown = state.Cooldown;
component.UseDelay = state.UseDelay;
component.Container = EnsureEntity<T>(state.Container, uid);
component.EntityIcon = EnsureEntity<T>(state.EntityIcon, uid);
component.CheckCanInteract = state.CheckCanInteract;
component.CheckConsciousness = state.CheckConsciousness;
component.ClientExclusive = state.ClientExclusive;
component.Priority = state.Priority;
component.AttachedEntity = EnsureEntity<T>(state.AttachedEntity, uid);
component.RaiseOnUser = state.RaiseOnUser;
component.RaiseOnAction = state.RaiseOnAction;
component.AutoPopulate = state.AutoPopulate;
component.Temporary = state.Temporary;
component.ItemIconStyle = state.ItemIconStyle;
component.Sound = state.Sound;
UpdateAction(uid, component);
}
public override void UpdateAction(EntityUid? actionId, BaseActionComponent? action = null)
{
if (!ResolveActionData(actionId, ref action))
return;
// TODO: Decouple this.
action.IconColor = _sharedCharges.GetCurrentCharges(actionId.Value) == 0 ? action.DisabledIconColor : action.OriginalIconColor;
base.UpdateAction(actionId, action);
if (_playerManager.LocalEntity != action.AttachedEntity)
ent.Comp.IconColor = _sharedCharges.GetCurrentCharges(ent.Owner) == 0 ? ent.Comp.DisabledIconColor : ent.Comp.OriginalIconColor;
base.UpdateAction(ent);
if (_playerManager.LocalEntity != ent.Comp.AttachedEntity)
return;
ActionsUpdated?.Invoke();
}
private void HandleComponentState(EntityUid uid, ActionsComponent component, ref ComponentHandleState args)
private void OnHandleState(Entity<ActionsComponent> ent, ref ComponentHandleState args)
{
if (args.Current is not ActionsComponentState state)
return;
var (uid, comp) = ent;
_added.Clear();
_removed.Clear();
var stateEnts = EnsureEntitySet<ActionsComponent>(state.Actions, uid);
foreach (var act in component.Actions)
foreach (var act in comp.Actions)
{
if (!stateEnts.Contains(act) && !IsClientSide(act))
_removed.Add(act);
}
component.Actions.ExceptWith(_removed);
comp.Actions.ExceptWith(_removed);
foreach (var actionId in stateEnts)
{
if (!actionId.IsValid())
continue;
if (!component.Actions.Add(actionId))
if (!comp.Actions.Add(actionId))
continue;
TryGetActionData(actionId, out var action);
_added.Add((actionId, action));
if (GetAction(actionId) is {} action)
_added.Add(action);
}
if (_playerManager.LocalEntity != uid)
@@ -177,47 +119,46 @@ namespace Content.Client.Actions
foreach (var action in _added)
{
OnActionAdded?.Invoke(action.Item1);
OnActionAdded?.Invoke(action);
}
ActionsUpdated?.Invoke();
}
public static int ActionComparer((EntityUid, BaseActionComponent?) a, (EntityUid, BaseActionComponent?) b)
public static int ActionComparer(Entity<ActionComponent> a, Entity<ActionComponent> b)
{
var priorityA = a.Item2?.Priority ?? 0;
var priorityB = b.Item2?.Priority ?? 0;
var priorityA = a.Comp?.Priority ?? 0;
var priorityB = b.Comp?.Priority ?? 0;
if (priorityA != priorityB)
return priorityA - priorityB;
priorityA = a.Item2?.Container?.Id ?? 0;
priorityB = b.Item2?.Container?.Id ?? 0;
priorityA = a.Comp?.Container?.Id ?? 0;
priorityB = b.Comp?.Container?.Id ?? 0;
return priorityA - priorityB;
}
protected override void ActionAdded(EntityUid performer, EntityUid actionId, ActionsComponent comp,
BaseActionComponent action)
protected override void ActionAdded(Entity<ActionsComponent> performer, Entity<ActionComponent> action)
{
if (_playerManager.LocalEntity != performer)
if (_playerManager.LocalEntity != performer.Owner)
return;
OnActionAdded?.Invoke(actionId);
OnActionAdded?.Invoke(action);
ActionsUpdated?.Invoke();
}
protected override void ActionRemoved(EntityUid performer, EntityUid actionId, ActionsComponent comp, BaseActionComponent action)
protected override void ActionRemoved(Entity<ActionsComponent> performer, Entity<ActionComponent> action)
{
if (_playerManager.LocalEntity != performer)
if (_playerManager.LocalEntity != performer.Owner)
return;
OnActionRemoved?.Invoke(actionId);
OnActionRemoved?.Invoke(action);
ActionsUpdated?.Invoke();
}
public IEnumerable<(EntityUid Id, BaseActionComponent Comp)> GetClientActions()
public IEnumerable<Entity<ActionComponent>> GetClientActions()
{
if (_playerManager.LocalEntity is not { } user)
return Enumerable.Empty<(EntityUid, BaseActionComponent)>();
return Enumerable.Empty<Entity<ActionComponent>>();
return GetActions(user);
}
@@ -254,24 +195,23 @@ namespace Content.Client.Actions
CommandBinds.Unregister<ActionsSystem>();
}
public void TriggerAction(EntityUid actionId, BaseActionComponent action)
public void TriggerAction(Entity<ActionComponent> action)
{
if (_playerManager.LocalEntity is not { } user ||
!TryComp(user, out ActionsComponent? actions))
{
return;
}
if (action is not InstantActionComponent instantAction)
if (_playerManager.LocalEntity is not { } user)
return;
if (action.ClientExclusive)
// TODO: unhardcode this somehow
if (!HasComp<InstantActionComponent>(action))
return;
if (action.Comp.ClientExclusive)
{
PerformAction(user, actions, actionId, instantAction, instantAction.Event, GameTiming.CurTime);
PerformAction(user, action);
}
else
{
var request = new RequestPerformActionEvent(GetNetEntity(actionId));
var request = new RequestPerformActionEvent(GetNetEntity(action));
EntityManager.RaisePredictiveEvent(request);
}
}
@@ -295,39 +235,137 @@ namespace Content.Client.Actions
if (yamlStream.Documents[0].RootNode.ToDataNode() is not SequenceDataNode sequence)
return;
var actions = EnsureComp<ActionsComponent>(user);
ClearAssignments?.Invoke();
var assignments = new List<SlotAssignment>();
foreach (var entry in sequence.Sequence)
{
if (entry is not MappingDataNode map)
continue;
if (!map.TryGet("action", out var actionNode))
continue;
var action = _serialization.Read<BaseActionComponent>(actionNode, notNullableOverride: true);
var actionId = Spawn();
AddComp(actionId, action);
AddActionDirect(user, actionId);
if (map.TryGet<ValueDataNode>("name", out var nameNode))
_metaData.SetEntityName(actionId, nameNode.Value);
if (!map.TryGet("assignments", out var assignmentNode))
continue;
var nodeAssignments = _serialization.Read<List<(byte Hotbar, byte Slot)>>(assignmentNode, notNullableOverride: true);
foreach (var index in nodeAssignments)
var actionId = EntityUid.Invalid;
if (map.TryGet<ValueDataNode>("action", out var actionNode))
{
var assignment = new SlotAssignment(index.Hotbar, index.Slot, actionId);
assignments.Add(assignment);
var id = new EntProtoId(actionNode.Value);
actionId = Spawn(id);
}
else if (map.TryGet<ValueDataNode>("entity", out var entityNode))
{
var id = new EntProtoId(entityNode.Value);
var proto = _proto.Index(id);
actionId = Spawn(MappingEntityAction);
SetIcon(actionId, new SpriteSpecifier.EntityPrototype(id));
SetEvent(actionId, new StartPlacementActionEvent()
{
PlacementOption = "SnapgridCenter",
EntityType = id
});
_metaData.SetEntityName(actionId, proto.Name);
}
else if (map.TryGet<ValueDataNode>("tileId", out var tileNode))
{
var id = new ProtoId<ContentTileDefinition>(tileNode.Value);
var proto = _proto.Index(id);
actionId = Spawn(MappingEntityAction);
if (proto.Sprite is {} sprite)
SetIcon(actionId, new SpriteSpecifier.Texture(sprite));
SetEvent(actionId, new StartPlacementActionEvent()
{
PlacementOption = "AlignTileAny",
TileId = id
});
_metaData.SetEntityName(actionId, Loc.GetString(proto.Name));
}
else
{
Log.Error($"Mapping actions from {path} had unknown action data!");
continue;
}
AddActionDirect((user, actions), actionId);
}
}
private void OnWorldTargetAttempt(Entity<WorldTargetActionComponent> ent, ref ActionTargetAttemptEvent args)
{
if (args.Handled)
return;
args.Handled = true;
var (uid, comp) = ent;
var action = args.Action;
var coords = args.Input.Coordinates;
var user = args.User;
if (!ValidateWorldTarget(user, coords, ent))
return;
// optionally send the clicked entity too, if it matches its whitelist etc
// this is the actual entity-world targeting magic
EntityUid? targetEnt = null;
if (TryComp<EntityTargetActionComponent>(ent, out var entity) &&
args.Input.EntityUid != null &&
ValidateEntityTarget(user, args.Input.EntityUid, (uid, entity)))
{
targetEnt = args.Input.EntityUid;
}
AssignSlot?.Invoke(assignments);
if (action.ClientExclusive)
{
// TODO: abstract away from single event or maybe just RaiseLocalEvent?
if (comp.Event is {} ev)
{
ev.Target = coords;
ev.Entity = targetEnt;
}
PerformAction((user, user.Comp), (uid, action));
}
else
RaisePredictiveEvent(new RequestPerformActionEvent(GetNetEntity(uid), GetNetEntity(targetEnt), GetNetCoordinates(coords)));
args.FoundTarget = true;
}
private void OnEntityTargetAttempt(Entity<EntityTargetActionComponent> ent, ref ActionTargetAttemptEvent args)
{
if (args.Handled || args.Input.EntityUid is not { Valid: true } entity)
return;
// let world target component handle it
var (uid, comp) = ent;
if (comp.Event is not {} ev)
{
DebugTools.Assert(HasComp<WorldTargetActionComponent>(ent), $"Action {ToPrettyString(ent)} requires WorldTargetActionComponent for entity-world targeting");
return;
}
args.Handled = true;
var action = args.Action;
var user = args.User;
if (!ValidateEntityTarget(user, entity, ent))
return;
if (action.ClientExclusive)
{
ev.Target = entity;
PerformAction((user, user.Comp), (uid, action));
}
else
{
RaisePredictiveEvent(new RequestPerformActionEvent(GetNetEntity(uid), GetNetEntity(entity)));
}
args.FoundTarget = true;
}
public record struct SlotAssignment(byte Hotbar, byte Slot, EntityUid ActionId);

View File

@@ -25,16 +25,14 @@ public sealed class ChargesSystem : SharedChargesSystem
while (query.MoveNext(out var uid, out var recharge, out var charges))
{
BaseActionComponent? actionComp = null;
if (!_actions.ResolveActionData(uid, ref actionComp, logError: false))
if (_actions.GetAction(uid, false) is not {} action)
continue;
var current = GetCurrentCharges((uid, charges, recharge));
if (!_lastCharges.TryGetValue(uid, out var last) || current != last)
{
_actions.UpdateAction(uid, actionComp);
_actions.UpdateAction(action);
}
_tempLastCharges[uid] = current;

View File

@@ -2,6 +2,7 @@ using System.Numerics;
using Content.Client.Actions;
using Content.Client.Decals.Overlays;
using Content.Shared.Actions;
using Content.Shared.Actions.Components;
using Content.Shared.Decals;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
@@ -21,9 +22,12 @@ public sealed class DecalPlacementSystem : EntitySystem
[Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly InputSystem _inputSystem = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SpriteSystem _sprite = default!;
public static readonly EntProtoId DecalAction = "BaseMappingDecalAction";
private string? _decalId;
private Color _decalColor = Color.White;
private Angle _decalAngle = Angle.Zero;
@@ -152,19 +156,12 @@ public sealed class DecalPlacementSystem : EntitySystem
Cleanable = _cleanable,
};
var actionId = Spawn(null);
AddComp(actionId, new WorldTargetActionComponent
{
// non-unique actions may be considered duplicates when saving/loading.
Icon = decalProto.Sprite,
Repeat = true,
ClientExclusive = true,
CheckCanAccess = false,
CheckCanInteract = false,
Range = -1,
Event = actionEvent,
IconColor = _decalColor,
});
var actionId = Spawn(DecalAction);
var action = Comp<ActionComponent>(actionId);
var ent = (actionId, action);
_actions.SetEvent(actionId, actionEvent);
_actions.SetIcon(ent, decalProto.Sprite);
_actions.SetIconColor(ent, _decalColor);
_metaData.SetEntityName(actionId, $"{_decalId} ({_decalColor.ToHex()}, {(int) _decalAngle.Degrees})");

View File

@@ -4,8 +4,8 @@ using Content.Shared.Mapping;
using Content.Shared.Maps;
using Robust.Client.Placement;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
using static Robust.Shared.Utility.SpriteSpecifier;
namespace Content.Client.Mapping;
@@ -14,16 +14,10 @@ public sealed partial class MappingSystem : EntitySystem
[Dependency] private readonly IPlacementManager _placementMan = default!;
[Dependency] private readonly ITileDefinitionManager _tileMan = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
/// <summary>
/// The icon to use for space tiles.
/// </summary>
private readonly SpriteSpecifier _spaceIcon = new Texture(new ("Tiles/cropped_parallax.png"));
/// <summary>
/// The icon to use for entity-eraser.
/// </summary>
private readonly SpriteSpecifier _deleteIcon = new Texture(new ("Interface/VerbIcons/delete.svg.192dpi.png"));
public static readonly EntProtoId SpawnAction = "BaseMappingSpawnAction";
public static readonly EntProtoId EraserAction = "ActionMappingEraser";
public override void Initialize()
{
@@ -38,90 +32,46 @@ public sealed partial class MappingSystem : EntitySystem
/// some entity or tile into an action. This is somewhat janky, but it seem to work well enough. Though I'd
/// prefer if it were to function more like DecalPlacementSystem.
/// </summary>
private void OnFillActionSlot(FillActionSlotEvent ev)
private void OnFillActionSlot(FillActionSlotEvent args)
{
if (!_placementMan.IsActive)
return;
if (ev.Action != null)
if (args.Action != null)
return;
var actionEvent = new StartPlacementActionEvent();
ITileDefinition? tileDef = null;
if (_placementMan.CurrentPermission != null)
if (_placementMan.CurrentPermission is {} permission)
{
actionEvent.EntityType = _placementMan.CurrentPermission.EntityType;
actionEvent.PlacementOption = _placementMan.CurrentPermission.PlacementOption;
var ev = new StartPlacementActionEvent()
{
EntityType = permission.EntityType,
PlacementOption = permission.PlacementOption,
};
var action = Spawn(SpawnAction);
if (_placementMan.CurrentPermission.IsTile)
{
tileDef = _tileMan[_placementMan.CurrentPermission.TileType];
actionEvent.TileId = tileDef.ID;
if (_tileMan[_placementMan.CurrentPermission.TileType] is not ContentTileDefinition tileDef)
return;
if (!tileDef.MapAtmosphere && tileDef.Sprite is {} sprite)
_actions.SetIcon(action, new SpriteSpecifier.Texture(sprite));
ev.TileId = tileDef.ID;
_metaData.SetEntityName(action, Loc.GetString(tileDef.Name));
}
else if (permission.EntityType is {} id)
{
_actions.SetIcon(action, new SpriteSpecifier.EntityPrototype(id));
_metaData.SetEntityName(action, id);
}
_actions.SetEvent(action, ev);
args.Action = action;
}
else if (_placementMan.Eraser)
{
actionEvent.Eraser = true;
args.Action = Spawn(EraserAction);
}
else
return;
InstantActionComponent action;
string name;
if (tileDef != null)
{
if (tileDef is not ContentTileDefinition contentTileDef)
return;
var tileIcon = contentTileDef.MapAtmosphere
? _spaceIcon
: new Texture(contentTileDef.Sprite!.Value);
action = new InstantActionComponent
{
ClientExclusive = true,
CheckCanInteract = false,
Event = actionEvent,
Icon = tileIcon
};
name = Loc.GetString(tileDef.Name);
}
else if (actionEvent.Eraser)
{
action = new InstantActionComponent
{
ClientExclusive = true,
CheckCanInteract = false,
Event = actionEvent,
Icon = _deleteIcon,
};
name = Loc.GetString("action-name-mapping-erase");
}
else
{
if (string.IsNullOrWhiteSpace(actionEvent.EntityType))
return;
action = new InstantActionComponent
{
ClientExclusive = true,
CheckCanInteract = false,
Event = actionEvent,
Icon = new EntityPrototype(actionEvent.EntityType),
};
name = actionEvent.EntityType;
}
var actionId = Spawn(null);
AddComp<Component>(actionId, action);
_metaData.SetEntityName(actionId, name);
ev.Action = actionId;
}
private void OnStartPlacementAction(StartPlacementActionEvent args)

View File

@@ -141,11 +141,8 @@ public sealed partial class StoreMenu : DefaultWindow
else if (listing.ProductAction != null)
{
var actionId = _entityManager.Spawn(listing.ProductAction);
if (_entityManager.System<ActionsSystem>().TryGetActionData(actionId, out var action) &&
action.Icon != null)
{
texture = spriteSys.Frame0(action.Icon);
}
if (_entityManager.System<ActionsSystem>().GetAction(actionId)?.Comp?.Icon is {} icon)
texture = spriteSys.Frame0(icon);
}
var listingInStock = GetListingPriceString(listing);

View File

@@ -12,6 +12,7 @@ using Content.Client.UserInterface.Systems.Actions.Widgets;
using Content.Client.UserInterface.Systems.Actions.Windows;
using Content.Client.UserInterface.Systems.Gameplay;
using Content.Shared.Actions;
using Content.Shared.Actions.Components;
using Content.Shared.Charges.Systems;
using Content.Shared.Input;
using Robust.Client.GameObjects;
@@ -162,142 +163,33 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
if (_playerManager.LocalEntity is not { } user)
return false;
if (!EntityManager.TryGetComponent(user, out ActionsComponent? comp))
if (!EntityManager.TryGetComponent<ActionsComponent>(user, out var comp))
return false;
if (!_actionsSystem.TryGetActionData(actionId, out var baseAction) ||
baseAction is not BaseTargetActionComponent action)
if (_actionsSystem.GetAction(actionId) is not {} action ||
!EntityManager.TryGetComponent<TargetActionComponent>(action, out var target))
{
return false;
}
// Is the action currently valid?
if (!action.Enabled
|| action.Cooldown.HasValue && action.Cooldown.Value.End > _timing.CurTime)
if (!_actionsSystem.ValidAction(action))
{
// The user is targeting with this action, but it is not valid. Maybe mark this click as
// handled and prevent further interactions.
return !action.InteractOnMiss;
return !target.InteractOnMiss;
}
switch (action)
var ev = new ActionTargetAttemptEvent(args, (user, comp), action);
EntityManager.EventBus.RaiseLocalEvent(action, ref ev);
if (!ev.Handled)
{
case WorldTargetActionComponent mapTarget:
return TryTargetWorld(args, actionId, mapTarget, user, comp) || !mapTarget.InteractOnMiss;
case EntityTargetActionComponent entTarget:
return TryTargetEntity(args, actionId, entTarget, user, comp) || !entTarget.InteractOnMiss;
case EntityWorldTargetActionComponent entMapTarget:
return TryTargetEntityWorld(args, actionId, entMapTarget, user, comp) || !entMapTarget.InteractOnMiss;
default:
Log.Error($"Unknown targeting action: {actionId.GetType()}");
return false;
}
}
private bool TryTargetWorld(in PointerInputCmdArgs args, EntityUid actionId, WorldTargetActionComponent action, EntityUid user, ActionsComponent actionComp)
{
if (_actionsSystem == null)
return false;
var coords = args.Coordinates;
if (!_actionsSystem.ValidateWorldTarget(user, coords, (actionId, action)))
{
// Invalid target.
if (action.DeselectOnMiss)
StopTargeting();
Log.Error($"Action {EntityManager.ToPrettyString(actionId)} did not handle ActionTargetAttemptEvent!");
return false;
}
if (action.ClientExclusive)
{
if (action.Event != null)
{
action.Event.Target = coords;
}
_actionsSystem.PerformAction(user, actionComp, actionId, action, action.Event, _timing.CurTime);
}
else
EntityManager.RaisePredictiveEvent(new RequestPerformActionEvent(EntityManager.GetNetEntity(actionId), EntityManager.GetNetCoordinates(coords)));
if (!action.Repeat)
StopTargeting();
return true;
}
private bool TryTargetEntity(in PointerInputCmdArgs args, EntityUid actionId, EntityTargetActionComponent action, EntityUid user, ActionsComponent actionComp)
{
if (_actionsSystem == null)
return false;
var entity = args.EntityUid;
if (!_actionsSystem.ValidateEntityTarget(user, entity, (actionId, action)))
{
if (action.DeselectOnMiss)
StopTargeting();
return false;
}
if (action.ClientExclusive)
{
if (action.Event != null)
{
action.Event.Target = entity;
}
_actionsSystem.PerformAction(user, actionComp, actionId, action, action.Event, _timing.CurTime);
}
else
EntityManager.RaisePredictiveEvent(new RequestPerformActionEvent(EntityManager.GetNetEntity(actionId), EntityManager.GetNetEntity(args.EntityUid)));
if (!action.Repeat)
StopTargeting();
return true;
}
private bool TryTargetEntityWorld(in PointerInputCmdArgs args,
EntityUid actionId,
EntityWorldTargetActionComponent action,
EntityUid user,
ActionsComponent actionComp)
{
if (_actionsSystem == null)
return false;
var entity = args.EntityUid;
var coords = args.Coordinates;
if (!_actionsSystem.ValidateEntityWorldTarget(user, entity, coords, (actionId, action)))
{
if (action.DeselectOnMiss)
StopTargeting();
return false;
}
if (action.ClientExclusive)
{
if (action.Event != null)
{
action.Event.Entity = entity;
action.Event.Coords = coords;
}
_actionsSystem.PerformAction(user, actionComp, actionId, action, action.Event, _timing.CurTime);
}
else
EntityManager.RaisePredictiveEvent(new RequestPerformActionEvent(EntityManager.GetNetEntity(actionId), EntityManager.GetNetEntity(args.EntityUid), EntityManager.GetNetCoordinates(coords)));
if (!action.Repeat)
// stop targeting when needed
if (ev.FoundTarget ? !target.Repeat : target.DeselectOnMiss)
StopTargeting();
return true;
@@ -305,36 +197,26 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
public void UnloadButton()
{
if (ActionButton == null)
{
return;
}
ActionButton.OnPressed -= ActionButtonPressed;
if (ActionButton != null)
ActionButton.OnPressed -= ActionButtonPressed;
}
public void LoadButton()
{
if (ActionButton == null)
{
return;
}
ActionButton.OnPressed += ActionButtonPressed;
if (ActionButton != null)
ActionButton.OnPressed += ActionButtonPressed;
}
private void OnWindowOpened()
{
if (ActionButton != null)
ActionButton.SetClickPressed(true);
ActionButton?.SetClickPressed(true);
SearchAndDisplay();
}
private void OnWindowClosed()
{
if (ActionButton != null)
ActionButton.SetClickPressed(false);
ActionButton?.SetClickPressed(false);
}
public void OnStateExited(GameplayState state)
@@ -351,35 +233,33 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
private void TriggerAction(int index)
{
if (_actionsSystem == null ||
!_actions.TryGetValue(index, out var actionId) ||
!_actionsSystem.TryGetActionData(actionId, out var baseAction))
if (!_actions.TryGetValue(index, out var actionId) ||
_actionsSystem?.GetAction(actionId) is not {} action)
{
return;
}
if (baseAction is BaseTargetActionComponent action)
ToggleTargeting(actionId.Value, action);
// TODO: probably should have a clientside event raised for flexibility
if (EntityManager.TryGetComponent<TargetActionComponent>(action, out var target))
ToggleTargeting((action, action, target));
else
_actionsSystem?.TriggerAction(actionId.Value, baseAction);
_actionsSystem?.TriggerAction(action);
}
private void OnActionAdded(EntityUid actionId)
{
if (_actionsSystem == null ||
!_actionsSystem.TryGetActionData(actionId, out var action))
{
if (_actionsSystem?.GetAction(actionId) is not {} action)
return;
}
// TODO: event
// if the action is toggled when we add it, start targeting
if (action is BaseTargetActionComponent targetAction && action.Toggled)
StartTargeting(actionId, targetAction);
if (action.Comp.Toggled && EntityManager.TryGetComponent<TargetActionComponent>(actionId, out var target))
StartTargeting((action, action, target));
if (_actions.Contains(actionId))
if (_actions.Contains(action))
return;
_actions.Add(actionId);
_actions.Add(action);
}
private void OnActionRemoved(EntityUid actionId)
@@ -437,15 +317,16 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
}
}
private bool MatchesFilter(BaseActionComponent action, Filters filter)
private bool MatchesFilter(Entity<ActionComponent> ent, Filters filter)
{
var (uid, comp) = ent;
return filter switch
{
Filters.Enabled => action.Enabled,
Filters.Item => action.Container != null && action.Container != _playerManager.LocalEntity,
Filters.Innate => action.Container == null || action.Container == _playerManager.LocalEntity,
Filters.Instant => action is InstantActionComponent,
Filters.Targeted => action is BaseTargetActionComponent,
Filters.Enabled => comp.Enabled,
Filters.Item => comp.Container != null && comp.Container != _playerManager.LocalEntity,
Filters.Innate => comp.Container == null || comp.Container == _playerManager.LocalEntity,
Filters.Instant => EntityManager.HasComponent<InstantActionComponent>(uid),
Filters.Targeted => EntityManager.HasComponent<TargetActionComponent>(uid),
_ => throw new ArgumentOutOfRangeException(nameof(filter), filter, null)
};
}
@@ -456,7 +337,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
_window.ResultsGrid.RemoveAllChildren();
}
private void PopulateActions(IEnumerable<(EntityUid Id, BaseActionComponent Comp)> actions)
private void PopulateActions(IEnumerable<Entity<ActionComponent>> actions)
{
if (_window is not { Disposed: false, IsOpen: true })
return;
@@ -478,7 +359,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
{
if (i < existing.Count)
{
existing[i++].UpdateData(action.Id, _actionsSystem);
existing[i++].UpdateData(action, _actionsSystem);
continue;
}
@@ -486,7 +367,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
button.ActionPressed += OnWindowActionPressed;
button.ActionUnpressed += OnWindowActionUnPressed;
button.ActionFocusExited += OnWindowActionFocusExisted;
button.UpdateData(action.Id, _actionsSystem);
button.UpdateData(action, _actionsSystem);
_window.ResultsGrid.AddChild(button);
}
@@ -525,13 +406,13 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
actions = actions.Where(action =>
{
if (filters.Count > 0 && filters.Any(filter => !MatchesFilter(action.Comp, filter)))
if (filters.Count > 0 && filters.Any(filter => !MatchesFilter(action, filter)))
return false;
if (action.Comp.Keywords.Any(keyword => search.Contains(keyword, StringComparison.OrdinalIgnoreCase)))
return true;
var name = EntityManager.GetComponent<MetaDataComponent>(action.Id).EntityName;
var name = EntityManager.GetComponent<MetaDataComponent>(action).EntityName;
if (name.Contains(search, StringComparison.OrdinalIgnoreCase))
return true;
@@ -581,7 +462,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
private void DragAction()
{
if (_menuDragHelper.Dragged is not {ActionId: {} action} dragged)
if (_menuDragHelper.Dragged is not {Action: {} action} dragged)
{
_menuDragHelper.EndDrag();
return;
@@ -591,7 +472,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
var currentlyHovered = UIManager.MouseGetControl(_input.MouseScreenPosition);
if (currentlyHovered is ActionButton button)
{
swapAction = button.ActionId;
swapAction = button.Action;
SetAction(button, action, false);
}
@@ -665,16 +546,13 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
private void HandleActionPressed(GUIBoundKeyEventArgs args, ActionButton button)
{
args.Handle();
if (button.ActionId != null)
if (button.Action != null)
{
_menuDragHelper.MouseDown(button);
return;
}
var ev = new FillActionSlotEvent();
EntityManager.EventBus.RaiseEvent(EventSource.Local, ev);
if (ev.Action != null)
SetAction(button, ev.Action);
// good job
}
private void OnActionUnpressed(GUIBoundKeyEventArgs args, ActionButton button)
@@ -700,12 +578,13 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
_menuDragHelper.EndDrag();
if (!_actionsSystem.TryGetActionData(button.ActionId, out var baseAction))
if (button.Action is not {} action)
return;
if (baseAction is not BaseTargetActionComponent action)
// TODO: make this an event
if (!EntityManager.TryGetComponent<TargetActionComponent>(action, out var target))
{
_actionsSystem?.TriggerAction(button.ActionId.Value, baseAction);
_actionsSystem?.TriggerAction(action);
return;
}
@@ -714,7 +593,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
// if we're clicking the same thing we're already targeting for, then we simply cancel
// targeting
ToggleTargeting(button.ActionId.Value, action);
ToggleTargeting((action, action.Comp, target));
}
private bool OnMenuBeginDrag()
@@ -722,16 +601,16 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
// TODO ACTIONS
// The dragging icon shuld be based on the entity's icon style. I.e. if the action has a large icon texture,
// and a small item/provider sprite, then the dragged icon should be the big texture, not the provider.
if (_actionsSystem != null && _actionsSystem.TryGetActionData(_menuDragHelper.Dragged?.ActionId, out var action))
if (_menuDragHelper.Dragged?.Action is {} action)
{
if (EntityManager.TryGetComponent(action.EntityIcon, out SpriteComponent? sprite)
if (EntityManager.TryGetComponent(action.Comp.EntityIcon, out SpriteComponent? sprite)
&& sprite.Icon?.GetFrame(RsiDirection.South, 0) is {} frame)
{
_dragShadow.Texture = frame;
}
else if (action.Icon != null)
else if (action.Comp.Icon is {} icon)
{
_dragShadow.Texture = _spriteSystem.Frame0(action.Icon);
_dragShadow.Texture = _spriteSystem.Frame0(icon);
}
else
{
@@ -898,33 +777,35 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
/// If currently targeting with no slot or a different slot, switches to
/// targeting with the specified slot.
/// </summary>
private void ToggleTargeting(EntityUid actionId, BaseTargetActionComponent action)
private void ToggleTargeting(Entity<ActionComponent, TargetActionComponent> ent)
{
if (SelectingTargetFor == actionId)
if (SelectingTargetFor == ent)
{
StopTargeting();
return;
}
StartTargeting(actionId, action);
StartTargeting(ent);
}
/// <summary>
/// Puts us in targeting mode, where we need to pick either a target point or entity
/// </summary>
private void StartTargeting(EntityUid actionId, BaseTargetActionComponent action)
private void StartTargeting(Entity<ActionComponent, TargetActionComponent> ent)
{
var (uid, action, target) = ent;
// If we were targeting something else we should stop
StopTargeting();
SelectingTargetFor = actionId;
SelectingTargetFor = uid;
// TODO inform the server
action.Toggled = true;
_actionsSystem?.SetToggled(uid, true);
// override "held-item" overlay
var provider = action.Container;
if (action.TargetingIndicator && _overlays.TryGetOverlay<ShowHandItemOverlay>(out var handOverlay))
if (target.TargetingIndicator && _overlays.TryGetOverlay<ShowHandItemOverlay>(out var handOverlay))
{
if (action.ItemIconStyle == ItemActionIconStyle.BigItem && action.Container != null)
{
@@ -940,7 +821,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
{
foreach (var button in _container.GetButtons())
{
if (button.ActionId == actionId)
if (button.Action?.Owner == uid)
button.UpdateIcons();
}
}
@@ -950,19 +831,19 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
// - Add a yes/no checkmark where the HandItemOverlay usually is
// Highlight valid entity targets
if (action is not EntityTargetActionComponent entityAction)
if (!EntityManager.TryGetComponent<EntityTargetActionComponent>(uid, out var entity))
return;
Func<EntityUid, bool>? predicate = null;
var attachedEnt = entityAction.AttachedEntity;
var attachedEnt = action.AttachedEntity;
if (!entityAction.CanTargetSelf)
if (!entity.CanTargetSelf)
predicate = e => e != attachedEnt;
var range = entityAction.CheckCanAccess ? action.Range : -1;
var range = target.CheckCanAccess ? target.Range : -1;
_interactionOutline?.SetEnabled(false);
_targetOutline?.Enable(range, entityAction.CheckCanAccess, predicate, entityAction.Whitelist, entityAction.Blacklist, null);
_targetOutline?.Enable(range, target.CheckCanAccess, predicate, entity.Whitelist, entity.Blacklist, null);
}
/// <summary>
@@ -974,11 +855,8 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
return;
var oldAction = SelectingTargetFor;
if (_actionsSystem != null && _actionsSystem.TryGetActionData(oldAction, out var action))
{
// TODO inform the server
action.Toggled = false;
}
// TODO inform the server
_actionsSystem?.SetToggled(oldAction, false);
SelectingTargetFor = null;
@@ -989,7 +867,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
{
foreach (var button in _container.GetButtons())
{
if (button.ActionId == oldAction)
if (button.Action?.Owner == oldAction)
button.UpdateIcons();
}
}

View File

@@ -4,6 +4,7 @@ using Content.Client.Actions.UI;
using Content.Client.Cooldown;
using Content.Client.Stylesheets;
using Content.Shared.Actions;
using Content.Shared.Actions.Components;
using Content.Shared.Charges.Components;
using Content.Shared.Charges.Systems;
using Robust.Client.GameObjects;
@@ -54,8 +55,7 @@ public sealed class ActionButton : Control, IEntityControl
private Texture? _buttonBackgroundTexture;
public EntityUid? ActionId { get; private set; }
private BaseActionComponent? _action;
public Entity<ActionComponent>? Action { get; private set; }
public bool Locked { get; set; }
public event Action<GUIBoundKeyEventArgs, ActionButton>? ActionPressed;
@@ -193,7 +193,7 @@ public sealed class ActionButton : Control, IEntityControl
private Control? SupplyTooltip(Control sender)
{
if (!_entities.TryGetComponent(ActionId, out MetaDataComponent? metadata))
if (!_entities.TryGetComponent(Action, out MetaDataComponent? metadata))
return null;
var name = FormattedMessage.FromMarkupPermissive(Loc.GetString(metadata.EntityName));
@@ -201,14 +201,14 @@ public sealed class ActionButton : Control, IEntityControl
FormattedMessage? chargesText = null;
// TODO: Don't touch this use an event make callers able to add their own shit for actions or I kill you.
if (_entities.TryGetComponent(ActionId, out LimitedChargesComponent? actionCharges))
if (_entities.TryGetComponent(Action, out LimitedChargesComponent? actionCharges))
{
var charges = _sharedChargesSys.GetCurrentCharges((ActionId.Value, actionCharges, null));
var charges = _sharedChargesSys.GetCurrentCharges((Action.Value, actionCharges, null));
chargesText = FormattedMessage.FromMarkupPermissive(Loc.GetString($"Charges: {charges.ToString()}/{actionCharges.MaxCharges}"));
if (_entities.TryGetComponent(ActionId, out AutoRechargeComponent? autoRecharge))
if (_entities.TryGetComponent(Action, out AutoRechargeComponent? autoRecharge))
{
var chargeTimeRemaining = _sharedChargesSys.GetNextRechargeTime((ActionId.Value, actionCharges, autoRecharge));
var chargeTimeRemaining = _sharedChargesSys.GetNextRechargeTime((Action.Value, actionCharges, autoRecharge));
chargesText.AddText(Loc.GetString($"{Environment.NewLine}Time Til Recharge: {chargeTimeRemaining}"));
}
}
@@ -223,7 +223,7 @@ public sealed class ActionButton : Control, IEntityControl
private void UpdateItemIcon()
{
if (_action is not {EntityIcon: { } entity} ||
if (Action?.Comp is not {EntityIcon: { } entity} ||
!_entities.HasComponent<SpriteComponent>(entity))
{
_bigItemSpriteView.Visible = false;
@@ -233,7 +233,7 @@ public sealed class ActionButton : Control, IEntityControl
}
else
{
switch (_action.ItemIconStyle)
switch (Action?.Comp.ItemIconStyle)
{
case ItemActionIconStyle.BigItem:
_bigItemSpriteView.Visible = true;
@@ -259,17 +259,17 @@ public sealed class ActionButton : Control, IEntityControl
private void SetActionIcon(Texture? texture)
{
if (_action == null || texture == null)
if (Action?.Comp is not {} action || texture == null)
{
_bigActionIcon.Texture = null;
_bigActionIcon.Visible = false;
_smallActionIcon.Texture = null;
_smallActionIcon.Visible = false;
}
else if (_action.EntityIcon != null && _action.ItemIconStyle == ItemActionIconStyle.BigItem)
else if (action.EntityIcon != null && action.ItemIconStyle == ItemActionIconStyle.BigItem)
{
_smallActionIcon.Texture = texture;
_smallActionIcon.Modulate = _action.IconColor;
_smallActionIcon.Modulate = action.IconColor;
_smallActionIcon.Visible = true;
_bigActionIcon.Texture = null;
_bigActionIcon.Visible = false;
@@ -277,7 +277,7 @@ public sealed class ActionButton : Control, IEntityControl
else
{
_bigActionIcon.Texture = texture;
_bigActionIcon.Modulate = _action.IconColor;
_bigActionIcon.Modulate = action.IconColor;
_bigActionIcon.Visible = true;
_smallActionIcon.Texture = null;
_smallActionIcon.Visible = false;
@@ -289,7 +289,7 @@ public sealed class ActionButton : Control, IEntityControl
UpdateItemIcon();
UpdateBackground();
if (_action == null)
if (Action is not {} action)
{
SetActionIcon(null);
return;
@@ -297,29 +297,27 @@ public sealed class ActionButton : Control, IEntityControl
_controller ??= UserInterfaceManager.GetUIController<ActionUIController>();
_spriteSys ??= _entities.System<SpriteSystem>();
if ((_controller.SelectingTargetFor == ActionId || _action.Toggled))
var icon = action.Comp.Icon;
if (_controller.SelectingTargetFor == action || action.Comp.Toggled)
{
if (_action.IconOn != null)
SetActionIcon(_spriteSys.Frame0(_action.IconOn));
else if (_action.Icon != null)
SetActionIcon(_spriteSys.Frame0(_action.Icon));
else
SetActionIcon(null);
if (action.Comp.IconOn is {} iconOn)
icon = iconOn;
if (_action.BackgroundOn != null)
_buttonBackgroundTexture = _spriteSys.Frame0(_action.BackgroundOn);
if (action.Comp.BackgroundOn is {} background)
_buttonBackgroundTexture = _spriteSys.Frame0(background);
}
else
{
SetActionIcon(_action.Icon != null ? _spriteSys.Frame0(_action.Icon) : null);
_buttonBackgroundTexture = Theme.ResolveTexture("SlotBackground");
}
SetActionIcon(icon != null ? _spriteSys.Frame0(icon) : null);
}
public void UpdateBackground()
{
_controller ??= UserInterfaceManager.GetUIController<ActionUIController>();
if (_action != null ||
if (Action != null ||
_controller.IsDragging && GetPositionInParent() == Parent?.ChildCount - 1)
{
Button.Texture = _buttonBackgroundTexture;
@@ -333,9 +331,7 @@ public sealed class ActionButton : Control, IEntityControl
public bool TryReplaceWith(EntityUid actionId, ActionsSystem system)
{
if (Locked)
{
return false;
}
UpdateData(actionId, system);
return true;
@@ -343,16 +339,15 @@ public sealed class ActionButton : Control, IEntityControl
public void UpdateData(EntityUid? actionId, ActionsSystem system)
{
ActionId = actionId;
system.TryGetActionData(actionId, out _action);
Label.Visible = actionId != null;
Action = system.GetAction(actionId);
Label.Visible = Action != null;
UpdateIcons();
}
public void ClearData()
{
ActionId = null;
_action = null;
Action = null;
Cooldown.Visible = false;
Cooldown.Progress = 1;
Label.Visible = false;
@@ -365,19 +360,15 @@ public sealed class ActionButton : Control, IEntityControl
UpdateBackground();
Cooldown.Visible = _action != null && _action.Cooldown != null;
if (_action == null)
Cooldown.Visible = Action?.Comp.Cooldown != null;
if (Action?.Comp is not {} action)
return;
if (_action.Cooldown != null)
{
Cooldown.FromTime(_action.Cooldown.Value.Start, _action.Cooldown.Value.End);
}
if (action.Cooldown is {} cooldown)
Cooldown.FromTime(cooldown.Start, cooldown.End);
if (ActionId != null && _toggled != _action.Toggled)
{
_toggled = _action.Toggled;
}
if (_toggled != action.Toggled)
_toggled = action.Toggled;
}
protected override void MouseEntered()
@@ -404,7 +395,7 @@ public sealed class ActionButton : Control, IEntityControl
public void Depress(GUIBoundKeyEventArgs args, bool depress)
{
// action can still be toggled if it's allowed to stay selected
if (_action is not {Enabled: true})
if (Action?.Comp is not {Enabled: true})
return;
_depressed = depress;
@@ -414,17 +405,17 @@ public sealed class ActionButton : Control, IEntityControl
public void DrawModeChanged()
{
_controller ??= UserInterfaceManager.GetUIController<ActionUIController>();
HighlightRect.Visible = _beingHovered && (_action != null || _controller.IsDragging);
HighlightRect.Visible = _beingHovered && (Action != null || _controller.IsDragging);
// always show the normal empty button style if no action in this slot
if (_action == null)
if (Action?.Comp is not {} action)
{
SetOnlyStylePseudoClass(ContainerButton.StylePseudoClassNormal);
return;
}
// show a hover only if the action is usable or another action is being dragged on top of this
if (_beingHovered && (_controller.IsDragging || _action!.Enabled))
if (_beingHovered && (_controller.IsDragging || action.Enabled))
{
SetOnlyStylePseudoClass(ContainerButton.StylePseudoClassHover);
}
@@ -439,16 +430,16 @@ public sealed class ActionButton : Control, IEntityControl
}
// if it's toggled on, always show the toggled on style (currently same as depressed style)
if (_action.Toggled || _controller.SelectingTargetFor == ActionId)
if (action.Toggled || _controller.SelectingTargetFor == Action?.Owner)
{
// when there's a toggle sprite, we're showing that sprite instead of highlighting this slot
SetOnlyStylePseudoClass(_action.IconOn != null
SetOnlyStylePseudoClass(action.IconOn != null
? ContainerButton.StylePseudoClassNormal
: ContainerButton.StylePseudoClassPressed);
return;
}
if (!_action.Enabled)
if (!action.Enabled)
{
SetOnlyStylePseudoClass(ContainerButton.StylePseudoClassDisabled);
return;
@@ -457,5 +448,5 @@ public sealed class ActionButton : Control, IEntityControl
SetOnlyStylePseudoClass(ContainerButton.StylePseudoClassNormal);
}
EntityUid? IEntityControl.UiEntity => ActionId;
EntityUid? IEntityControl.UiEntity => Action;
}