Changed 9p and tatlas' to use a separately loaded texture.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user