added in-game SHP viewer with frame slider

This commit is contained in:
Matthias Mailänder
2013-05-15 18:13:33 +02:00
parent ce021a4f62
commit 881fcf1191
10 changed files with 408 additions and 25 deletions

View File

@@ -18,6 +18,7 @@ namespace OpenRA.Widgets
public string Image = "";
public int Frame = 0;
public string Palette = "chrome";
public bool LoopAnimation = false;
public Func<string> GetImage;
public Func<int> GetFrame;
@@ -26,12 +27,13 @@ namespace OpenRA.Widgets
readonly WorldRenderer worldRenderer;
[ObjectCreator.UseCtor]
public ShpImageWidget( WorldRenderer worldRenderer)
public ShpImageWidget(WorldRenderer worldRenderer)
: base()
{
GetImage = () => { return Image; };
GetFrame = () => { return Frame; };
GetPalette = () => { return Palette; };
this.worldRenderer = worldRenderer;
}
@@ -41,9 +43,12 @@ namespace OpenRA.Widgets
Image = other.Image;
Frame = other.Frame;
Palette = other.Palette;
LoopAnimation = other.LoopAnimation;
GetImage = other.GetImage;
GetFrame = other.GetFrame;
GetPalette = other.GetPalette;
worldRenderer = other.worldRenderer;
}
@@ -68,5 +73,32 @@ namespace OpenRA.Widgets
Game.Renderer.SpriteRenderer.DrawSprite(sprite, RenderOrigin, worldRenderer, palette);
}
public int FrameCount
{
get { return Game.modData.SpriteLoader.LoadAllSprites(Image).Length-1; }
}
public void RenderNextFrame()
{
if (Frame < FrameCount)
Frame++;
else
Frame = 0;
}
public void RenderPreviousFrame()
{
if (Frame > 0)
Frame--;
else
Frame = FrameCount;
}
public override void Tick()
{
if (LoopAnimation)
RenderNextFrame();
}
}
}