From ea6b3cf9e342caa6d28a1b25ee6c7b2a2a7235f2 Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Mon, 21 Jan 2019 19:56:51 -0600 Subject: [PATCH] Added setup system. Changed reader and writer for texture atlas and nine patch to have image and serialized data be in same file. Some refactors occurred as well. --- .../NinePatch/NinePatchImporter.cs | 18 +++++-- .../NinePatch/NinePatchProcessor.cs | 18 +++++-- .../NinePatch/NinePatchWriter.cs | 9 ++-- .../TextureAtlas/TextureAtlasImporter.cs | 18 +++++-- .../TextureAtlas/TextureAtlasProcessor.cs | 19 ++++--- .../TextureAtlas/TextureAtlasWriter.cs | 11 ++-- RecrownedAthenaeum/Camera/Camera2D.cs | 10 ++-- .../ContentReaders/NinePatchDataReader.cs | 20 ++++++-- .../ContentReaders/TextureAtlasDataReader.cs | 17 ++++--- RecrownedAthenaeum/Data/TextureAtlasData.cs | 10 ++-- RecrownedAthenaeum/RecrownedAthenaeum.csproj | 1 + RecrownedAthenaeum/Render/PrimitiveBatch.cs | 9 ++-- .../Render/RectangleRenderer.cs | 50 +------------------ .../ScreenSystem/ScreenManager.cs | 9 ++-- RecrownedAthenaeum/Setup.cs | 15 ++++++ RecrownedAthenaeum/SpecialTypes/NinePatch.cs | 5 +- .../SpecialTypes/TextureAtlas.cs | 10 ++-- RecrownedAthenaeum/UI/Skin/SkinManager.cs | 7 +-- 18 files changed, 145 insertions(+), 111 deletions(-) create mode 100644 RecrownedAthenaeum/Setup.cs diff --git a/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchImporter.cs b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchImporter.cs index 7410188..16ee75c 100644 --- a/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchImporter.cs +++ b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchImporter.cs @@ -1,14 +1,26 @@ using Microsoft.Xna.Framework.Content.Pipeline; +using Newtonsoft.Json; +using RecrownedAthenaeum.Data; using System.IO; namespace RecrownedAthenaeum.Pipeline.NinePatch { [ContentImporter(".9p", DisplayName = "Nine Patch Importer", DefaultProcessor = "NinePatchProcessor")] - internal class NinePatchImporter : ContentImporter + internal class NinePatchImporter : ContentImporter { - public override string Import(string filename, ContentImporterContext context) + public override Package Import(string filename, ContentImporterContext context) { - return File.ReadAllText(filename); + 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; } } } diff --git a/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchProcessor.cs b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchProcessor.cs index 68b595c..6842a65 100644 --- a/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchProcessor.cs +++ b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchProcessor.cs @@ -1,17 +1,25 @@ using Microsoft.Xna.Framework.Content.Pipeline; using Newtonsoft.Json; using RecrownedAthenaeum.Data; +using System.Text; namespace RecrownedAthenaeum.Pipeline.NinePatch { [ContentImporter(DisplayName = "Nine Patch - RecrownedAthenaeum")] - class NinePatchProcessor : ContentProcessor + class NinePatchProcessor : ContentProcessor { - public override NinePatchData Process(string input, ContentProcessorContext context) + public override Package Process(NinePatchImporter.Package input, ContentProcessorContext context) { - NinePatchData ninePatchData = JsonConvert.DeserializeObject(input); - context.AddDependency(ninePatchData.textureName); - return ninePatchData; + 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; } } } diff --git a/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchWriter.cs b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchWriter.cs index dbdc293..3d1ab76 100644 --- a/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchWriter.cs +++ b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchWriter.cs @@ -6,16 +6,19 @@ using RecrownedAthenaeum.Data; 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, NinePatchData value) + protected override void Write(ContentWriter output, NinePatchProcessor.Package value) { - output.Write(JsonConvert.SerializeObject(value)); + output.Write(value.textureBytes.Length); + output.Write(value.textureBytes); + output.Write(value.ninePatchDataBytes.Length); + output.Write(value.ninePatchDataBytes); } } } diff --git a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasImporter.cs b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasImporter.cs index 1ce122e..230c307 100644 --- a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasImporter.cs +++ b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasImporter.cs @@ -1,15 +1,25 @@ using Microsoft.Xna.Framework.Content.Pipeline; +using Newtonsoft.Json; +using RecrownedAthenaeum.Data; using System.IO; -using TImport = System.String; namespace RecrownedAthenaeum.Pipeline.TextureAtlas { [ContentImporter(".tatlas", DisplayName = "Texture Atlas Importer", DefaultProcessor = "TextureAtlasProcessor")] - internal class TextureAtlasImporter : ContentImporter + internal class TextureAtlasImporter : ContentImporter { - public override TImport Import(string filename, ContentImporterContext context) + public override Package Import(string filename, ContentImporterContext context) { - return File.ReadAllText(filename); + 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; } } } diff --git a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasProcessor.cs b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasProcessor.cs index 4f02905..596af80 100644 --- a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasProcessor.cs +++ b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasProcessor.cs @@ -1,17 +1,24 @@ using Microsoft.Xna.Framework.Content.Pipeline; using Newtonsoft.Json; -using RecrownedAthenaeum.Data; +using System.Text; namespace RecrownedAthenaeum.Pipeline.TextureAtlas { [ContentProcessor(DisplayName = "Texture Atlas - RecrownedAthenaeum")] - class TextureAtlasProcessor : ContentProcessor + class TextureAtlasProcessor : ContentProcessor { - public override TextureAtlasData Process(string input, ContentProcessorContext context) + public override Package Process(TextureAtlasImporter.Package input, ContentProcessorContext context) { - TextureAtlasData textureAtlasData = JsonConvert.DeserializeObject(input); - context.AddDependency(textureAtlasData.textureName); - return textureAtlasData; + 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; } } } diff --git a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasWriter.cs b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasWriter.cs index 1d7ebf2..dfcf61f 100644 --- a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasWriter.cs +++ b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasWriter.cs @@ -1,21 +1,22 @@ using Microsoft.Xna.Framework.Content.Pipeline; using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler; -using Newtonsoft.Json; -using RecrownedAthenaeum.Data; 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, TextureAtlasData value) + protected override void Write(ContentWriter output, TextureAtlasProcessor.Package value) { - output.Write(JsonConvert.SerializeObject(value)); + output.Write(value.textureBytes.Length); + output.Write(value.textureBytes); + output.Write(value.textureAtlasDataBytes.Length); + output.Write(value.textureAtlasDataBytes); } } } diff --git a/RecrownedAthenaeum/Camera/Camera2D.cs b/RecrownedAthenaeum/Camera/Camera2D.cs index 869340d..7fa803c 100644 --- a/RecrownedAthenaeum/Camera/Camera2D.cs +++ b/RecrownedAthenaeum/Camera/Camera2D.cs @@ -24,15 +24,17 @@ namespace RecrownedAthenaeum.Camera /// public Matrix Matrix { get; private set; } - private GraphicsDevice graphicsDevice; + private GraphicsDevice graphicsDevice = Setup.graphicsDeviceManager.GraphicsDevice; /// /// Constructs 2D camera. /// - /// The graphics device to use. - public Camera2D(GraphicsDevice graphicsDevice) + /// The graphics device to use. Will use graphics device from 's graphics device manager if this is null which it is by default. + public Camera2D(GraphicsDevice graphicsDevice = null) { - this.graphicsDevice = graphicsDevice; + if (graphicsDevice != null) this.graphicsDevice = graphicsDevice; + if (this.graphicsDevice == null) throw new ArgumentNullException("Graphics device can't be null in setup and argument. One must not be null for use."); + Zoom = 1f; Position.X = this.graphicsDevice.Viewport.Width * 0.5f; Position.Y = this.graphicsDevice.Viewport.Height * 0.5f; diff --git a/RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs b/RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs index 7b7c244..38006f0 100644 --- a/RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs +++ b/RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs @@ -1,15 +1,25 @@ 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 + class NinePatchDataReader : ContentTypeReader { - protected override SpecialTypes.NinePatch Read(ContentReader input, SpecialTypes.NinePatch existingInstance) + protected override NinePatch Read(ContentReader input, NinePatch existingInstance) { - string serialized = input.ReadString(); - - return JsonConvert.DeserializeObject(serialized); + Texture2D texture; + using (MemoryStream stream = new MemoryStream(input.ReadBytes(input.ReadInt32()))) + { + texture = Texture2D.FromStream(Setup.graphicsDeviceManager.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); + return ninePatch; } } } diff --git a/RecrownedAthenaeum/ContentReaders/TextureAtlasDataReader.cs b/RecrownedAthenaeum/ContentReaders/TextureAtlasDataReader.cs index 2f84b3d..317da38 100644 --- a/RecrownedAthenaeum/ContentReaders/TextureAtlasDataReader.cs +++ b/RecrownedAthenaeum/ContentReaders/TextureAtlasDataReader.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using RecrownedAthenaeum.Data; using RecrownedAthenaeum.SpecialTypes; using System.IO; +using System.Text; namespace RecrownedAthenaeum.ContentReaders { @@ -11,9 +12,14 @@ namespace RecrownedAthenaeum.ContentReaders { protected override TextureAtlas Read(ContentReader input, TextureAtlas existingInstance) { - string serialized = input.ReadString(); - TextureAtlasData atlasData = JsonConvert.DeserializeObject(serialized); - Texture2D atlasTexture = input.ContentManager.Load(Path.GetFileNameWithoutExtension(atlasData.textureName)); + TextureAtlasData atlasData; + Texture2D atlasTexture; + using (MemoryStream stream = new MemoryStream(input.ReadBytes(input.ReadInt32()))) + { + atlasTexture = Texture2D.FromStream(Setup.graphicsDeviceManager.GraphicsDevice, stream); + } + string serialized = Encoding.ASCII.GetString(input.ReadBytes(input.ReadInt32())); + atlasData = JsonConvert.DeserializeObject(serialized); TextureAtlas atlas = new TextureAtlas(atlasTexture, GenerateAtlasRegionsFromData(atlasData, atlasTexture)); return atlas; @@ -35,10 +41,9 @@ namespace RecrownedAthenaeum.ContentReaders if (regionData.ninePatchData != null) { NinePatchData nPatchData = regionData.ninePatchData; - nPatch = new NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.bottom, nPatchData.bottom); + nPatch = new NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.bottom, nPatchData.bottom, regionData.bounds); } - - regions[regionID] = new TextureAtlas.Region(regionData.name, regionData.location, nPatch, atlasTexture); + regions[regionID] = new TextureAtlas.Region(regionData.name, regionData.bounds, nPatch, atlasTexture); } return regions; diff --git a/RecrownedAthenaeum/Data/TextureAtlasData.cs b/RecrownedAthenaeum/Data/TextureAtlasData.cs index ceacb49..f00d11d 100644 --- a/RecrownedAthenaeum/Data/TextureAtlasData.cs +++ b/RecrownedAthenaeum/Data/TextureAtlasData.cs @@ -39,7 +39,7 @@ namespace RecrownedAthenaeum.Data /// /// The location of the patch is designated by this rectangle. /// - public Rectangle location; + public Rectangle bounds; /// /// The ninepatch information. /// @@ -52,8 +52,8 @@ namespace RecrownedAthenaeum.Data /// Y coordinate of the position in the patch. public void SetPosition(int x, int y) { - location.X = x; - location.Y = y; + bounds.X = x; + bounds.Y = y; } /// @@ -63,8 +63,8 @@ namespace RecrownedAthenaeum.Data /// Height of the region. public void SetSize(int width, int height) { - location.Width = width; - location.Height = height; + bounds.Width = width; + bounds.Height = height; } /// diff --git a/RecrownedAthenaeum/RecrownedAthenaeum.csproj b/RecrownedAthenaeum/RecrownedAthenaeum.csproj index 0046184..21d9d75 100644 --- a/RecrownedAthenaeum/RecrownedAthenaeum.csproj +++ b/RecrownedAthenaeum/RecrownedAthenaeum.csproj @@ -58,6 +58,7 @@ + diff --git a/RecrownedAthenaeum/Render/PrimitiveBatch.cs b/RecrownedAthenaeum/Render/PrimitiveBatch.cs index c04f6b7..c463607 100644 --- a/RecrownedAthenaeum/Render/PrimitiveBatch.cs +++ b/RecrownedAthenaeum/Render/PrimitiveBatch.cs @@ -20,19 +20,20 @@ namespace RecrownedAthenaeum.Render BasicEffect basicEffect; PrimitiveType primitiveType; int verticesPerPrimitive; - GraphicsDevice graphicsDevice; + GraphicsDevice graphicsDevice = Setup.graphicsDeviceManager.GraphicsDevice; bool began; bool disposed; /// /// Creates a batch used to draw primitives. /// - /// The current graphics device being used. /// The current camera being used. + /// The graphics device used to draw the primitives. Will be using 's graphics device from graphics device manager if null. Default is null. /// The amount of vertices every batch can hold before flushing. Default is 450. Should be changed to be the most optimal number if possible to prevent unnecessary resizing. Especially if using strip primitive types. - public PrimitiveBatch(GraphicsDevice graphicsDevice, Camera2D camera, int verticesPerBatch = 500) + public PrimitiveBatch(Camera2D camera, GraphicsDevice graphicsDevice = null, int verticesPerBatch = 500) { - this.graphicsDevice = graphicsDevice ?? throw new ArgumentNullException("Graphics device can't be null."); + if (graphicsDevice != null) this.graphicsDevice = graphicsDevice; + if (this.graphicsDevice == null) throw new ArgumentNullException("Graphics device can't be null in setup and argument. One must not be null for use."); basicEffect = new BasicEffect(graphicsDevice); basicEffect.VertexColorEnabled = true; basicEffect.View = camera.Matrix; diff --git a/RecrownedAthenaeum/Render/RectangleRenderer.cs b/RecrownedAthenaeum/Render/RectangleRenderer.cs index 956f5b6..8a746c5 100644 --- a/RecrownedAthenaeum/Render/RectangleRenderer.cs +++ b/RecrownedAthenaeum/Render/RectangleRenderer.cs @@ -1,6 +1,5 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using RecrownedAthenaeum.Camera; using System; namespace RecrownedAthenaeum.Render @@ -8,10 +7,10 @@ namespace RecrownedAthenaeum.Render /// /// Renders rectangles using the . /// - public class RectangleRenderer : IDisposable + public class RectangleRenderer { /// - /// The used. + /// The used. Needs to be disposed. /// public readonly PrimitiveBatch primitiveBatch; private bool disposed; @@ -27,16 +26,6 @@ namespace RecrownedAthenaeum.Render this.primitiveBatch = primitiveBatch; } - /// - /// Creates a rectangle renderer. - /// - /// The graphics device used to create the - /// The camera containing the matrix to be used for the transformations. - public RectangleRenderer(GraphicsDevice graphicsDevice, Camera2D camera) : this(new PrimitiveBatch(graphicsDevice, camera, 4)) - { - - } - /// /// Begins the render batch. /// @@ -98,40 +87,5 @@ namespace RecrownedAthenaeum.Render primitiveBatch.AddVertex(corners[3], color); } } - - /// - /// Attempts to dispose of this object. - /// - public void Dispose() - { - if (disposed) throw new ObjectDisposedException(typeof(PrimitiveBatch).Name); - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// An overridable of disposable. - /// - /// Only true when called by user code dispose. Destructor calling this results in false. - public virtual void Dispose(bool disposing) - { - disposed = true; - if (!disposed && disposing) - { - disposed = true; - if (primitiveBatch != null) - { - primitiveBatch.Dispose(); - } - } - } - - /// - /// Destructor. - /// - ~RectangleRenderer () - { - Dispose(false); - } } } diff --git a/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs b/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs index f7d7b6c..c7b9b23 100644 --- a/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs +++ b/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs @@ -23,7 +23,7 @@ namespace RecrownedAthenaeum.ScreenSystem /// Called when the first loading screen is done, and needs to show the landing screen. /// public event ShowFirstScreen ShowFirstScreenEvent; - private GraphicsDeviceManager graphics; + private GraphicsDeviceManager graphics = Setup.graphicsDeviceManager; private Screen previousScreen; private RenderTarget2D previousScreenRenderTarget; private Screen currentScreen; @@ -63,11 +63,12 @@ namespace RecrownedAthenaeum.ScreenSystem /// /// Creates a screen manager that helps manage multiple screens and their transitions. /// - /// The graphics device manager to be used. /// The camera to be used to perform the correct translations and transformations. - public ScreenManager(GraphicsDeviceManager graphicsDeviceManager, Camera2D camera) + /// The graphics device manager to be used. + public ScreenManager(Camera2D camera, GraphicsDeviceManager graphicsDeviceManager = null) { - this.graphics = graphicsDeviceManager; + if (graphicsDeviceManager != null) this.graphics = graphicsDeviceManager; + if (graphics == null) throw new ArgumentNullException("Graphics device manager argument cannot be null if setup's graphics device manager is also null."); this.camera = camera; } diff --git a/RecrownedAthenaeum/Setup.cs b/RecrownedAthenaeum/Setup.cs new file mode 100644 index 0000000..c7b1398 --- /dev/null +++ b/RecrownedAthenaeum/Setup.cs @@ -0,0 +1,15 @@ +using Microsoft.Xna.Framework; + +namespace RecrownedAthenaeum +{ + /// + /// All variables here should be for RecrownedAthenaeum to use when needed and thus eliminates unessecary passing. + /// + public static class Setup + { + /// + /// The graphics device that will be used by default. + /// + public static GraphicsDeviceManager graphicsDeviceManager; + } +} diff --git a/RecrownedAthenaeum/SpecialTypes/NinePatch.cs b/RecrownedAthenaeum/SpecialTypes/NinePatch.cs index 1964258..48ad052 100644 --- a/RecrownedAthenaeum/SpecialTypes/NinePatch.cs +++ b/RecrownedAthenaeum/SpecialTypes/NinePatch.cs @@ -28,10 +28,11 @@ namespace RecrownedAthenaeum.SpecialTypes /// Right side. /// Bottom side. /// Top side. - public NinePatch(Texture2D texture, int left, int right, int bottom, int top) + /// The dimensions and potentially the coordinates of the rectangle on an atlas. If left to default of null, will only be set to texture bounds. + public NinePatch(Texture2D texture, int left, int right, int bottom, int top, Rectangle? textureBounds = null) { this.texture = texture; - textureRegion = texture.Bounds; + if (textureBounds.HasValue) textureRegion = textureBounds.Value; else textureRegion = texture.Bounds; if (left + right >= textureRegion.Width) throw new ArgumentOutOfRangeException("a and b cannot be greater than or equal to the width of region."); if (bottom + top >= textureRegion.Height) throw new ArgumentOutOfRangeException("c and d cannot be greater or equal to the height of the texture."); this.left = left; diff --git a/RecrownedAthenaeum/SpecialTypes/TextureAtlas.cs b/RecrownedAthenaeum/SpecialTypes/TextureAtlas.cs index b01405b..0f0a90a 100644 --- a/RecrownedAthenaeum/SpecialTypes/TextureAtlas.cs +++ b/RecrownedAthenaeum/SpecialTypes/TextureAtlas.cs @@ -65,10 +65,11 @@ namespace RecrownedAthenaeum.SpecialTypes /// Creates or obtains a previously created texture of a region. /// /// Name of region. - /// graphics device to be used. + /// graphics device to be used. Default is null and will resort to using graphics device from 's graphics device manager. /// The texture from the region. - public Texture2D ObtainRegionAsTexture(string name, GraphicsDevice graphicsDevice) + public Texture2D ObtainRegionAsTexture(string name, GraphicsDevice graphicsDevice = null) { + if (graphicsDevice == null) graphicsDevice = Setup.graphicsDeviceManager.GraphicsDevice; return dictionaryOfRegions[name].AsTexture2D(graphicsDevice); } @@ -174,15 +175,16 @@ namespace RecrownedAthenaeum.SpecialTypes /// /// Create or obtains a previously created texture of this region. /// - /// The graphics device to use to create the texture. + /// The graphics device to use to create the texture. Will use graphics device from 's graphics device manager if left to null. /// The texture of the region. - public Texture2D AsTexture2D(GraphicsDevice graphicsDevice) + public Texture2D AsTexture2D(GraphicsDevice graphicsDevice = null) { if (Disposed) throw new ObjectDisposedException(GetType().Name); if (regionTexture == null) { Color[] data = new Color[sourceRectangle.Width * sourceRectangle.Height]; + if (graphicsDevice == null) graphicsDevice = Setup.graphicsDeviceManager.GraphicsDevice; regionTexture = new Texture2D(graphicsDevice, sourceRectangle.Width, sourceRectangle.Height); atlasTexture.GetData(0, sourceRectangle, data, 0, sourceRectangle.Width * sourceRectangle.Height); regionTexture.SetData(data); diff --git a/RecrownedAthenaeum/UI/Skin/SkinManager.cs b/RecrownedAthenaeum/UI/Skin/SkinManager.cs index a5bf8f0..354f44b 100644 --- a/RecrownedAthenaeum/UI/Skin/SkinManager.cs +++ b/RecrownedAthenaeum/UI/Skin/SkinManager.cs @@ -66,7 +66,7 @@ namespace RecrownedAthenaeum.UI.Skin public ISkin Skin { get { return mergedSkin; } } /// - /// The user loaded skin. Set by the skin loaded by calling . + /// The user loaded skin. Set by the skin loaded by calling . /// public ISkin loadedSkin { get { return mergedSkin.mainSkin; } private set { mergedSkin.mainSkin = value; } } @@ -106,11 +106,12 @@ namespace RecrownedAthenaeum.UI.Skin /// /// loads a skin asynchronously. /// - /// Graphics device to use for texture creation. + /// Graphics device to use for texture creation. Uses graphics device from by default. /// The data to generate from. /// The path pointing to the file with the extension "". - public void LoadSkin(GraphicsDevice graphicsDevice, SkinData skinData, string path) + public void LoadSkin(SkinData skinData, string path, GraphicsDevice graphicsDevice = null) { + if (graphicsDevice == null) graphicsDevice = Setup.graphicsDeviceManager.GraphicsDevice; action = Action.LOAD; this.graphicsDevice = graphicsDevice; this.selectedSkinPath = path;