2018-12-30 18:00:05 +08:00
|
|
|
using CustomNPCFramework.Framework.Graphics;
|
2018-05-01 09:21:31 +08:00
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2018-02-24 17:04:35 +08:00
|
|
|
using StardewValley;
|
2018-05-01 09:21:31 +08:00
|
|
|
using StardustCore.UIUtilities;
|
2018-02-24 17:04:35 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
namespace CustomNPCFramework.Framework.ModularNpcs
|
2018-02-24 17:04:35 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Used as a wrapper for the AnimatedSprite class.</summary>
|
2018-02-24 17:04:35 +08:00
|
|
|
public class AnimatedSpriteExtended
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>The actual sprite of the object.</summary>
|
2018-02-24 17:04:35 +08:00
|
|
|
public AnimatedSprite sprite;
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>The path to the texture to load the sprite from.</summary>
|
|
|
|
public string path;
|
2018-02-24 17:04:35 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Construct an instance.</summary>
|
|
|
|
public AnimatedSpriteExtended(Texture2DExtended texture, AssetSheet assetSheet)
|
2018-02-24 17:04:35 +08:00
|
|
|
{
|
2018-05-01 09:21:31 +08:00
|
|
|
//Set the sprite texture
|
|
|
|
this.sprite = new AnimatedSprite();
|
2019-01-06 11:15:21 +08:00
|
|
|
Texture2D load = texture.Copy().Texture;
|
2018-05-01 09:21:31 +08:00
|
|
|
var thing = Class1.ModHelper.Reflection.GetField<Texture2D>(this.sprite, "Texture", true);
|
|
|
|
thing.SetValue(load);
|
|
|
|
|
|
|
|
this.path = assetSheet.path.Clone().ToString();
|
|
|
|
this.sprite.currentFrame = assetSheet.index;
|
|
|
|
|
|
|
|
this.sprite.SpriteWidth = (int)assetSheet.assetInfo.assetSize.X;
|
|
|
|
this.sprite.SpriteHeight = (int)assetSheet.assetInfo.assetSize.Y;
|
2018-02-24 17:04:35 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Construct an instance.</summary>
|
|
|
|
public AnimatedSpriteExtended(string path, int currentFrame, int spriteWidth, int spriteHeight)
|
2018-03-04 23:53:55 +08:00
|
|
|
{
|
|
|
|
this.path = Class1.getRelativeDirectory(path);
|
2018-05-01 09:21:31 +08:00
|
|
|
|
|
|
|
//Set the sprite texture
|
|
|
|
this.sprite = new AnimatedSprite();
|
|
|
|
Texture2D load = Class1.ModHelper.Content.Load<Texture2D>(this.path);
|
2018-12-30 18:00:05 +08:00
|
|
|
var thing = Class1.ModHelper.Reflection.GetField<Texture2D>(this.sprite, "Texture", true);
|
2018-05-01 09:21:31 +08:00
|
|
|
thing.SetValue(load);
|
|
|
|
|
|
|
|
//Set the fields.
|
|
|
|
this.sprite.currentFrame = currentFrame;
|
|
|
|
this.sprite.SpriteWidth = spriteWidth;
|
|
|
|
this.sprite.SpriteHeight = spriteHeight;
|
|
|
|
|
|
|
|
//this.sprite = new AnimatedSprite(texture, currentFrame, spriteWidth, spriteHeight);
|
2018-03-04 23:53:55 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Reloads the asset from disk.</summary>
|
2018-02-24 17:04:35 +08:00
|
|
|
public void reload()
|
|
|
|
{
|
2018-05-01 09:21:31 +08:00
|
|
|
//Set the sprite texture
|
|
|
|
Texture2D load = Class1.ModHelper.Content.Load<Texture2D>(this.path);
|
|
|
|
var thing = Class1.ModHelper.Reflection.GetField<Texture2D>(this.sprite, "Texture", true);
|
|
|
|
thing.SetValue(load);
|
2018-02-24 17:04:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|