Changed 9p and tatlas' to use a separately loaded texture.
This commit is contained in:
@@ -1,27 +1,15 @@
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Newtonsoft.Json;
|
||||
using RecrownedAthenaeum.Data;
|
||||
using RecrownedAthenaeum.SpecialTypes;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace RecrownedAthenaeum.ContentReaders
|
||||
{
|
||||
class NinePatchDataReader : ContentTypeReader<NinePatch>
|
||||
{
|
||||
public static GraphicsDevice graphicsDevice;
|
||||
|
||||
protected override NinePatch Read(ContentReader input, NinePatch existingInstance)
|
||||
{
|
||||
if (graphicsDevice == null) graphicsDevice = Configuration.GraphicsDeviceManager.GraphicsDevice;
|
||||
Texture2D texture;
|
||||
using (MemoryStream stream = new MemoryStream(input.ReadBytes(input.ReadInt32())))
|
||||
{
|
||||
texture = Texture2D.FromStream(graphicsDevice, stream);
|
||||
}
|
||||
NinePatchData ninePatchData = JsonConvert.DeserializeObject<NinePatchData>(Encoding.ASCII.GetString(input.ReadBytes(input.ReadInt32())));
|
||||
NinePatch ninePatch = new NinePatch(texture, ninePatchData.left, ninePatchData.right, ninePatchData.bottom, ninePatchData.top);
|
||||
Texture2D texture = input.ContentManager.Load<Texture2D>(input.ReadString());
|
||||
NinePatch ninePatch = new NinePatch(texture, input.ReadInt32(), input.ReadInt32(), input.ReadInt32(), input.ReadInt32());
|
||||
return ninePatch;
|
||||
}
|
||||
}
|
||||
|
@@ -1,34 +1,44 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Newtonsoft.Json;
|
||||
using RecrownedAthenaeum.Data;
|
||||
using RecrownedAthenaeum.SpecialTypes;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace RecrownedAthenaeum.ContentReaders
|
||||
{
|
||||
class TextureAtlasDataReader : ContentTypeReader<TextureAtlas>
|
||||
{
|
||||
public static GraphicsDevice graphicsDevice;
|
||||
|
||||
protected override TextureAtlas Read(ContentReader input, TextureAtlas existingInstance)
|
||||
{
|
||||
if (graphicsDevice == null) graphicsDevice = Configuration.GraphicsDeviceManager.GraphicsDevice;
|
||||
TextureAtlasData atlasData;
|
||||
Texture2D atlasTexture;
|
||||
using (MemoryStream stream = new MemoryStream(input.ReadBytes(input.ReadInt32())))
|
||||
{
|
||||
atlasTexture = Texture2D.FromStream(graphicsDevice, stream);
|
||||
}
|
||||
string serialized = Encoding.ASCII.GetString(input.ReadBytes(input.ReadInt32()));
|
||||
atlasData = JsonConvert.DeserializeObject<TextureAtlasData>(serialized);
|
||||
TextureAtlasData atlasData = ReadTextureAtlasData(input);
|
||||
Texture2D atlasTexture = input.ContentManager.Load<Texture2D>(atlasData.textureName);
|
||||
|
||||
TextureAtlas atlas = new TextureAtlas(atlasTexture, GenerateAtlasRegionsFromData(atlasData, atlasTexture));
|
||||
|
||||
return atlas;
|
||||
}
|
||||
|
||||
public TextureAtlasData ReadTextureAtlasData(BinaryReader reader)
|
||||
{
|
||||
string textureName = reader.ReadString();
|
||||
TextureAtlasData.AtlasRegionData[] regions = new TextureAtlasData.AtlasRegionData[reader.ReadInt32()];
|
||||
for (int i = 0; i < regions.Length; i++)
|
||||
{
|
||||
regions[i] = new TextureAtlasData.AtlasRegionData();
|
||||
regions[i].name = reader.ReadString();
|
||||
regions[i].bounds = new Rectangle(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
|
||||
if (reader.ReadBoolean())
|
||||
{
|
||||
regions[i].ninePatchData = new NinePatchData(null, reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
|
||||
}
|
||||
}
|
||||
|
||||
TextureAtlasData atlasData = new TextureAtlasData(textureName, regions);
|
||||
|
||||
return atlasData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates region given <see cref="TextureAtlasData"/>.
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user