* Make ghost roles collapsible * Save `BodyVisible` state of each `Collapsible` box * Make ghost role collapsible only when group has more than 1 role * Make it a little prettier * Make only ghost role buttons collapsible * Apply requested changes * Typo * Small cleanup * Store in list, instead of iterating * Make unique ids more unique * Move it out of the cycle * Make _collapsibleBoxes into dictionary and use key instead of Collapsible boxes names Added TODO. So after the problem will be fixed in `GhostRolesEui`, it should be mirrored and fixed here too. * Put TODO in GhostRolesEui. I guess Issue must be made for this * Use HashSet instead of Dictionary as suggested. Invert the HashSet, so being present means it uncollapsed I decided to invert HashSet to _uncollapsedStates, because players surely will have more collapsed buttons than opened, so we optimise memory usage a little bit. * Remove extra space from ghost roles window * Add buttons stretching. Size 3:1
56 lines
2.1 KiB
C#
56 lines
2.1 KiB
C#
using System.Numerics;
|
|
using Content.Shared.Ghost.Roles;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
|
|
{
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class GhostRoleButtonsBox : BoxContainer
|
|
{
|
|
private SpriteSystem _spriteSystem;
|
|
public event Action<GhostRoleInfo>? OnRoleSelected;
|
|
public event Action<GhostRoleInfo>? OnRoleFollow;
|
|
|
|
public GhostRoleButtonsBox(bool hasAccess, FormattedMessage? reason, IEnumerable<GhostRoleInfo> roles, SpriteSystem spriteSystem)
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
_spriteSystem = spriteSystem;
|
|
|
|
foreach (var role in roles)
|
|
{
|
|
var button = new GhostRoleEntryButtons(role);
|
|
button.RequestButton.OnPressed += _ => OnRoleSelected?.Invoke(role);
|
|
button.FollowButton.OnPressed += _ => OnRoleFollow?.Invoke(role);
|
|
|
|
if (!hasAccess)
|
|
{
|
|
button.RequestButton.Disabled = true;
|
|
|
|
if (reason != null && !reason.IsEmpty)
|
|
{
|
|
var tooltip = new Tooltip();
|
|
tooltip.SetMessage(reason);
|
|
button.RequestButton.TooltipSupplier = _ => tooltip;
|
|
}
|
|
|
|
button.RequestButton.AddChild(new TextureRect
|
|
{
|
|
TextureScale = new Vector2(0.4f, 0.4f),
|
|
Stretch = TextureRect.StretchMode.KeepCentered,
|
|
Texture = _spriteSystem.Frame0(new SpriteSpecifier.Texture(new ("/Textures/Interface/Nano/lock.svg.192dpi.png"))),
|
|
HorizontalExpand = true,
|
|
HorizontalAlignment = HAlignment.Right,
|
|
});
|
|
}
|
|
|
|
Buttons.AddChild(button);
|
|
}
|
|
}
|
|
}
|
|
}
|