CatStation/Content.Client/MainMenu/UI/MainMenuControl.xaml.cs
Thomas 0fc0362113
Randomize Main Menu Parallax (#43893)
* Random parallax

* Switch from enumerate to allow list

* Use ProtoId

* Validate

It's really been too long since I've done this kind of this, and it
shows...

* Update Content.Client/MainMenu/UI/MainMenuControl.xaml.cs

---------

Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
2026-05-16 17:35:36 +00:00

60 lines
2 KiB
C#

using Content.Client.Parallax.Data;
using Robust.Client.AutoGenerated;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Client.MainMenu.UI;
[GenerateTypedNameReferences]
public sealed partial class MainMenuControl : Control
{
[Dependency] private IRobustRandom _random = default!;
public const string StyleIdentifierMainMenu = "mainMenu";
public const string StyleIdentifierMainMenuVBox = "mainMenuVBox";
private static readonly ProtoId<ParallaxPrototype>[] Parallaxes =
[
"Wizard",
"TrainStation",
"PlasmaStation",
"AmberStation",
"FastSpace",
"AspidParallax",
"OriginStation",
"Default",
"Sky",
"KettleStation",
"BagelStation",
"ExoStation",
];
public MainMenuControl(IResourceCache resCache, IConfigurationManager configMan)
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);
LayoutContainer.SetAnchorPreset(this, LayoutContainer.LayoutPreset.Wide);
LayoutContainer.SetAnchorPreset(VBox, LayoutContainer.LayoutPreset.TopRight);
LayoutContainer.SetMarginRight(VBox, -25);
LayoutContainer.SetMarginTop(VBox, 30);
LayoutContainer.SetGrowHorizontal(VBox, LayoutContainer.GrowDirection.Begin);
// I don't just enumerate them all as there's some hideous parallaxes, and it's easier
// to update an allowlist than to randomly get an ugly one to fix a blocklist.
BackgroundParallax.ParallaxPrototype = _random.Pick(Parallaxes).Id;
var logoTexture = resCache.GetResource<TextureResource>("/Textures/Logo/logo.png");
Logo.Texture = logoTexture;
var currentUserName = configMan.GetCVar(CVars.PlayerName);
UsernameBox.Text = currentUserName;
}
}