Add a basic actor properties panel to the editor.

This commit is contained in:
David Wilson
2018-11-24 09:54:47 +00:00
committed by Paul Chote
parent 9b4db3468b
commit 22bece2dc9
8 changed files with 440 additions and 16 deletions

View File

@@ -23,18 +23,30 @@ namespace OpenRA.Mods.Common.Traits
{
public class EditorActorPreview
{
public readonly string Tooltip;
public readonly string ID;
public readonly string DescriptiveName;
public readonly ActorInfo Info;
public readonly PlayerReference Owner;
public readonly WPos CenterPosition;
public readonly IReadOnlyDictionary<CPos, SubCell> Footprint;
public readonly Rectangle Bounds;
public readonly SelectionBoxRenderable SelectionBox;
public string Tooltip
{
get
{
return (tooltip == null ? " < " + Info.Name + " >" : tooltip.Name) + "\n" + Owner.Name + " (" + Owner.Faction + ")"
+ "\nID: " + ID + "\nType: " + Info.Name;
}
}
public string ID { get; set; }
public PlayerReference Owner { get; set; }
public SubCell SubCell { get; private set; }
public bool Selected { get; set; }
readonly ActorReference actor;
readonly WorldRenderer worldRenderer;
readonly TooltipInfoBase tooltip;
IActorPreview[] previews;
public EditorActorPreview(WorldRenderer worldRenderer, string id, ActorReference actor, PlayerReference owner)
@@ -70,11 +82,10 @@ namespace OpenRA.Mods.Common.Traits
Footprint = new ReadOnlyDictionary<CPos, SubCell>(footprint);
}
var tooltip = Info.TraitInfos<EditorOnlyTooltipInfo>().FirstOrDefault(info => info.EnabledByDefault) as TooltipInfoBase
tooltip = Info.TraitInfos<EditorOnlyTooltipInfo>().FirstOrDefault(info => info.EnabledByDefault) as TooltipInfoBase
?? Info.TraitInfos<TooltipInfo>().FirstOrDefault(info => info.EnabledByDefault);
Tooltip = (tooltip == null ? " < " + Info.Name + " >" : tooltip.Name) + "\n" + owner.Name + " (" + owner.Faction + ")"
+ "\nID: " + ID + "\nType: " + Info.Name;
DescriptiveName = tooltip != null ? tooltip.Name : Info.Name;
GeneratePreviews();
@@ -88,6 +99,9 @@ namespace OpenRA.Mods.Common.Traits
foreach (var rr in r.Skip(1))
Bounds = Rectangle.Union(Bounds, rr);
}
SelectionBox = new SelectionBoxRenderable(new WPos(CenterPosition.X, CenterPosition.Y, 8192),
new Rectangle(Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height), Color.White);
}
public void Tick()
@@ -98,7 +112,16 @@ namespace OpenRA.Mods.Common.Traits
public IEnumerable<IRenderable> Render()
{
return previews.SelectMany(p => p.Render(worldRenderer, CenterPosition));
var items = previews.SelectMany(p => p.Render(worldRenderer, CenterPosition));
if (Selected)
{
var highlight = worldRenderer.Palette("highlight");
var overlay = items.Where(r => !r.IsDecoration)
.Select(r => r.WithPalette(highlight));
return items.Concat(overlay).Append(SelectionBox);
}
return items;
}
public void ReplaceInit<T>(T init)