Parallax refactors (#7654)
This commit is contained in:
@@ -118,7 +118,6 @@ namespace Content.Client.Entry
|
||||
factory.GenerateNetIds();
|
||||
|
||||
IoCManager.Resolve<IClientAdminManager>().Initialize();
|
||||
IoCManager.Resolve<IParallaxManager>().LoadParallax();
|
||||
IoCManager.Resolve<IBaseClient>().PlayerJoinedServer += SubscribePlayerAttachmentEvents;
|
||||
IoCManager.Resolve<IStylesheetManager>().Initialize();
|
||||
IoCManager.Resolve<IScreenshotHook>().Initialize();
|
||||
@@ -180,6 +179,7 @@ namespace Content.Client.Entry
|
||||
ContentContexts.SetupContexts(inputMan.Contexts);
|
||||
|
||||
IoCManager.Resolve<IGameHud>().Initialize();
|
||||
IoCManager.Resolve<IParallaxManager>().LoadParallax(); // Have to do this later because prototypes are needed.
|
||||
|
||||
var overlayMgr = IoCManager.Resolve<IOverlayManager>();
|
||||
overlayMgr.AddOverlay(new ParallaxOverlay());
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
Text="{Loc 'ui-options-vp-integer-scaling'}"
|
||||
ToolTip="{Loc 'ui-options-vp-integer-scaling-tooltip'}" />
|
||||
<CheckBox Name="ViewportLowResCheckBox" Text="{Loc 'ui-options-vp-low-res'}" />
|
||||
<CheckBox Name="ParallaxLowQualityCheckBox" Text="{Loc 'ui-options-parallax-low-quality'}" />
|
||||
<CheckBox Name="FpsCounterCheckBox" Text="{Loc 'ui-options-fps-counter'}" />
|
||||
</BoxContainer>
|
||||
<hudUi:StripeBack HasBottomEdge="False" HasMargins="False">
|
||||
|
||||
@@ -76,6 +76,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
||||
ShowHeldItemCheckBox.OnToggled += OnCheckBoxToggled;
|
||||
IntegerScalingCheckBox.OnToggled += OnCheckBoxToggled;
|
||||
ViewportLowResCheckBox.OnToggled += OnCheckBoxToggled;
|
||||
ParallaxLowQualityCheckBox.OnToggled += OnCheckBoxToggled;
|
||||
FpsCounterCheckBox.OnToggled += OnCheckBoxToggled;
|
||||
ApplyButton.OnPressed += OnApplyButtonPressed;
|
||||
VSyncCheckBox.Pressed = _cfg.GetCVar(CVars.DisplayVSync);
|
||||
@@ -87,6 +88,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
||||
ViewportStretchCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportStretch);
|
||||
IntegerScalingCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportSnapToleranceMargin) != 0;
|
||||
ViewportLowResCheckBox.Pressed = !_cfg.GetCVar(CCVars.ViewportScaleRender);
|
||||
ParallaxLowQualityCheckBox.Pressed = _cfg.GetCVar(CCVars.ParallaxLowQuality);
|
||||
FpsCounterCheckBox.Pressed = _cfg.GetCVar(CCVars.HudFpsCounterVisible);
|
||||
ShowHeldItemCheckBox.Pressed = _cfg.GetCVar(CCVars.HudHeldItemShow);
|
||||
|
||||
@@ -123,6 +125,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
||||
_cfg.SetCVar(CCVars.ViewportSnapToleranceMargin,
|
||||
IntegerScalingCheckBox.Pressed ? CCVars.ViewportSnapToleranceMargin.DefaultValue : 0);
|
||||
_cfg.SetCVar(CCVars.ViewportScaleRender, !ViewportLowResCheckBox.Pressed);
|
||||
_cfg.SetCVar(CCVars.ParallaxLowQuality, ParallaxLowQualityCheckBox.Pressed);
|
||||
_cfg.SetCVar(CCVars.HudHeldItemShow, ShowHeldItemCheckBox.Pressed);
|
||||
_cfg.SetCVar(CCVars.HudFpsCounterVisible, FpsCounterCheckBox.Pressed);
|
||||
_cfg.SaveToFile();
|
||||
@@ -151,6 +154,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
||||
var isVPScaleSame = (int) ViewportScaleSlider.Value == _cfg.GetCVar(CCVars.ViewportFixedScaleFactor);
|
||||
var isIntegerScalingSame = IntegerScalingCheckBox.Pressed == (_cfg.GetCVar(CCVars.ViewportSnapToleranceMargin) != 0);
|
||||
var isVPResSame = ViewportLowResCheckBox.Pressed == !_cfg.GetCVar(CCVars.ViewportScaleRender);
|
||||
var isPLQSame = ParallaxLowQualityCheckBox.Pressed == _cfg.GetCVar(CCVars.ParallaxLowQuality);
|
||||
var isShowHeldItemSame = ShowHeldItemCheckBox.Pressed == _cfg.GetCVar(CCVars.HudHeldItemShow);
|
||||
var isFpsCounterVisibleSame = FpsCounterCheckBox.Pressed == _cfg.GetCVar(CCVars.HudFpsCounterVisible);
|
||||
|
||||
@@ -162,6 +166,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
||||
isVPScaleSame &&
|
||||
isIntegerScalingSame &&
|
||||
isVPResSame &&
|
||||
isPLQSame &&
|
||||
isHudThemeSame &&
|
||||
isShowHeldItemSame &&
|
||||
isFpsCounterVisibleSame;
|
||||
|
||||
148
Content.Client/Parallax/Data/GeneratedParallaxTextureSource.cs
Normal file
148
Content.Client/Parallax/Data/GeneratedParallaxTextureSource.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using Nett;
|
||||
using Content.Shared;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Client.Resources;
|
||||
using Content.Client.IoC;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Utility;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
|
||||
namespace Content.Client.Parallax.Data;
|
||||
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public sealed class GeneratedParallaxTextureSource : IParallaxTextureSource
|
||||
{
|
||||
/// <summary>
|
||||
/// Parallax config path (the TOML file).
|
||||
/// In client resources.
|
||||
/// </summary>
|
||||
[DataField("configPath")]
|
||||
public ResourcePath ParallaxConfigPath { get; } = new("/parallax_config.toml");
|
||||
|
||||
/// <summary>
|
||||
/// ID for debugging, caching, and so forth.
|
||||
/// The empty string here is reserved for the original parallax.
|
||||
/// It is advisible to provide a roughly unique ID for any unique config contents.
|
||||
/// </summary>
|
||||
[DataField("id")]
|
||||
public string Identifier { get; } = "other";
|
||||
|
||||
/// <summary>
|
||||
/// Cached path.
|
||||
/// In user directory.
|
||||
/// </summary>
|
||||
private ResourcePath ParallaxCachedImagePath => new($"/parallax_{Identifier}cache.png");
|
||||
|
||||
/// <summary>
|
||||
/// Old parallax config path (for checking for parallax updates).
|
||||
/// In user directory.
|
||||
/// </summary>
|
||||
private ResourcePath PreviousParallaxConfigPath => new($"/parallax_{Identifier}config_old");
|
||||
|
||||
async Task<Texture> IParallaxTextureSource.GenerateTexture(CancellationToken cancel = default)
|
||||
{
|
||||
var parallaxConfig = GetParallaxConfig();
|
||||
if (parallaxConfig == null)
|
||||
{
|
||||
Logger.ErrorS("parallax", $"Parallax config not found or unreadable: {ParallaxConfigPath}");
|
||||
// The show must go on.
|
||||
return Texture.Transparent;
|
||||
}
|
||||
|
||||
var debugParallax = IoCManager.Resolve<IConfigurationManager>().GetCVar(CCVars.ParallaxDebug);
|
||||
|
||||
if (debugParallax
|
||||
|| !StaticIoC.ResC.UserData.TryReadAllText(PreviousParallaxConfigPath, out var previousParallaxConfig)
|
||||
|| previousParallaxConfig != parallaxConfig)
|
||||
{
|
||||
var table = Toml.ReadString(parallaxConfig);
|
||||
await UpdateCachedTexture(table, debugParallax, cancel);
|
||||
|
||||
//Update the previous config
|
||||
using var writer = StaticIoC.ResC.UserData.OpenWriteText(PreviousParallaxConfigPath);
|
||||
writer.Write(parallaxConfig);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return GetCachedTexture();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorS("parallax", $"Couldn't retrieve parallax cached texture: {ex}");
|
||||
// The show must go on.
|
||||
try
|
||||
{
|
||||
// Also try to at least sort of fix this if we've been fooled by a config backup
|
||||
StaticIoC.ResC.UserData.Delete(PreviousParallaxConfigPath);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
return Texture.Transparent;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateCachedTexture(TomlTable config, bool saveDebugLayers, CancellationToken cancel = default)
|
||||
{
|
||||
var debugImages = saveDebugLayers ? new List<Image<Rgba32>>() : null;
|
||||
|
||||
var sawmill = IoCManager.Resolve<ILogManager>().GetSawmill("parallax");
|
||||
|
||||
// Generate the parallax in the thread pool.
|
||||
using var newParallexImage = await Task.Run(() =>
|
||||
ParallaxGenerator.GenerateParallax(config, new Size(1920, 1080), sawmill, debugImages, cancel), cancel);
|
||||
|
||||
// And load it in the main thread for safety reasons.
|
||||
// But before spending time saving it, make sure to exit out early if it's not wanted.
|
||||
cancel.ThrowIfCancellationRequested();
|
||||
|
||||
// Store it and CRC so further game starts don't need to regenerate it.
|
||||
using var imageStream = StaticIoC.ResC.UserData.OpenWrite(ParallaxCachedImagePath);
|
||||
newParallexImage.SaveAsPng(imageStream);
|
||||
|
||||
if (saveDebugLayers)
|
||||
{
|
||||
for (var i = 0; i < debugImages!.Count; i++)
|
||||
{
|
||||
var debugImage = debugImages[i];
|
||||
using var debugImageStream = StaticIoC.ResC.UserData.OpenWrite(new ResourcePath($"/parallax_{Identifier}debug_{i}.png"));
|
||||
debugImage.SaveAsPng(debugImageStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Texture GetCachedTexture()
|
||||
{
|
||||
using var imageStream = StaticIoC.ResC.UserData.OpenRead(ParallaxCachedImagePath);
|
||||
return Texture.LoadFromPNGStream(imageStream, "Parallax");
|
||||
}
|
||||
|
||||
private string? GetParallaxConfig()
|
||||
{
|
||||
if (!StaticIoC.ResC.TryContentFileRead(ParallaxConfigPath, out var configStream))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var configReader = new StreamReader(configStream, EncodingHelpers.UTF8);
|
||||
return configReader.ReadToEnd().Replace(Environment.NewLine, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
19
Content.Client/Parallax/Data/IParallaxTextureSource.cs
Normal file
19
Content.Client/Parallax/Data/IParallaxTextureSource.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Client.Graphics;
|
||||
|
||||
namespace Content.Client.Parallax.Data
|
||||
{
|
||||
[ImplicitDataDefinitionForInheritors]
|
||||
public interface IParallaxTextureSource
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates or loads the texture.
|
||||
/// Note that this should be cached, but not necessarily *here*.
|
||||
/// </summary>
|
||||
Task<Texture> GenerateTexture(CancellationToken cancel = default);
|
||||
}
|
||||
}
|
||||
|
||||
29
Content.Client/Parallax/Data/ImageParallaxTextureSource.cs
Normal file
29
Content.Client/Parallax/Data/ImageParallaxTextureSource.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using Content.Client.Resources;
|
||||
using Content.Client.IoC;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Parallax.Data;
|
||||
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public sealed class ImageParallaxTextureSource : IParallaxTextureSource
|
||||
{
|
||||
/// <summary>
|
||||
/// Texture path.
|
||||
/// </summary>
|
||||
[DataField("path", required: true)]
|
||||
public ResourcePath Path { get; } = default!;
|
||||
|
||||
async Task<Texture> IParallaxTextureSource.GenerateTexture(CancellationToken cancel = default)
|
||||
{
|
||||
return StaticIoC.ResC.GetTexture(Path);
|
||||
}
|
||||
}
|
||||
|
||||
66
Content.Client/Parallax/Data/ParallaxLayerConfig.cs
Normal file
66
Content.Client/Parallax/Data/ParallaxLayerConfig.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using Robust.Client.Graphics;
|
||||
using Content.Client.Parallax.Data;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Client.Parallax.Data;
|
||||
|
||||
/// <summary>
|
||||
/// The configuration for a parallax layer.
|
||||
/// </summary>
|
||||
[DataDefinition]
|
||||
public sealed class ParallaxLayerConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// The texture source for this layer.
|
||||
/// </summary>
|
||||
[DataField("texture", required: true)]
|
||||
public IParallaxTextureSource Texture { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// A scaling factor for the texture.
|
||||
/// In the interest of simplifying maths, this is rounded down to integer for ParallaxControl, so be careful.
|
||||
/// </summary>
|
||||
[DataField("scale")]
|
||||
public Vector2 Scale { get; set; } = Vector2.One;
|
||||
|
||||
/// <summary>
|
||||
/// If true, this layer is tiled as the camera scrolls around.
|
||||
/// If false, this layer only shows up around it's home position.
|
||||
/// </summary>
|
||||
[DataField("tiled")]
|
||||
public bool Tiled { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// A position relative to the centre of a ParallaxControl that this parallax should be drawn at, in pixels.
|
||||
/// Used for menus.
|
||||
/// Note that this is ignored if the parallax layer is tiled - in that event a random pixel offset is used and slowness is applied.
|
||||
/// </summary>
|
||||
[DataField("controlHomePosition")]
|
||||
public Vector2 ControlHomePosition { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The "relative to ParallaxAnchor" starting world position for this layer.
|
||||
/// Essentially, an unclamped lerp occurs between here and the eye position, with Slowness as the factor.
|
||||
/// Used for in-game.
|
||||
/// </summary>
|
||||
[DataField("worldHomePosition")]
|
||||
public Vector2 WorldHomePosition { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// An adjustment performed to the world position of this layer after parallax shifting.
|
||||
/// Used for in-game.
|
||||
/// Useful for moving around Slowness = 1.0 objects (which can't otherwise be moved from screen centre).
|
||||
/// </summary>
|
||||
[DataField("worldAdjustPosition")]
|
||||
public Vector2 WorldAdjustPosition { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Multiplier of parallax shift.
|
||||
/// A slowness of 0.0f anchors this layer to the world.
|
||||
/// A slowness of 1.0f anchors this layer to the camera.
|
||||
/// </summary>
|
||||
[DataField("slowness")]
|
||||
public float Slowness { get; set; } = 0.5f;
|
||||
}
|
||||
|
||||
37
Content.Client/Parallax/Data/ParallaxPrototype.cs
Normal file
37
Content.Client/Parallax/Data/ParallaxPrototype.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Parallax.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Prototype data for a parallax.
|
||||
/// </summary>
|
||||
[Prototype("parallax")]
|
||||
public sealed class ParallaxPrototype : IPrototype
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
[IdDataFieldAttribute]
|
||||
public string ID { get; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Parallax layers.
|
||||
/// </summary>
|
||||
[DataField("layers")]
|
||||
public List<ParallaxLayerConfig> Layers { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Parallax layers, low-quality.
|
||||
/// </summary>
|
||||
[DataField("layersLQ")]
|
||||
public List<ParallaxLayerConfig> LayersLQ { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// If low-quality layers don't exist for this parallax and high-quality should be used instead.
|
||||
/// </summary>
|
||||
[DataField("layersLQUseHQ")]
|
||||
public bool LayersLQUseHQ { get; } = true;
|
||||
}
|
||||
@@ -1,12 +1,35 @@
|
||||
using System;
|
||||
using Robust.Client.Graphics;
|
||||
using Content.Client.Parallax;
|
||||
|
||||
namespace Content.Client.Parallax.Managers
|
||||
namespace Content.Client.Parallax.Managers;
|
||||
|
||||
public interface IParallaxManager
|
||||
{
|
||||
public interface IParallaxManager
|
||||
{
|
||||
event Action<Texture>? OnTextureLoaded;
|
||||
Texture? ParallaxTexture { get; }
|
||||
void LoadParallax();
|
||||
}
|
||||
/// <summary>
|
||||
/// The current parallax.
|
||||
/// Changing this causes a new parallax to be loaded (eventually).
|
||||
/// Do not alter until prototype manager is available.
|
||||
/// Useful "csi" input for testing new parallaxes:
|
||||
/// using Content.Client.Parallax.Managers; IoCManager.Resolve<IParallaxManager>().ParallaxName = "test";
|
||||
/// </summary>
|
||||
string ParallaxName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// All WorldHomePosition values are offset by this.
|
||||
/// </summary>
|
||||
Vector2 ParallaxAnchor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The layers of the currently loaded parallax.
|
||||
/// This will change on a whim without notification.
|
||||
/// </summary>
|
||||
ParallaxLayerPrepared[] ParallaxLayers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Used to initialize the manager.
|
||||
/// Do not call until prototype manager is available.
|
||||
/// </summary>
|
||||
void LoadParallax();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Client.Parallax.Data;
|
||||
using Content.Shared;
|
||||
using Content.Shared.CCVar;
|
||||
using Nett;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -15,91 +19,115 @@ using Robust.Shared.Utility;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
|
||||
namespace Content.Client.Parallax.Managers
|
||||
namespace Content.Client.Parallax.Managers;
|
||||
|
||||
internal sealed class ParallaxManager : IParallaxManager
|
||||
{
|
||||
internal sealed class ParallaxManager : IParallaxManager
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
||||
|
||||
private string _parallaxName = "";
|
||||
public string ParallaxName
|
||||
{
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
[Dependency] private readonly ILogManager _logManager = default!;
|
||||
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
||||
|
||||
private static readonly ResourcePath ParallaxConfigPath = new("/parallax_config.toml");
|
||||
|
||||
// Both of these below are in the user directory.
|
||||
private static readonly ResourcePath ParallaxCachedImagePath = new("/parallax_cache.png");
|
||||
private static readonly ResourcePath PreviousParallaxConfigPath = new("/parallax_config_old");
|
||||
|
||||
public event Action<Texture>? OnTextureLoaded;
|
||||
public Texture? ParallaxTexture { get; private set; }
|
||||
|
||||
public async void LoadParallax()
|
||||
get => _parallaxName;
|
||||
set
|
||||
{
|
||||
if (!_configurationManager.GetCVar(CCVars.ParallaxEnabled))
|
||||
return;
|
||||
|
||||
var parallaxConfig = GetParallaxConfig();
|
||||
if (parallaxConfig == null)
|
||||
return;
|
||||
|
||||
var debugParallax = _configurationManager.GetCVar(CCVars.ParallaxDebug);
|
||||
|
||||
if (debugParallax
|
||||
|| !_resourceCache.UserData.TryReadAllText(PreviousParallaxConfigPath, out var previousParallaxConfig)
|
||||
|| previousParallaxConfig != parallaxConfig)
|
||||
{
|
||||
var table = Toml.ReadString(parallaxConfig);
|
||||
await UpdateCachedTexture(table, debugParallax);
|
||||
|
||||
//Update the previous config
|
||||
using var writer = _resourceCache.UserData.OpenWriteText(PreviousParallaxConfigPath);
|
||||
writer.Write(parallaxConfig);
|
||||
}
|
||||
|
||||
ParallaxTexture = GetCachedTexture();
|
||||
OnTextureLoaded?.Invoke(ParallaxTexture);
|
||||
}
|
||||
|
||||
private async Task UpdateCachedTexture(TomlTable config, bool saveDebugLayers)
|
||||
{
|
||||
var debugImages = saveDebugLayers ? new List<Image<Rgba32>>() : null;
|
||||
|
||||
var sawmill = _logManager.GetSawmill("parallax");
|
||||
// Generate the parallax in the thread pool.
|
||||
using var newParallexImage = await Task.Run(() =>
|
||||
ParallaxGenerator.GenerateParallax(config, new Size(1920, 1080), sawmill, debugImages));
|
||||
// And load it in the main thread for safety reasons.
|
||||
|
||||
// Store it and CRC so further game starts don't need to regenerate it.
|
||||
using var imageStream = _resourceCache.UserData.OpenWrite(ParallaxCachedImagePath);
|
||||
newParallexImage.SaveAsPng(imageStream);
|
||||
|
||||
if (saveDebugLayers)
|
||||
{
|
||||
for (var i = 0; i < debugImages!.Count; i++)
|
||||
{
|
||||
var debugImage = debugImages[i];
|
||||
using var debugImageStream = _resourceCache.UserData.OpenWrite(new ResourcePath($"/parallax_debug_{i}.png"));
|
||||
debugImage.SaveAsPng(debugImageStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Texture GetCachedTexture()
|
||||
{
|
||||
using var imageStream = _resourceCache.UserData.OpenRead(ParallaxCachedImagePath);
|
||||
return Texture.LoadFromPNGStream(imageStream, "Parallax");
|
||||
}
|
||||
|
||||
private string? GetParallaxConfig()
|
||||
{
|
||||
if (!_resourceCache.TryContentFileRead(ParallaxConfigPath, out var configStream))
|
||||
{
|
||||
Logger.ErrorS("parallax", "Parallax config not found.");
|
||||
return null;
|
||||
}
|
||||
|
||||
using var configReader = new StreamReader(configStream, EncodingHelpers.UTF8);
|
||||
return configReader.ReadToEnd().Replace(Environment.NewLine, "\n");
|
||||
LoadParallaxByName(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 ParallaxAnchor { get; set; }
|
||||
|
||||
private CancellationTokenSource? _presentParallaxLoadCancel;
|
||||
|
||||
private ParallaxLayerPrepared[] _parallaxLayersHQ = {};
|
||||
private ParallaxLayerPrepared[] _parallaxLayersLQ = {};
|
||||
|
||||
public ParallaxLayerPrepared[] ParallaxLayers => _configurationManager.GetCVar(CCVars.ParallaxLowQuality) ? _parallaxLayersLQ : _parallaxLayersHQ;
|
||||
|
||||
public async void LoadParallax()
|
||||
{
|
||||
await LoadParallaxByName("default");
|
||||
}
|
||||
|
||||
private async Task LoadParallaxByName(string name)
|
||||
{
|
||||
// Update _parallaxName
|
||||
if (_parallaxName == name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_parallaxName = name;
|
||||
|
||||
// Cancel any existing load and setup the new cancellation token
|
||||
_presentParallaxLoadCancel?.Cancel();
|
||||
_presentParallaxLoadCancel = new CancellationTokenSource();
|
||||
var cancel = _presentParallaxLoadCancel.Token;
|
||||
|
||||
// Empty parallax name = no layers (this is so that the initial "" parallax name is consistent)
|
||||
if (_parallaxName == "")
|
||||
{
|
||||
_parallaxLayersHQ = _parallaxLayersLQ = new ParallaxLayerPrepared[] {};
|
||||
return;
|
||||
}
|
||||
|
||||
// Begin (for real)
|
||||
Logger.InfoS("parallax", $"Loading parallax {name}");
|
||||
|
||||
try
|
||||
{
|
||||
var parallaxPrototype = _prototypeManager.Index<ParallaxPrototype>(name);
|
||||
|
||||
ParallaxLayerPrepared[] hq;
|
||||
ParallaxLayerPrepared[] lq;
|
||||
|
||||
if (parallaxPrototype.LayersLQUseHQ)
|
||||
{
|
||||
lq = hq = await LoadParallaxLayers(parallaxPrototype.Layers, cancel);
|
||||
}
|
||||
else
|
||||
{
|
||||
var results = await Task.WhenAll(
|
||||
LoadParallaxLayers(parallaxPrototype.Layers, cancel),
|
||||
LoadParallaxLayers(parallaxPrototype.LayersLQ, cancel)
|
||||
);
|
||||
hq = results[0];
|
||||
lq = results[1];
|
||||
}
|
||||
|
||||
// Still keeping this check just in case.
|
||||
if (_parallaxName == name)
|
||||
{
|
||||
_parallaxLayersHQ = hq;
|
||||
_parallaxLayersLQ = lq;
|
||||
Logger.InfoS("parallax", $"Loaded parallax {name}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorS("parallax", $"Failed to loaded parallax {name}: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<ParallaxLayerPrepared[]> LoadParallaxLayers(List<ParallaxLayerConfig> layersIn, CancellationToken cancel = default)
|
||||
{
|
||||
// Because this is async, make sure it doesn't change (prototype reloads could muck this up)
|
||||
// Since the tasks aren't awaited until the end, this should be fine
|
||||
var tasks = new Task<ParallaxLayerPrepared>[layersIn.Count];
|
||||
for (var i = 0; i < layersIn.Count; i++)
|
||||
{
|
||||
tasks[i] = LoadParallaxLayer(layersIn[i], cancel);
|
||||
}
|
||||
return await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
private async Task<ParallaxLayerPrepared> LoadParallaxLayer(ParallaxLayerConfig config, CancellationToken cancel = default)
|
||||
{
|
||||
return new ParallaxLayerPrepared()
|
||||
{
|
||||
Texture = await config.Texture.GenerateTexture(cancel),
|
||||
Config = config
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,42 +6,60 @@ using Robust.Shared.Maths;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.Parallax
|
||||
namespace Content.Client.Parallax;
|
||||
|
||||
/// <summary>
|
||||
/// Renders the parallax background as a UI control.
|
||||
/// </summary>
|
||||
public sealed class ParallaxControl : Control
|
||||
{
|
||||
/// <summary>
|
||||
/// Renders the parallax background as a UI control.
|
||||
/// </summary>
|
||||
public sealed class ParallaxControl : Control
|
||||
[Dependency] private readonly IParallaxManager _parallaxManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] public Vector2i Offset { get; set; }
|
||||
|
||||
public ParallaxControl()
|
||||
{
|
||||
[Dependency] private readonly IParallaxManager _parallaxManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] public Vector2i Offset { get; set; }
|
||||
Offset = (_random.Next(0, 1000), _random.Next(0, 1000));
|
||||
RectClipContent = true;
|
||||
}
|
||||
|
||||
public ParallaxControl()
|
||||
protected override void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
foreach (var layer in _parallaxManager.ParallaxLayers)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
Offset = (_random.Next(0, 1000), _random.Next(0, 1000));
|
||||
RectClipContent = true;
|
||||
}
|
||||
|
||||
protected override void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
var tex = _parallaxManager.ParallaxTexture;
|
||||
if (tex == null)
|
||||
return;
|
||||
|
||||
var size = tex.Size;
|
||||
var tex = layer.Texture;
|
||||
var texSize = tex.Size * layer.Config.Scale.Floored();
|
||||
var ourSize = PixelSize;
|
||||
|
||||
for (var x = -size.X + Offset.X; x < ourSize.X; x += size.X)
|
||||
if (layer.Config.Tiled)
|
||||
{
|
||||
for (var y = -size.Y + Offset.Y; y < ourSize.Y; y += size.Y)
|
||||
// Multiply offset by slowness to match normal parallax
|
||||
var scaledOffset = (Offset * layer.Config.Slowness).Floored();
|
||||
|
||||
// Then modulo the scaled offset by the size to prevent drawing a bunch of offscreen tiles for really small images.
|
||||
scaledOffset.X %= texSize.X;
|
||||
scaledOffset.Y %= texSize.Y;
|
||||
|
||||
// Note: scaledOffset must never be below 0 or there will be visual issues.
|
||||
// It could be allowed to be >= texSize on a given axis but that would be wasteful.
|
||||
|
||||
for (var x = -scaledOffset.X; x < ourSize.X; x += texSize.X)
|
||||
{
|
||||
handle.DrawTexture(tex, (x, y));
|
||||
for (var y = -scaledOffset.Y; y < ourSize.Y; y += texSize.Y)
|
||||
{
|
||||
handle.DrawTextureRect(tex, UIBox2.FromDimensions((x, y), texSize));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var origin = ((ourSize - texSize) / 2) + layer.Config.ControlHomePosition;
|
||||
handle.DrawTextureRect(tex, UIBox2.FromDimensions(origin, texSize));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
@@ -18,7 +19,7 @@ namespace Content.Client.Parallax
|
||||
{
|
||||
private readonly List<Layer> Layers = new();
|
||||
|
||||
public static Image<Rgba32> GenerateParallax(TomlTable config, Size size, ISawmill sawmill, List<Image<Rgba32>>? debugLayerDump)
|
||||
public static Image<Rgba32> GenerateParallax(TomlTable config, Size size, ISawmill sawmill, List<Image<Rgba32>>? debugLayerDump, CancellationToken cancel = default)
|
||||
{
|
||||
sawmill.Debug("Generating parallax!");
|
||||
var generator = new ParallaxGenerator();
|
||||
@@ -27,10 +28,11 @@ namespace Content.Client.Parallax
|
||||
sawmill.Debug("Timing start!");
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
var image = new Image<Rgba32>(Configuration.Default, size.Width, size.Height, new Rgba32(0, 0, 0, 255));
|
||||
var image = new Image<Rgba32>(Configuration.Default, size.Width, size.Height, new Rgba32(0, 0, 0, 0));
|
||||
var count = 0;
|
||||
foreach (var layer in generator.Layers)
|
||||
{
|
||||
cancel.ThrowIfCancellationRequested();
|
||||
layer.Apply(image);
|
||||
debugLayerDump?.Add(image.Clone());
|
||||
sawmill.Debug("Layer {0} done!", count++);
|
||||
@@ -48,6 +50,16 @@ namespace Content.Client.Parallax
|
||||
{
|
||||
switch (((TomlValue<string>) layerArray.Get("type")).Value)
|
||||
{
|
||||
case "clear":
|
||||
var layerClear = new LayerClear(layerArray);
|
||||
Layers.Add(layerClear);
|
||||
break;
|
||||
|
||||
case "toalpha":
|
||||
var layerToAlpha = new LayerToAlpha(layerArray);
|
||||
Layers.Add(layerToAlpha);
|
||||
break;
|
||||
|
||||
case "noise":
|
||||
var layerNoise = new LayerNoise(layerArray);
|
||||
Layers.Add(layerNoise);
|
||||
@@ -69,6 +81,52 @@ namespace Content.Client.Parallax
|
||||
public abstract void Apply(Image<Rgba32> bitmap);
|
||||
}
|
||||
|
||||
private abstract class LayerConversion : Layer
|
||||
{
|
||||
public abstract Color ConvertColor(Color input);
|
||||
|
||||
public override void Apply(Image<Rgba32> bitmap)
|
||||
{
|
||||
var span = bitmap.GetPixelSpan();
|
||||
|
||||
for (var y = 0; y < bitmap.Height; y++)
|
||||
{
|
||||
for (var x = 0; x < bitmap.Width; x++)
|
||||
{
|
||||
var i = y * bitmap.Width + x;
|
||||
span[i] = ConvertColor(span[i].ConvertImgSharp()).ConvertImgSharp();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class LayerClear : LayerConversion
|
||||
{
|
||||
private readonly Color Color = Color.Black;
|
||||
|
||||
public LayerClear(TomlTable table)
|
||||
{
|
||||
if (table.TryGetValue("color", out var tomlObject))
|
||||
{
|
||||
Color = Color.FromHex(((TomlValue<string>) tomlObject).Value);
|
||||
}
|
||||
}
|
||||
|
||||
public override Color ConvertColor(Color input) => Color;
|
||||
}
|
||||
|
||||
private sealed class LayerToAlpha : LayerConversion
|
||||
{
|
||||
public LayerToAlpha(TomlTable table)
|
||||
{
|
||||
}
|
||||
|
||||
public override Color ConvertColor(Color input)
|
||||
{
|
||||
return new Color(input.R, input.G, input.B, MathF.Min(input.R + input.G + input.B, 1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class LayerNoise : Layer
|
||||
{
|
||||
private readonly Color InnerColor = Color.White;
|
||||
|
||||
22
Content.Client/Parallax/ParallaxLayerPrepared.cs
Normal file
22
Content.Client/Parallax/ParallaxLayerPrepared.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using Robust.Client.Graphics;
|
||||
using Content.Client.Parallax.Data;
|
||||
|
||||
namespace Content.Client.Parallax;
|
||||
|
||||
/// <summary>
|
||||
/// A 'prepared' (i.e. texture loaded and ready to use) parallax layer.
|
||||
/// </summary>
|
||||
public struct ParallaxLayerPrepared
|
||||
{
|
||||
/// <summary>
|
||||
/// The loaded texture for this layer.
|
||||
/// </summary>
|
||||
public Texture Texture { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The configuration for this layer.
|
||||
/// </summary>
|
||||
public ParallaxLayerConfig Config { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,72 +1,95 @@
|
||||
using System;
|
||||
using Content.Client.Parallax.Managers;
|
||||
using Content.Shared.CCVar;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Parallax
|
||||
namespace Content.Client.Parallax;
|
||||
|
||||
public sealed class ParallaxOverlay : Overlay
|
||||
{
|
||||
public sealed class ParallaxOverlay : Overlay
|
||||
[Dependency] private readonly IParallaxManager _parallaxManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
||||
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowWorld;
|
||||
private readonly ShaderInstance _shader;
|
||||
|
||||
public ParallaxOverlay()
|
||||
{
|
||||
[Dependency] private readonly IParallaxManager _parallaxManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
IoCManager.InjectDependencies(this);
|
||||
_shader = _prototypeManager.Index<ShaderPrototype>("unshaded").Instance();
|
||||
}
|
||||
|
||||
private const float Slowness = 0.5f;
|
||||
|
||||
private Texture? _parallaxTexture;
|
||||
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowWorld;
|
||||
private readonly ShaderInstance _shader;
|
||||
|
||||
public ParallaxOverlay()
|
||||
protected override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
if (args.Viewport.Eye == null)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
_shader = _prototypeManager.Index<ShaderPrototype>("unshaded").Instance();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_parallaxManager.ParallaxTexture == null)
|
||||
if (!_configurationManager.GetCVar(CCVars.ParallaxEnabled))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var screenHandle = args.WorldHandle;
|
||||
screenHandle.UseShader(_shader);
|
||||
|
||||
foreach (var layer in _parallaxManager.ParallaxLayers)
|
||||
{
|
||||
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 + _parallaxManager.ParallaxAnchor;
|
||||
|
||||
// Origin - start with the parallax shift itself.
|
||||
var originBL = (args.Viewport.Eye.Position.Position - home) * layer.Config.Slowness;
|
||||
|
||||
// Place at the home.
|
||||
originBL += home;
|
||||
|
||||
// Adjust.
|
||||
originBL += layer.Config.WorldAdjustPosition;
|
||||
|
||||
// Centre the image.
|
||||
originBL -= size / 2;
|
||||
|
||||
if (layer.Config.Tiled)
|
||||
{
|
||||
_parallaxManager.OnTextureLoaded += texture => _parallaxTexture = texture;
|
||||
// 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)
|
||||
{
|
||||
screenHandle.DrawTextureRect(tex, Box2.FromDimensions((x, y), size));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_parallaxTexture = _parallaxManager.ParallaxTexture;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
if (_parallaxTexture == null || args.Viewport.Eye == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var screenHandle = args.WorldHandle;
|
||||
screenHandle.UseShader(_shader);
|
||||
|
||||
var (sizeX, sizeY) = _parallaxTexture.Size / (float) EyeManager.PixelsPerMeter;
|
||||
var (posX, posY) = args.Viewport.Eye.Position;
|
||||
var o = new Vector2(posX * Slowness, posY * Slowness);
|
||||
|
||||
// Remove offset so we can floor.
|
||||
var (l, b) = args.WorldAABB.BottomLeft - o;
|
||||
|
||||
// Floor to background size.
|
||||
l = sizeX * MathF.Floor(l / sizeX);
|
||||
b = sizeY * MathF.Floor(b / sizeY);
|
||||
|
||||
// Re-offset.
|
||||
l += o.X;
|
||||
b += o.Y;
|
||||
|
||||
for (var x = l; x < args.WorldAABB.Right; x += sizeX)
|
||||
{
|
||||
for (var y = b; y < args.WorldAABB.Top; y += sizeY)
|
||||
{
|
||||
screenHandle.DrawTexture(_parallaxTexture, (x, y));
|
||||
}
|
||||
screenHandle.DrawTextureRect(tex, Box2.FromDimensions(originBL, size));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
using System;
|
||||
using Content.Client.Parallax.Managers;
|
||||
using Content.Client.Parallax;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.IntegrationTests
|
||||
{
|
||||
public sealed class DummyParallaxManager : IParallaxManager
|
||||
{
|
||||
public event Action<Texture> OnTextureLoaded
|
||||
{
|
||||
add
|
||||
{
|
||||
}
|
||||
remove
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public Texture ParallaxTexture => null;
|
||||
public string ParallaxName { get; set; } = "";
|
||||
public Vector2 ParallaxAnchor { get; set; }
|
||||
public ParallaxLayerPrepared[] ParallaxLayers { get; } = {};
|
||||
|
||||
public void LoadParallax()
|
||||
{
|
||||
ParallaxName = "default";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -51,6 +52,7 @@ namespace Content.Server.Entry
|
||||
new[] { "Content.Client", "Content.Shared", "Content.Shared.Database" });
|
||||
|
||||
var factory = IoCManager.Resolve<IComponentFactory>();
|
||||
var prototypes = IoCManager.Resolve<IPrototypeManager>();
|
||||
|
||||
factory.DoAutoRegistrations();
|
||||
|
||||
@@ -59,6 +61,8 @@ namespace Content.Server.Entry
|
||||
factory.RegisterIgnore(ignoreName);
|
||||
}
|
||||
|
||||
prototypes.RegisterIgnore("parallax");
|
||||
|
||||
ServerContentIoC.Register();
|
||||
|
||||
foreach (var callback in TestingCallbacks)
|
||||
|
||||
@@ -328,6 +328,9 @@ namespace Content.Shared.CCVar
|
||||
public static readonly CVarDef<bool> ParallaxDebug =
|
||||
CVarDef.Create("parallax.debug", false, CVar.CLIENTONLY);
|
||||
|
||||
public static readonly CVarDef<bool> ParallaxLowQuality =
|
||||
CVarDef.Create("parallax.low_quality", false, CVar.ARCHIVE | CVar.CLIENTONLY);
|
||||
|
||||
/*
|
||||
* Physics
|
||||
*/
|
||||
|
||||
@@ -49,6 +49,7 @@ ui-options-vp-integer-scaling-tooltip = If this option is enabled, the viewport
|
||||
means that black bars appear at the top/bottom of the screen or that part
|
||||
of the viewport is not visible.
|
||||
ui-options-vp-low-res = Low-resolution viewport
|
||||
ui-options-parallax-low-quality = Low-quality Parallax (background)
|
||||
ui-options-fps-counter = Show FPS counter
|
||||
|
||||
## Controls menu
|
||||
|
||||
26
Resources/Prototypes/Parallaxes/default.yml
Normal file
26
Resources/Prototypes/Parallaxes/default.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
- type: parallax
|
||||
id: default
|
||||
layers:
|
||||
- texture:
|
||||
!type:GeneratedParallaxTextureSource
|
||||
id: "hq_wizard_clouds"
|
||||
configPath: "/Prototypes/Parallaxes/parallax_config_clouds.toml"
|
||||
slowness: 0.5
|
||||
- texture:
|
||||
!type:GeneratedParallaxTextureSource
|
||||
id: "hq_wizard_stars_dim"
|
||||
configPath: "/Prototypes/Parallaxes/parallax_config_stars_dim.toml"
|
||||
slowness: 0.375
|
||||
- texture:
|
||||
!type:GeneratedParallaxTextureSource
|
||||
id: "hq_wizard_stars"
|
||||
configPath: "/Prototypes/Parallaxes/parallax_config_stars.toml"
|
||||
slowness: 0.25
|
||||
layersLQ:
|
||||
- texture:
|
||||
!type:GeneratedParallaxTextureSource
|
||||
id: ""
|
||||
configPath: "/Prototypes/Parallaxes/parallax_config.toml"
|
||||
slowness: 0.5
|
||||
layersLQUseHQ: false
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
# Clear to black.
|
||||
[[layers]]
|
||||
type = "clear"
|
||||
color = "#000000"
|
||||
|
||||
# Background nebula detail.
|
||||
[[layers]]
|
||||
type = "noise"
|
||||
31
Resources/Prototypes/Parallaxes/parallax_config_clouds.toml
Normal file
31
Resources/Prototypes/Parallaxes/parallax_config_clouds.toml
Normal file
@@ -0,0 +1,31 @@
|
||||
# Clear to black.
|
||||
[[layers]]
|
||||
type = "clear"
|
||||
color = "#000000"
|
||||
|
||||
# Background nebula detail.
|
||||
[[layers]]
|
||||
type = "noise"
|
||||
seed = 7832
|
||||
innercolor = "#5d1fe1"
|
||||
outercolor = "#230070"
|
||||
noise_type = "ridged"
|
||||
frequency = "4"
|
||||
octaves = 8
|
||||
power = "0.25"
|
||||
threshold = "0.40"
|
||||
|
||||
# Mask background nebula.
|
||||
[[layers]]
|
||||
type = "noise"
|
||||
noise_type = "fbm"
|
||||
innercolor = "#000000"
|
||||
outercolor = "#000000"
|
||||
destfactor = "SrcAlpha"
|
||||
seed = 3551
|
||||
octaves = 4
|
||||
power = "0.35"
|
||||
lacunarity = "1.5"
|
||||
frequency = "3"
|
||||
threshold = "0.0"
|
||||
|
||||
57
Resources/Prototypes/Parallaxes/parallax_config_stars.toml
Normal file
57
Resources/Prototypes/Parallaxes/parallax_config_stars.toml
Normal file
@@ -0,0 +1,57 @@
|
||||
# Clear to black.
|
||||
[[layers]]
|
||||
type = "clear"
|
||||
color = "#000000"
|
||||
|
||||
# Bright background nebula stars.
|
||||
[[layers]]
|
||||
type = "points"
|
||||
closecolor = "#7E86BF"
|
||||
count = 1000
|
||||
seed = 3472
|
||||
mask = true
|
||||
masknoise_type = "fbm"
|
||||
maskoctaves = 4
|
||||
maskpersistence = "0.5"
|
||||
maskpower = "0.35"
|
||||
masklacunarity = "1.5"
|
||||
maskfrequency = "3"
|
||||
maskthreshold = "0.37"
|
||||
maskseed = 3551
|
||||
|
||||
# Bright background nebula stars, dim edge.
|
||||
[[layers]]
|
||||
type = "points"
|
||||
closecolor = "#3D415C"
|
||||
pointsize = 2
|
||||
count = 1000
|
||||
seed = 3472
|
||||
mask = true
|
||||
masknoise_type = "fbm"
|
||||
maskoctaves = 4
|
||||
maskpersistence = "0.5"
|
||||
maskpower = "0.35"
|
||||
masklacunarity = "1.5"
|
||||
maskfrequency = "3"
|
||||
maskthreshold = "0.37"
|
||||
maskseed = 3551
|
||||
|
||||
# Couple of odd bright yellow-ish stars.
|
||||
[[layers]]
|
||||
type = "points"
|
||||
closecolor = "#FFD363"
|
||||
count = 30
|
||||
seed = 6454
|
||||
|
||||
# And their dim edge.
|
||||
[[layers]]
|
||||
type = "points"
|
||||
closecolor = "#43371A"
|
||||
pointsize = 2
|
||||
count = 30
|
||||
seed = 6454
|
||||
|
||||
# Colour-to-alpha.
|
||||
[[layers]]
|
||||
type = "toalpha"
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# Clear to black.
|
||||
[[layers]]
|
||||
type = "clear"
|
||||
color = "#000000"
|
||||
|
||||
# Dim background nebula stars.
|
||||
[[layers]]
|
||||
type = "points"
|
||||
seed = 3909
|
||||
closecolor = "#4B5072"
|
||||
count = 1500
|
||||
mask = true
|
||||
masknoise_type = "fbm"
|
||||
maskoctaves = 4
|
||||
maskpersistence = "0.5"
|
||||
maskpower = "0.35"
|
||||
masklacunarity = "1.5"
|
||||
maskfrequency = "3"
|
||||
maskthreshold = "0.0"
|
||||
maskseed = 3551
|
||||
|
||||
# Colour-to-alpha.
|
||||
[[layers]]
|
||||
type = "toalpha"
|
||||
|
||||
54
Resources/Prototypes/Parallaxes/test.yml
Normal file
54
Resources/Prototypes/Parallaxes/test.yml
Normal file
@@ -0,0 +1,54 @@
|
||||
# looks like the AME became the universe again.
|
||||
# someone call that guy who went and became the universe last time.
|
||||
# using Content.Client.Parallax.Managers; IoCManager.Resolve<IParallaxManager>().ParallaxName = "test";
|
||||
|
||||
- type: parallax
|
||||
id: test
|
||||
layers:
|
||||
- texture:
|
||||
!type:ImageParallaxTextureSource
|
||||
path: "/Textures/Decals/dirty.rsi/damaged.png"
|
||||
slowness: 0.5
|
||||
scale: "2, 2"
|
||||
- texture:
|
||||
!type:ImageParallaxTextureSource
|
||||
path: "/Textures/Decals/dirty.rsi/rust.png"
|
||||
slowness: 3.0
|
||||
scale: "3, 3"
|
||||
- texture:
|
||||
!type:ImageParallaxTextureSource
|
||||
path: "/Textures/Objects/Power/AME/ame_part.rsi/box.png"
|
||||
slowness: 0.995
|
||||
tiled: false
|
||||
controlHomePosition: "-128, -128"
|
||||
worldHomePosition: "0, 0"
|
||||
worldAdjustPosition: "4, 4"
|
||||
scale: "8, 8"
|
||||
- texture:
|
||||
!type:ImageParallaxTextureSource
|
||||
path: "/Textures/Objects/Power/AME/ame_jar.rsi/jar.png"
|
||||
slowness: 0.0
|
||||
tiled: false
|
||||
scale: "2, 2"
|
||||
- texture:
|
||||
!type:ImageParallaxTextureSource
|
||||
path: "/Textures/Objects/Power/AME/ame_jar.rsi/jar.png"
|
||||
slowness: 0.125
|
||||
tiled: false
|
||||
scale: "1, 1"
|
||||
- texture:
|
||||
!type:ImageParallaxTextureSource
|
||||
path: "/Textures/Objects/Power/AME/ame_part.rsi/box.png"
|
||||
slowness: 0.0
|
||||
tiled: false
|
||||
controlHomePosition: "0, 32"
|
||||
worldHomePosition: "0, 1"
|
||||
scale: "2, 2"
|
||||
layersLQ:
|
||||
- texture:
|
||||
!type:ImageParallaxTextureSource
|
||||
path: "/Textures/Decals/dirty.rsi/rust.png"
|
||||
slowness: 3.0
|
||||
scale: "3, 3"
|
||||
layersLQUseHQ: false
|
||||
|
||||
Reference in New Issue
Block a user