using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace MrAG { public partial class Gui { public class ImageBoxAnimated : Base { public Color BorderColor = Color.Black; public Color ImageColor = Color.White; public Texture2D Texture; public int BorderSize; public bool Playing = true; public bool FlipTextureH = false; public bool FlipTextureV = false; Dictionary> FrameList = new Dictionary>(); int speed; int curcolom; string curframe = ""; double lastanichange; public void SetFrameData(Dictionary> data, int speed, string animation) { this.FrameList = data; this.speed = speed; this.curframe = animation; this.curcolom = 0; } public void SetAnimationSpeed(int interval) { this.speed = interval; lastanichange = DateTime.Now.TimeOfDay.TotalMilliseconds; } public void SetAnimation(string name) { if (!this.FrameList.ContainsKey(name)) return; this.curframe = name; if (curcolom > this.FrameList[curframe].Count - 1) { curcolom = 0; } } public void AddAnimation(string name, Vector2 offset) { if (!this.FrameList.ContainsKey(name)) this.FrameList[name] = new List(); this.FrameList[name].Add(offset); } public override void Update() { base.Update(); if (!this.Playing) return; if (this.curframe == "") return; double curtime = DateTime.Now.TimeOfDay.TotalMilliseconds; if (Math.Abs(curtime - lastanichange) > speed) { lastanichange = curtime; curcolom++; if (curcolom > this.FrameList[curframe].Count - 1) { curcolom = 0; } } } public override void Draw() { if (this.curframe == "") return; MrAG.Draw.SpriteBatch.Draw(this.Texture, new Vector2(this.X + this.BorderSize, this.Y + this.BorderSize), new Rectangle((int)this.FrameList[this.curframe][this.curcolom].X, (int)this.FrameList[this.curframe][this.curcolom].Y, this.Width - (this.BorderSize * 2), this.Height - (this.BorderSize * 2)), this.ImageColor, 0, new Vector2(0, 0), 1, this.FlipTextureH ? SpriteEffects.FlipHorizontally : this.FlipTextureV ? SpriteEffects.FlipVertically : SpriteEffects.None, 1); MrAG.Draw.OutlinedBox(this.X, this.Y, this.Width, this.Height, this.BorderSize, this.BorderColor); base.Draw(); } } } }