Introduced VisualBounds on SelectionDecorations

To allow visual selection boxes to be independent from Selectable.Bounds.
This commit is contained in:
reaperrr
2015-04-07 22:32:38 +02:00
parent f72a14faea
commit d6fb05ce68
6 changed files with 51 additions and 10 deletions

View File

@@ -41,12 +41,14 @@ namespace OpenRA
public int Generation;
Lazy<Rectangle> bounds;
Lazy<Rectangle> visualBounds;
Lazy<IFacing> facing;
Lazy<Health> health;
Lazy<IOccupySpace> occupySpace;
Lazy<IEffectiveOwner> effectiveOwner;
public Rectangle Bounds { get { return bounds.Value; } }
public Rectangle VisualBounds { get { return visualBounds.Value; } }
public IOccupySpace OccupiesSpace { get { return occupySpace.Value; } }
public IEffectiveOwner EffectiveOwner { get { return effectiveOwner.Value; } }
@@ -110,6 +112,19 @@ namespace OpenRA
return new Rectangle(offset.X, offset.Y, size.X, size.Y);
});
visualBounds = Exts.Lazy(() =>
{
var sd = Info.Traits.GetOrDefault<SelectionDecorationsInfo>();
var size = (sd != null && sd.VisualBounds != null) ? new int2(sd.VisualBounds[0], sd.VisualBounds[1]) :
TraitsImplementing<IAutoSelectionSize>().Select(x => x.SelectionSize(this)).FirstOrDefault();
var offset = -size / 2;
if (sd != null && sd.VisualBounds != null && sd.VisualBounds.Length > 2)
offset += new int2(sd.VisualBounds[2], sd.VisualBounds[3]);
return new Rectangle(offset.X, offset.Y, size.X, size.Y);
});
renderModifiers = TraitsImplementing<IRenderModifier>().ToArray();
renders = TraitsImplementing<IRender>().ToArray();
disables = TraitsImplementing<IDisable>().ToArray();