diff --git a/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchImporter.cs b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchImporter.cs index 16ee75c..8bd8469 100644 --- a/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchImporter.cs +++ b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchImporter.cs @@ -5,22 +5,12 @@ using System.IO; namespace RecrownedAthenaeum.Pipeline.NinePatch { - [ContentImporter(".9p", DisplayName = "Nine Patch Importer", DefaultProcessor = "NinePatchProcessor")] - internal class NinePatchImporter : ContentImporter + [ContentImporter(".9p", DisplayName = "Nine Patch Importer - RecrownedAthenaeum", DefaultProcessor = "NinePatchProcessor")] + internal class NinePatchImporter : ContentImporter { - public override Package Import(string filename, ContentImporterContext context) + public override NinePatchData Import(string filename, ContentImporterContext context) { - Package package; - package.ninePatchData = JsonConvert.DeserializeObject(File.ReadAllText(filename)); - package.textureBytes = File.ReadAllBytes(package.ninePatchData.textureName); - - return package; - } - - internal struct Package - { - internal byte[] textureBytes; - internal NinePatchData ninePatchData; + return JsonConvert.DeserializeObject(File.ReadAllText(filename)); } } } diff --git a/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchProcessor.cs b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchProcessor.cs index 6842a65..98b3522 100644 --- a/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchProcessor.cs +++ b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchProcessor.cs @@ -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 + class NinePatchProcessor : ContentProcessor { - 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; } } } diff --git a/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchWriter.cs b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchWriter.cs index 3d1ab76..bb5b92d 100644 --- a/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchWriter.cs +++ b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchWriter.cs @@ -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 + class NinePatchWriter : ContentTypeWriter { 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); } } } diff --git a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasImporter.cs b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasImporter.cs index 230c307..b71712b 100644 --- a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasImporter.cs +++ b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasImporter.cs @@ -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 + [ContentImporter(".tatlas", DisplayName = "Texture Atlas Importer - RecrownedAthenaeum", DefaultProcessor = "TextureAtlasProcessor")] + internal class TextureAtlasImporter : ContentImporter { - public override Package Import(string filename, ContentImporterContext context) + public override TextureAtlasData Import(string filename, ContentImporterContext context) { - Package package; - package.textureAtlasData = JsonConvert.DeserializeObject(File.ReadAllText(filename)); - package.textureBytes = File.ReadAllBytes(package.textureAtlasData.textureName); - return package; - } - - internal struct Package - { - internal TextureAtlasData textureAtlasData; - internal byte[] textureBytes; + return JsonConvert.DeserializeObject(File.ReadAllText(filename)); } } } diff --git a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasProcessor.cs b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasProcessor.cs index 596af80..2df60be 100644 --- a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasProcessor.cs +++ b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasProcessor.cs @@ -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 + class TextureAtlasProcessor : ContentProcessor { - 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; } } } diff --git a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasWriter.cs b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasWriter.cs index dfcf61f..38fbb5d 100644 --- a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasWriter.cs +++ b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasWriter.cs @@ -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 + class TextureAtlasWriter : ContentTypeWriter { 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); + } + } } } } diff --git a/RecrownedAthenaeum.Tools/NinePatchTools/NinePatchCommand.cs b/RecrownedAthenaeum.Tools/NinePatchTools/NinePatchCommand.cs index f8612e1..dc39b3a 100644 --- a/RecrownedAthenaeum.Tools/NinePatchTools/NinePatchCommand.cs +++ b/RecrownedAthenaeum.Tools/NinePatchTools/NinePatchCommand.cs @@ -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(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); diff --git a/RecrownedAthenaeum.Tools/TextureAtlasTools/TexturePacker.cs b/RecrownedAthenaeum.Tools/TextureAtlasTools/TexturePacker.cs index e4c70a3..e98f67d 100644 --- a/RecrownedAthenaeum.Tools/TextureAtlasTools/TexturePacker.cs +++ b/RecrownedAthenaeum.Tools/TextureAtlasTools/TexturePacker.cs @@ -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 image = Image.Load(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); } diff --git a/RecrownedAthenaeum/Configuration.cs b/RecrownedAthenaeum/Configuration.cs index 4f2e0e7..cae16eb 100644 --- a/RecrownedAthenaeum/Configuration.cs +++ b/RecrownedAthenaeum/Configuration.cs @@ -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 /// 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; /// /// The begin sprite batch to use for custom begins and consistency. /// - 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; } } } } diff --git a/RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs b/RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs index 6b4a1fb..8339dd6 100644 --- a/RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs +++ b/RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs @@ -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 { - 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(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(input.ReadString()); + NinePatch ninePatch = new NinePatch(texture, input.ReadInt32(), input.ReadInt32(), input.ReadInt32(), input.ReadInt32()); return ninePatch; } } diff --git a/RecrownedAthenaeum/ContentReaders/TextureAtlasDataReader.cs b/RecrownedAthenaeum/ContentReaders/TextureAtlasDataReader.cs index 19e2d28..b856481 100644 --- a/RecrownedAthenaeum/ContentReaders/TextureAtlasDataReader.cs +++ b/RecrownedAthenaeum/ContentReaders/TextureAtlasDataReader.cs @@ -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 { - 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(serialized); + TextureAtlasData atlasData = ReadTextureAtlasData(input); + Texture2D atlasTexture = input.ContentManager.Load(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; + } + /// /// Generates region given . /// diff --git a/RecrownedAthenaeum/ContentSystem/ContentManagerController.cs b/RecrownedAthenaeum/ContentSystem/ContentManagerController.cs index 0fe225b..5c4ecca 100644 --- a/RecrownedAthenaeum/ContentSystem/ContentManagerController.cs +++ b/RecrownedAthenaeum/ContentSystem/ContentManagerController.cs @@ -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; diff --git a/RecrownedAthenaeum/Data/TextureAtlasData.cs b/RecrownedAthenaeum/Data/TextureAtlasData.cs index f00d11d..9922e91 100644 --- a/RecrownedAthenaeum/Data/TextureAtlasData.cs +++ b/RecrownedAthenaeum/Data/TextureAtlasData.cs @@ -30,7 +30,7 @@ namespace RecrownedAthenaeum.Data /// /// Data object that contains information about the region ninepatch situation of a given region in an atlas. /// - public class AtlasRegionData + public struct AtlasRegionData { /// /// Name of the region for referencial purposes. diff --git a/RecrownedAthenaeum/RecrownedAthenaeum.csproj b/RecrownedAthenaeum/RecrownedAthenaeum.csproj index fccb30f..12e3625 100644 --- a/RecrownedAthenaeum/RecrownedAthenaeum.csproj +++ b/RecrownedAthenaeum/RecrownedAthenaeum.csproj @@ -51,9 +51,10 @@ + - - + + @@ -99,5 +100,8 @@ + + + \ No newline at end of file diff --git a/RecrownedAthenaeum/View/Camera2D.cs b/RecrownedAthenaeum/Render/Camera2D.cs similarity index 100% rename from RecrownedAthenaeum/View/Camera2D.cs rename to RecrownedAthenaeum/Render/Camera2D.cs diff --git a/RecrownedAthenaeum/View/Camera3D.cs b/RecrownedAthenaeum/Render/Camera3D.cs similarity index 95% rename from RecrownedAthenaeum/View/Camera3D.cs rename to RecrownedAthenaeum/Render/Camera3D.cs index 6681407..9277e81 100644 --- a/RecrownedAthenaeum/View/Camera3D.cs +++ b/RecrownedAthenaeum/Render/Camera3D.cs @@ -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 { /// - /// The zoom of the camera. + /// The scale for the world. /// public float worldScale = 1f; diff --git a/RecrownedAthenaeum/Render/PrimitiveBatch.cs b/RecrownedAthenaeum/Render/PrimitiveBatch.cs index eece95e..73a55e5 100644 --- a/RecrownedAthenaeum/Render/PrimitiveBatch.cs +++ b/RecrownedAthenaeum/Render/PrimitiveBatch.cs @@ -2,7 +2,6 @@ using Microsoft.Xna.Framework.Graphics; using RecrownedAthenaeum.Camera; using System; -using System.Collections.Generic; namespace RecrownedAthenaeum.Render { diff --git a/RecrownedAthenaeum/Render/ScissorBox.cs b/RecrownedAthenaeum/Render/ScissorBox.cs new file mode 100644 index 0000000..0f67510 --- /dev/null +++ b/RecrownedAthenaeum/Render/ScissorBox.cs @@ -0,0 +1,41 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace RecrownedAthenaeum.Render +{ + /// + /// Box that crops off anything outside of the bounds. + /// + public class ScissorBox + { + + SpriteBatch spriteBatch; + Rectangle currentScissorRect; + + /// + /// Starts spritebatch with scissoring enabled. + /// + /// + /// + /// The settings for using the to perform the scissor. + 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; + } + + /// + /// Ends the scissoring and spritebatch. + /// + public void End() + { + spriteBatch.GraphicsDevice.ScissorRectangle = currentScissorRect; + spriteBatch.End(); + } + } +} diff --git a/RecrownedAthenaeum/Render/SpriteBatchSettings.cs b/RecrownedAthenaeum/Render/SpriteBatchSettings.cs index 79e1135..e20a17d 100644 --- a/RecrownedAthenaeum/Render/SpriteBatchSettings.cs +++ b/RecrownedAthenaeum/Render/SpriteBatchSettings.cs @@ -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 /// /// The transformation matrix to use. /// - public Matrix transformMatrix; + public Matrix? transformMatrix; + /// + /// See for uses and defaults. + /// + /// + /// + /// + /// + /// + /// + /// + 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; + } /// /// Begins the given sprite batch with the current set of settings. diff --git a/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs b/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs index 8cce222..c2b3141 100644 --- a/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs +++ b/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs @@ -81,7 +81,6 @@ namespace RecrownedAthenaeum.ScreenSystem { SpriteBatchSettings basicSettings = new SpriteBatchSettings(); basicSettings.effect = camera.BasicEffect; - basicSettings.blendState = BlendState.Additive; basicSettings.samplerState = null; spriteBatchSettings = basicSettings; } diff --git a/RecrownedAthenaeum/SpecialTypes/NinePatch.cs b/RecrownedAthenaeum/SpecialTypes/NinePatch.cs index e858b0a..141be62 100644 --- a/RecrownedAthenaeum/SpecialTypes/NinePatch.cs +++ b/RecrownedAthenaeum/SpecialTypes/NinePatch.cs @@ -91,7 +91,7 @@ namespace RecrownedAthenaeum.SpecialTypes /// The sprite batch settings to use to begin the batch in after drawing the ninepatch. 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; diff --git a/RecrownedAthenaeum/UI/BookSystem/Book.cs b/RecrownedAthenaeum/UI/BookSystem/Book.cs index 0963c71..2a34448 100644 --- a/RecrownedAthenaeum/UI/BookSystem/Book.cs +++ b/RecrownedAthenaeum/UI/BookSystem/Book.cs @@ -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); } diff --git a/RecrownedAthenaeum/UI/Modular/Modules/Interactive/TextButton.cs b/RecrownedAthenaeum/UI/Modular/Modules/Interactive/TextButton.cs index 135f2f6..4fd3aec 100644 --- a/RecrownedAthenaeum/UI/Modular/Modules/Interactive/TextButton.cs +++ b/RecrownedAthenaeum/UI/Modular/Modules/Interactive/TextButton.cs @@ -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 { diff --git a/RecrownedAthenaeum/UI/Modular/Modules/Text.cs b/RecrownedAthenaeum/UI/Modular/Modules/Text.cs index bb10fd1..5edc006 100644 --- a/RecrownedAthenaeum/UI/Modular/Modules/Text.cs +++ b/RecrownedAthenaeum/UI/Modular/Modules/Text.cs @@ -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; diff --git a/RecrownedAthenaeum/UI/Modular/UIModule.cs b/RecrownedAthenaeum/UI/Modular/UIModule.cs index a48cffb..2af44ba 100644 --- a/RecrownedAthenaeum/UI/Modular/UIModule.cs +++ b/RecrownedAthenaeum/UI/Modular/UIModule.cs @@ -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 diff --git a/RecrownedAthenaeum/UI/Modular/UIModuleGroup.cs b/RecrownedAthenaeum/UI/Modular/UIModuleGroup.cs index 7652025..93c2f55 100644 --- a/RecrownedAthenaeum/UI/Modular/UIModuleGroup.cs +++ b/RecrownedAthenaeum/UI/Modular/UIModuleGroup.cs @@ -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 modules = new List(); - Rectangle scissorBounds; - RasterizerState scissorRasterizer; - SpriteBatchSettings spriteBatchSettings; + ScissorBox scissorBox; /// - /// Camera used by the module for cropping. + /// Configuration for starting sprite batch after scissoring. Only used if cropping. /// - public Camera2D camera; + public SpriteBatchSettings spriteBatchSettings; /// /// Creates a module group. /// /// Whether or not to crop out of bounds. Default is false. - /// What camera to use for cropping. Default is null and will use 's camera if crop is enabled. - /// The settings to be used that begins the batch. - 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 /// Batch used to draw the group. 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(); + } } diff --git a/RecrownedAthenaeum/UI/SkinSystem/Definitions/ButtonSkinDefinition.cs b/RecrownedAthenaeum/UI/SkinSystem/Definitions/ButtonSkinDefinition.cs index d029d42..712282f 100644 --- a/RecrownedAthenaeum/UI/SkinSystem/Definitions/ButtonSkinDefinition.cs +++ b/RecrownedAthenaeum/UI/SkinSystem/Definitions/ButtonSkinDefinition.cs @@ -1,5 +1,4 @@ using RecrownedAthenaeum.UI.Modular.Modules.Interactive; -using System; namespace RecrownedAthenaeum.UI.SkinSystem.Definitions { diff --git a/RecrownedAthenaeum/UI/SkinSystem/Definitions/TextButtonSkinDefinition.cs b/RecrownedAthenaeum/UI/SkinSystem/Definitions/TextButtonSkinDefinition.cs index 2144350..d3a9c40 100644 --- a/RecrownedAthenaeum/UI/SkinSystem/Definitions/TextButtonSkinDefinition.cs +++ b/RecrownedAthenaeum/UI/SkinSystem/Definitions/TextButtonSkinDefinition.cs @@ -1,5 +1,4 @@ using RecrownedAthenaeum.UI.Modular.Modules.Interactive; -using System; namespace RecrownedAthenaeum.UI.SkinSystem.Definitions { diff --git a/RecrownedAthenaeum/UI/SkinSystem/ISkin.cs b/RecrownedAthenaeum/UI/SkinSystem/ISkin.cs index 8530eb5..09a5003 100644 --- a/RecrownedAthenaeum/UI/SkinSystem/ISkin.cs +++ b/RecrownedAthenaeum/UI/SkinSystem/ISkin.cs @@ -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; diff --git a/RecrownedAthenaeum/UI/SkinSystem/SkinManager.cs b/RecrownedAthenaeum/UI/SkinSystem/SkinManager.cs index a20c608..82a6f9e 100644 --- a/RecrownedAthenaeum/UI/SkinSystem/SkinManager.cs +++ b/RecrownedAthenaeum/UI/SkinSystem/SkinManager.cs @@ -156,23 +156,28 @@ namespace RecrownedAthenaeum.UI.SkinSystem { TextureAtlasDataReader textureAtlasDataReader = new TextureAtlasDataReader(); FileInfo[] skinFiles = Directory.GetParent(path).GetFiles(); - Dictionary fileNameWithPath = new Dictionary(); + Dictionary filePath = new Dictionary(); 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(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); }