mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* init * tweak lightness * add randomize helpers, refactor to use * wip * wip * wip * wip * docs, cleanup * review partial * review wip (doesnt build) * wip (now working, but found a bug) * touchups * less ambiguity * Tweak the UI, make LockButton a BoxContainer --------- Co-authored-by: AJCM-git <ajcm_mail@disroot.org>
91 lines
3 KiB
C#
91 lines
3 KiB
C#
using System.Numerics;
|
|
using Content.Client.Resources;
|
|
using Content.Client.Stylesheets;
|
|
using Content.Shared.Preferences;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using static Content.Client.Stylesheets.StylesheetHelpers;
|
|
|
|
namespace Content.Client.Lobby.UI;
|
|
|
|
/// <summary>
|
|
/// A toggle button with a lock icon meant to lock values for randomizing in the character editor screen.
|
|
/// </summary>
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class RandomizeLockButton : BoxContainer
|
|
{
|
|
/// <summary>
|
|
/// Which value this button locks.
|
|
/// </summary>
|
|
public HumanoidCharacterProfile.RandomizeCfg For { get; set; }
|
|
|
|
/// <summary>
|
|
/// Name of the button
|
|
/// </summary>
|
|
public string? LabelText { get => LockName.Text; set => LockName.Text = value; }
|
|
|
|
/// <summary>
|
|
/// Tracks which values are allowed to be randomized.
|
|
/// </summary>
|
|
public static HumanoidCharacterProfile.RandomizeCfg RandomizeCfg = HumanoidCharacterProfile.RandomizeConfigAll;
|
|
|
|
public RandomizeLockButton()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
|
|
// Ensure we reset this value to default every time the button is created
|
|
// Otherwise toggling, disconnecting and reconnecting will leave the cfg in an inconsistent state
|
|
RandomizeCfg = HumanoidCharacterProfile.RandomizeConfigAll;
|
|
|
|
LockButton.OnToggled += args => HandleToggle(args.Pressed);
|
|
}
|
|
|
|
private void HandleToggle(bool toggle)
|
|
{
|
|
if (For == default)
|
|
return;
|
|
if (toggle)
|
|
{
|
|
// if pressed, disable specific randomize by setting its bit to 0
|
|
RandomizeCfg &= ~For;
|
|
}
|
|
else
|
|
{
|
|
// if not pressed, enable specific randomize by setting its bit to 1
|
|
RandomizeCfg |= For;
|
|
}
|
|
}
|
|
}
|
|
|
|
[CommonSheetlet]
|
|
public sealed class RandomizeLockButtonStyles : Sheetlet<PalettedStylesheet>
|
|
{
|
|
public override StyleRule[] GetRules(PalettedStylesheet sheet, object config)
|
|
{
|
|
var textureLocked = ResCache.GetTexture("/Textures/Interface/VerbIcons/lock.svg.192dpi.png");
|
|
var textureUnlocked = ResCache.GetTexture("/Textures/Interface/VerbIcons/unlock.svg.192dpi.png");
|
|
|
|
return
|
|
[
|
|
E<TextureButton>()
|
|
.Identifier("RandomizerLockButton")
|
|
.Modulate(Color.FromHsl(new Vector4(0f, 0f, .65f, 1f)))
|
|
.Prop(TextureButton.StylePropertyTexture, textureUnlocked)
|
|
.Margin(new Thickness(0f, 0f, 3f, 0f)),
|
|
|
|
E<TextureButton>()
|
|
.Identifier("RandomizerLockButton")
|
|
.PseudoHovered()
|
|
.Modulate(Color.WhiteSmoke)
|
|
.Prop(TextureButton.StylePropertyTexture, textureLocked),
|
|
|
|
E<TextureButton>()
|
|
.Identifier("RandomizerLockButton")
|
|
.PseudoPressed()
|
|
.Modulate(Color.WhiteSmoke)
|
|
.Prop(TextureButton.StylePropertyTexture, textureLocked),
|
|
];
|
|
}
|
|
}
|