Moved SelectionDecorations to Mods.Common
And added more settings. Moved SelectionBoxRenderable to Mods.Common, too.
This commit is contained in:
72
OpenRA.Mods.Common/Graphics/SelectionBoxRenderable.cs
Normal file
72
OpenRA.Mods.Common/Graphics/SelectionBoxRenderable.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Graphics
|
||||
{
|
||||
public struct SelectionBoxRenderable : IRenderable, IFinalizedRenderable
|
||||
{
|
||||
readonly WPos pos;
|
||||
readonly float scale;
|
||||
readonly Rectangle visualBounds;
|
||||
readonly Color color;
|
||||
|
||||
public SelectionBoxRenderable(Actor actor, Color color)
|
||||
: this(actor.CenterPosition, actor.VisualBounds, 1f, color) { }
|
||||
|
||||
public SelectionBoxRenderable(WPos pos, Rectangle visualBounds, float scale, Color color)
|
||||
{
|
||||
this.pos = pos;
|
||||
this.visualBounds = visualBounds;
|
||||
this.scale = scale;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public WPos Pos { get { return pos; } }
|
||||
|
||||
public PaletteReference Palette { get { return null; } }
|
||||
public int ZOffset { get { return 0; } }
|
||||
public bool IsDecoration { get { return true; } }
|
||||
|
||||
public IRenderable WithPalette(PaletteReference newPalette) { return this; }
|
||||
public IRenderable WithZOffset(int newOffset) { return this; }
|
||||
public IRenderable OffsetBy(WVec vec) { return new SelectionBoxRenderable(pos + vec, visualBounds, scale, color); }
|
||||
public IRenderable AsDecoration() { return this; }
|
||||
|
||||
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
|
||||
public void Render(WorldRenderer wr)
|
||||
{
|
||||
var screenPos = wr.ScreenPxPosition(pos);
|
||||
var tl = screenPos + scale * new float2(visualBounds.Left, visualBounds.Top);
|
||||
var br = screenPos + scale * new float2(visualBounds.Right, visualBounds.Bottom);
|
||||
var tr = new float2(br.X, tl.Y);
|
||||
var bl = new float2(tl.X, br.Y);
|
||||
var u = new float2(4f / wr.Viewport.Zoom, 0);
|
||||
var v = new float2(0, 4f / wr.Viewport.Zoom);
|
||||
|
||||
var wlr = Game.Renderer.WorldLineRenderer;
|
||||
wlr.DrawLine(tl + u, tl, color);
|
||||
wlr.DrawLine(tl, tl + v, color);
|
||||
wlr.DrawLine(tr, tr - u, color);
|
||||
wlr.DrawLine(tr, tr + v, color);
|
||||
|
||||
wlr.DrawLine(bl, bl + u, color);
|
||||
wlr.DrawLine(bl, bl - v, color);
|
||||
wlr.DrawLine(br, br - u, color);
|
||||
wlr.DrawLine(br, br - v, color);
|
||||
}
|
||||
|
||||
public void RenderDebugGeometry(WorldRenderer wr) { }
|
||||
public Rectangle ScreenBounds(WorldRenderer wr) { return Rectangle.Empty; }
|
||||
}
|
||||
}
|
||||
@@ -171,6 +171,7 @@
|
||||
<Compile Include="Graphics\BeamRenderable.cs" />
|
||||
<Compile Include="Graphics\ContrailRenderable.cs" />
|
||||
<Compile Include="Graphics\RangeCircleRenderable.cs" />
|
||||
<Compile Include="Graphics\SelectionBoxRenderable.cs" />
|
||||
<Compile Include="Graphics\SpriteActorPreview.cs" />
|
||||
<Compile Include="Graphics\TextRenderable.cs" />
|
||||
<Compile Include="Graphics\VoxelActorPreview.cs" />
|
||||
@@ -438,6 +439,7 @@
|
||||
<Compile Include="Traits\RepairsBridges.cs" />
|
||||
<Compile Include="Traits\SeedsResource.cs" />
|
||||
<Compile Include="Traits\StoresResources.cs" />
|
||||
<Compile Include="Traits\SelectionDecorations.cs" />
|
||||
<Compile Include="Traits\SelfHealing.cs" />
|
||||
<Compile Include="Traits\Sellable.cs" />
|
||||
<Compile Include="Traits\ShakeOnDeath.cs" />
|
||||
|
||||
154
OpenRA.Mods.Common/Traits/SelectionDecorations.cs
Normal file
154
OpenRA.Mods.Common/Traits/SelectionDecorations.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class SelectionDecorationsInfo : ITraitInfo, ISelectionDecorationsInfo
|
||||
{
|
||||
public readonly string Palette = "chrome";
|
||||
[Desc("Visual bounds for selection box. If null, it uses AutoSelectionSize.")]
|
||||
public readonly int[] VisualBounds = null;
|
||||
[Desc("Health bar, production progress bar etc.")]
|
||||
public readonly bool RenderSelectionBars = true;
|
||||
public readonly bool RenderSelectionBox = true;
|
||||
public readonly Color SelectionBoxColor = Color.White;
|
||||
|
||||
public object Create(ActorInitializer init) { return new SelectionDecorations(init.Self, this); }
|
||||
|
||||
public int[] SelectionBoxBounds { get { return VisualBounds; } }
|
||||
}
|
||||
|
||||
public class SelectionDecorations : ISelectionDecorations, IPostRenderSelection
|
||||
{
|
||||
// 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[] TagStrings = { "", "tag-fake", "tag-primary" };
|
||||
|
||||
public SelectionDecorationsInfo Info;
|
||||
readonly Actor self;
|
||||
|
||||
public ISelectionDecorationsInfo SelectionDecorationsInfo { get { return Info; } }
|
||||
|
||||
public SelectionDecorations(Actor self, SelectionDecorationsInfo info)
|
||||
{
|
||||
this.self = self;
|
||||
Info = info;
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr)
|
||||
{
|
||||
if (!self.Owner.IsAlliedWith(self.World.RenderPlayer) || self.World.FogObscures(self))
|
||||
yield break;
|
||||
|
||||
if (Info.RenderSelectionBox)
|
||||
yield return new SelectionBoxRenderable(self, Info.SelectionBoxColor);
|
||||
|
||||
if (Info.RenderSelectionBars)
|
||||
yield return new SelectionBarsRenderable(self);
|
||||
|
||||
var b = self.VisualBounds;
|
||||
var pos = wr.ScreenPxPosition(self.CenterPosition);
|
||||
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 tm = wr.Viewport.WorldToViewPx(pos + new int2((b.Left + b.Right) / 2, b.Top));
|
||||
|
||||
foreach (var r in DrawControlGroup(wr, self, tl))
|
||||
yield return r;
|
||||
|
||||
foreach (var r in DrawPips(wr, self, bl))
|
||||
yield return r;
|
||||
|
||||
foreach (var r in DrawTags(wr, self, tm))
|
||||
yield return r;
|
||||
}
|
||||
|
||||
IEnumerable<IRenderable> DrawControlGroup(WorldRenderer wr, Actor self, int2 basePosition)
|
||||
{
|
||||
var group = self.World.Selection.GetControlGroupForActor(self);
|
||||
if (group == null)
|
||||
yield break;
|
||||
|
||||
var pipImages = new Animation(self.World, "pips");
|
||||
var pal = wr.Palette(Info.Palette);
|
||||
pipImages.PlayFetchIndex("groups", () => (int)group);
|
||||
pipImages.Tick();
|
||||
|
||||
var pos = basePosition - (0.5f * pipImages.Image.Size).ToInt2() + new int2(9, 5);
|
||||
yield return new UISpriteRenderable(pipImages.Image, pos, 0, pal, 1f);
|
||||
}
|
||||
|
||||
IEnumerable<IRenderable> DrawPips(WorldRenderer wr, Actor self, int2 basePosition)
|
||||
{
|
||||
var pipSources = self.TraitsImplementing<IPips>();
|
||||
if (!pipSources.Any())
|
||||
yield break;
|
||||
|
||||
var pipImages = new Animation(self.World, "pips");
|
||||
pipImages.PlayRepeating(PipStrings[0]);
|
||||
|
||||
var pipSize = pipImages.Image.Size.ToInt2();
|
||||
var pipxyBase = basePosition + new int2(1 - pipSize.X / 2, -(3 + pipSize.Y / 2));
|
||||
var pipxyOffset = new int2(0, 0);
|
||||
var pal = wr.Palette(Info.Palette);
|
||||
var width = self.VisualBounds.Width;
|
||||
|
||||
foreach (var pips in pipSources)
|
||||
{
|
||||
var thisRow = pips.GetPips(self);
|
||||
if (thisRow == null)
|
||||
continue;
|
||||
|
||||
foreach (var pip in thisRow)
|
||||
{
|
||||
if (pipxyOffset.X + pipSize.X >= width)
|
||||
pipxyOffset = new int2(0, pipxyOffset.Y - pipSize.Y);
|
||||
|
||||
pipImages.PlayRepeating(PipStrings[(int)pip]);
|
||||
pipxyOffset += new int2(pipSize.X, 0);
|
||||
|
||||
yield return new UISpriteRenderable(pipImages.Image, pipxyBase + pipxyOffset, 0, pal, 1f);
|
||||
}
|
||||
|
||||
// Increment row
|
||||
pipxyOffset = new int2(0, pipxyOffset.Y - (pipSize.Y + 1));
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerable<IRenderable> DrawTags(WorldRenderer wr, Actor self, int2 basePosition)
|
||||
{
|
||||
var tagImages = new Animation(self.World, "pips");
|
||||
var pal = wr.Palette(Info.Palette);
|
||||
var tagxyOffset = new int2(0, 6);
|
||||
|
||||
foreach (var tags in self.TraitsImplementing<ITags>())
|
||||
{
|
||||
foreach (var tag in tags.GetTags())
|
||||
{
|
||||
if (tag == TagType.None)
|
||||
continue;
|
||||
|
||||
tagImages.PlayRepeating(TagStrings[(int)tag]);
|
||||
var pos = basePosition + tagxyOffset - (0.5f * tagImages.Image.Size).ToInt2();
|
||||
yield return new UISpriteRenderable(tagImages.Image, pos, 0, pal, 1f);
|
||||
|
||||
// Increment row
|
||||
tagxyOffset = tagxyOffset.WithY(tagxyOffset.Y + 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
Reference in New Issue
Block a user