fix context menu bugs (#5527)

This commit is contained in:
Leon Friedrich
2021-11-26 18:00:28 +13:00
committed by GitHub
parent 3447956088
commit 17560de3c7
4 changed files with 18 additions and 7 deletions

View File

@@ -57,7 +57,8 @@ namespace Content.Client.ContextMenu.UI
/// </summary>
public void UpdateEntity(IEntity? entity = null)
{
entity ??= Entity;
if (Entity != null && !Entity.Deleted)
entity ??= Entity;
EntityIcon.Sprite = entity?.GetComponentOrNull<ISpriteComponent>();

View File

@@ -321,7 +321,7 @@ namespace Content.Client.ContextMenu.UI
}
/// <summary>
/// Look through a sub-menu and return the first entity.
/// Recursively look through a sub-menu and return the first entity.
/// </summary>
private IEntity? GetFirstEntityOrNull(ContextMenuPopup? menu)
{
@@ -334,8 +334,13 @@ namespace Content.Client.ContextMenu.UI
continue;
if (entityElement.Entity != null)
return entityElement.Entity;
{
if (!entityElement.Entity.Deleted)
return entityElement.Entity;
continue;
}
// if the element has no entity, its a group of entities with another attached sub-menu.
var entity = GetFirstEntityOrNull(entityElement.SubMenu);
if (entity != null)
return entity;

View File

@@ -37,8 +37,14 @@ namespace Content.Client.ContextMenu.UI
(a, b) => a.Prototype!.ID == b.Prototype!.ID,
(a, b) =>
{
var xStates = a.GetComponent<ISpriteComponent>().AllLayers.Where(e => e.Visible).Select(s => s.RsiState.Name);
var yStates = b.GetComponent<ISpriteComponent>().AllLayers.Where(e => e.Visible).Select(s => s.RsiState.Name);
a.TryGetComponent<ISpriteComponent>(out var spriteA);
b.TryGetComponent<ISpriteComponent>(out var spriteB);
if (spriteA == null || spriteB == null)
return spriteA == spriteB;
var xStates = spriteA.AllLayers.Where(e => e.Visible).Select(s => s.RsiState.Name);
var yStates = spriteB.AllLayers.Where(e => e.Visible).Select(s => s.RsiState.Name);
return xStates.OrderBy(t => t).SequenceEqual(yStates.OrderBy(t => t));
},