Easier actor selection in game by actor bounds center

This commit is contained in:
atlimit8
2015-11-15 11:30:40 -06:00
parent 387d0d0e3f
commit b07cd683e8
17 changed files with 100 additions and 75 deletions

View File

@@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace OpenRA.Traits
@@ -43,14 +44,22 @@ namespace OpenRA.Traits
}
}
public static Actor WithHighestSelectionPriority(this IEnumerable<Actor> actors)
public static Actor WithHighestSelectionPriority(this IEnumerable<Actor> actors, int2 selectionPixel)
{
return actors.MaxByOrDefault(a => a.Info.SelectionPriority());
return actors.MaxByOrDefault(a => CalculateActorSelectionPriority(a.Info, a.Bounds, selectionPixel));
}
public static FrozenActor WithHighestSelectionPriority(this IEnumerable<FrozenActor> actors)
public static FrozenActor WithHighestSelectionPriority(this IEnumerable<FrozenActor> actors, int2 selectionPixel)
{
return actors.MaxByOrDefault(a => a.Info.SelectionPriority());
return actors.MaxByOrDefault(a => CalculateActorSelectionPriority(a.Info, a.Bounds, selectionPixel));
}
static long CalculateActorSelectionPriority(ActorInfo info, Rectangle bounds, int2 selectionPixel)
{
var centerPixel = new int2(bounds.X, bounds.Y);
var pixelDistance = (centerPixel - selectionPixel).Length;
return ((long)-pixelDistance << 32) + info.SelectionPriority();
}
static readonly Actor[] NoActors = { };