Remove legacy bounds code.

This commit is contained in:
Paul Chote
2017-12-09 00:01:00 +00:00
committed by reaperrr
parent bf57eceeec
commit c87409ed1a
83 changed files with 418 additions and 563 deletions

View File

@@ -1,57 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Automatically calculates the screen map boundaries from the sprite size.")]
public class AutoRenderSizeInfo : ITraitInfo, Requires<RenderSpritesInfo>, IAutoRenderSizeInfo, IDecorationBoundsInfo
{
public object Create(ActorInitializer init) { return new AutoRenderSize(init.Self); }
}
public class AutoRenderSize : IAutoRenderSize, IMouseBounds, IDecorationBounds
{
readonly RenderSprites rs;
public AutoRenderSize(Actor self)
{
rs = self.Trait<RenderSprites>();
}
public int2 RenderSize(Actor self)
{
return rs.AutoRenderSize(self);
}
Rectangle Bounds(Actor self, WorldRenderer wr)
{
return self.TraitsImplementing<IAutoMouseBounds>()
.Select(s => s.AutoMouseoverBounds(self, wr))
.FirstOrDefault(r => !r.IsEmpty);
}
Rectangle IMouseBounds.MouseoverBounds(Actor self, WorldRenderer wr)
{
return Bounds(self, wr);
}
Rectangle IDecorationBounds.DecorationBounds(Actor self, WorldRenderer wr)
{
return Bounds(self, wr);
}
}
}

View File

@@ -1,32 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Automatically calculates the targetable area and screen map boundaries from the sprite size.")]
public class AutoSelectionSizeInfo : ITraitInfo, Requires<RenderSpritesInfo>, IAutoSelectionSizeInfo
{
public object Create(ActorInitializer init) { return new AutoSelectionSize(this); }
}
public class AutoSelectionSize : IAutoSelectionSize
{
public AutoSelectionSize(AutoSelectionSizeInfo info) { }
public int2 SelectionSize(Actor self)
{
var rs = self.Trait<RenderSprites>();
return rs.AutoSelectionSize(self);
}
}
}

View File

@@ -1,72 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Special case trait for actors that need to define targetable area and screen map bounds manually.")]
public class CustomRenderSizeInfo : ITraitInfo, IAutoRenderSizeInfo, IDecorationBoundsInfo
{
[FieldLoader.Require]
public readonly int[] CustomBounds = null;
[Desc("Defines a custom rectangle for Decorations.",
"If null, CustomBounds will be used instead")]
public readonly int[] DecorationBounds = null;
public object Create(ActorInitializer init) { return new CustomRenderSize(this); }
}
public class CustomRenderSize : IAutoRenderSize, IMouseBounds, IDecorationBounds
{
readonly CustomRenderSizeInfo info;
public CustomRenderSize(CustomRenderSizeInfo info) { this.info = info; }
public int2 RenderSize(Actor self)
{
return new int2(info.CustomBounds[0], info.CustomBounds[1]);
}
Rectangle IMouseBounds.MouseoverBounds(Actor self, WorldRenderer wr)
{
if (info.CustomBounds == null)
return Rectangle.Empty;
var size = new int2(info.CustomBounds[0], info.CustomBounds[1]);
var offset = -size / 2;
if (info.CustomBounds.Length > 2)
offset += new int2(info.CustomBounds[2], info.CustomBounds[3]);
var xy = wr.ScreenPxPosition(self.CenterPosition);
return new Rectangle(xy.X, xy.Y, size.X, size.Y);
}
Rectangle IDecorationBounds.DecorationBounds(Actor self, WorldRenderer wr)
{
var bounds = info.DecorationBounds ?? info.CustomBounds;
if (bounds == null)
return Rectangle.Empty;
var size = new int2(bounds[0], bounds[1]);
var offset = -size / 2;
if (bounds.Length > 2)
offset += new int2(bounds[2], bounds[3]);
var xy = wr.ScreenPxPosition(self.CenterPosition);
return new Rectangle(xy.X, xy.Y, size.X, size.Y);
}
}
}

View File

@@ -18,15 +18,10 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
public class SelectionDecorationsInfo : ITraitInfo, ISelectionDecorationsInfo, Requires<IDecorationBoundsInfo>
public class SelectionDecorationsInfo : ITraitInfo, Requires<IDecorationBoundsInfo>
{
[PaletteReference] public readonly string Palette = "chrome";
[Desc("Bounds for visual selection box. If null, it uses AutoSelectionSize.",
"The first two values define the bounds' size, the optional third and fourth",
"values specify the position relative to the actors' center. Defaults to selectable bounds.")]
public readonly int[] VisualBounds = null;
[Desc("Health bar, production progress bar etc.")]
public readonly bool RenderSelectionBars = true;
@@ -37,8 +32,6 @@ namespace OpenRA.Mods.Common.Traits.Render
public readonly string Image = "pips";
public object Create(ActorInitializer init) { return new SelectionDecorations(init.Self, this); }
public int[] SelectionBoxBounds { get { return VisualBounds; } }
}
public class SelectionDecorations : IRenderAboveShroud, INotifyCreated, ITick

View File

@@ -20,7 +20,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Also returns a default selection size that is calculated automatically from the voxel dimensions.")]
public class WithVoxelBodyInfo : ConditionalTraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>, IAutoSelectionSizeInfo, IAutoRenderSizeInfo
public class WithVoxelBodyInfo : ConditionalTraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>
{
public readonly string Sequence = "idle";
@@ -40,9 +40,8 @@ namespace OpenRA.Mods.Common.Traits.Render
}
}
public class WithVoxelBody : ConditionalTrait<WithVoxelBodyInfo>, IAutoSelectionSize, IAutoRenderSize, IAutoMouseBounds
public class WithVoxelBody : ConditionalTrait<WithVoxelBodyInfo>, IAutoMouseBounds
{
readonly int2 size;
readonly ModelAnimation modelAnimation;
readonly RenderVoxels rv;
@@ -58,15 +57,8 @@ namespace OpenRA.Mods.Common.Traits.Render
() => IsTraitDisabled, () => 0, info.ShowShadow);
rv.Add(modelAnimation);
// Selection size
var rvi = self.Info.TraitInfo<RenderVoxelsInfo>();
var s = (int)(rvi.Scale * model.Size.Aggregate(Math.Max));
size = new int2(s, s);
}
public int2 SelectionSize(Actor self) { return size; }
public int2 RenderSize(Actor self) { return size; }
Rectangle IAutoMouseBounds.AutoMouseoverBounds(Actor self, WorldRenderer wr)
{
return modelAnimation.ScreenBounds(self.CenterPosition, wr, rv.Info.Scale);