diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 2be0d3fea9..49d0e23b56 100644 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -114,13 +114,13 @@ namespace OpenRA visualBounds = Exts.Lazy(() => { - var sd = Info.Traits.GetOrDefault(); - var size = (sd != null && sd.VisualBounds != null) ? new int2(sd.VisualBounds[0], sd.VisualBounds[1]) : + var sd = Info.Traits.GetOrDefault(); + var size = (sd != null && sd.SelectionBoxBounds != null) ? new int2(sd.SelectionBoxBounds[0], sd.SelectionBoxBounds[1]) : TraitsImplementing().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]); + if (sd != null && sd.SelectionBoxBounds != null && sd.SelectionBoxBounds.Length > 2) + offset += new int2(sd.SelectionBoxBounds[2], sd.SelectionBoxBounds[3]); return new Rectangle(offset.X, offset.Y, size.X, size.Y); }); diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index e986b98116..6f66baceeb 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -180,7 +180,6 @@ - @@ -235,7 +234,6 @@ - diff --git a/OpenRA.Game/Traits/Selectable.cs b/OpenRA.Game/Traits/Selectable.cs index bc069114f5..6ba7b12f39 100644 --- a/OpenRA.Game/Traits/Selectable.cs +++ b/OpenRA.Game/Traits/Selectable.cs @@ -61,12 +61,6 @@ namespace OpenRA.Traits public IEnumerable RenderAfterWorld(WorldRenderer wr) { - if (!Info.Selectable) - yield break; - - yield return new SelectionBoxRenderable(self, Color.White); - yield return new SelectionBarsRenderable(self); - if (self.World.LocalPlayer != null && self.World.LocalPlayer.PlayerActor.Trait().PathDebug) yield return new TargetLineRenderable(ActivityTargetPath(), Color.Green); } diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 2e82851707..5fe2bc9551 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -110,6 +110,16 @@ namespace OpenRA.Traits public interface ISeedableResource { void Seed(Actor self); } + public interface ISelectionDecorations + { + ISelectionDecorationsInfo SelectionDecorationsInfo { get; } + } + + public interface ISelectionDecorationsInfo + { + int[] SelectionBoxBounds { get; } + } + public interface IVoiced { string VoiceSet { get; } diff --git a/OpenRA.Game/Graphics/SelectionBoxRenderable.cs b/OpenRA.Mods.Common/Graphics/SelectionBoxRenderable.cs similarity index 98% rename from OpenRA.Game/Graphics/SelectionBoxRenderable.cs rename to OpenRA.Mods.Common/Graphics/SelectionBoxRenderable.cs index e36eb24a59..fd1bb1f099 100644 --- a/OpenRA.Game/Graphics/SelectionBoxRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/SelectionBoxRenderable.cs @@ -12,7 +12,7 @@ using System.Drawing; using OpenRA.Graphics; using OpenRA.Traits; -namespace OpenRA.Graphics +namespace OpenRA.Mods.Common.Graphics { public struct SelectionBoxRenderable : IRenderable, IFinalizedRenderable { diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index b42d802411..447dd44b70 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -171,6 +171,7 @@ + @@ -438,6 +439,7 @@ + diff --git a/OpenRA.Game/Traits/SelectionDecorations.cs b/OpenRA.Mods.Common/Traits/SelectionDecorations.cs similarity index 81% rename from OpenRA.Game/Traits/SelectionDecorations.cs rename to OpenRA.Mods.Common/Traits/SelectionDecorations.cs index 4008a416ad..9d6c1531f4 100644 --- a/OpenRA.Game/Traits/SelectionDecorations.cs +++ b/OpenRA.Mods.Common/Traits/SelectionDecorations.cs @@ -9,21 +9,30 @@ #endregion using System.Collections.Generic; +using System.Drawing; using System.Linq; using OpenRA.Graphics; +using OpenRA.Mods.Common.Graphics; +using OpenRA.Traits; -namespace OpenRA.Traits +namespace OpenRA.Mods.Common.Traits { - public class SelectionDecorationsInfo : ITraitInfo + public class SelectionDecorationsInfo : ITraitInfo, ISelectionDecorationsInfo { public readonly string Palette = "chrome"; - [Desc("Visual bounds for the selection box. If null, it matches Bounds.")] + [Desc("Visual bounds for selection box. If null, it uses AutoSelectionSize.")] public readonly int[] VisualBounds = null; + [Desc("Health bar, production progress bar etc.")] + public readonly bool RenderSelectionBars = true; + public readonly bool RenderSelectionBox = true; + public readonly Color SelectionBoxColor = Color.White; public object Create(ActorInitializer init) { return new SelectionDecorations(init.Self, this); } + + public int[] SelectionBoxBounds { get { return VisualBounds; } } } - public class SelectionDecorations : IPostRenderSelection + public class SelectionDecorations : ISelectionDecorations, IPostRenderSelection { // depends on the order of pips in TraitsInterfaces.cs! static readonly string[] PipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray", "pip-blue", "pip-ammo", "pip-ammoempty" }; @@ -32,6 +41,8 @@ namespace OpenRA.Traits public SelectionDecorationsInfo Info; readonly Actor self; + public ISelectionDecorationsInfo SelectionDecorationsInfo { get { return Info; } } + public SelectionDecorations(Actor self, SelectionDecorationsInfo info) { this.self = self; @@ -43,6 +54,12 @@ namespace OpenRA.Traits if (!self.Owner.IsAlliedWith(self.World.RenderPlayer) || self.World.FogObscures(self)) yield break; + if (Info.RenderSelectionBox) + yield return new SelectionBoxRenderable(self, Info.SelectionBoxColor); + + if (Info.RenderSelectionBars) + yield return new SelectionBarsRenderable(self); + var b = self.VisualBounds; var pos = wr.ScreenPxPosition(self.CenterPosition); var tl = wr.Viewport.WorldToViewPx(pos + new int2(b.Left, b.Top)); diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/GrantUpgradePower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/GrantUpgradePower.cs index 76080d3239..18f2e1aaae 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/GrantUpgradePower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/GrantUpgradePower.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using OpenRA.Graphics; +using OpenRA.Mods.Common.Graphics; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits diff --git a/OpenRA.Mods.RA/Traits/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.RA/Traits/SupportPowers/ChronoshiftPower.cs index c6438fe380..642c4983d9 100644 --- a/OpenRA.Mods.RA/Traits/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.RA/Traits/SupportPowers/ChronoshiftPower.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using OpenRA.Graphics; +using OpenRA.Mods.Common.Graphics; using OpenRA.Mods.Common.Traits; using OpenRA.Mods.RA.Activities;