- tweak: some lobby screens

This commit is contained in:
2024-03-03 14:33:21 +03:00
parent ffaa0c6815
commit db920c3942
6 changed files with 202 additions and 46 deletions

View File

@@ -18,12 +18,7 @@ public sealed class AnimatedBackgroundControl : TextureRect
private string _rsiPath = "/Textures/Ohio/Lobby/backgrounds/native.rsi";
private const int States = 1;
private IRenderTexture? _buffer;
private readonly float[] _timer = new float[States];
private readonly float[][] _frameDelays = new float[States][];
private readonly int[] _frameCounter = new int[States];
private readonly Texture[][] _frames = new Texture[States][];
private readonly BackgroundData[] _data = new BackgroundData[States];
public AnimatedBackgroundControl()
{
@@ -41,9 +36,12 @@ public sealed class AnimatedBackgroundControl : TextureRect
if (!rsi.TryGetState((i + 1).ToString(), out var state))
continue;
_frames[i] = state.GetFrames(RsiDirection.South);
_frameDelays[i] = state.GetDelays();
_frameCounter[i] = 0;
var frames = state.GetFrames(RsiDirection.South);
var delays = state.GetDelays();
// Похуй, Linq во время инициализации можно юзать... полагаю
var frameData = frames.Select((texture, index) => new Frame(texture, delays[index])).ToArray();
_data[i] = new BackgroundData(frameData);
}
}
@@ -51,48 +49,21 @@ public sealed class AnimatedBackgroundControl : TextureRect
{
base.FrameUpdate(args);
for (var i = 0; i < _frames.Length; i++)
foreach (var backData in _data)
{
var delays = _frameDelays[i];
if (delays.Length == 0)
var frame = backData.Current();
backData.Timer += args.DeltaSeconds;
if(backData.Timer < frame.Delay)
continue;
_timer[i] += args.DeltaSeconds * 0.20f;
backData.Timer = 0;
var currentFrameIndex = _frameCounter[i];
if (!(_timer[i] >= delays[currentFrameIndex]))
continue;
_timer[i] -= delays[currentFrameIndex];
_frameCounter[i] = (currentFrameIndex + 1) % _frames[i].Length;
Texture = _frames[i][_frameCounter[i]];
Texture = frame.Texture;
backData.Next();
}
}
protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
if (_buffer is null)
return;
handle.DrawTextureRect(_buffer.Texture, PixelSizeBox);
}
protected override void Resized()
{
base.Resized();
_buffer?.Dispose();
_buffer = _clyde.CreateRenderTarget(PixelSize, RenderTargetColorFormat.Rgba8Srgb);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_buffer?.Dispose();
}
public void RandomizeBackground()
{
var backgroundsProto = _prototypeManager.EnumeratePrototypes<AnimatedLobbyScreenPrototype>().ToList();
@@ -102,3 +73,27 @@ public sealed class AnimatedBackgroundControl : TextureRect
InitializeStates();
}
}
public record struct Frame(Texture Texture,float Delay);
public sealed class BackgroundData
{
public readonly Frame[] Frames;
public int Counter;
public float Timer;
public BackgroundData(Frame[] frames)
{
Frames = frames;
}
public Frame Current()
{
return Frames[Counter];
}
public void Next()
{
Counter = (Counter + 1) % Frames.Length;
}
}