New pips interface; use pips.shp instead of native drawing
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Drawing;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using IjwFramework.Types;
|
||||
@@ -145,42 +146,43 @@ namespace OpenRa.Game.Graphics
|
||||
z + new float2(0, -4),
|
||||
healthColor2, healthColor2);
|
||||
|
||||
|
||||
// Render Pips
|
||||
var pips = selectedUnit.traits.WithInterface<IPips>().FirstOrDefault();
|
||||
if (pips != null)
|
||||
// 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<IPips>())
|
||||
{
|
||||
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++)
|
||||
foreach (var pip in pips.GetPips())
|
||||
{
|
||||
lineRenderer.DrawLine(pipxy + new float2(i * (pipSize + 1), -(pipSize + 1)),
|
||||
pipxy + new float2(i * (pipSize + 1), 0),
|
||||
pipBorderColor, pipBorderColor);
|
||||
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();
|
||||
}
|
||||
|
||||
// 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);
|
||||
spriteRenderer.DrawSprite(pipImages.Image, pipxyBase+pipxyOffset, 0);
|
||||
pipxyOffset +=new float2(4,0);
|
||||
}
|
||||
// Increment row
|
||||
pipxyOffset.X = 0;
|
||||
pipxyOffset.Y -= 5;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,6 +204,7 @@ namespace OpenRa.Game.Graphics
|
||||
}
|
||||
}
|
||||
}
|
||||
spriteRenderer.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,8 +36,9 @@ 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;
|
||||
@@ -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()
|
||||
{
|
||||
return chronoshiftActive ? 0f : 1f;
|
||||
}
|
||||
|
||||
public Color GetBorderColor() { return Color.Black; }
|
||||
public int GetPipCount() { return 5; }
|
||||
public Color GetColorForPip(int index)
|
||||
// Display 5 pips indicating the current charge status
|
||||
public IEnumerable<PipType> GetPips()
|
||||
{
|
||||
// TODO: Check how many pips to display
|
||||
if ((1 - remainingChargeTime*1.0f / chargeTime) * GetPipCount() < index + 1)
|
||||
return Color.Transparent;
|
||||
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 (index)
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
return Color.Red;
|
||||
yield return PipType.Red;
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
return Color.Yellow;
|
||||
yield return PipType.Yellow;
|
||||
break;
|
||||
case 4:
|
||||
return Color.LimeGreen;
|
||||
}
|
||||
|
||||
return Color.Transparent;
|
||||
yield return PipType.Green;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Drawing;
|
||||
using System.Collections.Generic;
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
class Harvester : IOrder, IPips
|
||||
@@ -55,17 +55,24 @@ namespace OpenRa.Game.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public Color GetBorderColor() { return Color.Black; }
|
||||
public int GetPipCount() { return 10; }
|
||||
public Color GetColorForPip(int index)
|
||||
public IEnumerable<PipType> GetPips()
|
||||
{
|
||||
if (gemsCarried * 1.0f / Rules.General.BailCount > index * 1.0f / GetPipCount())
|
||||
return Color.Red;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ 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<Tuple<Sprite, float2, int>> Render(Actor self); }
|
||||
@@ -23,9 +24,5 @@ namespace OpenRa.Game.Traits
|
||||
ModifyRender( Actor self, IEnumerable<Tuple<Sprite, float2, int>> r ); }
|
||||
interface IDamageModifier { float GetDamageModifier(); }
|
||||
interface ISpeedModifier { float GetSpeedModifier(); }
|
||||
interface IPips {
|
||||
Color GetBorderColor();
|
||||
int GetPipCount();
|
||||
Color GetColorForPip(int index);
|
||||
}
|
||||
interface IPips { IEnumerable<PipType> GetPips(); }
|
||||
}
|
||||
|
||||
@@ -530,11 +530,14 @@
|
||||
</unit>
|
||||
<unit name="pips">
|
||||
<sequence name="groups" start="8" length="10" />
|
||||
<sequence name="ore" start="0" length="2" />
|
||||
<sequence name="cargo" start="5" length="3" />
|
||||
<sequence name="pip-green" start="1" length="1" />
|
||||
<sequence name="pip-empty" start="0" length="1" />
|
||||
<sequence name="medic" start="20" length="1" />
|
||||
<sequence name="ready" start="3" 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 name="mig">
|
||||
<sequence name="idle" start="0" length="16" />
|
||||
|
||||
Reference in New Issue
Block a user