-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Анимированный фон в лобби #306
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
Content.Client/ADT/UI/AnimatedBackground/AnimatedBackgroundControl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System.Linq; | ||
using Content.Shared.ADT; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.ResourceManagement; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Shared.Graphics.RSI; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Timing; | ||
|
||
namespace Content.Client.ADT.UI.AnimatedBackground; | ||
|
||
public sealed class AnimatedBackgroundControl : TextureRect | ||
{ | ||
[Dependency] private readonly IResourceCache _resourceCache = default!; | ||
[Dependency] private readonly IClyde _clyde = default!; | ||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; | ||
|
||
private string _rsiPath = "/Textures/ADT/LobbyScreens/backgrounds/native.rsi"; | ||
public RSI? _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][]; | ||
|
||
public AnimatedBackgroundControl() | ||
{ | ||
IoCManager.InjectDependencies(this); | ||
|
||
InitializeStates(); | ||
} | ||
|
||
private void InitializeStates() | ||
{ | ||
_RSI ??= _resourceCache.GetResource<RSIResource>(_rsiPath).RSI; | ||
|
||
for (var i = 0; i < States; i++) | ||
{ | ||
if (!_RSI.TryGetState((i + 1).ToString(), out var state)) | ||
continue; | ||
|
||
_frames[i] = state.GetFrames(RsiDirection.South); | ||
_frameDelays[i] = state.GetDelays(); | ||
_frameCounter[i] = 0; | ||
} | ||
} | ||
|
||
public void SetRSI(RSI? rsi) | ||
{ | ||
_RSI = rsi; | ||
InitializeStates(); | ||
} | ||
|
||
protected override void FrameUpdate(FrameEventArgs args) | ||
{ | ||
base.FrameUpdate(args); | ||
|
||
for (var i = 0; i < _frames.Length; i++) | ||
{ | ||
var delays = _frameDelays[i]; | ||
if (delays.Length == 0) | ||
continue; | ||
|
||
_timer[i] += args.DeltaSeconds; | ||
|
||
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]]; | ||
} | ||
} | ||
|
||
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(); | ||
var random = new Random(); | ||
var index = random.Next(backgroundsProto.Count); | ||
_rsiPath = $"/Textures/{backgroundsProto[index].Path}"; | ||
InitializeStates(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using Content.Server.GameTicking.Prototypes; | ||
using Robust.Shared.Random; | ||
using Content.Shared.ADT; | ||
using Robust.Shared.Utility; | ||
using System.Linq; | ||
|
||
|
@@ -11,21 +12,19 @@ public sealed partial class GameTicker | |
public string? LobbyBackground { get; private set; } | ||
|
||
[ViewVariables] | ||
private List<ResPath>? _lobbyBackgrounds; | ||
|
||
private static readonly string[] WhitelistedBackgroundExtensions = new string[] {"png", "jpg", "jpeg", "webp"}; | ||
private List<string>? _lobbyBackgrounds; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. комментарии |
||
|
||
private void InitializeLobbyBackground() | ||
{ | ||
_lobbyBackgrounds = _prototypeManager.EnumeratePrototypes<LobbyBackgroundPrototype>() | ||
.Select(x => x.Background) | ||
.Where(x => WhitelistedBackgroundExtensions.Contains(x.Extension)) | ||
_lobbyBackgrounds = _prototypeManager.EnumeratePrototypes<AnimatedLobbyScreenPrototype>() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. комментарии |
||
.Select(x => x.Path) | ||
.ToList(); | ||
|
||
RandomizeLobbyBackground(); | ||
} | ||
|
||
private void RandomizeLobbyBackground() { | ||
LobbyBackground = _lobbyBackgrounds!.Any() ? _robustRandom.Pick(_lobbyBackgrounds!).ToString() : null; | ||
private void RandomizeLobbyBackground() | ||
Darkiich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
LobbyBackground = _lobbyBackgrounds!.Any() ? _robustRandom.Pick(_lobbyBackgrounds!) : null; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Content.Shared/ADT/AnimatedLobbyScreen/AnimatedLobbyScreenPrototype.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Shared.ADT; | ||
|
||
/// <summary> | ||
/// This is a prototype for... | ||
/// </summary> | ||
[Prototype] | ||
public sealed partial class AnimatedLobbyScreenPrototype : IPrototype | ||
{ | ||
/// <inheritdoc/> | ||
[IdDataField] | ||
public string ID { get; } = default!; | ||
|
||
[DataField(required: true)] | ||
public string Path = default!; | ||
} |
35 changes: 35 additions & 0 deletions
35
Resources/Prototypes/ADT/AnimatedLobbyScreen/lobbyScreens.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
- type: animatedLobbyScreen | ||
id: SeaLobbyScreen | ||
path: /Textures/ADT/LobbyScreens/backgrounds/sea.rsi | ||
|
||
- type: animatedLobbyScreen | ||
id: RocketLobbyScreen | ||
path: /Textures/ADT/LobbyScreens/backgrounds/rocket.rsi | ||
|
||
- type: animatedLobbyScreen | ||
id: CubeLobbyScreen | ||
path: /Textures/ADT/LobbyScreens/backgrounds/cube.rsi | ||
|
||
- type: animatedLobbyScreen | ||
id: MilkywayLobbyScreen | ||
path: /Textures/ADT/LobbyScreens/backgrounds/milkyway.rsi | ||
|
||
#- type: animatedLobbyScreen | ||
# id: NativeLobbyScreen | ||
# path: White/Lobby/backgrounds/native.rsi | ||
|
||
- type: animatedLobbyScreen | ||
id: CentcommLobbyScreen | ||
path: /Textures/ADT/LobbyScreens/backgrounds/centcomm.rsi | ||
|
||
- type: animatedLobbyScreen | ||
id: VangoghLobbyScreen | ||
path: /Textures/ADT/LobbyScreens/backgrounds/vangogh.rsi | ||
|
||
#- type: animatedLobbyScreen | ||
# id: ThirdLobbyScreen | ||
# path: Ohio/Lobby/backgrounds/3.rsi | ||
|
||
#- type: animatedLobbyScreen | ||
# id: FifthLobbyScreen | ||
# path: Ohio/Lobby/backgrounds/5.rsi |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions
19
Resources/Textures/ADT/LobbyScreens/backgrounds/3.rsi/meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"version": 1, | ||
"license": "CC-BY-NC-SA-4.0", | ||
"copyright": "WhiteDream", | ||
"size": { | ||
"x": 1920, | ||
"y": 875 | ||
}, | ||
"states": [ | ||
{ | ||
"name": "1", | ||
"delays": [ | ||
[ | ||
0.1 | ||
] | ||
] | ||
} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions
38
Resources/Textures/ADT/LobbyScreens/backgrounds/centcomm.rsi/meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"version": 1, | ||
"license": "CC-BY-NC-SA-4.0", | ||
"copyright": "WhiteDream", | ||
"size": { | ||
"x": 901, | ||
"y": 676 | ||
}, | ||
"states": [ | ||
{ | ||
"name": "1", | ||
"delays": [ | ||
[ | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015, | ||
0.015 | ||
] | ||
] | ||
} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
комментарии