Introduce IMouseBounds and split/rework mouse rectangles.

The render bounds for an actor now include the area covered
by bibs, shadows, and any other widgets. In many cases this
area is much larger than we really want to consider for
tooltips and mouse selection.

An optional Margin is added to Selectable to support cases
like infantry, where we want the mouse area of the actor
to be larger than the drawn selection box.
This commit is contained in:
Paul Chote
2017-12-07 23:15:07 +00:00
committed by reaperrr
parent 8fcc80b05a
commit 6f5d035e79
25 changed files with 349 additions and 117 deletions

View File

@@ -186,7 +186,8 @@ namespace OpenRA.Mods.Cnc.Traits
yield break;
}
var underCursor = world.ScreenMap.ActorsAt(mi)
var underCursor = world.ScreenMap.ActorsAtMouse(mi)
.Select(a => a.Actor)
.Where(a => !world.FogObscures(a))
.MaxByOrDefault(a => a.Info.HasTraitInfo<SelectableInfo>()
? a.Info.TraitInfo<SelectableInfo>().Priority : int.MinValue);

View File

@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
@@ -45,22 +46,26 @@ namespace OpenRA.Mods.Cnc.Traits.Render
}
}
public class WithVoxelUnloadBody : IAutoSelectionSize, IAutoRenderSize
public class WithVoxelUnloadBody : IAutoSelectionSize, IAutoRenderSize, IAutoMouseBounds
{
public bool Docked;
readonly int2 size;
readonly ModelAnimation modelAnimation;
readonly RenderVoxels rv;
public WithVoxelUnloadBody(Actor self, WithVoxelUnloadBodyInfo info)
{
var body = self.Trait<BodyOrientation>();
var rv = self.Trait<RenderVoxels>();
rv = self.Trait<RenderVoxels>();
var idleModel = self.World.ModelCache.GetModelSequence(rv.Image, info.IdleSequence);
rv.Add(new ModelAnimation(idleModel, () => WVec.Zero,
modelAnimation = new ModelAnimation(idleModel, () => WVec.Zero,
() => new[] { body.QuantizeOrientation(self, self.Orientation) },
() => Docked,
() => 0, info.ShowShadow));
() => 0, info.ShowShadow);
rv.Add(modelAnimation);
// Selection size
var rvi = self.Info.TraitInfo<RenderVoxelsInfo>();
@@ -76,5 +81,10 @@ namespace OpenRA.Mods.Cnc.Traits.Render
int2 IAutoSelectionSize.SelectionSize(Actor self) { return size; }
int2 IAutoRenderSize.RenderSize(Actor self) { return size; }
Rectangle IAutoMouseBounds.AutoMouseoverBounds(Actor self, WorldRenderer wr)
{
return modelAnimation.ScreenBounds(self.CenterPosition, wr, rv.Info.Scale);
}
}
}

View File

@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common;
@@ -47,12 +48,15 @@ namespace OpenRA.Mods.Cnc.Traits.Render
}
}
public class WithVoxelWalkerBody : IAutoSelectionSize, ITick, IActorPreviewInitModifier, IAutoRenderSize
public class WithVoxelWalkerBody : IAutoSelectionSize, ITick, IActorPreviewInitModifier, IAutoRenderSize, IAutoMouseBounds
{
readonly WithVoxelWalkerBodyInfo info;
readonly IMove movement;
readonly IFacing facing;
readonly int2 size;
readonly ModelAnimation modelAnimation;
readonly RenderVoxels rv;
int oldFacing;
uint tick, frame, frames;
@@ -63,13 +67,15 @@ namespace OpenRA.Mods.Cnc.Traits.Render
facing = self.Trait<IFacing>();
var body = self.Trait<BodyOrientation>();
var rv = self.Trait<RenderVoxels>();
rv = self.Trait<RenderVoxels>();
var model = self.World.ModelCache.GetModelSequence(rv.Image, info.Sequence);
frames = model.Frames;
rv.Add(new ModelAnimation(model, () => WVec.Zero,
modelAnimation = new ModelAnimation(model, () => WVec.Zero,
() => new[] { body.QuantizeOrientation(self, self.Orientation) },
() => false, () => frame, info.ShowShadow));
() => false, () => frame, info.ShowShadow);
rv.Add(modelAnimation);
// Selection size
var rvi = self.Info.TraitInfo<RenderVoxelsInfo>();
@@ -98,6 +104,11 @@ namespace OpenRA.Mods.Cnc.Traits.Render
{
inits.Add(new BodyAnimationFrameInit(frame));
}
Rectangle IAutoMouseBounds.AutoMouseoverBounds(Actor self, WorldRenderer wr)
{
return modelAnimation.ScreenBounds(self.CenterPosition, wr, rv.Info.Scale);
}
}
public class BodyAnimationFrameInit : IActorInit<uint>