Re-organize all projects (#4166)

This commit is contained in:
DrSmugleaf
2021-06-09 22:19:39 +02:00
committed by GitHub
parent 9f50e4061b
commit ff1a2d97ea
1773 changed files with 5258 additions and 5508 deletions

View File

@@ -0,0 +1,68 @@
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Client.Interactable.Components
{
[RegisterComponent]
public class InteractionOutlineComponent : Component
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private const float DefaultWidth = 1;
private const string ShaderInRange = "SelectionOutlineInrange";
private const string ShaderOutOfRange = "SelectionOutline";
public override string Name => "InteractionOutline";
private bool _inRange;
private ShaderInstance? _shader;
private int _lastRenderScale;
public void OnMouseEnter(bool inInteractionRange, int renderScale)
{
_lastRenderScale = renderScale;
_inRange = inInteractionRange;
if (Owner.TryGetComponent(out ISpriteComponent? sprite))
{
sprite.PostShader = MakeNewShader(inInteractionRange, renderScale);
sprite.RenderOrder = Owner.EntityManager.CurrentTick.Value;
}
}
public void OnMouseLeave()
{
if (Owner.TryGetComponent(out ISpriteComponent? sprite))
{
sprite.PostShader = null;
sprite.RenderOrder = 0;
}
_shader?.Dispose();
_shader = null;
}
public void UpdateInRange(bool inInteractionRange, int renderScale)
{
if (Owner.TryGetComponent(out ISpriteComponent? sprite)
&& (inInteractionRange != _inRange || _lastRenderScale != renderScale))
{
_inRange = inInteractionRange;
_lastRenderScale = renderScale;
_shader = MakeNewShader(_inRange, _lastRenderScale);
sprite.PostShader = _shader;
}
}
private ShaderInstance MakeNewShader(bool inRange, int renderScale)
{
var shaderName = inRange ? ShaderInRange : ShaderOutOfRange;
var instance = _prototypeManager.Index<ShaderPrototype>(shaderName).InstanceUnique();
instance.SetParameter("outline_width", DefaultWidth * renderScale);
return instance;
}
}
}

View File

@@ -0,0 +1,91 @@
using Content.Shared.Interaction;
using Content.Shared.Physics;
using Robust.Client.Player;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using static Content.Shared.Interaction.SharedInteractionSystem;
namespace Content.Client.Interactable
{
public static class UnobstructedExtensions
{
private static SharedInteractionSystem SharedInteractionSystem => EntitySystem.Get<SharedInteractionSystem>();
public static bool InRangeUnobstructed(
this LocalPlayer origin,
IEntity other,
float range = InteractionRange,
CollisionGroup collisionMask = CollisionGroup.Impassable,
Ignored? predicate = null,
bool ignoreInsideBlocker = false,
bool popup = false)
{
var otherPosition = other.Transform.MapPosition;
return origin.InRangeUnobstructed(otherPosition, range, collisionMask, predicate, ignoreInsideBlocker,
popup);
}
public static bool InRangeUnobstructed(
this LocalPlayer origin,
IComponent other,
float range = InteractionRange,
CollisionGroup collisionMask = CollisionGroup.Impassable,
Ignored? predicate = null,
bool ignoreInsideBlocker = false,
bool popup = false)
{
return origin.InRangeUnobstructed(other.Owner, range, collisionMask, predicate, ignoreInsideBlocker, popup);
}
public static bool InRangeUnobstructed(
this LocalPlayer origin,
IContainer other,
float range = InteractionRange,
CollisionGroup collisionMask = CollisionGroup.Impassable,
Ignored? predicate = null,
bool ignoreInsideBlocker = false,
bool popup = false)
{
return origin.InRangeUnobstructed(other.Owner, range, collisionMask, predicate, ignoreInsideBlocker, popup);
}
public static bool InRangeUnobstructed(
this LocalPlayer origin,
EntityCoordinates other,
float range = InteractionRange,
CollisionGroup collisionMask = CollisionGroup.Impassable,
Ignored? predicate = null,
bool ignoreInsideBlocker = false,
bool popup = false)
{
var entityManager = IoCManager.Resolve<IEntityManager>();
var otherPosition = other.ToMap(entityManager);
return origin.InRangeUnobstructed(otherPosition, range, collisionMask, predicate, ignoreInsideBlocker,
popup);
}
public static bool InRangeUnobstructed(
this LocalPlayer origin,
MapCoordinates other,
float range = InteractionRange,
CollisionGroup collisionMask = CollisionGroup.Impassable,
Ignored? predicate = null,
bool ignoreInsideBlocker = false,
bool popup = false)
{
var originEntity = origin.ControlledEntity;
if (originEntity == null)
{
// TODO: Take into account the player's camera position?
return false;
}
return SharedInteractionSystem.InRangeUnobstructed(originEntity, other, range, collisionMask, predicate,
ignoreInsideBlocker, popup);
}
}
}