ParallaxControl UI Dehardcode (#36071)

* Parallax Control Improve

* Update MainMenuControl.xaml

* PJBControl.cs
This commit is contained in:
Ed
2025-04-13 15:44:44 +03:00
committed by GitHub
parent f61bbebb7f
commit 5f78b72763
7 changed files with 41 additions and 11 deletions

View File

@@ -3,7 +3,7 @@
xmlns:info="clr-namespace:Content.Client.Info" xmlns:info="clr-namespace:Content.Client.Info"
VerticalExpand="True" HorizontalExpand="True" VerticalExpand="True" HorizontalExpand="True"
MouseFilter="Stop"> MouseFilter="Stop">
<parallax:ParallaxControl /> <parallax:ParallaxControl SpeedX="20"/>
<Control VerticalExpand="True" <Control VerticalExpand="True"
MaxWidth="800" MaxWidth="800"
MaxHeight="900"> MaxHeight="900">

View File

@@ -3,7 +3,7 @@
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client" xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:parallax="clr-namespace:Content.Client.Parallax" xmlns:parallax="clr-namespace:Content.Client.Parallax"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"> xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls">
<parallax:ParallaxControl /> <parallax:ParallaxControl SpeedX="20"/>
<Control HorizontalAlignment="Center" VerticalAlignment="Center"> <Control HorizontalAlignment="Center" VerticalAlignment="Center">
<PanelContainer StyleClasses="AngleRect" /> <PanelContainer StyleClasses="AngleRect" />
<BoxContainer Orientation="Vertical" MinSize="300 200"> <BoxContainer Orientation="Vertical" MinSize="300 200">

View File

@@ -1,7 +1,12 @@
<Control xmlns="https://spacestation14.io" <Control xmlns="https://spacestation14.io"
xmlns:pllax="clr-namespace:Content.Client.Parallax" xmlns:pllax="clr-namespace:Content.Client.Parallax"
xmlns:clog="clr-namespace:Content.Client.Changelog"> xmlns:clog="clr-namespace:Content.Client.Changelog">
<pllax:ParallaxControl /> <pllax:ParallaxControl
ParallaxPrototype="TrainStation"
SpeedX="5"
SpeedY="20"
ScaleX="3"
ScaleY="3"/>
<BoxContainer Name="VBox" <BoxContainer Name="VBox"
Orientation="Vertical" Orientation="Vertical"
HorizontalAlignment="Center" HorizontalAlignment="Center"

View File

@@ -1,7 +1,9 @@
using System.Numerics; using System.Numerics;
using Content.Client.Parallax.Data;
using Content.Client.Parallax.Managers; using Content.Client.Parallax.Managers;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
using Robust.Shared.Random; using Robust.Shared.Random;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
@@ -17,27 +19,50 @@ public sealed class ParallaxControl : Control
[Dependency] private readonly IParallaxManager _parallaxManager = default!; [Dependency] private readonly IParallaxManager _parallaxManager = default!;
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
private string _parallaxPrototype = "FastSpace";
[ViewVariables(VVAccess.ReadWrite)] public Vector2 Offset { get; set; } [ViewVariables(VVAccess.ReadWrite)] public Vector2 Offset { get; set; }
[ViewVariables(VVAccess.ReadWrite)] public float SpeedX { get; set; } = 0.0f;
[ViewVariables(VVAccess.ReadWrite)] public float SpeedY { get; set; } = 0.0f;
[ViewVariables(VVAccess.ReadWrite)] public float ScaleX { get; set; } = 1.0f;
[ViewVariables(VVAccess.ReadWrite)] public float ScaleY { get; set; } = 1.0f;
[ViewVariables(VVAccess.ReadWrite)] public string ParallaxPrototype
{
get => _parallaxPrototype;
set
{
_parallaxPrototype = value;
_parallaxManager.LoadParallaxByName(value);
}
}
public ParallaxControl() public ParallaxControl()
{ {
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
Offset = new Vector2(_random.Next(0, 1000), _random.Next(0, 1000)); Offset = new Vector2(_random.Next(0, 1000), _random.Next(0, 1000));
RectClipContent = true; RectClipContent = true;
_parallaxManager.LoadParallaxByName("FastSpace"); _parallaxManager.LoadParallaxByName(_parallaxPrototype);
} }
protected override void Draw(DrawingHandleScreen handle) 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 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 ourSize = PixelSize;
var currentTime = (float) _timing.RealTime.TotalSeconds; //Protection from division by zero.
var offset = Offset + new Vector2(currentTime * 100f, currentTime * 0f); texSize.X = Math.Max(texSize.X, 1);
texSize.Y = Math.Max(texSize.Y, 1);
if (layer.Config.Tiled) if (layer.Config.Tiled)
{ {

View File

@@ -1,6 +1,6 @@
<Control xmlns="https://spacestation14.io" <Control xmlns="https://spacestation14.io"
xmlns:pllax="clr-namespace:Content.Client.Parallax"> xmlns:pllax="clr-namespace:Content.Client.Parallax">
<pllax:ParallaxControl /> <pllax:ParallaxControl SpeedX="20"/>
<PanelContainer Name="Background" <PanelContainer Name="Background"
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center"> VerticalAlignment="Center">

View File

@@ -1,6 +1,6 @@
<Control xmlns="https://spacestation14.io" <Control xmlns="https://spacestation14.io"
xmlns:pllax="clr-namespace:Content.Client.Parallax"> xmlns:pllax="clr-namespace:Content.Client.Parallax">
<pllax:ParallaxControl /> <pllax:ParallaxControl SpeedX="20"/>
<Control HorizontalAlignment="Center" VerticalAlignment="Center"> <Control HorizontalAlignment="Center" VerticalAlignment="Center">
<PanelContainer StyleClasses="AngleRect" /> <PanelContainer StyleClasses="AngleRect" />
<BoxContainer Orientation="Vertical" SetSize="800 600" Margin="2"> <BoxContainer Orientation="Vertical" SetSize="800 600" Margin="2">

View File

@@ -3,7 +3,7 @@
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls;assembly=Content.Client" xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls;assembly=Content.Client"
xmlns:style="clr-namespace:Content.Client.Stylesheets;assembly=Content.Client" xmlns:style="clr-namespace:Content.Client.Stylesheets;assembly=Content.Client"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<pllax:ParallaxControl /> <pllax:ParallaxControl SpeedX="20"/>
<LayoutContainer> <LayoutContainer>
<BoxContainer Name="VBox" Orientation="Vertical" StyleIdentifier="mainMenuVBox"> <BoxContainer Name="VBox" Orientation="Vertical" StyleIdentifier="mainMenuVBox">
<TextureRect Name="Logo" Stretch="KeepCentered" /> <TextureRect Name="Logo" Stretch="KeepCentered" />