* DungeonData rework Back to fields, serializes better, just make new layers dumby. * wawawewa * Fix this * Fixes * Port the work over * wawawewa * zoom * Kinda workin * Adjust wawa * Unloading work * Ore + entitytable fixes Iterate every dungeon not just last. * Big shot * wawawewa * Fixes * true * Fixes # Conflicts: # Content.Server/Procedural/DungeonJob/DungeonJob.cs * wawawewa * Fixes * Fix * Lot of work * wawawewa * Fixing * eh? * a * Fix a heap of stuff * Better ignored check * Reserve tile changes * biome * changes * wawawewa * Fixes & snow * Shadow fixes * wawawewa * smol * Add layer API * More work * wawawewa * Preloads and running again * wawawewa * Modified * Replacements and command * Runtime support * werk * Fix expeds + dungeon alltiles * reh --------- Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
117 lines
4.1 KiB
C#
117 lines
4.1 KiB
C#
using System.Numerics;
|
|
using Content.Client.Parallax.Managers;
|
|
using Content.Shared.CCVar;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Enums;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Client.Parallax;
|
|
|
|
public sealed class ParallaxOverlay : Overlay
|
|
{
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
|
[Dependency] private readonly IParallaxManager _manager = default!;
|
|
private readonly ParallaxSystem _parallax;
|
|
|
|
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowWorld;
|
|
|
|
public ParallaxOverlay()
|
|
{
|
|
ZIndex = ParallaxSystem.ParallaxZIndex;
|
|
IoCManager.InjectDependencies(this);
|
|
_parallax = _entManager.System<ParallaxSystem>();
|
|
}
|
|
|
|
protected override bool BeforeDraw(in OverlayDrawArgs args)
|
|
{
|
|
if (args.MapId == MapId.Nullspace)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
protected override void Draw(in OverlayDrawArgs args)
|
|
{
|
|
if (args.MapId == MapId.Nullspace)
|
|
return;
|
|
|
|
if (!_configurationManager.GetCVar(CCVars.ParallaxEnabled))
|
|
return;
|
|
|
|
var position = args.Viewport.Eye?.Position.Position ?? Vector2.Zero;
|
|
var worldHandle = args.WorldHandle;
|
|
|
|
var layers = _parallax.GetParallaxLayers(args.MapId);
|
|
var realTime = (float) _timing.RealTime.TotalSeconds;
|
|
|
|
foreach (var layer in layers)
|
|
{
|
|
ShaderInstance? shader;
|
|
|
|
if (!string.IsNullOrEmpty(layer.Config.Shader))
|
|
shader = _prototypeManager.Index<ShaderPrototype>(layer.Config.Shader).Instance();
|
|
else
|
|
shader = null;
|
|
|
|
worldHandle.UseShader(shader);
|
|
var tex = layer.Texture;
|
|
|
|
// Size of the texture in world units.
|
|
var size = (tex.Size / (float) EyeManager.PixelsPerMeter) * layer.Config.Scale;
|
|
|
|
// The "home" position is the effective origin of this layer.
|
|
// Parallax shifting is relative to the home, and shifts away from the home and towards the Eye centre.
|
|
// The effects of this are such that a slowness of 1 anchors the layer to the centre of the screen, while a slowness of 0 anchors the layer to the world.
|
|
// (For values 0.0 to 1.0 this is in effect a lerp, but it's deliberately unclamped.)
|
|
// The ParallaxAnchor adapts the parallax for station positioning and possibly map-specific tweaks.
|
|
var home = layer.Config.WorldHomePosition + _manager.ParallaxAnchor;
|
|
var scrolled = layer.Config.Scrolling * realTime;
|
|
|
|
// Origin - start with the parallax shift itself.
|
|
var originBL = (position - home) * layer.Config.Slowness + scrolled;
|
|
|
|
// Place at the home.
|
|
originBL += home;
|
|
|
|
// Adjust.
|
|
originBL += layer.Config.WorldAdjustPosition;
|
|
|
|
// Centre the image.
|
|
originBL -= size / 2;
|
|
|
|
if (layer.Config.Tiled)
|
|
{
|
|
// Remove offset so we can floor.
|
|
var flooredBL = args.WorldAABB.BottomLeft - originBL;
|
|
|
|
// Floor to background size.
|
|
flooredBL = (flooredBL / size).Floored() * size;
|
|
|
|
// Re-offset.
|
|
flooredBL += originBL;
|
|
|
|
for (var x = flooredBL.X; x < args.WorldAABB.Right; x += size.X)
|
|
{
|
|
for (var y = flooredBL.Y; y < args.WorldAABB.Top; y += size.Y)
|
|
{
|
|
worldHandle.DrawTextureRect(tex, Box2.FromDimensions(new Vector2(x, y), size));
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
worldHandle.DrawTextureRect(tex, Box2.FromDimensions(originBL, size));
|
|
}
|
|
}
|
|
|
|
worldHandle.UseShader(null);
|
|
}
|
|
}
|
|
|