Start of transition to OTK

This commit is contained in:
Harrison Deng 2019-11-24 00:17:21 -05:00
parent c04f2f1b78
commit 9387611b19
8 changed files with 8 additions and 91 deletions

View File

@ -3,7 +3,6 @@
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="MonoGame.Framework.Content.Pipeline.Portable" Version="3.7.1.189" PrivateAssets="All"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\RecrownedAthenaeum\RecrownedAthenaeum.csproj" PrivateAssets="All"/> <ProjectReference Include="..\RecrownedAthenaeum\RecrownedAthenaeum.csproj" PrivateAssets="All"/>

View File

@ -1,16 +0,0 @@
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using RecrownedAthenaeum.SpecialTypes;
namespace RecrownedAthenaeum.ContentReaders
{
class NinePatchDataReader : ContentTypeReader<NinePatch>
{
protected override NinePatch Read(ContentReader input, NinePatch existingInstance)
{
Texture2D texture = input.ContentManager.Load<Texture2D>(input.ReadString());
NinePatch ninePatch = new NinePatch(texture, input.ReadInt32(), input.ReadInt32(), input.ReadInt32(), input.ReadInt32());
return ninePatch;
}
}
}

View File

@ -1,66 +0,0 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using RecrownedAthenaeum.Data;
using RecrownedAthenaeum.SpecialTypes;
using System.IO;
namespace RecrownedAthenaeum.ContentReaders
{
class TextureAtlasDataReader : ContentTypeReader<TextureAtlas>
{
protected override TextureAtlas Read(ContentReader input, TextureAtlas existingInstance)
{
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>
/// <param name="textureAtlasData">The data to generate the regions from.</param>
/// <param name="atlasTexture">The texture containing the atlas.</param>
/// <returns>An array of regions.</returns>
public TextureAtlas.Region[] GenerateAtlasRegionsFromData(TextureAtlasData textureAtlasData, Texture2D atlasTexture)
{
TextureAtlas.Region[] regions = new TextureAtlas.Region[textureAtlasData.regions.Length];
for (int regionID = 0; regionID < regions.Length; regionID++)
{
TextureAtlasData.AtlasRegionData regionData = textureAtlasData.regions[regionID];
NinePatch nPatch = null;
if (regionData.ninePatchData != null)
{
NinePatchData nPatchData = regionData.ninePatchData;
nPatch = new NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.bottom, nPatchData.bottom, regionData.bounds);
}
regions[regionID] = new TextureAtlas.Region(regionData.name, regionData.bounds, nPatch, atlasTexture);
}
return regions;
}
}
}

View File

@ -9,7 +9,7 @@ namespace RecrownedAthenaeum.ContentSystem
/// <summary> /// <summary>
/// Wrapper for the content manager that helps with controlling it by adding automated multithreaded content loading. /// Wrapper for the content manager that helps with controlling it by adding automated multithreaded content loading.
/// </summary> /// </summary>
public class ContentManagerController public class AssetManager
{ {
Thread thread; Thread thread;
readonly ContentManager contentManager; readonly ContentManager contentManager;
@ -40,7 +40,7 @@ namespace RecrownedAthenaeum.ContentSystem
/// Wraps the <see cref="ContentManager"/>. /// Wraps the <see cref="ContentManager"/>.
/// </summary> /// </summary>
/// <param name="contentManager">The manager to wrap.</param> /// <param name="contentManager">The manager to wrap.</param>
public ContentManagerController(ContentManager contentManager) public AssetManager()
{ {
this.contentManager = contentManager; this.contentManager = contentManager;
assets = new Dictionary<string, Object>(); assets = new Dictionary<string, Object>();

View File

@ -1,7 +1,7 @@
namespace RecrownedAthenaeum.ContentSystem namespace RecrownedAthenaeum.ContentSystem
{ {
/// <summary> /// <summary>
/// Modifies the given path based on a name. Used to simplify long paths for the <see cref="ContentManagerController"/> /// Modifies the given path based on a name. Used to simplify long paths for the <see cref="AssetManager"/>
/// </summary> /// </summary>
public interface IContentPathResolver public interface IContentPathResolver
{ {

View File

@ -4,6 +4,6 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3"/> <PackageReference Include="Newtonsoft.Json" Version="12.0.3"/>
<PackageReference Include="MonoGame.Framework.Portable" Version="3.6.0.1625" PrivateAssets="All"/> <PackageReference Include="OpenTK" Version="3.1.0"/>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -15,7 +15,7 @@ namespace RecrownedAthenaeum.UI.BookSystem
/// </summary> /// </summary>
public class Book : IInputListener public class Book : IInputListener
{ {
readonly ContentManagerController assets; readonly AssetManager assets;
readonly ISkin skin; readonly ISkin skin;
Page targetPage; Page targetPage;
int width, height; int width, height;
@ -31,10 +31,10 @@ namespace RecrownedAthenaeum.UI.BookSystem
/// <summary> /// <summary>
/// Creates a book. /// Creates a book.
/// </summary> /// </summary>
/// <param name="assets"><see cref="ContentManagerController"/> that holds the assets that are to be used in the pages for this book during initialization.</param> /// <param name="assets"><see cref="AssetManager"/> that holds the assets that are to be used in the pages for this book during initialization.</param>
/// <param name="skin">The skin that will be passed to pages during their initialization.</param> /// <param name="skin">The skin that will be passed to pages during their initialization.</param>
/// <param name="camera">Camera to move to change pages.</param> /// <param name="camera">Camera to move to change pages.</param>
public Book(ContentManagerController assets, ISkin skin, Camera2D camera) public Book(AssetManager assets, ISkin skin, Camera2D camera)
{ {
this.assets = assets; this.assets = assets;
this.skin = skin; this.skin = skin;

View File

@ -49,7 +49,7 @@ namespace RecrownedAthenaeum.UI.BookSystem
/// <param name="assets">The assets to be used during initialization passed by the book this page belongs to.</param> /// <param name="assets">The assets to be used during initialization passed by the book this page belongs to.</param>
/// <param name="skin">The skin the book containing this page is given that can be used by this page.</param> /// <param name="skin">The skin the book containing this page is given that can be used by this page.</param>
/// <param name="basicScissor">The scissor box to use for cropping.</param> /// <param name="basicScissor">The scissor box to use for cropping.</param>
protected internal virtual void Initialize(ContentManagerController assets, ISkin skin, BasicScissor basicScissor) protected internal virtual void Initialize(AssetManager assets, ISkin skin, BasicScissor basicScissor)
{ {
this.basicScissor = basicScissor; this.basicScissor = basicScissor;
} }