Refactor Traits.fake into a Tags interface for primary production structures +mods
This commit is contained in:
@@ -93,9 +93,6 @@ namespace OpenRa.Game.Graphics
|
|||||||
spriteRenderer.Flush();
|
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)
|
public void DrawSelectionBox(Actor selectedUnit, Color c, bool drawHealthBar)
|
||||||
{
|
{
|
||||||
var center = selectedUnit.CenterLocation;
|
var center = selectedUnit.CenterLocation;
|
||||||
@@ -119,19 +116,14 @@ namespace OpenRa.Game.Graphics
|
|||||||
if (drawHealthBar)
|
if (drawHealthBar)
|
||||||
{
|
{
|
||||||
DrawHealthBar(selectedUnit, xy, Xy);
|
DrawHealthBar(selectedUnit, xy, Xy);
|
||||||
DrawPips(selectedUnit, xY);
|
|
||||||
}
|
// Only display pips and tags to the owner
|
||||||
float2 fakexyBase = new float2(-16, -4);
|
if (selectedUnit.Owner == Game.LocalPlayer)
|
||||||
if (selectedUnit.Owner == Game.LocalPlayer){
|
|
||||||
foreach (var fake in selectedUnit.traits.WithInterface<Fake>())
|
|
||||||
{
|
{
|
||||||
float2 fakexyOffset = xY + new float2(selectedUnit.Bounds.Width/2, 0) + fakexyBase;
|
DrawPips(selectedUnit, xY);
|
||||||
var fakeImage = new Animation("pips");
|
DrawTags(selectedUnit, new float2(center.X, xy.Y));
|
||||||
fakeImage.PlayRepeating("fake");
|
|
||||||
spriteRenderer.DrawSprite(fakeImage.Image, fakexyOffset, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (ShowUnitPaths)
|
if (ShowUnitPaths)
|
||||||
{
|
{
|
||||||
@@ -180,11 +172,14 @@ namespace OpenRa.Game.Graphics
|
|||||||
lineRenderer.DrawLine(xy + new float2(0, -4), z + new float2(0, -4), healthColor2, healthColor2);
|
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
|
// If a mod wants to implement a unit with multiple pip sources, then they are placed on multiple rows
|
||||||
|
var pipxyBase = basePosition + new float2(-12, -7); // Correct for the offset in the shp file
|
||||||
var pipxyBase = xY + 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
|
var pipxyOffset = new float2(0, 0); // Correct for offset due to multiple columns/rows
|
||||||
|
|
||||||
foreach (var pips in selectedUnit.traits.WithInterface<IPips>())
|
foreach (var pips in selectedUnit.traits.WithInterface<IPips>())
|
||||||
@@ -201,5 +196,25 @@ namespace OpenRa.Game.Graphics
|
|||||||
pipxyOffset.Y -= 5;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
using OpenRa.Game.GameRules;
|
using OpenRa.Game.GameRules;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
class Production : IProducer
|
class Production : IProducer, ITags
|
||||||
{
|
{
|
||||||
public Production( Actor self ) { }
|
public Production( Actor self ) { }
|
||||||
|
|
||||||
@@ -50,6 +51,11 @@ namespace OpenRa.Game.Traits
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<TagType> GetTags()
|
||||||
|
{
|
||||||
|
yield return (true) ? TagType.Primary : TagType.None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProductionSurround : Production
|
class ProductionSurround : Production
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ using System.Drawing;
|
|||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
enum DamageState { Normal, Half, Dead };
|
enum DamageState { Normal, Half, Dead };
|
||||||
|
|
||||||
|
// depends on the order of pips in WorldRenderer.cs!
|
||||||
enum PipType { Transparent, Green, Yellow, Red, Gray };
|
enum PipType { Transparent, Green, Yellow, Red, Gray };
|
||||||
|
enum TagType { None, Fake, Primary };
|
||||||
|
|
||||||
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); }
|
||||||
@@ -25,4 +28,5 @@ namespace OpenRa.Game.Traits
|
|||||||
interface IDamageModifier { float GetDamageModifier(); }
|
interface IDamageModifier { float GetDamageModifier(); }
|
||||||
interface ISpeedModifier { float GetSpeedModifier(); }
|
interface ISpeedModifier { float GetSpeedModifier(); }
|
||||||
interface IPips { IEnumerable<PipType> GetPips(); }
|
interface IPips { IEnumerable<PipType> GetPips(); }
|
||||||
|
interface ITags { IEnumerable<TagType> GetTags(); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -530,15 +530,16 @@
|
|||||||
</unit>
|
</unit>
|
||||||
<unit name="pips">
|
<unit name="pips">
|
||||||
<sequence name="groups" start="8" length="10" />
|
<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="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-empty" start="0" length="1" />
|
||||||
|
<sequence name="pip-green" start="1" length="1" />
|
||||||
<sequence name="pip-yellow" start="5" length="1" />
|
<sequence name="pip-yellow" start="5" length="1" />
|
||||||
<sequence name="pip-gray" start="6" length="1" />
|
<sequence name="pip-gray" start="6" length="1" />
|
||||||
<sequence name="pip-red" start="7" 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>
|
||||||
<unit name="mig">
|
<unit name="mig">
|
||||||
<sequence name="idle" start="0" length="16" />
|
<sequence name="idle" start="0" length="16" />
|
||||||
|
|||||||
Reference in New Issue
Block a user