Rework decoration renderable traits:
- Removed implicit pip definitions and IPips interface. New decoration traits have been added to render them. Pip types are no longer hardcoded in OpenRA.Game. - Decoration rendering is now managed by SelectionDecorations(Base), which allows us to remove assumptions about the selection box geometry from the decoration traits. - RenderNameTag has been replaced by WithNameTagDecoration, which is an otherwise normal decoration trait. - Unify the configuration and reduce duplication between traits. - Removed hardcoded references to specific selection box renderables. - Remove legacy cruft.
This commit is contained in:
@@ -66,6 +66,11 @@ namespace OpenRA.Primitives
|
||||
public int2 Location { get { return new int2(X, Y); } }
|
||||
public Size Size { get { return new Size(Width, Height); } }
|
||||
|
||||
public int2 TopLeft { get { return Location; } }
|
||||
public int2 TopRight { get { return new int2(X + Width, Y); } }
|
||||
public int2 BottomLeft { get { return new int2(X, Y + Height); } }
|
||||
public int2 BottomRight { get { return new int2(X + Width, Y + Height); } }
|
||||
|
||||
public bool Contains(int x, int y)
|
||||
{
|
||||
return x >= Left && x < Right && y >= Top && y < Bottom;
|
||||
|
||||
@@ -66,9 +66,6 @@ namespace OpenRA.Traits
|
||||
void Kill(Actor self, Actor attacker, BitSet<DamageType> damageTypes);
|
||||
}
|
||||
|
||||
// depends on the order of pips in WorldRenderer.cs!
|
||||
public enum PipType { Transparent, Green, Yellow, Red, Gray, Blue, Ammo, AmmoEmpty }
|
||||
|
||||
[Flags]
|
||||
public enum Stance
|
||||
{
|
||||
@@ -128,38 +125,6 @@ namespace OpenRA.Traits
|
||||
public interface IMouseBoundsInfo : ITraitInfoInterface { }
|
||||
public interface IAutoMouseBounds { Rectangle AutoMouseoverBounds(Actor self, WorldRenderer wr); }
|
||||
|
||||
// HACK: This provides a shim for legacy code until it can be rewritten
|
||||
public interface IDecorationBounds { Rectangle DecorationBounds(Actor self, WorldRenderer wr); }
|
||||
public interface IDecorationBoundsInfo : ITraitInfoInterface { }
|
||||
public static class DecorationBoundsExtensions
|
||||
{
|
||||
public static Rectangle FirstNonEmptyBounds(this IEnumerable<IDecorationBounds> decorationBounds, Actor self, WorldRenderer wr)
|
||||
{
|
||||
// PERF: Avoid LINQ.
|
||||
foreach (var decoration in decorationBounds)
|
||||
{
|
||||
var bounds = decoration.DecorationBounds(self, wr);
|
||||
if (!bounds.IsEmpty)
|
||||
return bounds;
|
||||
}
|
||||
|
||||
return Rectangle.Empty;
|
||||
}
|
||||
|
||||
public static Rectangle FirstNonEmptyBounds(this IDecorationBounds[] decorationBounds, Actor self, WorldRenderer wr)
|
||||
{
|
||||
// PERF: Avoid LINQ.
|
||||
foreach (var decoration in decorationBounds)
|
||||
{
|
||||
var bounds = decoration.DecorationBounds(self, wr);
|
||||
if (!bounds.IsEmpty)
|
||||
return bounds;
|
||||
}
|
||||
|
||||
return Rectangle.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IIssueOrder
|
||||
{
|
||||
IEnumerable<IOrderTargeter> Orders { get; }
|
||||
@@ -296,12 +261,15 @@ namespace OpenRA.Traits
|
||||
public interface ILoadsPalettes { void LoadPalettes(WorldRenderer wr); }
|
||||
public interface ILoadsPlayerPalettes { void LoadPlayerPalettes(WorldRenderer wr, string playerName, Color playerColor, bool replaceExisting); }
|
||||
public interface IPaletteModifier { void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> b); }
|
||||
public interface IPips { IEnumerable<PipType> GetPips(Actor self); }
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
public interface ISelectionBar { float GetValue(); Color GetColor(); bool DisplayWhenEmpty { get; } }
|
||||
|
||||
public interface ISelectionDecorations { void DrawRollover(Actor self, WorldRenderer worldRenderer); }
|
||||
public interface ISelectionDecorations
|
||||
{
|
||||
IEnumerable<IRenderable> RenderRolloverAnnotations(Actor self, WorldRenderer worldRenderer);
|
||||
IEnumerable<IRenderable> RenderSelectionAnnotations(Actor self, WorldRenderer worldRenderer, Color color);
|
||||
}
|
||||
|
||||
public interface IMapPreviewSignatureInfo : ITraitInfoInterface
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user