Collapsible ghost roles menu (#32717)
* 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
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using System.Linq;
|
||||
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
|
||||
@@ -12,20 +15,86 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
|
||||
public event Action<GhostRoleInfo>? OnRoleRequestButtonClicked;
|
||||
public event Action<GhostRoleInfo>? OnRoleFollow;
|
||||
|
||||
private Dictionary<(string name, string description), Collapsible> _collapsibleBoxes = new();
|
||||
private HashSet<(string name, string description)> _uncollapsedStates = new();
|
||||
|
||||
public GhostRolesWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
public void ClearEntries()
|
||||
{
|
||||
NoRolesMessage.Visible = true;
|
||||
EntryContainer.DisposeAllChildren();
|
||||
_collapsibleBoxes.Clear();
|
||||
}
|
||||
|
||||
public void SaveCollapsibleBoxesStates()
|
||||
{
|
||||
_uncollapsedStates.Clear();
|
||||
foreach (var (key, collapsible) in _collapsibleBoxes)
|
||||
{
|
||||
if (collapsible.BodyVisible)
|
||||
{
|
||||
_uncollapsedStates.Add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RestoreCollapsibleBoxesStates()
|
||||
{
|
||||
foreach (var (key, collapsible) in _collapsibleBoxes)
|
||||
{
|
||||
collapsible.BodyVisible = _uncollapsedStates.Contains(key);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddEntry(string name, string description, bool hasAccess, FormattedMessage? reason, IEnumerable<GhostRoleInfo> roles, SpriteSystem spriteSystem)
|
||||
{
|
||||
NoRolesMessage.Visible = false;
|
||||
|
||||
var entry = new GhostRolesEntry(name, description, hasAccess, reason, roles, spriteSystem);
|
||||
entry.OnRoleSelected += OnRoleRequestButtonClicked;
|
||||
entry.OnRoleFollow += OnRoleFollow;
|
||||
EntryContainer.AddChild(entry);
|
||||
var ghostRoleInfos = roles.ToList();
|
||||
var rolesCount = ghostRoleInfos.Count;
|
||||
|
||||
var info = new GhostRoleInfoBox(name, description);
|
||||
var buttons = new GhostRoleButtonsBox(hasAccess, reason, ghostRoleInfos, spriteSystem);
|
||||
buttons.OnRoleSelected += OnRoleRequestButtonClicked;
|
||||
buttons.OnRoleFollow += OnRoleFollow;
|
||||
|
||||
EntryContainer.AddChild(info);
|
||||
|
||||
if (rolesCount > 1)
|
||||
{
|
||||
var buttonHeading = new CollapsibleHeading(Loc.GetString("ghost-roles-window-available-button", ("rolesCount", rolesCount)));
|
||||
|
||||
buttonHeading.AddStyleClass(ContainerButton.StyleClassButton);
|
||||
buttonHeading.Label.HorizontalAlignment = HAlignment.Center;
|
||||
buttonHeading.Label.HorizontalExpand = true;
|
||||
|
||||
var body = new CollapsibleBody
|
||||
{
|
||||
Margin = new Thickness(0, 5, 0, 0),
|
||||
};
|
||||
|
||||
// TODO: Add Requirements to this key when it'll be fixed and work as an equality key in GhostRolesEui
|
||||
var key = (name, description);
|
||||
|
||||
var collapsible = new Collapsible(buttonHeading, body)
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Vertical,
|
||||
Margin = new Thickness(0, 0, 0, 8),
|
||||
};
|
||||
|
||||
body.AddChild(buttons);
|
||||
|
||||
EntryContainer.AddChild(collapsible);
|
||||
_collapsibleBoxes.Add(key, collapsible);
|
||||
}
|
||||
else
|
||||
{
|
||||
EntryContainer.AddChild(buttons);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user