refactoring; removed configuration setup; added consistent sprite batch; got rid of sprite batch settings; implemented newer setup;
This commit is contained in:
@@ -4,7 +4,9 @@ using Microsoft.Xna.Framework.Input;
|
||||
using RecrownedAthenaeum.Camera;
|
||||
using RecrownedAthenaeum.ContentSystem;
|
||||
using RecrownedAthenaeum.Input;
|
||||
using RecrownedAthenaeum.Render;
|
||||
using RecrownedAthenaeum.UI.SkinSystem;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -17,46 +19,80 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
||||
{
|
||||
readonly ContentManagerController assets;
|
||||
readonly ISkin skin;
|
||||
Camera2D camera;
|
||||
Page targetPage;
|
||||
Rectangle dimensions;
|
||||
int width, height;
|
||||
Dictionary<string, Page> pages = new Dictionary<string, Page>();
|
||||
List<Page> orderedPages = new List<Page>();
|
||||
|
||||
/// <summary>
|
||||
/// The camera to use to change between pages.
|
||||
/// </summary>
|
||||
public Camera2D camera;
|
||||
|
||||
/// <summary>
|
||||
/// The scissorbox used to crop things.
|
||||
/// </summary>
|
||||
public ScissorBox scissorBox;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a book.
|
||||
/// </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="skin">The skin that will be passed to pages during their initialization.</param>
|
||||
public Book(ContentManagerController assets, ISkin skin)
|
||||
/// <param name="camera">Camera to move to change pages.</param>
|
||||
/// <param name="scissorBox">The scissor box to use to crop the pages to the given dimensions. Default is null, and will not crop anything.</param>
|
||||
public Book(ContentManagerController assets, ISkin skin, Camera2D camera, ScissorBox scissorBox = null)
|
||||
{
|
||||
this.assets = assets;
|
||||
this.skin = skin;
|
||||
|
||||
this.camera = camera ?? throw new ArgumentNullException("Camera can't be null since book needs a camera to move to change between the slides (pages).");
|
||||
this.scissorBox = scissorBox;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Should be called whenever a valid camera and dimensions for the book exist.
|
||||
/// Initializes book with given parameters.
|
||||
/// Generally used with a <see cref="ScreenSystem.Screen"/> and called in the <see cref="ScreenSystem.Screen.Initiate(Rectangle, Camera2D)"/> function.
|
||||
/// Generally used with a <see cref="ScreenSystem.Screen"/> and called in the <see cref="ScreenSystem.Screen.ApplySize(int, int)"/> function.
|
||||
/// </summary>
|
||||
/// <param name="camera">Camera game is currently using.</param>
|
||||
/// <param name="camera">Camera to move to change pages.</param>
|
||||
/// <param name="dimensions">Dimensions of the book and the dimensions the pages will use.</param>
|
||||
public void Initiate(Camera2D camera, Rectangle dimensions)
|
||||
/// <param name="scissorBox">The scissor box to use to crop the pages to the given dimensions. Default is null, and will not crop anything.</param>
|
||||
public void Initiate(Camera2D camera, Rectangle dimensions, ScissorBox scissorBox = null)
|
||||
{
|
||||
this.camera = camera;
|
||||
this.dimensions = dimensions;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the size if the book's pages.
|
||||
/// </summary>
|
||||
/// <param name="width">The width of one page.</param>
|
||||
/// <param name="height">The height of one page.</param>
|
||||
public void ApplySize(int width, int height)
|
||||
{
|
||||
if (this.width == width && this.height == height) return;
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
||||
{
|
||||
Page page = orderedPages[pageIndex];
|
||||
if (page.Boundaries.Width != width || page.Boundaries.Height != height)
|
||||
{
|
||||
page.requiresSizeUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the pages.
|
||||
/// </summary>
|
||||
/// <param name="batch">Batch used to draw.</param>
|
||||
public void Draw(SpriteBatch batch)
|
||||
public void Draw(ConsistentSpriteBatch batch)
|
||||
{
|
||||
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
||||
{
|
||||
Page page = orderedPages[pageIndex];
|
||||
page.Draw(batch);
|
||||
orderedPages[pageIndex].Draw(batch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +118,7 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
||||
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
||||
{
|
||||
Page page = pages.ElementAt(pageIndex).Value;
|
||||
if (page.requiresSizeUpdate) page.ApplySize(dimensions.Width, dimensions.Height);
|
||||
if (page.requiresSizeUpdate) page.ApplySize(width, height);
|
||||
page.Update(gameTime);
|
||||
}
|
||||
}
|
||||
@@ -97,6 +133,7 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
||||
{
|
||||
orderedPages.Add(page);
|
||||
this.pages.Add(page.name, page);
|
||||
page.Initialize(assets, skin, scissorBox);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using RecrownedAthenaeum.ContentSystem;
|
||||
using RecrownedAthenaeum.Render;
|
||||
using RecrownedAthenaeum.UI.Modular;
|
||||
using RecrownedAthenaeum.UI.SkinSystem;
|
||||
|
||||
@@ -20,7 +21,7 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
||||
/// </summary>
|
||||
/// <param name="pageX">The X position in the book.</param>
|
||||
/// <param name="pageY">The Y position in the book.</param>
|
||||
public Page(int pageX, int pageY) : base(false)
|
||||
public Page(int pageX, int pageY) : base()
|
||||
{
|
||||
this.pageX = pageX;
|
||||
this.pageY = pageY;
|
||||
@@ -47,9 +48,10 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
||||
/// </summary>
|
||||
/// <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>
|
||||
protected internal virtual void Initialize(ContentManagerController assets, ISkin skin)
|
||||
/// <param name="scissorBox">The scissor box to use for cropping.</param>
|
||||
protected internal virtual void Initialize(ContentManagerController assets, ISkin skin, ScissorBox scissorBox)
|
||||
{
|
||||
|
||||
this.scissorBox = scissorBox;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user