Entity menu tweaks (#5414)
* adjust lookup * change grouping * change range from 0.2 to 0.25
This commit is contained in:
@@ -20,7 +20,7 @@ namespace Content.Client.ContextMenu.UI
|
|||||||
{
|
{
|
||||||
if (GroupingContextMenuType == 0)
|
if (GroupingContextMenuType == 0)
|
||||||
{
|
{
|
||||||
var newEntities = entities.GroupBy(e => e, new PrototypeContextMenuComparer()).ToList();
|
var newEntities = entities.GroupBy(e => e.Name + (e.Prototype?.ID ?? string.Empty)).ToList();
|
||||||
return newEntities.Select(grp => grp.ToList()).ToList();
|
return newEntities.Select(grp => grp.ToList()).ToList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -80,42 +80,5 @@ namespace Content.Client.ContextMenu.UI
|
|||||||
return GetHashCodeList[_depth](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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace Content.Client.Verbs
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// When a user right clicks somewhere, how large is the box we use to get entities for the context menu?
|
/// When a user right clicks somewhere, how large is the box we use to get entities for the context menu?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const float EntityMenuLookupSize = 1f;
|
public const float EntityMenuLookupSize = 0.25f;
|
||||||
|
|
||||||
public EntityMenuPresenter EntityMenu = default!;
|
public EntityMenuPresenter EntityMenu = default!;
|
||||||
public VerbMenuPresenter VerbMenu = default!;
|
public VerbMenuPresenter VerbMenu = default!;
|
||||||
@@ -100,9 +100,7 @@ namespace Content.Client.Verbs
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Get entities
|
// Get entities
|
||||||
var entities = _entityLookup.GetEntitiesIntersecting(
|
var entities = _entityLookup.GetEntitiesInRange(targetPos.MapId, targetPos.Position, EntityMenuLookupSize)
|
||||||
targetPos.MapId,
|
|
||||||
Box2.CenteredAround(targetPos.Position, (EntityMenuLookupSize, EntityMenuLookupSize)))
|
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
if (entities.Count == 0)
|
if (entities.Count == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user