diff --git a/OpenRa.Game/Graphics/WorldRenderer.cs b/OpenRa.Game/Graphics/WorldRenderer.cs index 9d8fbb1a9d..b58cceacf2 100644 --- a/OpenRa.Game/Graphics/WorldRenderer.cs +++ b/OpenRa.Game/Graphics/WorldRenderer.cs @@ -93,9 +93,6 @@ namespace OpenRa.Game.Graphics spriteRenderer.Flush(); } - // depends on the order of pips in TraitsInterfaces.cs! - static readonly string[] pipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray" }; - public void DrawSelectionBox(Actor selectedUnit, Color c, bool drawHealthBar) { var center = selectedUnit.CenterLocation; @@ -119,19 +116,14 @@ namespace OpenRa.Game.Graphics if (drawHealthBar) { DrawHealthBar(selectedUnit, xy, Xy); - DrawPips(selectedUnit, xY); - } - float2 fakexyBase = new float2(-16, -4); - if (selectedUnit.Owner == Game.LocalPlayer){ - foreach (var fake in selectedUnit.traits.WithInterface()) + + // Only display pips and tags to the owner + if (selectedUnit.Owner == Game.LocalPlayer) { - float2 fakexyOffset = xY + new float2(selectedUnit.Bounds.Width/2, 0) + fakexyBase; - var fakeImage = new Animation("pips"); - fakeImage.PlayRepeating("fake"); - spriteRenderer.DrawSprite(fakeImage.Image, fakexyOffset, 0); + DrawPips(selectedUnit, xY); + DrawTags(selectedUnit, new float2(center.X, xy.Y)); } - } - + } if (ShowUnitPaths) { @@ -180,11 +172,14 @@ namespace OpenRa.Game.Graphics lineRenderer.DrawLine(xy + new float2(0, -4), z + new float2(0, -4), healthColor2, healthColor2); } - void DrawPips(Actor selectedUnit, float2 xY) + // depends on the order of pips in TraitsInterfaces.cs! + static readonly string[] pipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray" }; + static readonly string[] tagStrings = { "", "tag-fake", "tag-primary" }; + + void DrawPips(Actor selectedUnit, float2 basePosition) { // If a mod wants to implement a unit with multiple pip sources, then they are placed on multiple rows - - var pipxyBase = xY + new float2(-12, -7); // Correct for the offset in the shp file + var pipxyBase = basePosition + new float2(-12, -7); // Correct for the offset in the shp file var pipxyOffset = new float2(0, 0); // Correct for offset due to multiple columns/rows foreach (var pips in selectedUnit.traits.WithInterface()) @@ -201,5 +196,25 @@ namespace OpenRa.Game.Graphics pipxyOffset.Y -= 5; } } + + void DrawTags(Actor selectedUnit, float2 basePosition) + { + // If a mod wants to implement a unit with multiple tags, then they are placed on multiple rows + var tagxyBase = basePosition + new float2(-16, 2); // Correct for the offset in the shp file + var tagxyOffset = new float2(0, 0); // Correct for offset due to multiple rows + + foreach (var tags in selectedUnit.traits.WithInterface()) + { + foreach (var tag in tags.GetTags()) + { + var tagImages = new Animation("pips"); + tagImages.PlayRepeating(tagStrings[(int)tag]); + spriteRenderer.DrawSprite(tagImages.Image, tagxyBase + tagxyOffset, 0); + + // Increment row + tagxyOffset.Y += 8; + } + } + } } } diff --git a/OpenRa.Game/Traits/Fake.cs b/OpenRa.Game/Traits/Fake.cs index ce76ff2d8a..9cf09b2c9d 100644 --- a/OpenRa.Game/Traits/Fake.cs +++ b/OpenRa.Game/Traits/Fake.cs @@ -1,14 +1,16 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace OpenRa.Game.Traits { - class Fake + class Fake : ITags { - - public Fake(Actor self){} - + public Fake(Actor self){} + + public IEnumerable GetTags() + { + yield return TagType.Fake; + } } } diff --git a/OpenRa.Game/Traits/Production.cs b/OpenRa.Game/Traits/Production.cs index ba783a4c61..98e2dee533 100755 --- a/OpenRa.Game/Traits/Production.cs +++ b/OpenRa.Game/Traits/Production.cs @@ -1,9 +1,10 @@ using OpenRa.Game.GameRules; using System.Linq; +using System.Collections.Generic; namespace OpenRa.Game.Traits { - class Production : IProducer + class Production : IProducer, ITags { public Production( Actor self ) { } @@ -50,6 +51,11 @@ namespace OpenRa.Game.Traits return true; } + + public IEnumerable GetTags() + { + yield return (true) ? TagType.Primary : TagType.None; + } } class ProductionSurround : Production diff --git a/OpenRa.Game/Traits/TraitsInterfaces.cs b/OpenRa.Game/Traits/TraitsInterfaces.cs index 2cc62161f4..9fc8dcbcac 100644 --- a/OpenRa.Game/Traits/TraitsInterfaces.cs +++ b/OpenRa.Game/Traits/TraitsInterfaces.cs @@ -6,7 +6,10 @@ using System.Drawing; namespace OpenRa.Game.Traits { enum DamageState { Normal, Half, Dead }; + + // depends on the order of pips in WorldRenderer.cs! enum PipType { Transparent, Green, Yellow, Red, Gray }; + enum TagType { None, Fake, Primary }; interface ITick { void Tick(Actor self); } interface IRender { IEnumerable> Render(Actor self); } @@ -25,4 +28,5 @@ namespace OpenRa.Game.Traits interface IDamageModifier { float GetDamageModifier(); } interface ISpeedModifier { float GetSpeedModifier(); } interface IPips { IEnumerable GetPips(); } + interface ITags { IEnumerable GetTags(); } } diff --git a/sequences.xml b/sequences.xml index 554f5a6bcd..7c2c4dcac4 100644 --- a/sequences.xml +++ b/sequences.xml @@ -530,15 +530,16 @@ - - + + - + +