Draw editor selection box using the UI renderers.

This commit is contained in:
Paul Chote
2019-12-07 11:36:27 +00:00
committed by teinarss
parent 2918ecadaa
commit 630ca0aefb
2 changed files with 19 additions and 2 deletions

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new EditorActorLayer(init.Self, this); } public object Create(ActorInitializer init) { return new EditorActorLayer(init.Self, this); }
} }
public class EditorActorLayer : IWorldLoaded, ITickRender, IRender, IRadarSignature, ICreatePlayers public class EditorActorLayer : IWorldLoaded, ITickRender, IRender, IRadarSignature, ICreatePlayers, IRenderAnnotations
{ {
readonly EditorActorLayerInfo info; readonly EditorActorLayerInfo info;
readonly List<EditorActorPreview> previews = new List<EditorActorPreview>(); readonly List<EditorActorPreview> previews = new List<EditorActorPreview>();
@@ -103,6 +103,17 @@ namespace OpenRA.Mods.Common.Traits
yield break; yield break;
} }
public IEnumerable<IRenderable> RenderAnnotations(Actor self, WorldRenderer wr)
{
if (wr.World.Type != WorldType.Editor)
return NoRenderables;
return PreviewsInBox(wr.Viewport.TopLeft, wr.Viewport.BottomRight)
.SelectMany(p => p.RenderAnnotations());
}
bool IRenderAnnotations.SpatiallyPartitionable { get { return false; } }
public EditorActorPreview Add(ActorReference reference) { return Add(NextActorName(), reference); } public EditorActorPreview Add(ActorReference reference) { return Add(NextActorName(), reference); }
public EditorActorPreview Add(string id, ActorReference reference, bool initialSetup = false) public EditorActorPreview Add(string id, ActorReference reference, bool initialSetup = false)

View File

@@ -112,12 +112,18 @@ namespace OpenRA.Mods.Common.Traits
var highlight = worldRenderer.Palette("highlight"); var highlight = worldRenderer.Palette("highlight");
var overlay = items.Where(r => !r.IsDecoration) var overlay = items.Where(r => !r.IsDecoration)
.Select(r => r.WithPalette(highlight)); .Select(r => r.WithPalette(highlight));
return items.Concat(overlay).Append(SelectionBox); return items.Concat(overlay);
} }
return items; return items;
} }
public IEnumerable<IRenderable> RenderAnnotations()
{
if (Selected)
yield return SelectionBox;
}
public void ReplaceInit<T>(T init) public void ReplaceInit<T>(T init)
{ {
var original = Actor.InitDict.GetOrDefault<T>(); var original = Actor.InitDict.GetOrDefault<T>();