Click Drag Functionality + Refactor Interaction Interfaces (#1125)
Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> Co-authored-by: ComicIronic <comicironic@gmail.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Interaction;
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
@@ -22,14 +23,15 @@ namespace Content.Server.Utility
|
||||
|
||||
/// <summary>
|
||||
/// Default interaction check for targeted attack interaction types.
|
||||
/// Same as <see cref="SharedInteractionSystem.InRangeUnobstructed"/>, but defaults to allow inside blockers.
|
||||
/// Same as <see cref="SharedInteractionSystem.InRangeUnobstructed"/>, but defaults to ignore inside blockers
|
||||
/// (making the check less restrictive).
|
||||
/// Validates that attacker is in range of the attacked entity. Additionally shows a popup if
|
||||
/// validation fails.
|
||||
/// </summary>
|
||||
public static bool InRangeUnobstructed(ITargetedInteractEventArgs eventArgs, bool insideBlockerValid = true)
|
||||
public static bool InRangeUnobstructed(ITargetedInteractEventArgs eventArgs, bool ignoreInsideBlocker = true)
|
||||
{
|
||||
if (!EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(eventArgs.User.Transform.MapPosition,
|
||||
eventArgs.Target.Transform.MapPosition, ignoredEnt: eventArgs.Target, insideBlockerValid: insideBlockerValid))
|
||||
eventArgs.Target.Transform.MapPosition, ignoredEnt: eventArgs.Target, ignoreInsideBlocker: ignoreInsideBlocker))
|
||||
{
|
||||
var localizationManager = IoCManager.Resolve<ILocalizationManager>();
|
||||
eventArgs.Target.PopupMessage(eventArgs.User, localizationManager.GetString("You can't reach there!"));
|
||||
@@ -39,19 +41,46 @@ namespace Content.Server.Utility
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default interaction check for Drag drop interaction types.
|
||||
/// Same as <see cref="SharedInteractionSystem.InRangeUnobstructed"/>, but defaults to ignore inside blockers
|
||||
/// (making the check less restrictive) and checks reachability of both the target and the dragged / dropped object.
|
||||
/// Additionally shows a popup if validation fails.
|
||||
/// </summary>
|
||||
public static bool InRangeUnobstructed(DragDropEventArgs eventArgs, bool ignoreInsideBlocker = true)
|
||||
{
|
||||
if (!EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(eventArgs.User.Transform.MapPosition,
|
||||
eventArgs.Target.Transform.MapPosition, ignoredEnt: eventArgs.Target, ignoreInsideBlocker: ignoreInsideBlocker))
|
||||
{
|
||||
var localizationManager = IoCManager.Resolve<ILocalizationManager>();
|
||||
eventArgs.Target.PopupMessage(eventArgs.User, localizationManager.GetString("You can't reach there!"));
|
||||
return false;
|
||||
}
|
||||
if (!EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(eventArgs.User.Transform.MapPosition,
|
||||
eventArgs.Dropped.Transform.MapPosition, ignoredEnt: eventArgs.Dropped, ignoreInsideBlocker: ignoreInsideBlocker))
|
||||
{
|
||||
var localizationManager = IoCManager.Resolve<ILocalizationManager>();
|
||||
eventArgs.Dropped.PopupMessage(eventArgs.User, localizationManager.GetString("You can't reach there!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default interaction check for after attack interaction types.
|
||||
/// Same as <see cref="SharedInteractionSystem.InRangeUnobstructed"/>, but defaults to allow inside blockers.
|
||||
/// Same as <see cref="SharedInteractionSystem.InRangeUnobstructed"/>, but defaults to ignore inside blockers
|
||||
/// (making the check less restrictive).
|
||||
/// Validates that attacker is in range of the attacked entity, if there is such an entity.
|
||||
/// If there is no attacked entity, validates that they are in range of the clicked position.
|
||||
/// Additionally shows a popup if validation fails.
|
||||
/// </summary>
|
||||
public static bool InRangeUnobstructed(AfterInteractEventArgs eventArgs, bool insideBlockerValid = true)
|
||||
public static bool InRangeUnobstructed(AfterInteractEventArgs eventArgs, bool ignoreInsideBlocker = true)
|
||||
{
|
||||
if (eventArgs.Target != null)
|
||||
{
|
||||
if (!EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(eventArgs.User.Transform.MapPosition,
|
||||
eventArgs.Target.Transform.MapPosition, ignoredEnt: eventArgs.Target, insideBlockerValid: insideBlockerValid))
|
||||
eventArgs.Target.Transform.MapPosition, ignoredEnt: eventArgs.Target, ignoreInsideBlocker: ignoreInsideBlocker))
|
||||
{
|
||||
var localizationManager = IoCManager.Resolve<ILocalizationManager>();
|
||||
eventArgs.Target.PopupMessage(eventArgs.User, localizationManager.GetString("You can't reach there!"));
|
||||
@@ -61,7 +90,7 @@ namespace Content.Server.Utility
|
||||
else
|
||||
{
|
||||
if (!EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(eventArgs.User.Transform.MapPosition,
|
||||
eventArgs.ClickLocation.ToMap(IoCManager.Resolve<IMapManager>()), ignoredEnt: eventArgs.User, insideBlockerValid: insideBlockerValid))
|
||||
eventArgs.ClickLocation.ToMap(IoCManager.Resolve<IMapManager>()), ignoredEnt: eventArgs.User, ignoreInsideBlocker: ignoreInsideBlocker))
|
||||
{
|
||||
var localizationManager = IoCManager.Resolve<ILocalizationManager>();
|
||||
eventArgs.User.PopupMessage(eventArgs.User, localizationManager.GetString("You can't reach there!"));
|
||||
@@ -80,12 +109,12 @@ namespace Content.Server.Utility
|
||||
public static bool InRangeUnobstructed(IEntity user, MapCoordinates otherCoords,
|
||||
float range = SharedInteractionSystem.InteractionRange,
|
||||
int collisionMask = (int) CollisionGroup.Impassable, IEntity ignoredEnt = null,
|
||||
bool insideBlockerValid = false)
|
||||
bool ignoreInsideBlocker = false)
|
||||
{
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var interactionSystem = EntitySystem.Get<SharedInteractionSystem>();
|
||||
if (!interactionSystem.InRangeUnobstructed(user.Transform.MapPosition, otherCoords, range, collisionMask,
|
||||
ignoredEnt, insideBlockerValid))
|
||||
ignoredEnt, ignoreInsideBlocker))
|
||||
{
|
||||
var localizationManager = IoCManager.Resolve<ILocalizationManager>();
|
||||
user.PopupMessage(user, localizationManager.GetString("You can't reach there!"));
|
||||
|
||||
Reference in New Issue
Block a user