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; /// /// A toggle button with a lock icon meant to lock values for randomizing in the character editor screen. /// [GenerateTypedNameReferences] public sealed partial class RandomizeLockButton : BoxContainer { /// /// Which value this button locks. /// public HumanoidCharacterProfile.RandomizeCfg For { get; set; } /// /// Name of the button /// public string? LabelText { get => LockName.Text; set => LockName.Text = value; } /// /// Tracks which values are allowed to be randomized. /// 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 { 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() .Identifier("RandomizerLockButton") .Modulate(Color.FromHsl(new Vector4(0f, 0f, .65f, 1f))) .Prop(TextureButton.StylePropertyTexture, textureUnlocked) .Margin(new Thickness(0f, 0f, 3f, 0f)), E() .Identifier("RandomizerLockButton") .PseudoHovered() .Modulate(Color.WhiteSmoke) .Prop(TextureButton.StylePropertyTexture, textureLocked), E() .Identifier("RandomizerLockButton") .PseudoPressed() .Modulate(Color.WhiteSmoke) .Prop(TextureButton.StylePropertyTexture, textureLocked), ]; } }