Merge pull request #11567 from Mailaender/lint-pips-groups
Documented and exposed the control group sprites to lint testing
This commit is contained in:
@@ -34,23 +34,32 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
public readonly Color SelectionBoxColor = Color.White;
|
public readonly Color SelectionBoxColor = Color.White;
|
||||||
|
|
||||||
|
public readonly string Image = "pips";
|
||||||
|
|
||||||
|
[Desc("Sprite sequence used to render the control group 0-9 numbers.")]
|
||||||
|
[SequenceReference("Image")] public readonly string GroupSequence = "groups";
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new SelectionDecorations(init.Self, this); }
|
public object Create(ActorInitializer init) { return new SelectionDecorations(init.Self, this); }
|
||||||
|
|
||||||
public int[] SelectionBoxBounds { get { return VisualBounds; } }
|
public int[] SelectionBoxBounds { get { return VisualBounds; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SelectionDecorations : IPostRenderSelection
|
public class SelectionDecorations : IPostRenderSelection, ITick
|
||||||
{
|
{
|
||||||
// depends on the order of pips in TraitsInterfaces.cs!
|
// depends on the order of pips in TraitsInterfaces.cs!
|
||||||
static readonly string[] PipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray", "pip-blue", "pip-ammo", "pip-ammoempty" };
|
static readonly string[] PipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray", "pip-blue", "pip-ammo", "pip-ammoempty" };
|
||||||
|
|
||||||
public readonly SelectionDecorationsInfo Info;
|
public readonly SelectionDecorationsInfo Info;
|
||||||
|
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
|
readonly Animation pipImages;
|
||||||
|
|
||||||
public SelectionDecorations(Actor self, SelectionDecorationsInfo info)
|
public SelectionDecorations(Actor self, SelectionDecorationsInfo info)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
Info = info;
|
Info = info;
|
||||||
|
|
||||||
|
pipImages = new Animation(self.World, Info.Image);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<WPos> ActivityTargetPath()
|
IEnumerable<WPos> ActivityTargetPath()
|
||||||
@@ -90,42 +99,38 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
var pos = wr.ScreenPxPosition(self.CenterPosition);
|
var pos = wr.ScreenPxPosition(self.CenterPosition);
|
||||||
var tl = wr.Viewport.WorldToViewPx(pos + new int2(b.Left, b.Top));
|
var tl = wr.Viewport.WorldToViewPx(pos + new int2(b.Left, b.Top));
|
||||||
var bl = wr.Viewport.WorldToViewPx(pos + new int2(b.Left, b.Bottom));
|
var bl = wr.Viewport.WorldToViewPx(pos + new int2(b.Left, b.Bottom));
|
||||||
|
var pal = wr.Palette(Info.Palette);
|
||||||
|
|
||||||
foreach (var r in DrawControlGroup(wr, self, tl))
|
foreach (var r in DrawControlGroup(wr, self, tl, pal))
|
||||||
yield return r;
|
yield return r;
|
||||||
|
|
||||||
foreach (var r in DrawPips(wr, self, bl))
|
foreach (var r in DrawPips(wr, self, bl, pal))
|
||||||
yield return r;
|
yield return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<IRenderable> DrawControlGroup(WorldRenderer wr, Actor self, int2 basePosition)
|
IEnumerable<IRenderable> DrawControlGroup(WorldRenderer wr, Actor self, int2 basePosition, PaletteReference palette)
|
||||||
{
|
{
|
||||||
var group = self.World.Selection.GetControlGroupForActor(self);
|
var group = self.World.Selection.GetControlGroupForActor(self);
|
||||||
if (group == null)
|
if (group == null)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
var pipImages = new Animation(self.World, "pips");
|
pipImages.PlayFetchIndex(Info.GroupSequence, () => (int)group);
|
||||||
var pal = wr.Palette(Info.Palette);
|
|
||||||
pipImages.PlayFetchIndex("groups", () => (int)group);
|
|
||||||
pipImages.Tick();
|
|
||||||
|
|
||||||
var pos = basePosition - (0.5f * pipImages.Image.Size.XY).ToInt2() + new int2(9, 5);
|
var pos = basePosition - (0.5f * pipImages.Image.Size.XY).ToInt2() + new int2(9, 5);
|
||||||
yield return new UISpriteRenderable(pipImages.Image, self.CenterPosition, pos, 0, pal, 1f);
|
yield return new UISpriteRenderable(pipImages.Image, self.CenterPosition, pos, 0, palette, 1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<IRenderable> DrawPips(WorldRenderer wr, Actor self, int2 basePosition)
|
IEnumerable<IRenderable> DrawPips(WorldRenderer wr, Actor self, int2 basePosition, PaletteReference palette)
|
||||||
{
|
{
|
||||||
var pipSources = self.TraitsImplementing<IPips>();
|
var pipSources = self.TraitsImplementing<IPips>();
|
||||||
if (!pipSources.Any())
|
if (!pipSources.Any())
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
var pipImages = new Animation(self.World, "pips");
|
|
||||||
pipImages.PlayRepeating(PipStrings[0]);
|
pipImages.PlayRepeating(PipStrings[0]);
|
||||||
|
|
||||||
var pipSize = pipImages.Image.Size.XY.ToInt2();
|
var pipSize = pipImages.Image.Size.XY.ToInt2();
|
||||||
var pipxyBase = basePosition + new int2(1 - pipSize.X / 2, -(3 + pipSize.Y / 2));
|
var pipxyBase = basePosition + new int2(1 - pipSize.X / 2, -(3 + pipSize.Y / 2));
|
||||||
var pipxyOffset = new int2(0, 0);
|
var pipxyOffset = new int2(0, 0);
|
||||||
var pal = wr.Palette(Info.Palette);
|
|
||||||
var width = self.VisualBounds.Width;
|
var width = self.VisualBounds.Width;
|
||||||
|
|
||||||
foreach (var pips in pipSources)
|
foreach (var pips in pipSources)
|
||||||
@@ -142,12 +147,17 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
pipImages.PlayRepeating(PipStrings[(int)pip]);
|
pipImages.PlayRepeating(PipStrings[(int)pip]);
|
||||||
pipxyOffset += new int2(pipSize.X, 0);
|
pipxyOffset += new int2(pipSize.X, 0);
|
||||||
|
|
||||||
yield return new UISpriteRenderable(pipImages.Image, self.CenterPosition, pipxyBase + pipxyOffset, 0, pal, 1f);
|
yield return new UISpriteRenderable(pipImages.Image, self.CenterPosition, pipxyBase + pipxyOffset, 0, palette, 1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increment row
|
// Increment row
|
||||||
pipxyOffset = new int2(0, pipxyOffset.Y - (pipSize.Y + 1));
|
pipxyOffset = new int2(0, pipxyOffset.Y - (pipSize.Y + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ITick.Tick(Actor self)
|
||||||
|
{
|
||||||
|
pipImages.Tick();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user