Extract auto-selection-size into its own interface.

This commit is contained in:
Paul Chote
2013-02-24 13:11:43 +13:00
parent 000a5eaa56
commit 0703f3f164
3 changed files with 16 additions and 10 deletions

View File

@@ -82,10 +82,7 @@ namespace OpenRA
if (si != null && si.Bounds != null)
return new int2(si.Bounds[0], si.Bounds[1]);
// auto size from render
var firstSprite = TraitsImplementing<IRender>().SelectMany(ApplyIRender).FirstOrDefault();
if (firstSprite.Sprite == null) return int2.Zero;
return (firstSprite.Sprite.size * firstSprite.Scale).ToInt2();
return TraitsImplementing<IAutoSelectionSize>().Select(x => x.SelectionSize(this)).FirstOrDefault();
});
if (this.HasTrait<RevealsShroud>())
@@ -95,7 +92,6 @@ namespace OpenRA
range = this.Trait<RevealsShroud>().RevealRange,
vis = Shroud.GetVisOrigins(this).ToArray()
};
}
ApplyIRender = x => x.Render(this);

View File

@@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
namespace OpenRA.Traits
@@ -32,7 +33,7 @@ namespace OpenRA.Traits
}
}
public class RenderSimple : IRender, ITick
public class RenderSimple : IRender, IAutoSelectionSize, ITick
{
public Dictionary<string, AnimationWithOffset> anims = new Dictionary<string, AnimationWithOffset>();
@@ -94,6 +95,14 @@ namespace OpenRA.Traits
}
}
public int2 SelectionSize(Actor self)
{
return anims.Values.Where(b => (b.DisableFunc == null || !b.DisableFunc())
&& b.Animation.CurrentSequence != null)
.Select(a => (a.Animation.Image.size*Info.Scale).ToInt2())
.FirstOrDefault();
}
public virtual void Tick(Actor self)
{
foreach (var a in anims.Values)

View File

@@ -35,6 +35,7 @@ namespace OpenRA.Traits
public interface ITick { void Tick(Actor self); }
public interface IRender { IEnumerable<Renderable> Render(Actor self); }
public interface IAutoSelectionSize { int2 SelectionSize(Actor self); }
public interface IIssueOrder
{