Fix actions not being usable, ordering, and containers (#19964)
This commit is contained in:
@@ -63,13 +63,16 @@ namespace Content.Client.Actions
|
||||
|
||||
private void HandleComponentState(EntityUid uid, ActionsComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not ActionsComponentState)
|
||||
if (args.Current is not ActionsComponentState state)
|
||||
return;
|
||||
|
||||
component.Actions.Clear();
|
||||
component.Actions.UnionWith(state.Actions);
|
||||
|
||||
_actionHoldersQueue.Enqueue(uid);
|
||||
}
|
||||
|
||||
protected override void AddActionInternal(EntityUid actionId, IContainer container)
|
||||
protected override void AddActionInternal(EntityUid holderId, EntityUid actionId, IContainer container, ActionsComponent holder)
|
||||
{
|
||||
// Sometimes the client receives actions from the server, before predicting that newly added components will add
|
||||
// their own shared actions. Just in case those systems ever decided to directly access action properties (e.g.,
|
||||
@@ -80,7 +83,7 @@ namespace Content.Client.Actions
|
||||
}
|
||||
else
|
||||
{
|
||||
container.Insert(actionId);
|
||||
base.AddActionInternal(holderId, actionId, container, holder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +106,7 @@ namespace Content.Client.Actions
|
||||
ActionAdded?.Invoke(actionId);
|
||||
}
|
||||
|
||||
public override void RemoveAction(EntityUid holderId, EntityUid? actionId, ActionsComponent? comp = null, BaseActionComponent? action = null, bool dirty = true, ContainerManagerComponent? actionContainer = null)
|
||||
public override void RemoveAction(EntityUid holderId, EntityUid? actionId, ActionsComponent? comp = null, BaseActionComponent? action = null, bool dirty = true)
|
||||
{
|
||||
if (GameTiming.ApplyingState)
|
||||
return;
|
||||
@@ -120,7 +123,7 @@ namespace Content.Client.Actions
|
||||
return;
|
||||
|
||||
dirty &= !action?.ClientExclusive ?? true;
|
||||
base.RemoveAction(holderId, actionId, comp, action, dirty, actionContainer);
|
||||
base.RemoveAction(holderId, actionId, comp, action, dirty);
|
||||
|
||||
if (_playerManager.LocalPlayer?.ControlledEntity != holderId)
|
||||
return;
|
||||
@@ -281,7 +284,7 @@ namespace Content.Client.Actions
|
||||
return;
|
||||
|
||||
var removed = new List<EntityUid>();
|
||||
var added = new List<EntityUid>();
|
||||
var added = new List<(EntityUid Id, BaseActionComponent Comp)>();
|
||||
var query = GetEntityQuery<ActionsComponent>();
|
||||
var queue = new Queue<EntityUid>(_actionHoldersQueue);
|
||||
_actionHoldersQueue.Clear();
|
||||
@@ -305,7 +308,7 @@ namespace Content.Client.Actions
|
||||
if (data.ClientExclusive)
|
||||
continue;
|
||||
|
||||
if (!container.Contains(act))
|
||||
if (!holder.Actions.Contains(act))
|
||||
{
|
||||
holder.OldClientActions.Remove(act);
|
||||
if (data.AutoRemove)
|
||||
@@ -314,13 +317,15 @@ namespace Content.Client.Actions
|
||||
}
|
||||
|
||||
// Anything that remains is a new action
|
||||
foreach (var newAct in container.ContainedEntities)
|
||||
foreach (var newAct in holder.Actions)
|
||||
{
|
||||
if (!holder.OldClientActions.ContainsKey(newAct))
|
||||
added.Add(newAct);
|
||||
if (!TryGetActionData(newAct, out var serverData))
|
||||
continue;
|
||||
|
||||
if (TryGetActionData(newAct, out var serverData))
|
||||
holder.OldClientActions[newAct] = new ActionMetaData(serverData.ClientExclusive, serverData.AutoRemove);
|
||||
if (!holder.OldClientActions.ContainsKey(newAct))
|
||||
added.Add((newAct, serverData));
|
||||
|
||||
holder.OldClientActions[newAct] = new ActionMetaData(serverData.ClientExclusive, serverData.AutoRemove);
|
||||
}
|
||||
|
||||
if (_playerManager.LocalPlayer?.ControlledEntity != holderId)
|
||||
@@ -331,9 +336,29 @@ namespace Content.Client.Actions
|
||||
ActionRemoved?.Invoke(action);
|
||||
}
|
||||
|
||||
added.Sort(static (a, b) =>
|
||||
{
|
||||
if (a.Comp.Priority != b.Comp.Priority)
|
||||
return a.Comp.Priority - b.Comp.Priority;
|
||||
|
||||
if (a.Comp.Provider != b.Comp.Provider)
|
||||
{
|
||||
if (a.Comp.Provider == null)
|
||||
return -1;
|
||||
|
||||
if (b.Comp.Provider == null)
|
||||
return 1;
|
||||
|
||||
// uid to int casting... it says "Do NOT use this in content". You can't tell me what to do.
|
||||
return (int) a.Comp.Provider - (int) b.Comp.Provider;
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
foreach (var action in added)
|
||||
{
|
||||
ActionAdded?.Invoke(action);
|
||||
ActionAdded?.Invoke(action.Item1);
|
||||
}
|
||||
|
||||
ActionsUpdated?.Invoke();
|
||||
|
||||
Reference in New Issue
Block a user