Changed 9p and tatlas' to use a separately loaded texture.
This commit is contained in:
parent
4add103f94
commit
e3535f5662
@ -5,22 +5,12 @@ using System.IO;
|
||||
|
||||
namespace RecrownedAthenaeum.Pipeline.NinePatch
|
||||
{
|
||||
[ContentImporter(".9p", DisplayName = "Nine Patch Importer", DefaultProcessor = "NinePatchProcessor")]
|
||||
internal class NinePatchImporter : ContentImporter<NinePatchImporter.Package>
|
||||
[ContentImporter(".9p", DisplayName = "Nine Patch Importer - RecrownedAthenaeum", DefaultProcessor = "NinePatchProcessor")]
|
||||
internal class NinePatchImporter : ContentImporter<NinePatchData>
|
||||
{
|
||||
public override Package Import(string filename, ContentImporterContext context)
|
||||
public override NinePatchData Import(string filename, ContentImporterContext context)
|
||||
{
|
||||
Package package;
|
||||
package.ninePatchData = JsonConvert.DeserializeObject<NinePatchData>(File.ReadAllText(filename));
|
||||
package.textureBytes = File.ReadAllBytes(package.ninePatchData.textureName);
|
||||
|
||||
return package;
|
||||
}
|
||||
|
||||
internal struct Package
|
||||
{
|
||||
internal byte[] textureBytes;
|
||||
internal NinePatchData ninePatchData;
|
||||
return JsonConvert.DeserializeObject<NinePatchData>(File.ReadAllText(filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,19 @@
|
||||
using Microsoft.Xna.Framework.Content.Pipeline;
|
||||
using Newtonsoft.Json;
|
||||
using RecrownedAthenaeum.Data;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace RecrownedAthenaeum.Pipeline.NinePatch
|
||||
{
|
||||
[ContentImporter(DisplayName = "Nine Patch - RecrownedAthenaeum")]
|
||||
class NinePatchProcessor : ContentProcessor<NinePatchImporter.Package, NinePatchProcessor.Package>
|
||||
class NinePatchProcessor : ContentProcessor<NinePatchData, NinePatchData>
|
||||
{
|
||||
public override Package Process(NinePatchImporter.Package input, ContentProcessorContext context)
|
||||
public override NinePatchData Process(NinePatchData input, ContentProcessorContext context)
|
||||
{
|
||||
Package package;
|
||||
package.ninePatchDataBytes = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(input.ninePatchData));
|
||||
package.textureBytes = input.textureBytes;
|
||||
return package;
|
||||
}
|
||||
|
||||
internal struct Package
|
||||
{
|
||||
internal byte[] ninePatchDataBytes;
|
||||
internal byte[] textureBytes;
|
||||
if (Path.GetFileNameWithoutExtension(context.SourceIdentity.SourceFilename) == Path.GetFileNameWithoutExtension(input.textureName)) throw new InvalidContentException("Ninepatch data and texture for the data can't have the same name.");
|
||||
context.AddDependency(input.textureName);
|
||||
return input;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,23 +2,25 @@
|
||||
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
|
||||
using Newtonsoft.Json;
|
||||
using RecrownedAthenaeum.Data;
|
||||
using System.IO;
|
||||
|
||||
namespace RecrownedAthenaeum.Pipeline.NinePatch
|
||||
{
|
||||
[ContentTypeWriter]
|
||||
class NinePatchWriter : ContentTypeWriter<NinePatchProcessor.Package>
|
||||
class NinePatchWriter : ContentTypeWriter<NinePatchData>
|
||||
{
|
||||
public override string GetRuntimeReader(TargetPlatform targetPlatform)
|
||||
{
|
||||
return "RecrownedAthenaeum.ContentReaders.NinePatchDataReader, RecrownedAthenaeum";
|
||||
}
|
||||
|
||||
protected override void Write(ContentWriter output, NinePatchProcessor.Package value)
|
||||
protected override void Write(ContentWriter output, NinePatchData value)
|
||||
{
|
||||
output.Write(value.textureBytes.Length);
|
||||
output.Write(value.textureBytes);
|
||||
output.Write(value.ninePatchDataBytes.Length);
|
||||
output.Write(value.ninePatchDataBytes);
|
||||
output.Write(Path.GetFileNameWithoutExtension(value.textureName));
|
||||
output.Write(value.left);
|
||||
output.Write(value.right);
|
||||
output.Write(value.bottom);
|
||||
output.Write(value.top);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,18 @@
|
||||
using Microsoft.Xna.Framework.Content.Pipeline;
|
||||
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
|
||||
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
|
||||
using Newtonsoft.Json;
|
||||
using RecrownedAthenaeum.Data;
|
||||
using System.IO;
|
||||
|
||||
namespace RecrownedAthenaeum.Pipeline.TextureAtlas
|
||||
{
|
||||
[ContentImporter(".tatlas", DisplayName = "Texture Atlas Importer", DefaultProcessor = "TextureAtlasProcessor")]
|
||||
internal class TextureAtlasImporter : ContentImporter<TextureAtlasImporter.Package>
|
||||
[ContentImporter(".tatlas", DisplayName = "Texture Atlas Importer - RecrownedAthenaeum", DefaultProcessor = "TextureAtlasProcessor")]
|
||||
internal class TextureAtlasImporter : ContentImporter<TextureAtlasData>
|
||||
{
|
||||
public override Package Import(string filename, ContentImporterContext context)
|
||||
public override TextureAtlasData Import(string filename, ContentImporterContext context)
|
||||
{
|
||||
Package package;
|
||||
package.textureAtlasData = JsonConvert.DeserializeObject<TextureAtlasData>(File.ReadAllText(filename));
|
||||
package.textureBytes = File.ReadAllBytes(package.textureAtlasData.textureName);
|
||||
return package;
|
||||
}
|
||||
|
||||
internal struct Package
|
||||
{
|
||||
internal TextureAtlasData textureAtlasData;
|
||||
internal byte[] textureBytes;
|
||||
return JsonConvert.DeserializeObject<TextureAtlasData>(File.ReadAllText(filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,21 @@
|
||||
using Microsoft.Xna.Framework.Content.Pipeline;
|
||||
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
|
||||
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
|
||||
using Newtonsoft.Json;
|
||||
using RecrownedAthenaeum.Data;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace RecrownedAthenaeum.Pipeline.TextureAtlas
|
||||
{
|
||||
[ContentProcessor(DisplayName = "Texture Atlas - RecrownedAthenaeum")]
|
||||
class TextureAtlasProcessor : ContentProcessor<TextureAtlasImporter.Package, TextureAtlasProcessor.Package>
|
||||
class TextureAtlasProcessor : ContentProcessor<TextureAtlasData, TextureAtlasData>
|
||||
{
|
||||
public override Package Process(TextureAtlasImporter.Package input, ContentProcessorContext context)
|
||||
public override TextureAtlasData Process(TextureAtlasData input, ContentProcessorContext context)
|
||||
{
|
||||
Package package;
|
||||
package.textureBytes = input.textureBytes;
|
||||
package.textureAtlasDataBytes = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(input.textureAtlasData));
|
||||
return package;
|
||||
}
|
||||
|
||||
internal struct Package
|
||||
{
|
||||
public byte[] textureBytes;
|
||||
public byte[] textureAtlasDataBytes;
|
||||
if (context.SourceIdentity.SourceFilename == input.textureName) throw new InvalidContentException("Texture atlas data and texture file for the atlas can't have the same name.");
|
||||
context.AddDependency(input.textureName);
|
||||
return input;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,41 @@
|
||||
using Microsoft.Xna.Framework.Content.Pipeline;
|
||||
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
|
||||
using Newtonsoft.Json;
|
||||
using RecrownedAthenaeum.Data;
|
||||
using System.IO;
|
||||
|
||||
namespace RecrownedAthenaeum.Pipeline.TextureAtlas
|
||||
{
|
||||
[ContentTypeWriter]
|
||||
class TextureAtlasWriter : ContentTypeWriter<TextureAtlasProcessor.Package>
|
||||
class TextureAtlasWriter : ContentTypeWriter<TextureAtlasData>
|
||||
{
|
||||
public override string GetRuntimeReader(TargetPlatform targetPlatform)
|
||||
{
|
||||
return "RecrownedAthenaeum.ContentReaders.TextureAtlasDataReader, RecrownedAthenaeum";
|
||||
}
|
||||
|
||||
protected override void Write(ContentWriter output, TextureAtlasProcessor.Package value)
|
||||
protected override void Write(ContentWriter output, TextureAtlasData value)
|
||||
{
|
||||
output.Write(value.textureBytes.Length);
|
||||
output.Write(value.textureBytes);
|
||||
output.Write(value.textureAtlasDataBytes.Length);
|
||||
output.Write(value.textureAtlasDataBytes);
|
||||
output.Write(Path.GetFileNameWithoutExtension(value.textureName));
|
||||
output.Write(value.regions.Length);
|
||||
|
||||
for (int i = 0; i < value.regions.Length; i++)
|
||||
{
|
||||
output.Write(value.regions[i].name);
|
||||
output.Write(value.regions[i].bounds.X);
|
||||
output.Write(value.regions[i].bounds.Y);
|
||||
output.Write(value.regions[i].bounds.Width);
|
||||
output.Write(value.regions[i].bounds.Height);
|
||||
bool hasNPatch = value.regions[i].ninePatchData != null;
|
||||
output.Write(hasNPatch);
|
||||
if (hasNPatch)
|
||||
{
|
||||
output.Write(value.regions[i].ninePatchData.left);
|
||||
output.Write(value.regions[i].ninePatchData.right);
|
||||
output.Write(value.regions[i].ninePatchData.bottom);
|
||||
output.Write(value.regions[i].ninePatchData.top);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,6 @@ namespace RecrownedAthenaeum.Tools.NinePatchTools
|
||||
{
|
||||
public class NinePatchCommand : EngineCommand
|
||||
{
|
||||
private enum SupportedExtensions
|
||||
{
|
||||
jpeg, jpg, png
|
||||
}
|
||||
|
||||
public NinePatchCommand() : base("9p", "ninepatch", "9patch")
|
||||
{
|
||||
@ -34,6 +30,7 @@ namespace RecrownedAthenaeum.Tools.NinePatchTools
|
||||
string imagePath, outPath;
|
||||
if (IndexOfArgument("-i", arguments) + 1 >= arguments.Length) throw new ArgumentException("Missing -i path after argument.");
|
||||
imagePath = arguments[IndexOfArgument("-i", arguments) + 1];
|
||||
if (!File.Exists(imagePath)) throw new ArgumentException("Input file does not exist at " + imagePath + ".");
|
||||
|
||||
if (HasArgument(commandArguments[1], arguments))
|
||||
{
|
||||
@ -51,10 +48,7 @@ namespace RecrownedAthenaeum.Tools.NinePatchTools
|
||||
NinePatchData npData = new NinePatchData(Path.GetFileName(imagePath), leftBound, rightBound, bottomBound, topBound);
|
||||
string serialized = JsonConvert.SerializeObject(npData, Formatting.Indented);
|
||||
|
||||
if (!File.Exists(imagePath)) throw new ArgumentException("Input file does not exist at " + imagePath + ".");
|
||||
SupportedExtensions extension;
|
||||
if (!Enum.TryParse<SupportedExtensions>(Path.GetExtension(imagePath).ToLower().Substring(1), out extension)) throw new ArgumentException("Input file extension \"" + Path.GetExtension(imagePath).ToLower().Substring(1) + "\" not supported.");
|
||||
|
||||
File.Move(imagePath, Path.GetFileNameWithoutExtension(imagePath) + "-texture" + Path.GetExtension(imagePath));
|
||||
File.WriteAllText(outPath + ".9p", serialized);
|
||||
|
||||
ConsoleUtilities.WriteWrappedLine("Done. Written to \"" + outPath + "\" with values: left = " + leftBound + " right = " + rightBound + " top = " + topBound + " bottom = " + bottomBound);
|
||||
|
@ -133,6 +133,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
||||
ImageHandler ih = imageHandlers[i];
|
||||
regions[i].SetBounds(ih.x, ih.y, ih.Width, ih.Height);
|
||||
regions[i].ninePatchData = ih.ninePatchData;
|
||||
regions[i].ninePatchData.textureName = null;
|
||||
regions[i].name = Path.GetFileNameWithoutExtension(ih.Name);
|
||||
using (Image<Rgba32> image = Image.Load<Rgba32>(ih.path))
|
||||
{
|
||||
@ -140,12 +141,12 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
||||
}
|
||||
}
|
||||
Directory.CreateDirectory(output);
|
||||
using (FileStream stream = new FileStream(output + "/" + atlasName + ".png", FileMode.Create))
|
||||
using (FileStream stream = new FileStream(output + "/" + atlasName + "-texture" + ".png", FileMode.Create))
|
||||
{
|
||||
atlasTexture.SaveAsPng(stream);
|
||||
}
|
||||
}
|
||||
string serialized = JsonConvert.SerializeObject(new TextureAtlasData(atlasName + ".png", regions), Formatting.Indented);
|
||||
string serialized = JsonConvert.SerializeObject(new TextureAtlasData(atlasName + "-texture" + ".png", regions), Formatting.Indented);
|
||||
File.WriteAllText(output + "/" + atlasName + ".tatlas", serialized);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using RecrownedAthenaeum.Camera;
|
||||
using RecrownedAthenaeum.Render;
|
||||
using RecrownedAthenaeum.ScreenSystem;
|
||||
using System;
|
||||
|
||||
namespace RecrownedAthenaeum
|
||||
@ -24,10 +23,10 @@ namespace RecrownedAthenaeum
|
||||
/// </summary>
|
||||
public static Camera2D Camera2D { set { camera2D = value; } get { if (camera2D == null) throw new InvalidOperationException("2D camera property requested as substitute but configuration does not have one."); return camera2D; } }
|
||||
|
||||
private static SpriteBatchSettings? beginBatchFunction;
|
||||
private static SpriteBatchSettings? spriteBatchSettings;
|
||||
/// <summary>
|
||||
/// The begin sprite batch to use for custom begins and consistency.
|
||||
/// </summary>
|
||||
public static SpriteBatchSettings? spriteBatchSettings { set { beginBatchFunction = value.Value; } get { if (!beginBatchFunction.HasValue) throw new InvalidOperationException("No default begin batch has been set yet has been requested."); return beginBatchFunction; } }
|
||||
public static SpriteBatchSettings? SpriteBatchSettings { set { spriteBatchSettings = value.Value; } get { if (!spriteBatchSettings.HasValue) throw new InvalidOperationException("No default begin batch has been set yet has been requested."); return spriteBatchSettings; } }
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RecrownedAthenaeum.ContentSystem;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
@ -30,7 +30,7 @@ namespace RecrownedAthenaeum.Data
|
||||
/// <summary>
|
||||
/// Data object that contains information about the region ninepatch situation of a given region in an atlas.
|
||||
/// </summary>
|
||||
public class AtlasRegionData
|
||||
public struct AtlasRegionData
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the region for referencial purposes.
|
||||
|
@ -51,9 +51,10 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Render\ScissorBox.cs" />
|
||||
<Compile Include="Render\SpriteBatchSettings.cs" />
|
||||
<Compile Include="View\Camera3D.cs" />
|
||||
<Compile Include="View\Camera2D.cs" />
|
||||
<Compile Include="Render\Camera3D.cs" />
|
||||
<Compile Include="Render\Camera2D.cs" />
|
||||
<Compile Include="ContentSystem\ContentData.cs" />
|
||||
<Compile Include="ContentSystem\ContentManagerController.cs" />
|
||||
<Compile Include="ContentSystem\IContentPathResolver.cs" />
|
||||
@ -99,5 +100,8 @@
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="View\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
@ -1,10 +1,5 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RecrownedAthenaeum.Camera
|
||||
{
|
||||
@ -14,7 +9,7 @@ namespace RecrownedAthenaeum.Camera
|
||||
public class Camera3D
|
||||
{
|
||||
/// <summary>
|
||||
/// The zoom of the camera.
|
||||
/// The scale for the world.
|
||||
/// </summary>
|
||||
public float worldScale = 1f;
|
||||
|
@ -2,7 +2,6 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RecrownedAthenaeum.Camera;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RecrownedAthenaeum.Render
|
||||
{
|
||||
|
41
RecrownedAthenaeum/Render/ScissorBox.cs
Normal file
41
RecrownedAthenaeum/Render/ScissorBox.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace RecrownedAthenaeum.Render
|
||||
{
|
||||
/// <summary>
|
||||
/// Box that crops off anything outside of the bounds.
|
||||
/// </summary>
|
||||
public class ScissorBox
|
||||
{
|
||||
|
||||
SpriteBatch spriteBatch;
|
||||
Rectangle currentScissorRect;
|
||||
|
||||
/// <summary>
|
||||
/// Starts spritebatch with scissoring enabled.
|
||||
/// </summary>
|
||||
/// <param name="rectangle"></param>
|
||||
/// <param name="spriteBatch"></param>
|
||||
/// <param name="spriteBatchSettings">The settings for using the <see cref="SpriteBatch"/> to perform the scissor.</param>
|
||||
public void Begin(Rectangle rectangle, SpriteBatch spriteBatch, SpriteBatchSettings? spriteBatchSettings = null)
|
||||
{
|
||||
if (spriteBatchSettings == null) spriteBatchSettings = Configuration.SpriteBatchSettings;
|
||||
|
||||
this.spriteBatch = spriteBatch;
|
||||
spriteBatchSettings.Value.rasterizerState.ScissorTestEnable = true;
|
||||
spriteBatchSettings.Value.BeginSpriteBatch(spriteBatch);
|
||||
currentScissorRect = spriteBatch.GraphicsDevice.ScissorRectangle;
|
||||
spriteBatch.GraphicsDevice.ScissorRectangle = rectangle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ends the scissoring and spritebatch.
|
||||
/// </summary>
|
||||
public void End()
|
||||
{
|
||||
spriteBatch.GraphicsDevice.ScissorRectangle = currentScissorRect;
|
||||
spriteBatch.End();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,5 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RecrownedAthenaeum.Render
|
||||
{
|
||||
@ -46,8 +41,28 @@ namespace RecrownedAthenaeum.Render
|
||||
/// <summary>
|
||||
/// The transformation matrix to use.
|
||||
/// </summary>
|
||||
public Matrix transformMatrix;
|
||||
public Matrix? transformMatrix;
|
||||
|
||||
/// <summary>
|
||||
/// See <see cref="SpriteBatch.Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> for uses and defaults.
|
||||
/// </summary>
|
||||
/// <param name="spriteSortMode"></param>
|
||||
/// <param name="blendState"></param>
|
||||
/// <param name="samplerState"></param>
|
||||
/// <param name="depthStencilState"></param>
|
||||
/// <param name="rasterizerState"></param>
|
||||
/// <param name="effect"></param>
|
||||
/// <param name="transformMatrix"></param>
|
||||
public SpriteBatchSettings(SpriteSortMode spriteSortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null, Matrix? transformMatrix = null)
|
||||
{
|
||||
this.spriteSortMode = spriteSortMode;
|
||||
this.blendState = blendState;
|
||||
this.samplerState = samplerState;
|
||||
this.depthStencilState = depthStencilState;
|
||||
this.rasterizerState = rasterizerState;
|
||||
this.effect = effect;
|
||||
this.transformMatrix = transformMatrix;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins the given sprite batch with the current set of settings.
|
||||
|
@ -81,7 +81,6 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
{
|
||||
SpriteBatchSettings basicSettings = new SpriteBatchSettings();
|
||||
basicSettings.effect = camera.BasicEffect;
|
||||
basicSettings.blendState = BlendState.Additive;
|
||||
basicSettings.samplerState = null;
|
||||
spriteBatchSettings = basicSettings;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
/// <param name="spriteBatchSettings">The sprite batch settings to use to begin the batch in after drawing the ninepatch.</param>
|
||||
public void Draw(SpriteBatch spriteBatch, Color color, Rectangle destination, SpriteBatchSettings? spriteBatchSettings = null)
|
||||
{
|
||||
if (spriteBatchSettings == null) spriteBatchSettings = Configuration.spriteBatchSettings;
|
||||
if (spriteBatchSettings == null) spriteBatchSettings = Configuration.SpriteBatchSettings;
|
||||
spriteBatch.End();
|
||||
|
||||
SpriteBatchSettings ss = spriteBatchSettings.Value;
|
||||
|
@ -95,8 +95,6 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
||||
{
|
||||
foreach (Page page in pages)
|
||||
{
|
||||
page.camera = camera;
|
||||
page.Initialize(assets, skin);
|
||||
orderedPages.Add(page);
|
||||
this.pages.Add(page.name, page);
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ using Microsoft.Xna.Framework.Graphics;
|
||||
using RecrownedAthenaeum.SpecialTypes;
|
||||
using RecrownedAthenaeum.UI.SkinSystem;
|
||||
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
||||
using System;
|
||||
|
||||
namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||
{
|
||||
|
@ -1,7 +1,5 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RecrownedAthenaeum.UI.SkinSystem;
|
||||
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using RecrownedAthenaeum.Input;
|
||||
using RecrownedAthenaeum.Render;
|
||||
using System;
|
||||
|
||||
namespace RecrownedAthenaeum.UI.Modular
|
||||
|
@ -3,9 +3,7 @@ using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using RecrownedAthenaeum.Camera;
|
||||
using RecrownedAthenaeum.Render;
|
||||
using RecrownedAthenaeum.ScreenSystem;
|
||||
|
||||
namespace RecrownedAthenaeum.UI.Modular
|
||||
{
|
||||
@ -16,32 +14,23 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
public class UIModuleGroup : UIModule
|
||||
{
|
||||
List<UIModule> modules = new List<UIModule>();
|
||||
Rectangle scissorBounds;
|
||||
RasterizerState scissorRasterizer;
|
||||
SpriteBatchSettings spriteBatchSettings;
|
||||
ScissorBox scissorBox;
|
||||
|
||||
/// <summary>
|
||||
/// Camera used by the module for cropping.
|
||||
/// Configuration for starting sprite batch after scissoring. Only used if cropping.
|
||||
/// </summary>
|
||||
public Camera2D camera;
|
||||
public SpriteBatchSettings spriteBatchSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a module group.
|
||||
/// </summary>
|
||||
/// <param name="crop">Whether or not to crop out of bounds. Default is false.</param>
|
||||
/// <param name="camera">What camera to use for cropping. Default is null and will use <see cref="Configuration"/>'s camera if crop is enabled.</param>
|
||||
/// <param name="spriteBatchSettings">The settings to be used that begins the batch.</param>
|
||||
public UIModuleGroup(bool crop = false, Camera2D camera = null, SpriteBatchSettings? spriteBatchSettings = null)
|
||||
public UIModuleGroup(bool crop = false)
|
||||
{
|
||||
if (spriteBatchSettings == null) spriteBatchSettings = Configuration.spriteBatchSettings;
|
||||
if (crop && camera == null) camera = Configuration.Camera2D;
|
||||
this.spriteBatchSettings = spriteBatchSettings.Value;
|
||||
this.camera = camera;
|
||||
this.spriteBatchSettings = Configuration.SpriteBatchSettings.Value;
|
||||
if (crop)
|
||||
{
|
||||
scissorRasterizer = new RasterizerState();
|
||||
scissorRasterizer.ScissorTestEnable = true;
|
||||
scissorBounds = new Rectangle();
|
||||
scissorBox = new ScissorBox();
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,17 +40,10 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
/// <param name="batch">Batch used to draw the group.</param>
|
||||
public override void Draw(SpriteBatch batch)
|
||||
{
|
||||
if (scissorBounds != null)
|
||||
if (scissorBox != null)
|
||||
{
|
||||
batch.End();
|
||||
spriteBatchSettings.BeginSpriteBatch(batch);
|
||||
scissorBounds.Width = situation.Width;
|
||||
scissorBounds.Height = situation.Height;
|
||||
scissorBounds.X = situation.X;
|
||||
scissorBounds.Y = situation.Y;
|
||||
Rectangle scissor = scissorBounds;
|
||||
scissorBounds = batch.GraphicsDevice.ScissorRectangle;
|
||||
batch.GraphicsDevice.ScissorRectangle = scissor;
|
||||
scissorBox.Begin(Boundaries, batch, spriteBatchSettings);
|
||||
}
|
||||
|
||||
foreach (UIModule module in modules)
|
||||
@ -75,11 +57,10 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
module.situation.Y = offsetY;
|
||||
}
|
||||
|
||||
if (scissorBounds != null)
|
||||
if (scissorBox != null)
|
||||
{
|
||||
batch.GraphicsDevice.ScissorRectangle = scissorBounds;
|
||||
batch.End();
|
||||
spriteBatchSettings.BeginSpriteBatch(batch);
|
||||
scissorBox.End();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using RecrownedAthenaeum.UI.Modular.Modules.Interactive;
|
||||
using System;
|
||||
|
||||
namespace RecrownedAthenaeum.UI.SkinSystem.Definitions
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
using RecrownedAthenaeum.UI.Modular.Modules.Interactive;
|
||||
using System;
|
||||
|
||||
namespace RecrownedAthenaeum.UI.SkinSystem.Definitions
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RecrownedAthenaeum.SpecialTypes;
|
||||
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
||||
|
@ -156,23 +156,28 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
||||
{
|
||||
TextureAtlasDataReader textureAtlasDataReader = new TextureAtlasDataReader();
|
||||
FileInfo[] skinFiles = Directory.GetParent(path).GetFiles();
|
||||
Dictionary<string, string> fileNameWithPath = new Dictionary<string, string>();
|
||||
Dictionary<string, string> filePath = new Dictionary<string, string>();
|
||||
for (int i = 0; i < skinFiles.Length; i++)
|
||||
{
|
||||
fileNameWithPath.Add(skinFiles[i].Name, skinFiles[i].FullName);
|
||||
filePath.Add(skinFiles[i].Name, skinFiles[i].FullName);
|
||||
}
|
||||
TextureAtlasDataReader tatlasDataReader = new TextureAtlasDataReader();
|
||||
TextureAtlasData atlasData;
|
||||
using (FileStream fileStream = new FileStream(filePath[skinData.nameOfTextureAtlas], FileMode.Open))
|
||||
{
|
||||
atlasData = tatlasDataReader.ReadTextureAtlasData(new BinaryReader(fileStream));
|
||||
}
|
||||
TextureAtlasData atlasData = JsonConvert.DeserializeObject<TextureAtlasData>(fileNameWithPath[skinData.nameOfTextureAtlas]);
|
||||
Texture2D atlasTexture;
|
||||
using (FileStream stream = new FileStream(fileNameWithPath[atlasData.textureName], FileMode.Open))
|
||||
using (FileStream stream = new FileStream(filePath[atlasData.textureName], FileMode.Open))
|
||||
{
|
||||
atlasTexture = Texture2D.FromStream(graphicsDevice, stream);
|
||||
}
|
||||
TextureAtlas.Region[] regions = textureAtlasDataReader.GenerateAtlasRegionsFromData(atlasData, atlasTexture);
|
||||
TextureAtlas textureAtlas = new TextureAtlas(atlasTexture, regions);
|
||||
Texture2D cursorTexture;
|
||||
if (Path.HasExtension(skinData.cursorTextureName) && fileNameWithPath.ContainsKey(skinData.cursorTextureName))
|
||||
if (Path.HasExtension(skinData.cursorTextureName) && filePath.ContainsKey(skinData.cursorTextureName))
|
||||
{
|
||||
using (FileStream stream = new FileStream(fileNameWithPath[skinData.cursorTextureName], FileMode.Open))
|
||||
using (FileStream stream = new FileStream(filePath[skinData.cursorTextureName], FileMode.Open))
|
||||
{
|
||||
cursorTexture = Texture2D.FromStream(graphicsDevice, stream);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user