action refactor proper ecs edition (#27422)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user