From 036800531c13c3f3c06fdbe709f08fb38d8d8e4e Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 2 Mar 2011 22:16:47 +1300 Subject: [PATCH] add support for aux. bars in selection --- OpenRA.Game/Traits/Selectable.cs | 36 ++++++++++++++++++++++---- OpenRA.Game/Traits/TraitsInterfaces.cs | 3 ++- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/OpenRA.Game/Traits/Selectable.cs b/OpenRA.Game/Traits/Selectable.cs index 92c7c1c7f8..f985deee49 100644 --- a/OpenRA.Game/Traits/Selectable.cs +++ b/OpenRA.Game/Traits/Selectable.cs @@ -49,7 +49,14 @@ namespace OpenRA.Traits DrawControlGroup(wr, self, xy); DrawPips(wr, self, xY); DrawTags(wr, self, new float2(.5f * (bounds.Left + bounds.Right), bounds.Top)); - DrawUnitPath(self); + DrawUnitPath(self); + + foreach (var extraBar in self.TraitsImplementing()) + { + DrawSelectionBar(self, xy, Xy, extraBar.GetValue(), extraBar.GetColor()); + xy.Y += 4; + Xy.Y += 4; + } } void DrawSelectionBox(Actor self, float2 xy, float2 Xy, float2 xY, float2 XY, Color c) @@ -63,6 +70,29 @@ namespace OpenRA.Traits Game.Renderer.LineRenderer.DrawLine(xY, xY + new float2(0, -4), c, c); Game.Renderer.LineRenderer.DrawLine(XY, XY + new float2(-4, 0), c, c); Game.Renderer.LineRenderer.DrawLine(XY, XY + new float2(0, -4), c, c); + } + + void DrawSelectionBar(Actor self, float2 xy, float2 Xy, float value, Color barColor) + { + if (!self.IsInWorld) return; + + var health = self.TraitOrDefault(); + if (health == null || health.IsDead) return; + + var c = Color.FromArgb(128, 30, 30, 30); + var c2 = Color.FromArgb(128, 10, 10, 10); + + var barColor2 = Color.FromArgb(255, barColor.R / 2, barColor.G / 2, barColor.B / 2); + + var z = float2.Lerp(xy, Xy, value); + + Game.Renderer.LineRenderer.DrawLine(xy + new float2(0, -4), Xy + new float2(0, -4), c, c); + Game.Renderer.LineRenderer.DrawLine(xy + new float2(0, -3), Xy + new float2(0, -3), c2, c2); + Game.Renderer.LineRenderer.DrawLine(xy + new float2(0, -2), Xy + new float2(0, -2), c, c); + + Game.Renderer.LineRenderer.DrawLine(xy + new float2(0, -3), z + new float2(0, -3), barColor, barColor); + Game.Renderer.LineRenderer.DrawLine(xy + new float2(0, -2), z + new float2(0, -2), barColor2, barColor2); + Game.Renderer.LineRenderer.DrawLine(xy + new float2(0, -4), z + new float2(0, -4), barColor2, barColor2); } void DrawHealthBar(Actor self, float2 xy, float2 Xy) @@ -74,8 +104,6 @@ namespace OpenRA.Traits var c = Color.FromArgb(128, 30, 30, 30); var c2 = Color.FromArgb(128, 10, 10, 10); -// Game.Renderer.LineRenderer.DrawLine(xy + new float2(0, -2), xy + new float2(0, -4), c, c); -// Game.Renderer.LineRenderer.DrawLine(Xy + new float2(0, -2), Xy + new float2(0, -4), c, c); var healthColor = (health.DamageState == DamageState.Critical) ? Color.Red : (health.DamageState == DamageState.Heavy) ? Color.Yellow : Color.LimeGreen; @@ -92,8 +120,6 @@ namespace OpenRA.Traits Game.Renderer.LineRenderer.DrawLine(xy + new float2(0, -4), Xy + new float2(0, -4), c, c); Game.Renderer.LineRenderer.DrawLine(xy + new float2(0, -3), Xy + new float2(0, -3), c2, c2); Game.Renderer.LineRenderer.DrawLine(xy + new float2(0, -2), Xy + new float2(0, -2), c, c); -// Game.Renderer.LineRenderer.DrawLine(z + new float2(0, -4), Xy + new float2(0, -4), c, c); -// Game.Renderer.LineRenderer.DrawLine(z + new float2(0, -2), Xy + new float2(0, -2), c, c); Game.Renderer.LineRenderer.DrawLine(xy + new float2(0, -3), z + new float2(0, -3), healthColor, healthColor); Game.Renderer.LineRenderer.DrawLine(xy + new float2(0, -2), z + new float2(0, -2), healthColor2, healthColor2); diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 7d38494ee0..d7fdf31cb0 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -126,7 +126,8 @@ namespace OpenRA.Traits public interface IPalette { void InitPalette( WorldRenderer wr ); } public interface IPaletteModifier { void AdjustPalette(Dictionary b); } public interface IPips { IEnumerable GetPips(Actor self); } - public interface ITags { IEnumerable GetTags(); } + public interface ITags { IEnumerable GetTags(); } + public interface ISelectionBar { float GetValue(); Color GetColor(); } public interface ITeleportable : IHasLocation /* crap name! */ {