diff --git a/OpenRa.Game/Graphics/WorldRenderer.cs b/OpenRa.Game/Graphics/WorldRenderer.cs index cdaa2b5ffa..2c995b30c8 100644 --- a/OpenRa.Game/Graphics/WorldRenderer.cs +++ b/OpenRa.Game/Graphics/WorldRenderer.cs @@ -1,4 +1,5 @@ using System.Drawing; +using System; using System.Linq; using System.Windows.Forms; using IjwFramework.Types; @@ -145,43 +146,44 @@ namespace OpenRa.Game.Graphics z + new float2(0, -4), healthColor2, healthColor2); - // Render Pips - var pips = selectedUnit.traits.WithInterface().FirstOrDefault(); - if (pips != null) - { - const int pipSize = 2; // How big are the pips? - int pipCount = pips.GetPipCount(); - Color pipBorderColor = pips.GetBorderColor(); - float2 pipxy = xY + new float2(1, -1); - // Draw the border - lineRenderer.DrawLine(pipxy, - pipxy + new float2(pipCount * (pipSize + 1) + 1, 0), - pipBorderColor, pipBorderColor); - - lineRenderer.DrawLine(pipxy + new float2(0, -(pipSize + 1)), - pipxy + new float2(pipCount * (pipSize + 1) + 1, -(pipSize + 1)), - pipBorderColor, pipBorderColor); - - // Draw vertical dividers - for (int i = 0; i <= pipCount; i++) - { - lineRenderer.DrawLine(pipxy + new float2(i * (pipSize + 1), -(pipSize + 1)), - pipxy + new float2(i * (pipSize + 1), 0), - pipBorderColor, pipBorderColor); - } - - // Draw pips - for (int i = 0; i < pipCount; i++) - { - Color pipColor = pips.GetColorForPip(i); - if (pipColor == Color.Transparent) continue; // Empty pip - - lineRenderer.DrawLine(pipxy + new float2(1 + i * (pipSize + 1), -2), - pipxy + new float2(1 + i * (pipSize + 1) + pipSize, -2), - pipColor, pipColor); - } - } + // Render Pips + // If a mod wants to implement a unit with multiple pip sources, then they are placed on multiple rows + float2 pipxyBase = xY+ new float2(-12,-7); // Correct for the offset in the shp file + float2 pipxyOffset = new float2(0,0); // Correct for offset due to multiple columns/rows + foreach (var pips in selectedUnit.traits.WithInterface()) + { + foreach (var pip in pips.GetPips()) + { + Animation pipImages = new Animation("pips"); + + switch(pip) + { + case PipType.Transparent: + pipImages.PlayRepeating("pip-empty"); + break; + case PipType.Green: + pipImages.PlayRepeating("pip-green"); + break; + case PipType.Yellow: + pipImages.PlayRepeating("pip-yellow"); + break; + case PipType.Red: + pipImages.PlayRepeating("pip-red"); + break; + case PipType.Gray: + pipImages.PlayRepeating("pip-gray"); + break; + default: + throw new NotImplementedException(); + } + spriteRenderer.DrawSprite(pipImages.Image, pipxyBase+pipxyOffset, 0); + pipxyOffset +=new float2(4,0); + } + // Increment row + pipxyOffset.X = 0; + pipxyOffset.Y -= 5; + } } if (ShowUnitPaths) @@ -202,6 +204,7 @@ namespace OpenRa.Game.Graphics } } } + spriteRenderer.Flush(); } } } diff --git a/OpenRa.Game/Traits/ChronoshiftDeploy.cs b/OpenRa.Game/Traits/ChronoshiftDeploy.cs index 23d4fb82b7..2839fd0b18 100644 --- a/OpenRa.Game/Traits/ChronoshiftDeploy.cs +++ b/OpenRa.Game/Traits/ChronoshiftDeploy.cs @@ -1,5 +1,5 @@ using OpenRa.Game.GameRules; -using System.Drawing; +using System.Collections.Generic; namespace OpenRa.Game.Traits { class ChronoshiftDeploy : IOrder, ISpeedModifier, ITick, IPips @@ -36,48 +36,48 @@ namespace OpenRa.Game.Traits self.CancelActivity(); } - if (order.OrderString == "UsePortableChronoshift" && CanEnterCell(order.TargetLocation, self)) + if (order.OrderString == "UsePortableChronoshift" && Game.IsCellBuildable(order.TargetLocation, self.Info.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel, self)) { + self.CancelActivity(); self.QueueActivity(new Activities.Teleport(order.TargetLocation)); Sound.Play("chrotnk1.aud"); chronoshiftActive = false; remainingChargeTime = chargeTime; } } - - static bool CanEnterCell(int2 c, Actor self) - { - if (!Game.BuildingInfluence.CanMoveHere(c)) return false; - var u = Game.UnitInfluence.GetUnitAt(c); - return (u == null || u == self); - } - + public float GetSpeedModifier() { return chronoshiftActive ? 0f : 1f; } - - public Color GetBorderColor() { return Color.Black; } - public int GetPipCount() { return 5; } - public Color GetColorForPip(int index) - { - // TODO: Check how many pips to display - if ((1 - remainingChargeTime*1.0f / chargeTime) * GetPipCount() < index + 1) - return Color.Transparent; - - switch (index) - { - case 0: - case 1: - return Color.Red; - case 2: - case 3: - return Color.Yellow; - case 4: - return Color.LimeGreen; - } - - return Color.Transparent; - } + + // Display 5 pips indicating the current charge status + public IEnumerable GetPips() + { + const int numPips = 5; + for (int i = 0; i < numPips; i++) + { + if ((1 - remainingChargeTime * 1.0f / chargeTime) * numPips < i + 1) + { + yield return PipType.Transparent; + continue; + } + + switch (i) + { + case 0: + case 1: + yield return PipType.Red; + break; + case 2: + case 3: + yield return PipType.Yellow; + break; + case 4: + yield return PipType.Green; + break; + } + } + } } } diff --git a/OpenRa.Game/Traits/Harvester.cs b/OpenRa.Game/Traits/Harvester.cs index 097c676262..588d7a9d7a 100644 --- a/OpenRa.Game/Traits/Harvester.cs +++ b/OpenRa.Game/Traits/Harvester.cs @@ -1,4 +1,4 @@ -using System.Drawing; +using System.Collections.Generic; namespace OpenRa.Game.Traits { class Harvester : IOrder, IPips @@ -9,7 +9,7 @@ namespace OpenRa.Game.Traits public bool IsFull { get { return oreCarried + gemsCarried == Rules.General.BailCount; } } public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } } - public Harvester( Actor self ) { } + public Harvester(Actor self) { } public void AcceptResource(bool isGem) { @@ -29,8 +29,8 @@ namespace OpenRa.Game.Traits { if (mi.Button == MouseButton.Left) return null; - if (underCursor != null - && underCursor.Owner == self.Owner + if (underCursor != null + && underCursor.Owner == self.Owner && underCursor.traits.Contains() && !IsEmpty) return Order.DeliverOre(self, underCursor); @@ -40,32 +40,39 @@ namespace OpenRa.Game.Traits return null; } - public void ResolveOrder( Actor self, Order order ) + public void ResolveOrder(Actor self, Order order) { - if( order.OrderString == "Harvest" ) + if (order.OrderString == "Harvest") { self.CancelActivity(); - self.QueueActivity( new Traits.Activities.Move( order.TargetLocation, 0 ) ); - self.QueueActivity( new Traits.Activities.Harvest() ); + self.QueueActivity(new Traits.Activities.Move(order.TargetLocation, 0)); + self.QueueActivity(new Traits.Activities.Harvest()); } - else if( order.OrderString == "DeliverOre" ) + else if (order.OrderString == "DeliverOre") { self.CancelActivity(); - self.QueueActivity( new Traits.Activities.DeliverOre( order.TargetActor ) ); + self.QueueActivity(new Traits.Activities.DeliverOre(order.TargetActor)); } } - public Color GetBorderColor() { return Color.Black; } - public int GetPipCount() { return 10; } - public Color GetColorForPip(int index) - { - if (gemsCarried * 1.0f / Rules.General.BailCount > index * 1.0f / GetPipCount()) - return Color.Red; + public IEnumerable GetPips() + { + const int numPips = 7; + for (int i = 0; i < numPips; i++) + { + if (gemsCarried * 1.0f / Rules.General.BailCount > i * 1.0f / numPips) + { + yield return PipType.Red; + continue; + } - if ((gemsCarried + oreCarried) * 1.0f / Rules.General.BailCount > index * 1.0f / GetPipCount()) - return Color.Yellow; - - return Color.Transparent; - } + if ((gemsCarried + oreCarried) * 1.0f / Rules.General.BailCount > i * 1.0f / numPips) + { + yield return PipType.Yellow; + continue; + } + yield return PipType.Transparent; + } + } } } diff --git a/OpenRa.Game/Traits/TraitsInterfaces.cs b/OpenRa.Game/Traits/TraitsInterfaces.cs index d5998373e0..2cc62161f4 100644 --- a/OpenRa.Game/Traits/TraitsInterfaces.cs +++ b/OpenRa.Game/Traits/TraitsInterfaces.cs @@ -6,7 +6,8 @@ using System.Drawing; namespace OpenRa.Game.Traits { enum DamageState { Normal, Half, Dead }; - + enum PipType { Transparent, Green, Yellow, Red, Gray }; + interface ITick { void Tick(Actor self); } interface IRender { IEnumerable> Render(Actor self); } interface INotifyDamage { void Damaged(Actor self, AttackInfo e); } @@ -23,9 +24,5 @@ namespace OpenRa.Game.Traits ModifyRender( Actor self, IEnumerable> r ); } interface IDamageModifier { float GetDamageModifier(); } interface ISpeedModifier { float GetSpeedModifier(); } - interface IPips { - Color GetBorderColor(); - int GetPipCount(); - Color GetColorForPip(int index); - } + interface IPips { IEnumerable GetPips(); } } diff --git a/sequences.xml b/sequences.xml index c07e576fb2..4c18e47ae0 100644 --- a/sequences.xml +++ b/sequences.xml @@ -530,11 +530,14 @@ - - + + + + +