Action container rejig (#20260)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Leon Friedrich
2023-09-23 04:49:39 -04:00
committed by GitHub
parent c80c90ed65
commit 684b334806
50 changed files with 889 additions and 740 deletions

View File

@@ -111,8 +111,8 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
{
if (_actionsSystem != null)
{
_actionsSystem.ActionAdded += OnActionAdded;
_actionsSystem.ActionRemoved += OnActionRemoved;
_actionsSystem.OnActionAdded += OnActionAdded;
_actionsSystem.OnActionRemoved += OnActionRemoved;
_actionsSystem.ActionReplaced += OnActionReplaced;
_actionsSystem.ActionsUpdated += OnActionsUpdated;
}
@@ -319,8 +319,8 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
{
if (_actionsSystem != null)
{
_actionsSystem.ActionAdded -= OnActionAdded;
_actionsSystem.ActionRemoved -= OnActionRemoved;
_actionsSystem.OnActionAdded -= OnActionAdded;
_actionsSystem.OnActionRemoved -= OnActionRemoved;
_actionsSystem.ActionReplaced -= OnActionReplaced;
_actionsSystem.ActionsUpdated -= OnActionsUpdated;
}
@@ -522,8 +522,8 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
return filter switch
{
Filters.Enabled => action.Enabled,
Filters.Item => action.Provider != null && action.Provider != _playerManager.LocalPlayer?.ControlledEntity,
Filters.Innate => action.Provider == null || action.Provider == _playerManager.LocalPlayer?.ControlledEntity,
Filters.Item => action.Container != null && action.Container != _playerManager.LocalPlayer?.ControlledEntity,
Filters.Innate => action.Container == null || action.Container == _playerManager.LocalPlayer?.ControlledEntity,
Filters.Instant => action is InstantActionComponent,
Filters.Targeted => action is BaseTargetActionComponent,
_ => throw new ArgumentOutOfRangeException(nameof(filter), filter, null)
@@ -561,6 +561,9 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
if (_window is not { Disposed: false } || _actionsSystem == null)
return;
if (_playerManager.LocalPlayer?.ControlledEntity is not { } player)
return;
var search = _window.SearchBar.Text;
var filters = _window.FilterButton.SelectedKeys;
var actions = _actionsSystem.GetClientActions();
@@ -583,10 +586,10 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
if (name.Contains(search, StringComparison.OrdinalIgnoreCase))
return true;
if (action.Comp.Provider == null || action.Comp.Provider == _playerManager.LocalPlayer?.ControlledEntity)
if (action.Comp.Container == null || action.Comp.Container == player)
return false;
var providerName = EntityManager.GetComponent<MetaDataComponent>(action.Comp.Provider.Value).EntityName;
var providerName = EntityManager.GetComponent<MetaDataComponent>(action.Comp.Container.Value).EntityName;
return providerName.Contains(search, StringComparison.OrdinalIgnoreCase);
});
@@ -744,11 +747,9 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
{
if (_actionsSystem != null && _actionsSystem.TryGetActionData(_menuDragHelper.Dragged?.ActionId, out var action))
{
var entIcon = action.EntityIcon;
if (entIcon != null)
if (action.EntityIcon is {} entIcon)
{
_dragShadow.Texture = EntityManager.GetComponent<SpriteComponent>(entIcon.Value).Icon?
_dragShadow.Texture = EntityManager.GetComponent<SpriteComponent>(entIcon).Icon?
.GetFrame(RsiDirection.South, 0);
}
else if (action.Icon != null)
@@ -902,6 +903,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
return;
var actions = _actionsSystem.GetClientActions().Where(action => action.Comp.AutoPopulate).ToList();
actions.Sort(ActionComparer);
var offset = 0;
var totalPages = _pages.Count;
@@ -965,11 +967,11 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
action.Toggled = true;
// override "held-item" overlay
var provider = action.Provider;
var provider = action.Container;
if (action.TargetingIndicator && _overlays.TryGetOverlay<ShowHandItemOverlay>(out var handOverlay))
{
if (action.ItemIconStyle == ItemActionIconStyle.BigItem && action.Provider != null)
if (action.ItemIconStyle == ItemActionIconStyle.BigItem && action.Container != null)
{
handOverlay.EntityOverride = provider;
}

View File

@@ -19,14 +19,6 @@ public class ActionButtonContainer : GridContainer
public ActionButton this[int index]
{
get => (ActionButton) GetChild(index);
set
{
AddChild(value);
value.SetPositionInParent(index);
value.ActionPressed += ActionPressed;
value.ActionUnpressed += ActionUnpressed;
value.ActionFocusExited += ActionFocusExited;
}
}
public void SetActionData(params EntityUid?[] actionTypes)
@@ -63,6 +55,16 @@ public class ActionButtonContainer : GridContainer
button.ActionFocusExited += ActionFocusExited;
}
protected override void ChildRemoved(Control newChild)
{
if (newChild is not ActionButton button)
return;
button.ActionPressed -= ActionPressed;
button.ActionUnpressed -= ActionUnpressed;
button.ActionFocusExited -= ActionFocusExited;
}
public bool TryGetButtonIndex(ActionButton button, out int position)
{
if (button.Parent != this)