diff --git a/Content.Client/_Ohio/UI/AnimatedBackgroundControl.cs b/Content.Client/_Ohio/UI/AnimatedBackgroundControl.cs index e75c4a6db2..393b7c3942 100644 --- a/Content.Client/_Ohio/UI/AnimatedBackgroundControl.cs +++ b/Content.Client/_Ohio/UI/AnimatedBackgroundControl.cs @@ -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().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; + } +} diff --git a/Resources/Prototypes/_White/AnimatedLobbyScreens/lobbyScreens.yml b/Resources/Prototypes/_White/AnimatedLobbyScreens/lobbyScreens.yml index 1aa7e431b4..f94ef1af9d 100644 --- a/Resources/Prototypes/_White/AnimatedLobbyScreens/lobbyScreens.yml +++ b/Resources/Prototypes/_White/AnimatedLobbyScreens/lobbyScreens.yml @@ -1,6 +1,14 @@ - type: animatedLobbyScreen - id: FourthLobbyScreen - path: Ohio/Lobby/backgrounds/4.rsi + id: CyberLobbyScreen + path: Ohio/Lobby/backgrounds/cyber.rsi + +- type: animatedLobbyScreen + id: DoorLobbyScreen + path: Ohio/Lobby/backgrounds/door.rsi + +#- type: animatedLobbyScreen +# id: FourthLobbyScreen +# path: Ohio/Lobby/backgrounds/4.rsi #- type: animatedLobbyScreen # id: NativeLobbyScreen diff --git a/Resources/Textures/Ohio/Lobby/backgrounds/cyber.rsi/1.png b/Resources/Textures/Ohio/Lobby/backgrounds/cyber.rsi/1.png new file mode 100644 index 0000000000..066235dad1 Binary files /dev/null and b/Resources/Textures/Ohio/Lobby/backgrounds/cyber.rsi/1.png differ diff --git a/Resources/Textures/Ohio/Lobby/backgrounds/cyber.rsi/meta.json b/Resources/Textures/Ohio/Lobby/backgrounds/cyber.rsi/meta.json new file mode 100644 index 0000000000..98a05567c3 --- /dev/null +++ b/Resources/Textures/Ohio/Lobby/backgrounds/cyber.rsi/meta.json @@ -0,0 +1,89 @@ +{ + "version": 1, + "license": "CC-BY-SA-4.0", + "copyright": "212", + "size": { + "x": 498, + "y": 220 + }, + "states": [ + { + "name": "1", + "delays": [ + [ + 0.04, + 0.04, + 0.04, + 0.04, + 0.08, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.08, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.08, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04, + 0.04 + ] + ] + } + ] +} \ No newline at end of file diff --git a/Resources/Textures/Ohio/Lobby/backgrounds/door.rsi/1.png b/Resources/Textures/Ohio/Lobby/backgrounds/door.rsi/1.png new file mode 100644 index 0000000000..a6c1f379ce Binary files /dev/null and b/Resources/Textures/Ohio/Lobby/backgrounds/door.rsi/1.png differ diff --git a/Resources/Textures/Ohio/Lobby/backgrounds/door.rsi/meta.json b/Resources/Textures/Ohio/Lobby/backgrounds/door.rsi/meta.json new file mode 100644 index 0000000000..248040cd9e --- /dev/null +++ b/Resources/Textures/Ohio/Lobby/backgrounds/door.rsi/meta.json @@ -0,0 +1,64 @@ +{ + "version": 1, + "license": "CC-BY-SA-4.0", + "copyright": "1", + "size": { + "x": 811, + "y": 455 + }, + "states": [ + { + "name": "1", + "delays": [ + [ + 1, + 0.1, + 0.2, + 2, + 0.1, + 0.1, + 0.1, + 0.1, + 0.05, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1, + 0.05, + 0.05, + 0.05, + 0.05, + 2, + 0.05, + 0.05, + 0.2, + 0.1, + 0.1, + 0.1, + 0.5, + 0.05, + 0.05, + 2, + 0.05, + 0.05, + 0.05, + 0.05, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1 + ] + ] + } + ] +} \ No newline at end of file