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,42 +146,43 @@ namespace OpenRa.Game.Graphics
z + new float2(0, -4), z + new float2(0, -4),
healthColor2, healthColor2); healthColor2, healthColor2);
// Render Pips // Render Pips
var pips = selectedUnit.traits.WithInterface<IPips>().FirstOrDefault(); // If a mod wants to implement a unit with multiple pip sources, then they are placed on multiple rows
if (pips != null) 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<IPips>())
{ {
const int pipSize = 2; // How big are the pips? foreach (var pip in pips.GetPips())
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)), Animation pipImages = new Animation("pips");
pipxy + new float2(i * (pipSize + 1), 0),
pipBorderColor, pipBorderColor); 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);
// Draw pips pipxyOffset +=new float2(4,0);
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);
} }
// Increment row
pipxyOffset.X = 0;
pipxyOffset.Y -= 5;
} }
} }
@@ -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,8 +36,9 @@ 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;
@@ -45,39 +46,38 @@ namespace OpenRa.Game.Traits
} }
} }
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)
{ {
// TODO: Check how many pips to display const int numPips = 5;
if ((1 - remainingChargeTime*1.0f / chargeTime) * GetPipCount() < index + 1) for (int i = 0; i < numPips; i++)
return Color.Transparent; {
if ((1 - remainingChargeTime * 1.0f / chargeTime) * numPips < i + 1)
{
yield return PipType.Transparent;
continue;
}
switch (index) switch (i)
{ {
case 0: case 0:
case 1: case 1:
return Color.Red; yield return PipType.Red;
break;
case 2: case 2:
case 3: case 3:
return Color.Yellow; yield return PipType.Yellow;
break;
case 4: case 4:
return Color.LimeGreen; yield return PipType.Green;
break;
}
} }
return Color.Transparent;
} }
} }
} }

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)
{ {
@@ -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)
{ {
if (gemsCarried * 1.0f / Rules.General.BailCount > index * 1.0f / GetPipCount()) const int numPips = 7;
return Color.Red; 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()) 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,6 +6,7 @@ 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); }
@@ -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" />