Better logic related to selecting / deselecting target-based actions (#2962)
This commit is contained in:
@@ -184,8 +184,10 @@ namespace Content.Client.GameObjects.Components.Mobs
|
|||||||
|
|
||||||
// only do something for actual target-based actions
|
// only do something for actual target-based actions
|
||||||
if (_ui?.SelectingTargetFor?.Action == null ||
|
if (_ui?.SelectingTargetFor?.Action == null ||
|
||||||
(_ui.SelectingTargetFor.Action.BehaviorType != BehaviorType.TargetEntity &&
|
(!_ui.SelectingTargetFor.Action.IsTargetAction)) return false;
|
||||||
_ui.SelectingTargetFor.Action.BehaviorType != BehaviorType.TargetPoint)) return false;
|
|
||||||
|
// do nothing if we know it's on cooldown
|
||||||
|
if (_ui.SelectingTargetFor.IsOnCooldown) return false;
|
||||||
|
|
||||||
var attempt = _ui.SelectingTargetFor.ActionAttempt();
|
var attempt = _ui.SelectingTargetFor.ActionAttempt();
|
||||||
if (attempt == null)
|
if (attempt == null)
|
||||||
@@ -217,6 +219,13 @@ namespace Content.Client.GameObjects.Components.Mobs
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// we are supposed to target an entity but we didn't click it
|
||||||
|
case BehaviorType.TargetEntity when args.EntityUid == EntityUid.Invalid:
|
||||||
|
{
|
||||||
|
if (attempt.Action.DeselectWhenEntityNotClicked)
|
||||||
|
_ui.StopTargeting();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
_ui.StopTargeting();
|
_ui.StopTargeting();
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -404,8 +404,7 @@ namespace Content.Client.UserInterface
|
|||||||
ItemTag => action is ItemActionPrototype,
|
ItemTag => action is ItemActionPrototype,
|
||||||
NotItemTag => action is ActionPrototype,
|
NotItemTag => action is ActionPrototype,
|
||||||
InstantActionTag => action.BehaviorType == BehaviorType.Instant,
|
InstantActionTag => action.BehaviorType == BehaviorType.Instant,
|
||||||
TargetActionTag => action.BehaviorType == BehaviorType.TargetEntity ||
|
TargetActionTag => action.IsTargetAction,
|
||||||
action.BehaviorType == BehaviorType.TargetPoint,
|
|
||||||
ToggleActionTag => action.BehaviorType == BehaviorType.Toggle,
|
ToggleActionTag => action.BehaviorType == BehaviorType.Toggle,
|
||||||
_ => action.Filters.Contains(tag)
|
_ => action.Filters.Contains(tag)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -337,9 +337,9 @@ namespace Content.Client.UserInterface
|
|||||||
actionSlot.EnableAction();
|
actionSlot.EnableAction();
|
||||||
actionSlot.Cooldown = actionState.Cooldown;
|
actionSlot.Cooldown = actionState.Cooldown;
|
||||||
|
|
||||||
// if we are targeting with an action now on cooldown, stop targeting
|
// if we are targeting for this action and it's now on cooldown, stop targeting if we're supposed to
|
||||||
if (SelectingTargetFor?.Action != null && SelectingTargetFor.Action == action &&
|
if (SelectingTargetFor?.Action != null && SelectingTargetFor.Action == action &&
|
||||||
actionState.IsOnCooldown(_gameTiming))
|
actionState.IsOnCooldown(_gameTiming) && action.DeselectOnCooldown)
|
||||||
{
|
{
|
||||||
StopTargeting();
|
StopTargeting();
|
||||||
}
|
}
|
||||||
@@ -410,10 +410,10 @@ namespace Content.Client.UserInterface
|
|||||||
// action is currently granted
|
// action is currently granted
|
||||||
actionSlot.EnableAction();
|
actionSlot.EnableAction();
|
||||||
|
|
||||||
// if we are targeting with an action now on cooldown, stop targeting
|
// if we are targeting with an action now on cooldown, stop targeting if we should
|
||||||
if (SelectingTargetFor?.Action != null && SelectingTargetFor.Action == action &&
|
if (SelectingTargetFor?.Action != null && SelectingTargetFor.Action == action &&
|
||||||
SelectingTargetFor.Item == itemEntity &&
|
SelectingTargetFor.Item == itemEntity &&
|
||||||
actionState.IsOnCooldown(_gameTiming))
|
actionState.IsOnCooldown(_gameTiming) && action.DeselectOnCooldown)
|
||||||
{
|
{
|
||||||
StopTargeting();
|
StopTargeting();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,8 +53,10 @@ namespace Content.Client.UserInterface.Controls
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is there an action in the slot that can currently be used?
|
/// Is there an action in the slot that can currently be used?
|
||||||
|
/// Target-basedActions on cooldown can still be selected / deselected if they've been configured as such
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool CanUseAction => HasAssignment && ActionEnabled && !IsOnCooldown;
|
public bool CanUseAction => Action != null && ActionEnabled &&
|
||||||
|
(!IsOnCooldown || (Action.IsTargetAction && !Action.DeselectOnCooldown));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Item the action is provided by, only valid if Action is an ItemActionPrototype. May be null
|
/// Item the action is provided by, only valid if Action is an ItemActionPrototype. May be null
|
||||||
@@ -340,8 +342,10 @@ namespace Content.Client.UserInterface.Controls
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Depress(bool depress)
|
public void Depress(bool depress)
|
||||||
{
|
{
|
||||||
|
// action can still be toggled if it's allowed to stay selected
|
||||||
if (!CanUseAction) return;
|
if (!CanUseAction) return;
|
||||||
|
|
||||||
|
|
||||||
if (_depressed && !depress)
|
if (_depressed && !depress)
|
||||||
{
|
{
|
||||||
// fire the action
|
// fire the action
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ namespace Content.Shared.Actions
|
|||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public SpriteSpecifier IconOn { get; private set; }
|
public SpriteSpecifier IconOn { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Name to show in UI. Accepts formatting.
|
/// Name to show in UI. Accepts formatting.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -60,6 +58,18 @@ namespace Content.Shared.Actions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Repeat { get; private set; }
|
public bool Repeat { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// For TargetEntity/TargetPoint actions, should the action be de-selected if currently selected (choosing a target)
|
||||||
|
/// when it goes on cooldown. Defaults to false.
|
||||||
|
/// </summary>
|
||||||
|
public bool DeselectOnCooldown { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// For TargetEntity actions, should the action be de-selected if the user doesn't click an entity when
|
||||||
|
/// selecting a target. Defaults to false.
|
||||||
|
/// </summary>
|
||||||
|
public bool DeselectWhenEntityNotClicked { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Filters that can be used to filter this item in action menu.
|
/// Filters that can be used to filter this item in action menu.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -70,6 +80,12 @@ namespace Content.Shared.Actions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<string> Keywords { get; private set; }
|
public IEnumerable<string> Keywords { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True if this is an action that requires selecting a target
|
||||||
|
/// </summary>
|
||||||
|
public bool IsTargetAction =>
|
||||||
|
BehaviorType == BehaviorType.TargetEntity || BehaviorType == BehaviorType.TargetPoint;
|
||||||
|
|
||||||
public virtual void LoadFrom(YamlMappingNode mapping)
|
public virtual void LoadFrom(YamlMappingNode mapping)
|
||||||
{
|
{
|
||||||
var serializer = YamlObjectSerializer.NewReader(mapping);
|
var serializer = YamlObjectSerializer.NewReader(mapping);
|
||||||
@@ -106,6 +122,9 @@ namespace Content.Shared.Actions
|
|||||||
Name, BehaviorType);
|
Name, BehaviorType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
serializer.DataField(this, x => x.DeselectOnCooldown, "deselectOnCooldown", false);
|
||||||
|
serializer.DataField(this, x => x.DeselectWhenEntityNotClicked, "deselectWhenEntityNotClicked", false);
|
||||||
|
|
||||||
serializer.DataReadFunction("filters", new List<string>(),
|
serializer.DataReadFunction("filters", new List<string>(),
|
||||||
rawTags =>
|
rawTags =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user