Refactor Context Menus and make them use XAML & stylesheets (#4768)
* XAML verb menu * fix ghost FOV * spacing * rename missed "ContextMenu"->"EntityMenu" instances * move visibility checks to verb system * update comment * Remove CanSeeContainerCheck * use ScrollContainer measure option * MaxWidth / texxt line wrapping * verb category default Now when you click on a verb category, it should default to running the first member of that category. This makes it much more convenient to eject/insert when there is only a single option * only apply style to first verb category entry * Use new visibility flags * FoV -> Fov * Revert "only apply style to first verb category entry" This reverts commit 9a6a17dba600e3ae0421caed59fcab145c260c99. * make all entity menu visibility checks clientside * Fix empty unbuckle category * fix merge
This commit is contained in:
121
Content.Client/ContextMenu/UI/EntityMenuPresenterGrouping.cs
Normal file
121
Content.Client/ContextMenu/UI/EntityMenuPresenterGrouping.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.ContextMenu.UI
|
||||
{
|
||||
public sealed partial class EntityMenuPresenter : ContextMenuPresenter
|
||||
{
|
||||
public const int GroupingTypesCount = 2;
|
||||
private int GroupingContextMenuType { get; set; }
|
||||
public void OnGroupingChanged(int obj)
|
||||
{
|
||||
Close();
|
||||
GroupingContextMenuType = obj;
|
||||
}
|
||||
|
||||
private List<List<IEntity>> GroupEntities(IEnumerable<IEntity> entities, int depth = 0)
|
||||
{
|
||||
if (GroupingContextMenuType == 0)
|
||||
{
|
||||
var newEntities = entities.GroupBy(e => e, new PrototypeContextMenuComparer()).ToList();
|
||||
return newEntities.Select(grp => grp.ToList()).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
var newEntities = entities.GroupBy(e => e, new PrototypeAndStatesContextMenuComparer(depth)).ToList();
|
||||
return newEntities.Select(grp => grp.ToList()).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class PrototypeAndStatesContextMenuComparer : IEqualityComparer<IEntity>
|
||||
{
|
||||
private static readonly List<Func<IEntity, IEntity, bool>> EqualsList = new()
|
||||
{
|
||||
(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);
|
||||
|
||||
return xStates.OrderBy(t => t).SequenceEqual(yStates.OrderBy(t => t));
|
||||
},
|
||||
};
|
||||
private static readonly List<Func<IEntity, int>> GetHashCodeList = new()
|
||||
{
|
||||
e => EqualityComparer<string>.Default.GetHashCode(e.Prototype!.ID),
|
||||
e =>
|
||||
{
|
||||
var hash = 0;
|
||||
foreach (var element in e.GetComponent<ISpriteComponent>().AllLayers.Where(obj => obj.Visible).Select(s => s.RsiState.Name))
|
||||
{
|
||||
hash ^= EqualityComparer<string>.Default.GetHashCode(element!);
|
||||
}
|
||||
return hash;
|
||||
},
|
||||
};
|
||||
|
||||
private static int Count => EqualsList.Count - 1;
|
||||
|
||||
private readonly int _depth;
|
||||
public PrototypeAndStatesContextMenuComparer(int step = 0)
|
||||
{
|
||||
_depth = step > Count ? Count : step;
|
||||
}
|
||||
|
||||
public bool Equals(IEntity? x, IEntity? y)
|
||||
{
|
||||
if (x == null)
|
||||
{
|
||||
return y == null;
|
||||
}
|
||||
|
||||
return y != null && EqualsList[_depth](x, y);
|
||||
}
|
||||
|
||||
public int GetHashCode(IEntity e)
|
||||
{
|
||||
return GetHashCodeList[_depth](e);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class PrototypeContextMenuComparer : IEqualityComparer<IEntity>
|
||||
{
|
||||
public bool Equals(IEntity? x, IEntity? y)
|
||||
{
|
||||
if (x == null)
|
||||
{
|
||||
return y == null;
|
||||
}
|
||||
if (y != null)
|
||||
{
|
||||
if (x.Prototype?.ID == y.Prototype?.ID)
|
||||
{
|
||||
var xStates = x.GetComponent<ISpriteComponent>().AllLayers.Where(e => e.Visible).Select(s => s.RsiState.Name);
|
||||
var yStates = y.GetComponent<ISpriteComponent>().AllLayers.Where(e => e.Visible).Select(s => s.RsiState.Name);
|
||||
|
||||
return xStates.OrderBy(t => t).SequenceEqual(yStates.OrderBy(t => t));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int GetHashCode(IEntity e)
|
||||
{
|
||||
var hash = EqualityComparer<string>.Default.GetHashCode(e.Prototype?.ID!);
|
||||
|
||||
if (e.TryGetComponent<ISpriteComponent>(out var sprite))
|
||||
{
|
||||
foreach (var element in sprite.AllLayers.Where(obj => obj.Visible).Select(s => s.RsiState.Name))
|
||||
{
|
||||
hash ^= EqualityComparer<string>.Default.GetHashCode(element!);
|
||||
}
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user