New pips interface; use pips.shp instead of native drawing

This commit is contained in:
pchote
2009-12-18 19:07:21 -08:00
parent a18fae872e
commit fce0a8787d
5 changed files with 108 additions and 98 deletions

View File

@@ -1,4 +1,5 @@
using System.Drawing; using System.Drawing;
using System;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using IjwFramework.Types; using IjwFramework.Types;
@@ -145,43 +146,44 @@ namespace OpenRa.Game.Graphics
z + new float2(0, -4), z + new float2(0, -4),
healthColor2, healthColor2); healthColor2, healthColor2);
// Render Pips
var pips = selectedUnit.traits.WithInterface<IPips>().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 // Render Pips
lineRenderer.DrawLine(pipxy, // If a mod wants to implement a unit with multiple pip sources, then they are placed on multiple rows
pipxy + new float2(pipCount * (pipSize + 1) + 1, 0), float2 pipxyBase = xY+ new float2(-12,-7); // Correct for the offset in the shp file
pipBorderColor, pipBorderColor); float2 pipxyOffset = new float2(0,0); // Correct for offset due to multiple columns/rows
foreach (var pips in selectedUnit.traits.WithInterface<IPips>())
lineRenderer.DrawLine(pipxy + new float2(0, -(pipSize + 1)), {
pipxy + new float2(pipCount * (pipSize + 1) + 1, -(pipSize + 1)), foreach (var pip in pips.GetPips())
pipBorderColor, pipBorderColor); {
Animation pipImages = new Animation("pips");
// Draw vertical dividers
for (int i = 0; i <= pipCount; i++) switch(pip)
{ {
lineRenderer.DrawLine(pipxy + new float2(i * (pipSize + 1), -(pipSize + 1)), case PipType.Transparent:
pipxy + new float2(i * (pipSize + 1), 0), pipImages.PlayRepeating("pip-empty");
pipBorderColor, pipBorderColor); break;
} case PipType.Green:
pipImages.PlayRepeating("pip-green");
// Draw pips break;
for (int i = 0; i < pipCount; i++) case PipType.Yellow:
{ pipImages.PlayRepeating("pip-yellow");
Color pipColor = pips.GetColorForPip(i); break;
if (pipColor == Color.Transparent) continue; // Empty pip case PipType.Red:
pipImages.PlayRepeating("pip-red");
lineRenderer.DrawLine(pipxy + new float2(1 + i * (pipSize + 1), -2), break;
pipxy + new float2(1 + i * (pipSize + 1) + pipSize, -2), case PipType.Gray:
pipColor, pipColor); 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) if (ShowUnitPaths)
@@ -202,6 +204,7 @@ namespace OpenRa.Game.Graphics
} }
} }
} }
spriteRenderer.Flush();
} }
} }
} }

View File

@@ -1,5 +1,5 @@
using OpenRa.Game.GameRules; using OpenRa.Game.GameRules;
using System.Drawing; using System.Collections.Generic;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class ChronoshiftDeploy : IOrder, ISpeedModifier, ITick, IPips class ChronoshiftDeploy : IOrder, ISpeedModifier, ITick, IPips
@@ -36,48 +36,48 @@ namespace OpenRa.Game.Traits
self.CancelActivity(); 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)); self.QueueActivity(new Activities.Teleport(order.TargetLocation));
Sound.Play("chrotnk1.aud"); Sound.Play("chrotnk1.aud");
chronoshiftActive = false; chronoshiftActive = false;
remainingChargeTime = chargeTime; 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() public float GetSpeedModifier()
{ {
return chronoshiftActive ? 0f : 1f; return chronoshiftActive ? 0f : 1f;
} }
public Color GetBorderColor() { return Color.Black; } // Display 5 pips indicating the current charge status
public int GetPipCount() { return 5; } public IEnumerable<PipType> GetPips()
public Color GetColorForPip(int index) {
{ const int numPips = 5;
// TODO: Check how many pips to display for (int i = 0; i < numPips; i++)
if ((1 - remainingChargeTime*1.0f / chargeTime) * GetPipCount() < index + 1) {
return Color.Transparent; if ((1 - remainingChargeTime * 1.0f / chargeTime) * numPips < i + 1)
{
switch (index) yield return PipType.Transparent;
{ continue;
case 0: }
case 1:
return Color.Red; switch (i)
case 2: {
case 3: case 0:
return Color.Yellow; case 1:
case 4: yield return PipType.Red;
return Color.LimeGreen; break;
} case 2:
case 3:
return Color.Transparent; yield return PipType.Yellow;
} break;
case 4:
yield return PipType.Green;
break;
}
}
}
} }
} }

View File

@@ -1,4 +1,4 @@
using System.Drawing; using System.Collections.Generic;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class Harvester : IOrder, IPips class Harvester : IOrder, IPips
@@ -9,7 +9,7 @@ namespace OpenRa.Game.Traits
public bool IsFull { get { return oreCarried + gemsCarried == Rules.General.BailCount; } } public bool IsFull { get { return oreCarried + gemsCarried == Rules.General.BailCount; } }
public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } } public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } }
public Harvester( Actor self ) { } public Harvester(Actor self) { }
public void AcceptResource(bool isGem) public void AcceptResource(bool isGem)
{ {
@@ -29,8 +29,8 @@ namespace OpenRa.Game.Traits
{ {
if (mi.Button == MouseButton.Left) return null; if (mi.Button == MouseButton.Left) return null;
if (underCursor != null if (underCursor != null
&& underCursor.Owner == self.Owner && underCursor.Owner == self.Owner
&& underCursor.traits.Contains<AcceptsOre>() && !IsEmpty) && underCursor.traits.Contains<AcceptsOre>() && !IsEmpty)
return Order.DeliverOre(self, underCursor); return Order.DeliverOre(self, underCursor);
@@ -40,32 +40,39 @@ namespace OpenRa.Game.Traits
return null; 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.CancelActivity();
self.QueueActivity( new Traits.Activities.Move( order.TargetLocation, 0 ) ); self.QueueActivity(new Traits.Activities.Move(order.TargetLocation, 0));
self.QueueActivity( new Traits.Activities.Harvest() ); self.QueueActivity(new Traits.Activities.Harvest());
} }
else if( order.OrderString == "DeliverOre" ) else if (order.OrderString == "DeliverOre")
{ {
self.CancelActivity(); 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 IEnumerable<PipType> GetPips()
public int GetPipCount() { return 10; } {
public Color GetColorForPip(int index) const int numPips = 7;
{ for (int i = 0; i < numPips; i++)
if (gemsCarried * 1.0f / Rules.General.BailCount > index * 1.0f / GetPipCount()) {
return Color.Red; 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()) if ((gemsCarried + oreCarried) * 1.0f / Rules.General.BailCount > i * 1.0f / numPips)
return Color.Yellow; {
yield return PipType.Yellow;
return Color.Transparent; continue;
} }
yield return PipType.Transparent;
}
}
} }
} }

View File

@@ -6,7 +6,8 @@ using System.Drawing;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
enum DamageState { Normal, Half, Dead }; enum DamageState { Normal, Half, Dead };
enum PipType { Transparent, Green, Yellow, Red, Gray };
interface ITick { void Tick(Actor self); } interface ITick { void Tick(Actor self); }
interface IRender { IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self); } interface IRender { IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self); }
interface INotifyDamage { void Damaged(Actor self, AttackInfo e); } interface INotifyDamage { void Damaged(Actor self, AttackInfo e); }
@@ -23,9 +24,5 @@ namespace OpenRa.Game.Traits
ModifyRender( Actor self, IEnumerable<Tuple<Sprite, float2, int>> r ); } ModifyRender( Actor self, IEnumerable<Tuple<Sprite, float2, int>> r ); }
interface IDamageModifier { float GetDamageModifier(); } interface IDamageModifier { float GetDamageModifier(); }
interface ISpeedModifier { float GetSpeedModifier(); } interface ISpeedModifier { float GetSpeedModifier(); }
interface IPips { interface IPips { IEnumerable<PipType> GetPips(); }
Color GetBorderColor();
int GetPipCount();
Color GetColorForPip(int index);
}
} }

View File

@@ -530,11 +530,14 @@
</unit> </unit>
<unit name="pips"> <unit name="pips">
<sequence name="groups" start="8" length="10" /> <sequence name="groups" start="8" length="10" />
<sequence name="ore" start="0" length="2" /> <sequence name="pip-green" start="1" length="1" />
<sequence name="cargo" start="5" length="3" /> <sequence name="pip-empty" start="0" length="1" />
<sequence name="medic" start="20" length="1" /> <sequence name="medic" start="20" length="1" />
<sequence name="ready" start="3" length="1" /> <sequence name="ready" start="3" length="1" />
<sequence name="hold" start="4" length="1" /> <sequence name="hold" start="4" length="1" />
<sequence name="pip-yellow" start="5" length="1" />
<sequence name="pip-gray" start="6" length="1" />
<sequence name="pip-red" start="7" length="1" />
</unit> </unit>
<unit name="mig"> <unit name="mig">
<sequence name="idle" start="0" length="16" /> <sequence name="idle" start="0" length="16" />