Refactor Traits.fake into a Tags interface for primary production structures +mods

This commit is contained in:
Paul
2009-12-19 19:08:15 -08:00
parent 301873f88e
commit 975624d2f9
5 changed files with 54 additions and 26 deletions

View File

@@ -93,9 +93,6 @@ namespace OpenRa.Game.Graphics
spriteRenderer.Flush();
}
// depends on the order of pips in TraitsInterfaces.cs!
static readonly string[] pipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray" };
public void DrawSelectionBox(Actor selectedUnit, Color c, bool drawHealthBar)
{
var center = selectedUnit.CenterLocation;
@@ -119,20 +116,15 @@ namespace OpenRa.Game.Graphics
if (drawHealthBar)
{
DrawHealthBar(selectedUnit, xy, Xy);
DrawPips(selectedUnit, xY);
}
float2 fakexyBase = new float2(-16, -4);
if (selectedUnit.Owner == Game.LocalPlayer){
foreach (var fake in selectedUnit.traits.WithInterface<Fake>())
// Only display pips and tags to the owner
if (selectedUnit.Owner == Game.LocalPlayer)
{
float2 fakexyOffset = xY + new float2(selectedUnit.Bounds.Width/2, 0) + fakexyBase;
var fakeImage = new Animation("pips");
fakeImage.PlayRepeating("fake");
spriteRenderer.DrawSprite(fakeImage.Image, fakexyOffset, 0);
DrawPips(selectedUnit, xY);
DrawTags(selectedUnit, new float2(center.X, xy.Y));
}
}
if (ShowUnitPaths)
{
var mobile = selectedUnit.traits.GetOrDefault<Mobile>();
@@ -180,11 +172,14 @@ namespace OpenRa.Game.Graphics
lineRenderer.DrawLine(xy + new float2(0, -4), z + new float2(0, -4), healthColor2, healthColor2);
}
void DrawPips(Actor selectedUnit, float2 xY)
// depends on the order of pips in TraitsInterfaces.cs!
static readonly string[] pipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray" };
static readonly string[] tagStrings = { "", "tag-fake", "tag-primary" };
void DrawPips(Actor selectedUnit, float2 basePosition)
{
// If a mod wants to implement a unit with multiple pip sources, then they are placed on multiple rows
var pipxyBase = xY + new float2(-12, -7); // Correct for the offset in the shp file
var pipxyBase = basePosition + new float2(-12, -7); // Correct for the offset in the shp file
var pipxyOffset = new float2(0, 0); // Correct for offset due to multiple columns/rows
foreach (var pips in selectedUnit.traits.WithInterface<IPips>())
@@ -201,5 +196,25 @@ namespace OpenRa.Game.Graphics
pipxyOffset.Y -= 5;
}
}
void DrawTags(Actor selectedUnit, float2 basePosition)
{
// If a mod wants to implement a unit with multiple tags, then they are placed on multiple rows
var tagxyBase = basePosition + new float2(-16, 2); // Correct for the offset in the shp file
var tagxyOffset = new float2(0, 0); // Correct for offset due to multiple rows
foreach (var tags in selectedUnit.traits.WithInterface<ITags>())
{
foreach (var tag in tags.GetTags())
{
var tagImages = new Animation("pips");
tagImages.PlayRepeating(tagStrings[(int)tag]);
spriteRenderer.DrawSprite(tagImages.Image, tagxyBase + tagxyOffset, 0);
// Increment row
tagxyOffset.Y += 8;
}
}
}
}
}

View File

@@ -1,14 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.Traits
{
class Fake
class Fake : ITags
{
public Fake(Actor self){}
public Fake(Actor self){}
public IEnumerable<TagType> GetTags()
{
yield return TagType.Fake;
}
}
}

View File

@@ -1,9 +1,10 @@
using OpenRa.Game.GameRules;
using System.Linq;
using System.Collections.Generic;
namespace OpenRa.Game.Traits
{
class Production : IProducer
class Production : IProducer, ITags
{
public Production( Actor self ) { }
@@ -50,6 +51,11 @@ namespace OpenRa.Game.Traits
return true;
}
public IEnumerable<TagType> GetTags()
{
yield return (true) ? TagType.Primary : TagType.None;
}
}
class ProductionSurround : Production

View File

@@ -6,7 +6,10 @@ using System.Drawing;
namespace OpenRa.Game.Traits
{
enum DamageState { Normal, Half, Dead };
// depends on the order of pips in WorldRenderer.cs!
enum PipType { Transparent, Green, Yellow, Red, Gray };
enum TagType { None, Fake, Primary };
interface ITick { void Tick(Actor self); }
interface IRender { IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self); }
@@ -25,4 +28,5 @@ namespace OpenRa.Game.Traits
interface IDamageModifier { float GetDamageModifier(); }
interface ISpeedModifier { float GetSpeedModifier(); }
interface IPips { IEnumerable<PipType> GetPips(); }
interface ITags { IEnumerable<TagType> GetTags(); }
}

View File

@@ -530,15 +530,16 @@
</unit>
<unit name="pips">
<sequence name="groups" start="8" length="10" />
<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-empty" start="0" length="1" />
<sequence name="pip-green" start="1" 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" />
<sequence name="fake" start="18" length="1" />
<sequence name="tag-fake" start="18" length="1" />
<sequence name="tag-primary" start="2" length="1" />
</unit>
<unit name="mig">
<sequence name="idle" start="0" length="16" />