2018-03-04 23:53:55 +08:00
|
|
|
|
using CustomNPCFramework.Framework.Enums;
|
2018-03-05 06:32:59 +08:00
|
|
|
|
using CustomNPCFramework.Framework.Graphics.TextureGroups;
|
2018-03-04 23:53:55 +08:00
|
|
|
|
using Microsoft.Xna.Framework;
|
2018-02-24 11:10:56 +08:00
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2018-05-01 09:21:31 +08:00
|
|
|
|
using StardustCore.UIUtilities;
|
2018-02-24 11:10:56 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace CustomNPCFramework.Framework.Graphics
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used to handle loading different textures and handling opperations on those textures.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class AssetSheet
|
|
|
|
|
{
|
2018-03-19 18:32:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used to hold the textures for the AssetSheet.
|
|
|
|
|
/// </summary>
|
2018-03-05 05:23:40 +08:00
|
|
|
|
public TextureGroups.TextureGroup textures;
|
2018-03-04 23:53:55 +08:00
|
|
|
|
|
2018-03-19 18:32:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used to hold the info for the paths to these textures.
|
|
|
|
|
/// </summary>
|
2018-02-24 11:10:56 +08:00
|
|
|
|
public AssetInfo assetInfo;
|
2018-03-19 18:32:00 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The path to this assetinfo.json file
|
|
|
|
|
/// </summary>
|
2018-02-24 11:10:56 +08:00
|
|
|
|
public string path;
|
|
|
|
|
|
2018-03-19 18:32:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The soruce rectangle for the current texture to draw.
|
|
|
|
|
/// </summary>
|
2018-02-24 11:10:56 +08:00
|
|
|
|
public Rectangle currentAsset;
|
|
|
|
|
|
2018-03-19 18:32:00 +08:00
|
|
|
|
public int index;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info">The asset info file to be read in or created. Holds path information.</param>
|
|
|
|
|
/// <param name="path">The path to the assetinfo file.</param>
|
|
|
|
|
/// <param name="direction">The direction to set the animation.</param>
|
2018-03-04 23:53:55 +08:00
|
|
|
|
public AssetSheet(AssetInfo info,string path,Direction direction=Direction.down)
|
2018-02-24 11:10:56 +08:00
|
|
|
|
{
|
|
|
|
|
this.assetInfo = info;
|
2018-03-05 06:32:59 +08:00
|
|
|
|
this.textures = new TextureGroup(info,path,direction);
|
2018-03-17 19:04:04 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
this.path = Class1.getShortenedDirectory(path);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception err)
|
|
|
|
|
{
|
|
|
|
|
this.path = path;
|
|
|
|
|
}
|
2018-03-19 18:32:00 +08:00
|
|
|
|
|
2018-02-24 11:10:56 +08:00
|
|
|
|
this.index = 0;
|
|
|
|
|
}
|
2018-03-19 18:32:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get the path to the current texture.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2018-05-01 09:21:31 +08:00
|
|
|
|
public virtual KeyValuePair<string, Texture2DExtended> getPathTexturePair()
|
2018-03-04 20:36:46 +08:00
|
|
|
|
{
|
2018-05-01 09:21:31 +08:00
|
|
|
|
return new KeyValuePair<string, Texture2DExtended>(this.path, this.textures.currentTexture.currentTexture);
|
2018-03-04 20:36:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-24 11:10:56 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-03-04 23:53:55 +08:00
|
|
|
|
/// Used just to get a copy of this asset sheet.
|
2018-02-24 11:10:56 +08:00
|
|
|
|
/// </summary>
|
2018-03-05 05:23:40 +08:00
|
|
|
|
public virtual AssetSheet clone()
|
2018-02-24 11:10:56 +08:00
|
|
|
|
{
|
2018-03-04 23:53:55 +08:00
|
|
|
|
var asset = new AssetSheet(this.assetInfo,(string)this.path.Clone());
|
|
|
|
|
return asset;
|
2018-02-24 11:10:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-19 18:32:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the textures for this sheet to face left.
|
|
|
|
|
/// </summary>
|
2018-03-05 05:23:40 +08:00
|
|
|
|
public virtual void setLeft()
|
|
|
|
|
{
|
|
|
|
|
this.textures.setLeft();
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-19 18:32:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the textures for this sheet to face up.
|
|
|
|
|
/// </summary>
|
2018-03-05 05:23:40 +08:00
|
|
|
|
public virtual void setUp()
|
|
|
|
|
{
|
|
|
|
|
this.textures.setUp();
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-19 18:32:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the textures for this sheet to face down.
|
|
|
|
|
/// </summary>
|
2018-03-05 05:23:40 +08:00
|
|
|
|
public virtual void setDown()
|
2018-02-24 11:10:56 +08:00
|
|
|
|
{
|
2018-03-05 05:23:40 +08:00
|
|
|
|
this.textures.setDown();
|
2018-02-24 11:10:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-19 18:32:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the textures for this sheet to face left.
|
|
|
|
|
/// </summary>
|
2018-03-05 05:23:40 +08:00
|
|
|
|
public virtual void setRight()
|
2018-02-24 11:10:56 +08:00
|
|
|
|
{
|
2018-03-05 05:23:40 +08:00
|
|
|
|
this.textures.setRight();
|
2018-02-24 11:10:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-19 18:32:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get the current animation texture.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2018-05-01 09:21:31 +08:00
|
|
|
|
public virtual Texture2DExtended getCurrentSpriteTexture()
|
2018-02-24 11:10:56 +08:00
|
|
|
|
{
|
2018-03-05 05:23:40 +08:00
|
|
|
|
return this.textures.currentTexture.currentTexture;
|
2018-02-24 11:10:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-19 18:32:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get the specific texture depending on the direction and animation type.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="direction"></param>
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
/// <returns></returns>
|
2018-05-01 09:21:31 +08:00
|
|
|
|
public virtual Texture2DExtended getTexture(Direction direction,AnimationType type)
|
2018-02-24 11:10:56 +08:00
|
|
|
|
{
|
2018-03-05 05:23:40 +08:00
|
|
|
|
return this.textures.getTextureFromAnimation(type).getTextureFromDirection(direction);
|
2018-02-24 11:10:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|