Fix actions bar and window not updating (#11899)
This commit is contained in:
@@ -39,9 +39,9 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
|||||||
[Dependency] private readonly IEntityManager _entities = default!;
|
[Dependency] private readonly IEntityManager _entities = default!;
|
||||||
[Dependency] private readonly IOverlayManager _overlays = default!;
|
[Dependency] private readonly IOverlayManager _overlays = default!;
|
||||||
|
|
||||||
[UISystemDependency] private readonly ActionsSystem _actionsSystem = default!;
|
[UISystemDependency] private readonly ActionsSystem? _actionsSystem = default;
|
||||||
[UISystemDependency] private readonly InteractionOutlineSystem _interactionOutline = default!;
|
[UISystemDependency] private readonly InteractionOutlineSystem? _interactionOutline = default;
|
||||||
[UISystemDependency] private readonly TargetOutlineSystem _targetOutline = default!;
|
[UISystemDependency] private readonly TargetOutlineSystem? _targetOutline = default;
|
||||||
|
|
||||||
private const int DefaultPageIndex = 0;
|
private const int DefaultPageIndex = 0;
|
||||||
private ActionButtonContainer? _container;
|
private ActionButtonContainer? _container;
|
||||||
@@ -100,8 +100,14 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
|||||||
_actionButton.OnPressed += ActionButtonPressed;
|
_actionButton.OnPressed += ActionButtonPressed;
|
||||||
_actionsBar.PageButtons.LeftArrow.OnPressed += OnLeftArrowPressed;
|
_actionsBar.PageButtons.LeftArrow.OnPressed += OnLeftArrowPressed;
|
||||||
_actionsBar.PageButtons.RightArrow.OnPressed += OnRightArrowPressed;
|
_actionsBar.PageButtons.RightArrow.OnPressed += OnRightArrowPressed;
|
||||||
|
|
||||||
|
if (_actionsSystem != null)
|
||||||
|
{
|
||||||
|
_actionsSystem.ActionAdded += OnActionAdded;
|
||||||
|
_actionsSystem.ActionRemoved += OnActionRemoved;
|
||||||
_actionsSystem.ActionReplaced += OnActionReplaced;
|
_actionsSystem.ActionReplaced += OnActionReplaced;
|
||||||
_actionsSystem.ActionsUpdated += OnActionsUpdated;
|
_actionsSystem.ActionsUpdated += OnActionsUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
UpdateFilterLabel();
|
UpdateFilterLabel();
|
||||||
SearchAndDisplay();
|
SearchAndDisplay();
|
||||||
@@ -154,8 +160,13 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
|||||||
|
|
||||||
public void OnStateExited(GameplayState state)
|
public void OnStateExited(GameplayState state)
|
||||||
{
|
{
|
||||||
|
if (_actionsSystem != null)
|
||||||
|
{
|
||||||
|
_actionsSystem.ActionAdded -= OnActionAdded;
|
||||||
|
_actionsSystem.ActionRemoved -= OnActionRemoved;
|
||||||
_actionsSystem.ActionReplaced -= OnActionReplaced;
|
_actionsSystem.ActionReplaced -= OnActionReplaced;
|
||||||
_actionsSystem.ActionsUpdated -= OnActionsUpdated;
|
_actionsSystem.ActionsUpdated -= OnActionsUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
if (_window != null)
|
if (_window != null)
|
||||||
{
|
{
|
||||||
@@ -189,7 +200,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
|||||||
if (CurrentPage[index] is not { } type)
|
if (CurrentPage[index] is not { } type)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_actionsSystem.TriggerAction(type);
|
_actionsSystem?.TriggerAction(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ChangePage(int index)
|
private void ChangePage(int index)
|
||||||
@@ -221,6 +232,78 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
|||||||
ChangePage(_currentPageIndex + 1);
|
ChangePage(_currentPageIndex + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AppendAction(ActionType action)
|
||||||
|
{
|
||||||
|
if (_container == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (var button in _container.GetButtons())
|
||||||
|
{
|
||||||
|
if (button.Action != null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
SetAction(button, action);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var page in _pages)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < page.Size; i++)
|
||||||
|
{
|
||||||
|
var pageAction = page[i];
|
||||||
|
if (pageAction != null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
page[i] = action;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnActionAdded(ActionType action)
|
||||||
|
{
|
||||||
|
foreach (var page in _pages)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < page.Size; i++)
|
||||||
|
{
|
||||||
|
if (page[i] == action)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AppendAction(action);
|
||||||
|
SearchAndDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnActionRemoved(ActionType action)
|
||||||
|
{
|
||||||
|
if (_container == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (var button in _container.GetButtons())
|
||||||
|
{
|
||||||
|
if (button.Action == action)
|
||||||
|
{
|
||||||
|
SetAction(button, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var page in _pages)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < page.Size; i++)
|
||||||
|
{
|
||||||
|
if (page[i] == action)
|
||||||
|
{
|
||||||
|
page[i] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SearchAndDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
private void OnActionReplaced(ActionType existing, ActionType action)
|
private void OnActionReplaced(ActionType existing, ActionType action)
|
||||||
{
|
{
|
||||||
if (_container == null)
|
if (_container == null)
|
||||||
@@ -285,8 +368,8 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
|||||||
return filter switch
|
return filter switch
|
||||||
{
|
{
|
||||||
Filters.Enabled => action.Enabled,
|
Filters.Enabled => action.Enabled,
|
||||||
Filters.Item => action.Provider != null && action.Provider != _actionsSystem.PlayerActions?.Owner,
|
Filters.Item => action.Provider != null && action.Provider != _actionsSystem?.PlayerActions?.Owner,
|
||||||
Filters.Innate => action.Provider == null || action.Provider == _actionsSystem.PlayerActions?.Owner,
|
Filters.Innate => action.Provider == null || action.Provider == _actionsSystem?.PlayerActions?.Owner,
|
||||||
Filters.Instant => action is InstantAction,
|
Filters.Instant => action is InstantAction,
|
||||||
Filters.Targeted => action is TargetedAction,
|
Filters.Targeted => action is TargetedAction,
|
||||||
_ => throw new ArgumentOutOfRangeException(nameof(filter), filter, null)
|
_ => throw new ArgumentOutOfRangeException(nameof(filter), filter, null)
|
||||||
@@ -326,7 +409,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
|||||||
var search = _window.SearchBar.Text;
|
var search = _window.SearchBar.Text;
|
||||||
var filters = _window.FilterButton.SelectedKeys;
|
var filters = _window.FilterButton.SelectedKeys;
|
||||||
|
|
||||||
IEnumerable<ActionType>? actions = _actionsSystem.PlayerActions?.Actions;
|
IEnumerable<ActionType>? actions = _actionsSystem?.PlayerActions?.Actions;
|
||||||
actions ??= Array.Empty<ActionType>();
|
actions ??= Array.Empty<ActionType>();
|
||||||
|
|
||||||
if (filters.Count == 0 && string.IsNullOrWhiteSpace(search))
|
if (filters.Count == 0 && string.IsNullOrWhiteSpace(search))
|
||||||
@@ -346,7 +429,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
|||||||
if (action.DisplayName.Contains(search, StringComparison.OrdinalIgnoreCase))
|
if (action.DisplayName.Contains(search, StringComparison.OrdinalIgnoreCase))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (action.Provider == null || action.Provider == _actionsSystem.PlayerActions?.Owner)
|
if (action.Provider == null || action.Provider == _actionsSystem?.PlayerActions?.Owner)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var name = _entities.GetComponent<MetaDataComponent>(action.Provider.Value).EntityName;
|
var name = _entities.GetComponent<MetaDataComponent>(action.Provider.Value).EntityName;
|
||||||
@@ -477,7 +560,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_actionsSystem.TriggerAction(button.Action);
|
_actionsSystem?.TriggerAction(button.Action);
|
||||||
_menuDragHelper.EndDrag();
|
_menuDragHelper.EndDrag();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -559,18 +642,18 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
|||||||
|
|
||||||
public void OnSystemLoaded(ActionsSystem system)
|
public void OnSystemLoaded(ActionsSystem system)
|
||||||
{
|
{
|
||||||
_actionsSystem.LinkActions += OnComponentLinked;
|
system.LinkActions += OnComponentLinked;
|
||||||
_actionsSystem.UnlinkActions += OnComponentUnlinked;
|
system.UnlinkActions += OnComponentUnlinked;
|
||||||
_actionsSystem.ClearAssignments += ClearActions;
|
system.ClearAssignments += ClearActions;
|
||||||
_actionsSystem.AssignSlot += AssignSlots;
|
system.AssignSlot += AssignSlots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnSystemUnloaded(ActionsSystem system)
|
public void OnSystemUnloaded(ActionsSystem system)
|
||||||
{
|
{
|
||||||
_actionsSystem.LinkActions -= OnComponentLinked;
|
system.LinkActions -= OnComponentLinked;
|
||||||
_actionsSystem.UnlinkActions -= OnComponentUnlinked;
|
system.UnlinkActions -= OnComponentUnlinked;
|
||||||
_actionsSystem.ClearAssignments -= ClearActions;
|
system.ClearAssignments -= ClearActions;
|
||||||
_actionsSystem.AssignSlot -= AssignSlots;
|
system.AssignSlot -= AssignSlots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void FrameUpdate(FrameEventArgs args)
|
public override void FrameUpdate(FrameEventArgs args)
|
||||||
@@ -688,8 +771,8 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
|||||||
|
|
||||||
var range = entityAction.CheckCanAccess ? action.Range : -1;
|
var range = entityAction.CheckCanAccess ? action.Range : -1;
|
||||||
|
|
||||||
_interactionOutline.SetEnabled(false);
|
_interactionOutline?.SetEnabled(false);
|
||||||
_targetOutline.Enable(range, entityAction.CheckCanAccess, predicate, entityAction.Whitelist, null);
|
_targetOutline?.Enable(range, entityAction.CheckCanAccess, predicate, entityAction.Whitelist, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -701,8 +784,8 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
SelectingTargetFor = null;
|
SelectingTargetFor = null;
|
||||||
_targetOutline.Disable();
|
_targetOutline?.Disable();
|
||||||
_interactionOutline.SetEnabled(true);
|
_interactionOutline?.SetEnabled(true);
|
||||||
|
|
||||||
if (!_overlays.TryGetOverlay<ShowHandItemOverlay>(out var handOverlay) || handOverlay == null)
|
if (!_overlays.TryGetOverlay<ShowHandItemOverlay>(out var handOverlay) || handOverlay == null)
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user