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:
@@ -5,7 +5,6 @@ using Content.Shared.Eui;
|
||||
using Content.Shared.Ghost.Roles;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
|
||||
{
|
||||
@@ -77,6 +76,13 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
|
||||
|
||||
if (state is not GhostRolesEuiState ghostState)
|
||||
return;
|
||||
|
||||
// We must save BodyVisible state, so all Collapsible boxes will not close
|
||||
// on adding new ghost role.
|
||||
// Save the current state of each Collapsible box being visible or not
|
||||
_window.SaveCollapsibleBoxesStates();
|
||||
|
||||
// Clearing the container before adding new roles
|
||||
_window.ClearEntries();
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
@@ -84,28 +90,32 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
|
||||
var spriteSystem = sysManager.GetEntitySystem<SpriteSystem>();
|
||||
var requirementsManager = IoCManager.Resolve<JobRequirementsManager>();
|
||||
|
||||
// TODO: role.Requirements value doesn't work at all as an equality key, this must be fixed
|
||||
// Grouping roles
|
||||
var groupedRoles = ghostState.GhostRoles.GroupBy(
|
||||
role => (role.Name, role.Description, role.Requirements));
|
||||
|
||||
// Add a new entry for each role group
|
||||
foreach (var group in groupedRoles)
|
||||
{
|
||||
var name = group.Key.Name;
|
||||
var description = group.Key.Description;
|
||||
bool hasAccess = true;
|
||||
FormattedMessage? reason;
|
||||
|
||||
if (!requirementsManager.CheckRoleRequirements(group.Key.Requirements, null, out reason))
|
||||
{
|
||||
hasAccess = false;
|
||||
}
|
||||
var hasAccess = requirementsManager.CheckRoleRequirements(
|
||||
group.Key.Requirements,
|
||||
null,
|
||||
out var reason);
|
||||
|
||||
// Adding a new role
|
||||
_window.AddEntry(name, description, hasAccess, reason, group, spriteSystem);
|
||||
}
|
||||
|
||||
// Restore the Collapsible box state if it is saved
|
||||
_window.RestoreCollapsibleBoxesStates();
|
||||
|
||||
// Close the rules window if it is no longer needed
|
||||
var closeRulesWindow = ghostState.GhostRoles.All(role => role.Identifier != _windowRulesId);
|
||||
if (closeRulesWindow)
|
||||
{
|
||||
_windowRules?.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user