Pinpointer (#5131)
* Add pinpointer sprites * Start working on pinpointer * Updated pinpointer * Working on visuals * Working on a pinpointer and eye rotation * Add client/server pinpointers systems * Minor cleanup * Add distance support * Add nuke tag * Remove redundant flag and add pinpointer to caps locker * Disable rotation of pinpointer * Fixed distance Co-authored-by: Alexander Evgrashin <evgrashin.adl@gmail.com>
This commit is contained in:
93
Content.Shared/Pinpointer/SharedPinpointerSystem.cs
Normal file
93
Content.Shared/Pinpointer/SharedPinpointerSystem.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Shared.Pinpointer
|
||||
{
|
||||
public abstract class SharedPinpointerSystem : EntitySystem
|
||||
{
|
||||
protected readonly HashSet<EntityUid> ActivePinpointers = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<PinpointerComponent, ComponentGetState>(GetCompState);
|
||||
}
|
||||
|
||||
private void GetCompState(EntityUid uid, PinpointerComponent pinpointer, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new PinpointerComponentState
|
||||
{
|
||||
IsActive = pinpointer.IsActive,
|
||||
DirectionToTarget = pinpointer.DirectionToTarget,
|
||||
DistanceToTarget = pinpointer.DistanceToTarget
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Manually set distance from pinpointer to target
|
||||
/// </summary>
|
||||
public void SetDistance(EntityUid uid, Distance distance, PinpointerComponent? pinpointer = null)
|
||||
{
|
||||
if (!Resolve(uid, ref pinpointer))
|
||||
return;
|
||||
|
||||
if (distance == pinpointer.DistanceToTarget)
|
||||
return;
|
||||
|
||||
pinpointer.DistanceToTarget = distance;
|
||||
pinpointer.Dirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Manually set pinpointer arrow direction
|
||||
/// </summary>
|
||||
public void SetDirection(EntityUid uid, Direction directionToTarget, PinpointerComponent? pinpointer = null)
|
||||
{
|
||||
if (!Resolve(uid, ref pinpointer))
|
||||
return;
|
||||
|
||||
if (directionToTarget == pinpointer.DirectionToTarget)
|
||||
return;
|
||||
|
||||
pinpointer.DirectionToTarget = directionToTarget;
|
||||
pinpointer.Dirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activate/deactivate pinpointer screen. If it has target it will start tracking it.
|
||||
/// </summary>
|
||||
public void SetActive(EntityUid uid, bool isActive, PinpointerComponent? pinpointer = null)
|
||||
{
|
||||
if (!Resolve(uid, ref pinpointer))
|
||||
return;
|
||||
if (isActive == pinpointer.IsActive)
|
||||
return;
|
||||
|
||||
// add-remove pinpointer from update list
|
||||
if (isActive)
|
||||
ActivePinpointers.Add(uid);
|
||||
else
|
||||
ActivePinpointers.Remove(uid);
|
||||
|
||||
pinpointer.IsActive = isActive;
|
||||
pinpointer.Dirty();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Toggle Pinpointer screen. If it has target it will start tracking it.
|
||||
/// </summary>
|
||||
/// <returns>True if pinpointer was activated, false otherwise</returns>
|
||||
public bool TogglePinpointer(EntityUid uid, PinpointerComponent? pinpointer = null)
|
||||
{
|
||||
if (!Resolve(uid, ref pinpointer))
|
||||
return false;
|
||||
|
||||
var isActive = !pinpointer.IsActive;
|
||||
SetActive(uid, isActive, pinpointer);
|
||||
return isActive;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user