From 5f78b72763065545f16ce4b6eef4efb05adee72b Mon Sep 17 00:00:00 2001 From: Ed <96445749+TheShuEd@users.noreply.github.com> Date: Sun, 13 Apr 2025 15:44:44 +0300 Subject: [PATCH] ParallaxControl UI Dehardcode (#36071) * Parallax Control Improve * Update MainMenuControl.xaml * PJBControl.cs --- Content.Client/Info/RulesPopup.xaml | 2 +- .../Launcher/LauncherConnectingGui.xaml | 2 +- .../MainMenu/UI/MainMenuControl.xaml | 7 +++- Content.Client/Parallax/ParallaxControl.cs | 35 ++++++++++++++++--- .../UI/Loading/LoadingScreenControl.xaml | 2 +- .../Loading/ReplayLoadingFailedControl.xaml | 2 +- .../Menu/ReplayMainMenuControl.xaml | 2 +- 7 files changed, 41 insertions(+), 11 deletions(-) diff --git a/Content.Client/Info/RulesPopup.xaml b/Content.Client/Info/RulesPopup.xaml index ca1e35f08e..80ed415550 100644 --- a/Content.Client/Info/RulesPopup.xaml +++ b/Content.Client/Info/RulesPopup.xaml @@ -3,7 +3,7 @@ xmlns:info="clr-namespace:Content.Client.Info" VerticalExpand="True" HorizontalExpand="True" MouseFilter="Stop"> - + diff --git a/Content.Client/Launcher/LauncherConnectingGui.xaml b/Content.Client/Launcher/LauncherConnectingGui.xaml index 2cb349d4e7..34b32f84fe 100644 --- a/Content.Client/Launcher/LauncherConnectingGui.xaml +++ b/Content.Client/Launcher/LauncherConnectingGui.xaml @@ -3,7 +3,7 @@ xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client" xmlns:parallax="clr-namespace:Content.Client.Parallax" xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"> - + diff --git a/Content.Client/MainMenu/UI/MainMenuControl.xaml b/Content.Client/MainMenu/UI/MainMenuControl.xaml index d6c3f4b941..5aa5901783 100644 --- a/Content.Client/MainMenu/UI/MainMenuControl.xaml +++ b/Content.Client/MainMenu/UI/MainMenuControl.xaml @@ -1,7 +1,12 @@  - + _parallaxPrototype; + set + { + _parallaxPrototype = value; + _parallaxManager.LoadParallaxByName(value); + } + } public ParallaxControl() { IoCManager.InjectDependencies(this); Offset = new Vector2(_random.Next(0, 1000), _random.Next(0, 1000)); + RectClipContent = true; - _parallaxManager.LoadParallaxByName("FastSpace"); + _parallaxManager.LoadParallaxByName(_parallaxPrototype); } protected override void Draw(DrawingHandleScreen handle) { - foreach (var layer in _parallaxManager.GetParallaxLayers("FastSpace")) + var currentTime = (float) _timing.RealTime.TotalSeconds; + var offset = Offset + new Vector2(currentTime * SpeedX, currentTime * SpeedY); + + foreach (var layer in _parallaxManager.GetParallaxLayers(_parallaxPrototype)) { var tex = layer.Texture; - var texSize = (tex.Size.X * (int) Size.X, tex.Size.Y * (int) Size.X) * layer.Config.Scale.Floored() / 1920; + var texSize = new Vector2i( + (int)(tex.Size.X * Size.X * layer.Config.Scale.X / 1920 * ScaleX), + (int)(tex.Size.Y * Size.X * layer.Config.Scale.Y / 1920 * ScaleY) + ); var ourSize = PixelSize; - var currentTime = (float) _timing.RealTime.TotalSeconds; - var offset = Offset + new Vector2(currentTime * 100f, currentTime * 0f); + //Protection from division by zero. + texSize.X = Math.Max(texSize.X, 1); + texSize.Y = Math.Max(texSize.Y, 1); if (layer.Config.Tiled) { diff --git a/Content.Client/Replay/UI/Loading/LoadingScreenControl.xaml b/Content.Client/Replay/UI/Loading/LoadingScreenControl.xaml index 58f353a5ff..0ad05435cc 100644 --- a/Content.Client/Replay/UI/Loading/LoadingScreenControl.xaml +++ b/Content.Client/Replay/UI/Loading/LoadingScreenControl.xaml @@ -1,6 +1,6 @@ - + diff --git a/Content.Client/Replay/UI/Loading/ReplayLoadingFailedControl.xaml b/Content.Client/Replay/UI/Loading/ReplayLoadingFailedControl.xaml index 5f77a66e53..8967b948e0 100644 --- a/Content.Client/Replay/UI/Loading/ReplayLoadingFailedControl.xaml +++ b/Content.Client/Replay/UI/Loading/ReplayLoadingFailedControl.xaml @@ -1,6 +1,6 @@ - + diff --git a/Content.Replay/Menu/ReplayMainMenuControl.xaml b/Content.Replay/Menu/ReplayMainMenuControl.xaml index f26db1121f..9eeafd95de 100644 --- a/Content.Replay/Menu/ReplayMainMenuControl.xaml +++ b/Content.Replay/Menu/ReplayMainMenuControl.xaml @@ -3,7 +3,7 @@ xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls;assembly=Content.Client" xmlns:style="clr-namespace:Content.Client.Stylesheets;assembly=Content.Client" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> - +