2018-12-04 21:46:44 +00:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
using Recrowned_Athenaeum.DataTypes;
|
2018-12-04 13:45:09 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2018-12-04 21:46:44 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml.Serialization;
|
2018-12-04 13:45:09 +00:00
|
|
|
|
|
|
|
|
|
namespace RecrownedAthenaeum.DataTypes
|
|
|
|
|
{
|
|
|
|
|
public class TextureAtlas
|
|
|
|
|
{
|
2018-12-04 21:46:44 +00:00
|
|
|
|
string assetName;
|
2018-12-04 13:45:09 +00:00
|
|
|
|
private TextureAtlasRegion[] textureRegions;
|
|
|
|
|
|
2018-12-04 21:46:44 +00:00
|
|
|
|
[XmlIgnore]
|
|
|
|
|
private Texture2D texture;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
private Dictionary<string, TextureAtlasRegion> dictionaryOfRegions = new Dictionary<string, TextureAtlasRegion>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Should be called after serialization to prepare the data.
|
|
|
|
|
/// More specifically, loads the texture map, as well as load the regions into a dictionary.
|
|
|
|
|
/// <param name="texture">the texture for the atlas.</param>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Initialize(Texture2D texture)
|
2018-12-04 13:45:09 +00:00
|
|
|
|
{
|
2018-12-04 21:46:44 +00:00
|
|
|
|
SetTextureRegions(texture, textureRegions);
|
2018-12-04 13:45:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 21:46:44 +00:00
|
|
|
|
public void SetTextureRegions(Texture2D texture, TextureAtlasRegion[] regions)
|
|
|
|
|
{
|
|
|
|
|
this.texture = texture;
|
|
|
|
|
Array.Sort(regions);
|
|
|
|
|
this.textureRegions = regions;
|
|
|
|
|
dictionaryOfRegions.Clear();
|
|
|
|
|
foreach (TextureAtlasRegion region in textureRegions)
|
|
|
|
|
{
|
|
|
|
|
dictionaryOfRegions.Add(region.name, region);
|
|
|
|
|
}
|
2018-12-04 13:45:09 +00:00
|
|
|
|
|
2018-12-04 21:46:44 +00:00
|
|
|
|
}
|
2018-12-04 13:45:09 +00:00
|
|
|
|
|
2018-12-04 21:46:44 +00:00
|
|
|
|
public void Draw(SpriteBatch batch, Rectangle destinationRectangle, string textureRegionName)
|
|
|
|
|
{
|
|
|
|
|
dictionaryOfRegions[textureRegionName].Draw(batch, destinationRectangle, );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Texture2D TextureOfRegion(string name, GraphicsDevice graphicsDevice)
|
|
|
|
|
{
|
|
|
|
|
return dictionaryOfRegions[name].AsTexture2D(graphicsDevice, texture);
|
|
|
|
|
}
|
2018-12-04 13:45:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|