refactoring; removed configuration setup; added consistent sprite batch; got rid of sprite batch settings; implemented newer setup;
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RecrownedAthenaeum.Render;
|
||||
using RecrownedAthenaeum.SpecialTypes;
|
||||
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
||||
|
||||
@@ -24,7 +25,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
||||
/// <param name="destination">The destination to draw to.</param>
|
||||
/// <param name="rotation">The rotation to use in radians.</param>
|
||||
/// <param name="origin">The origin for the rotation.</param>
|
||||
void Draw(string regionName, string color, SpriteBatch batch, Rectangle destination, float rotation = 0, Vector2 origin = default(Vector2));
|
||||
void Draw(string regionName, string color, ConsistentSpriteBatch batch, Rectangle destination, float rotation = 0, Vector2 origin = default(Vector2));
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="Color"/> with given name of defined color;
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RecrownedAthenaeum.Render;
|
||||
using RecrownedAthenaeum.SpecialTypes;
|
||||
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
||||
|
||||
@@ -33,7 +34,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(string regionName, string color, SpriteBatch batch, Rectangle destination, float rotation = 0, Vector2 origin = default(Vector2))
|
||||
public void Draw(string regionName, string color, ConsistentSpriteBatch batch, Rectangle destination, float rotation = 0, Vector2 origin = default(Vector2))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RecrownedAthenaeum.Render;
|
||||
using RecrownedAthenaeum.SpecialTypes;
|
||||
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
||||
using System;
|
||||
@@ -80,7 +81,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
||||
/// <param name="destination">The destination to draw to.</param>
|
||||
/// <param name="rotation">The rotation to use in radians.</param>
|
||||
/// <param name="origin">The origin for the rotation.</param>
|
||||
public void Draw(string regionName, string color, SpriteBatch batch, Rectangle destination, float rotation = 0, Vector2 origin = default(Vector2))
|
||||
public void Draw(string regionName, string color, ConsistentSpriteBatch batch, Rectangle destination, float rotation = 0, Vector2 origin = default(Vector2))
|
||||
{
|
||||
if (disposed) throw new ObjectDisposedException(GetType().Name);
|
||||
textureAtlas.Draw(regionName, batch, destination, colors[color], rotation, origin);
|
||||
|
@@ -71,7 +71,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
||||
public ISkin Skin { get { return mergedSkin; } }
|
||||
|
||||
/// <summary>
|
||||
/// The user loaded skin. Set by the skin loaded by calling <see cref="LoadSkin(SkinData, string, GraphicsDevice)"/>.
|
||||
/// The user loaded skin resulted from asynchronous <see cref="LoadSkin(string, GraphicsDevice)"/>.
|
||||
/// </summary>
|
||||
public ISkin loadedSkin { get { return mergedSkin.mainSkin; } private set { mergedSkin.mainSkin = value; } }
|
||||
|
||||
@@ -111,16 +111,14 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
||||
/// <summary>
|
||||
/// loads a skin asynchronously to the <see cref="loadedSkin"/>.
|
||||
/// </summary>
|
||||
/// <param name="graphicsDevice">Graphics device to use for texture creation. Uses graphics device from <see cref="Configuration"/>by default.</param>
|
||||
/// <param name="skinData">The data to generate from.</param>
|
||||
/// <param name="path">The path pointing to the file with the extension "<see cref="EXTENSION"/>".</param>
|
||||
public void LoadSkin(SkinData skinData, string path, GraphicsDevice graphicsDevice = null)
|
||||
/// <param name="graphicsDevice">Graphics device to use for texture creation.</param>
|
||||
public void LoadSkin(string path, GraphicsDevice graphicsDevice)
|
||||
{
|
||||
if (graphicsDevice == null) graphicsDevice = Configuration.GraphicsDeviceManager.GraphicsDevice;
|
||||
action = Action.LOAD;
|
||||
this.graphicsDevice = graphicsDevice;
|
||||
this.selectedSkinPath = path;
|
||||
this.skinDataToUse = skinData;
|
||||
this.graphicsDevice = graphicsDevice ?? throw new ArgumentNullException("Requires graphics device to create textures.");
|
||||
selectedSkinPath = path ?? throw new ArgumentNullException("Requires path to find textures.");
|
||||
skinDataToUse = ReadSkinData(path);
|
||||
|
||||
AttemptAsync();
|
||||
}
|
||||
@@ -163,14 +161,18 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
||||
}
|
||||
TextureAtlasDataReader tatlasDataReader = new TextureAtlasDataReader();
|
||||
TextureAtlasData atlasData;
|
||||
using (FileStream fileStream = new FileStream(filePath[skinData.nameOfTextureAtlas], FileMode.Open))
|
||||
{
|
||||
atlasData = tatlasDataReader.ReadTextureAtlasData(new BinaryReader(fileStream));
|
||||
}
|
||||
atlasData = JsonConvert.DeserializeObject<TextureAtlasData>(File.ReadAllText(filePath[skinData.nameOfTextureAtlas]));
|
||||
Texture2D atlasTexture;
|
||||
using (FileStream stream = new FileStream(filePath[atlasData.textureName], FileMode.Open))
|
||||
{
|
||||
atlasTexture = Texture2D.FromStream(graphicsDevice, stream);
|
||||
Vector4[] data = new Vector4[atlasTexture.Width * atlasTexture.Height];
|
||||
atlasTexture.GetData(data);
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
Color.FromNonPremultiplied(data[i]);
|
||||
}
|
||||
atlasTexture.SetData(data);
|
||||
}
|
||||
TextureAtlas.Region[] regions = textureAtlasDataReader.GenerateAtlasRegionsFromData(atlasData, atlasTexture);
|
||||
TextureAtlas textureAtlas = new TextureAtlas(atlasTexture, regions);
|
||||
@@ -180,6 +182,13 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
||||
using (FileStream stream = new FileStream(filePath[skinData.cursorTextureName], FileMode.Open))
|
||||
{
|
||||
cursorTexture = Texture2D.FromStream(graphicsDevice, stream);
|
||||
Vector4[] data = new Vector4[cursorTexture.Width * cursorTexture.Height];
|
||||
atlasTexture.GetData(data);
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
Color.FromNonPremultiplied(data[i]);
|
||||
}
|
||||
cursorTexture.SetData(data);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Reference in New Issue
Block a user