2024-01-28 17:32:55 +07:00
|
|
|
|
using Content.Client._White.Trail.Line.Manager;
|
2024-06-04 11:00:48 +00:00
|
|
|
|
using Content.Shared._White;
|
2024-01-24 12:58:57 +07:00
|
|
|
|
using Robust.Client.Graphics;
|
|
|
|
|
|
using Robust.Client.ResourceManagement;
|
2024-06-04 11:00:48 +00:00
|
|
|
|
using Robust.Shared.Configuration;
|
2024-01-24 12:58:57 +07:00
|
|
|
|
using Robust.Shared.Enums;
|
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
|
2024-01-28 17:32:55 +07:00
|
|
|
|
namespace Content.Client._White.Trail;
|
2024-01-24 12:58:57 +07:00
|
|
|
|
|
|
|
|
|
|
public sealed class TrailOverlay : Overlay
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IPrototypeManager _protoManager;
|
|
|
|
|
|
private readonly IResourceCache _cache;
|
|
|
|
|
|
private readonly ITrailLineManager _lineManager;
|
2024-06-04 11:00:48 +00:00
|
|
|
|
private readonly IConfigurationManager _cfg;
|
|
|
|
|
|
|
|
|
|
|
|
private bool _showTrails;
|
2024-01-24 12:58:57 +07:00
|
|
|
|
|
|
|
|
|
|
private readonly Dictionary<string, ShaderInstance?> _shaderDict;
|
|
|
|
|
|
private readonly Dictionary<string, Texture?> _textureDict;
|
|
|
|
|
|
|
|
|
|
|
|
public override OverlaySpace Space => OverlaySpace.WorldSpaceEntities;
|
|
|
|
|
|
|
|
|
|
|
|
public TrailOverlay(
|
|
|
|
|
|
IPrototypeManager protoManager,
|
|
|
|
|
|
IResourceCache cache,
|
2024-06-04 11:00:48 +00:00
|
|
|
|
IConfigurationManager cfg,
|
2024-01-24 12:58:57 +07:00
|
|
|
|
ITrailLineManager lineManager
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
_protoManager = protoManager;
|
|
|
|
|
|
_cache = cache;
|
2024-06-04 11:00:48 +00:00
|
|
|
|
_cfg = cfg;
|
2024-01-24 12:58:57 +07:00
|
|
|
|
_lineManager = lineManager;
|
|
|
|
|
|
|
2024-06-04 11:00:48 +00:00
|
|
|
|
_cfg.OnValueChanged(WhiteCVars.ShowTrails, val => _showTrails = val, true);
|
|
|
|
|
|
|
2024-01-24 12:58:57 +07:00
|
|
|
|
_shaderDict = new Dictionary<string, ShaderInstance?>();
|
|
|
|
|
|
_textureDict = new Dictionary<string, Texture?>();
|
|
|
|
|
|
|
|
|
|
|
|
ZIndex = (int) Shared.DrawDepth.DrawDepth.Effects;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Draw(in OverlayDrawArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
var handle = args.WorldHandle;
|
|
|
|
|
|
foreach (var item in _lineManager.Lines)
|
|
|
|
|
|
{
|
2024-06-04 11:00:48 +00:00
|
|
|
|
if (!_showTrails && item.Settings.OptionsConcealable)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2024-01-24 12:58:57 +07:00
|
|
|
|
item.Render(handle, GetCachedTexture(item.Settings.TexurePath ?? ""));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//влепить на ети два метода мемори кеш со слайдинг експирейшоном вместо дикта если проблемы будут
|
|
|
|
|
|
private ShaderInstance? GetCachedShader(string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_shaderDict.TryGetValue(id, out var shader))
|
|
|
|
|
|
return shader;
|
|
|
|
|
|
|
|
|
|
|
|
if (_protoManager.TryIndex<ShaderPrototype>(id, out var shaderRes))
|
|
|
|
|
|
shader = shaderRes?.InstanceUnique();
|
|
|
|
|
|
|
|
|
|
|
|
_shaderDict.Add(id, shader);
|
|
|
|
|
|
return shader;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Texture? GetCachedTexture(string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_textureDict.TryGetValue(path, out var texture))
|
|
|
|
|
|
return texture;
|
|
|
|
|
|
|
|
|
|
|
|
if (_cache.TryGetResource<TextureResource>(path, out var texRes))
|
|
|
|
|
|
texture = texRes;
|
|
|
|
|
|
|
|
|
|
|
|
_textureDict.Add(path, texture);
|
|
|
|
|
|
return texture;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|