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

@@ -16,11 +16,11 @@ namespace OpenRA.Graphics
{
public class SpriteLoader
{
public SpriteLoader( string[] exts, SheetBuilder sheetBuilder )
public SpriteLoader(string[] exts, SheetBuilder sheetBuilder)
{
SheetBuilder = sheetBuilder;
this.exts = exts;
sprites = new Cache<string, Sprite[]>( LoadSprites );
sprites = new Cache<string, Sprite[]>(LoadSprites);
}
readonly SheetBuilder SheetBuilder;

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();
}
}
}

View File

@@ -24,10 +24,15 @@ namespace OpenRA.Widgets
public float MinimumValue = 0;
public float MaximumValue = 1;
public float Value = 0;
public Func<float> GetValue;
protected bool isMoving = false;
public SliderWidget() : base() {}
public SliderWidget()
: base()
{
GetValue = () => Value;
}
public SliderWidget(SliderWidget other)
: base(other)
@@ -38,6 +43,7 @@ namespace OpenRA.Widgets
MaximumValue = other.MaximumValue;
Value = other.Value;
TrackHeight = other.TrackHeight;
GetValue = other.GetValue;
}
void UpdateValue(float newValue)
@@ -53,7 +59,7 @@ namespace OpenRA.Widgets
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi)) return false;
if (!Focused) return false;
switch( mi.Event )
switch(mi.Event)
{
case MouseInputEvent.Up:
isMoving = false;
@@ -99,6 +105,8 @@ namespace OpenRA.Widgets
if (!IsVisible())
return;
Value = GetValue();
var tr = ThumbRect;
var rb = RenderBounds;
var trackWidth = rb.Width;