New pips interface; use pips.shp instead of native drawing
This commit is contained in:
@@ -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<PipType> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<AcceptsOre>() && !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<PipType> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Tuple<Sprite, float2, int>> Render(Actor self); }
|
||||
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 ); }
|
||||
interface IDamageModifier { float GetDamageModifier(); }
|
||||
interface ISpeedModifier { float GetSpeedModifier(); }
|
||||
interface IPips {
|
||||
Color GetBorderColor();
|
||||
int GetPipCount();
|
||||
Color GetColorForPip(int index);
|
||||
}
|
||||
interface IPips { IEnumerable<PipType> GetPips(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user