mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
Adds real-time charge & disabled action information to Actions (#31821)
(cherry picked from commit 7168959929b87dd392c5cbc3d29bdb9bd315c060)
This commit is contained in:
@@ -52,6 +52,29 @@ namespace Content.Client.Actions
|
||||
SubscribeLocalEvent<EntityWorldTargetActionComponent, ComponentHandleState>(OnEntityWorldTargetHandleState);
|
||||
}
|
||||
|
||||
public override void FrameUpdate(float frameTime)
|
||||
{
|
||||
base.FrameUpdate(frameTime);
|
||||
|
||||
var worldActionQuery = EntityQueryEnumerator<WorldTargetActionComponent>();
|
||||
while (worldActionQuery.MoveNext(out var uid, out var action))
|
||||
{
|
||||
UpdateAction(uid, action);
|
||||
}
|
||||
|
||||
var instantActionQuery = EntityQueryEnumerator<InstantActionComponent>();
|
||||
while (instantActionQuery.MoveNext(out var uid, out var action))
|
||||
{
|
||||
UpdateAction(uid, action);
|
||||
}
|
||||
|
||||
var entityActionQuery = EntityQueryEnumerator<EntityTargetActionComponent>();
|
||||
while (entityActionQuery.MoveNext(out var uid, out var action))
|
||||
{
|
||||
UpdateAction(uid, action);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInstantHandleState(EntityUid uid, InstantActionComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not InstantActionComponentState state)
|
||||
@@ -97,6 +120,8 @@ namespace Content.Client.Actions
|
||||
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;
|
||||
@@ -127,6 +152,8 @@ namespace Content.Client.Actions
|
||||
if (!ResolveActionData(actionId, ref action))
|
||||
return;
|
||||
|
||||
action.IconColor = action.Charges < 1 ? action.DisabledIconColor : action.OriginalIconColor;
|
||||
|
||||
base.UpdateAction(actionId, action);
|
||||
if (_playerManager.LocalEntity != action.AttachedEntity)
|
||||
return;
|
||||
|
||||
@@ -50,6 +50,16 @@ public abstract partial class BaseActionComponent : Component
|
||||
/// </remarks>
|
||||
[DataField("iconColor")] public Color IconColor = Color.White;
|
||||
|
||||
/// <summary>
|
||||
/// The original <see cref="IconColor"/> this action was.
|
||||
/// </summary>
|
||||
[DataField] public Color OriginalIconColor;
|
||||
|
||||
/// <summary>
|
||||
/// The color the action should turn to when disabled
|
||||
/// </summary>
|
||||
[DataField] public Color DisabledIconColor = Color.DimGray;
|
||||
|
||||
/// <summary>
|
||||
/// Keywords that can be used to search for this action in the action menu.
|
||||
/// </summary>
|
||||
@@ -194,6 +204,8 @@ public abstract class BaseActionComponentState : ComponentState
|
||||
public SpriteSpecifier? Icon;
|
||||
public SpriteSpecifier? IconOn;
|
||||
public Color IconColor;
|
||||
public Color OriginalIconColor;
|
||||
public Color DisabledIconColor;
|
||||
public HashSet<string> Keywords;
|
||||
public bool Enabled;
|
||||
public bool Toggled;
|
||||
@@ -224,6 +236,8 @@ public abstract class BaseActionComponentState : ComponentState
|
||||
Icon = component.Icon;
|
||||
IconOn = component.IconOn;
|
||||
IconColor = component.IconColor;
|
||||
OriginalIconColor = component.OriginalIconColor;
|
||||
DisabledIconColor = component.DisabledIconColor;
|
||||
Keywords = component.Keywords;
|
||||
Enabled = component.Enabled;
|
||||
Toggled = component.Toggled;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Shared._Shitmed.Antags.Abductor;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Actions.Events;
|
||||
using Content.Shared.Administration.Logs;
|
||||
@@ -8,21 +9,19 @@ using Content.Shared.Hands;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Rejuvenate;
|
||||
using Content.Shared.Silicons.StationAi;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
namespace Content.Shared.Actions;
|
||||
|
||||
// Shitmed Change
|
||||
using Content.Shared._Shitmed.Antags.Abductor;
|
||||
using Content.Shared.Silicons.StationAi;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Shared.Prototypes;
|
||||
namespace Content.Shared.Actions;
|
||||
|
||||
public abstract class SharedActionsSystem : EntitySystem
|
||||
{
|
||||
@@ -79,8 +78,42 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
SubscribeAllEvent<RequestPerformActionEvent>(OnActionRequest);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
var worldActionQuery = EntityQueryEnumerator<WorldTargetActionComponent>();
|
||||
while (worldActionQuery.MoveNext(out var uid, out var action))
|
||||
{
|
||||
if (IsCooldownActive(action) || !ShouldResetCharges(action))
|
||||
continue;
|
||||
|
||||
ResetCharges(uid, dirty: true);
|
||||
}
|
||||
|
||||
var instantActionQuery = EntityQueryEnumerator<InstantActionComponent>();
|
||||
while (instantActionQuery.MoveNext(out var uid, out var action))
|
||||
{
|
||||
if (IsCooldownActive(action) || !ShouldResetCharges(action))
|
||||
continue;
|
||||
|
||||
ResetCharges(uid, dirty: true);
|
||||
}
|
||||
|
||||
var entityActionQuery = EntityQueryEnumerator<EntityTargetActionComponent>();
|
||||
while (entityActionQuery.MoveNext(out var uid, out var action))
|
||||
{
|
||||
if (IsCooldownActive(action) || !ShouldResetCharges(action))
|
||||
continue;
|
||||
|
||||
ResetCharges(uid, dirty: true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnActionMapInit(EntityUid uid, BaseActionComponent component, MapInitEvent args)
|
||||
{
|
||||
component.OriginalIconColor = component.IconColor;
|
||||
|
||||
if (component.Charges == null)
|
||||
return;
|
||||
|
||||
@@ -336,14 +369,18 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
public void ResetCharges(EntityUid? actionId)
|
||||
public void ResetCharges(EntityUid? actionId, bool update = false, bool dirty = false)
|
||||
{
|
||||
if (!TryGetActionData(actionId, out var action))
|
||||
return;
|
||||
|
||||
action.Charges = action.MaxCharges;
|
||||
UpdateAction(actionId, action);
|
||||
Dirty(actionId.Value, action);
|
||||
|
||||
if (update)
|
||||
UpdateAction(actionId, action);
|
||||
|
||||
if (dirty)
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
public void SetMaxCharges(EntityUid? actionId, int? maxCharges)
|
||||
@@ -407,13 +444,12 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
return;
|
||||
|
||||
var curTime = GameTiming.CurTime;
|
||||
// TODO: Check for charge recovery timer
|
||||
if (action.Cooldown.HasValue && action.Cooldown.Value.End > curTime)
|
||||
if (IsCooldownActive(action, curTime))
|
||||
return;
|
||||
|
||||
// TODO: Replace with individual charge recovery when we have the visuals to aid it
|
||||
if (action is { Charges: < 1, RenewCharges: true })
|
||||
ResetCharges(actionEnt);
|
||||
ResetCharges(actionEnt, true, true);
|
||||
|
||||
BaseActionEvent? performEvent = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user