Implement module var name refactor and added way to keep insertion order.
This commit is contained in:
parent
ce2f402153
commit
782ca31f15
@ -1,7 +1,9 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
using RecrownedAthenaeum.Camera;
|
using RecrownedAthenaeum.Camera;
|
||||||
using RecrownedAthenaeum.ContentSystem;
|
using RecrownedAthenaeum.ContentSystem;
|
||||||
|
using RecrownedAthenaeum.Input;
|
||||||
using RecrownedAthenaeum.UI.SkinSystem;
|
using RecrownedAthenaeum.UI.SkinSystem;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -11,7 +13,7 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains the pages.
|
/// Contains the pages.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Book
|
public class Book : IInputListener
|
||||||
{
|
{
|
||||||
readonly ContentManagerController assets;
|
readonly ContentManagerController assets;
|
||||||
readonly ISkin skin;
|
readonly ISkin skin;
|
||||||
@ -19,6 +21,7 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
|||||||
Page targetPage;
|
Page targetPage;
|
||||||
Rectangle dimensions;
|
Rectangle dimensions;
|
||||||
Dictionary<string, Page> pages = new Dictionary<string, Page>();
|
Dictionary<string, Page> pages = new Dictionary<string, Page>();
|
||||||
|
List<Page> orderedPages = new List<Page>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a book.
|
/// Creates a book.
|
||||||
@ -52,7 +55,7 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
|||||||
{
|
{
|
||||||
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
||||||
{
|
{
|
||||||
Page page = pages.ElementAt(pageIndex).Value;
|
Page page = orderedPages[pageIndex];
|
||||||
page.Draw(batch);
|
page.Draw(batch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,7 +69,7 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
|||||||
if (targetPage != null)
|
if (targetPage != null)
|
||||||
{
|
{
|
||||||
Vector2 position;
|
Vector2 position;
|
||||||
Rectangle targetBounds = targetPage.bounds;
|
Rectangle targetBounds = targetPage.situation;
|
||||||
position.X = targetBounds.X + (targetBounds.Width * 0.5f);
|
position.X = targetBounds.X + (targetBounds.Width * 0.5f);
|
||||||
position.Y = targetBounds.Y + (targetBounds.Height * 0.5f);
|
position.Y = targetBounds.Y + (targetBounds.Height * 0.5f);
|
||||||
camera.LinearInterpolationToPosition(0.4f, position, (float)gameTime.ElapsedGameTime.TotalSeconds);
|
camera.LinearInterpolationToPosition(0.4f, position, (float)gameTime.ElapsedGameTime.TotalSeconds);
|
||||||
@ -94,6 +97,7 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
|||||||
{
|
{
|
||||||
page.camera = camera;
|
page.camera = camera;
|
||||||
page.Initialize(assets, skin);
|
page.Initialize(assets, skin);
|
||||||
|
orderedPages.Add(page);
|
||||||
this.pages.Add(page.Name, page);
|
this.pages.Add(page.Name, page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,9 +117,20 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
|||||||
/// <param name="name">Name of page to remove.</param>
|
/// <param name="name">Name of page to remove.</param>
|
||||||
public void RemovePage(string name)
|
public void RemovePage(string name)
|
||||||
{
|
{
|
||||||
|
orderedPages.Remove(pages[name]);
|
||||||
pages.Remove(name);
|
pages.Remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes all pages.
|
||||||
|
/// </summary>
|
||||||
|
public void ClearPages()
|
||||||
|
{
|
||||||
|
orderedPages.Clear();
|
||||||
|
pages.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Perform a step of linear interpolation to the given page.
|
/// Perform a step of linear interpolation to the given page.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -131,9 +146,39 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
|||||||
/// <param name="page">Page to go to.</param>
|
/// <param name="page">Page to go to.</param>
|
||||||
public void GoToPage(Page page)
|
public void GoToPage(Page page)
|
||||||
{
|
{
|
||||||
Rectangle targetBounds = page.bounds;
|
Rectangle targetBounds = page.situation;
|
||||||
camera.position.X = targetBounds.X + (targetBounds.Width * 0.5f);
|
camera.position.X = targetBounds.X + (targetBounds.Width * 0.5f);
|
||||||
camera.position.Y = targetBounds.Y + (targetBounds.Height * 0.5f);
|
camera.position.Y = targetBounds.Y + (targetBounds.Height * 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Passes the new keyboard state down to each page in order of when it was added.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="state"></param>
|
||||||
|
/// <returns>True if the state change should to trigger further input listeners.</returns>
|
||||||
|
public bool KeyboardStateChanged(KeyboardState state)
|
||||||
|
{
|
||||||
|
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
||||||
|
{
|
||||||
|
Page page = orderedPages[pageIndex];
|
||||||
|
if (!page.KeyboardStateChanged(state)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Passes the new mouse state down to each page in order of when it was added.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="state"></param>
|
||||||
|
/// <returns>True if the state change should to trigger further input listeners.</returns>
|
||||||
|
public bool MouseStateChanged(MouseState state)
|
||||||
|
{
|
||||||
|
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
||||||
|
{
|
||||||
|
Page page = orderedPages[pageIndex];
|
||||||
|
if (!page.MouseStateChanged(state)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,10 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
|||||||
/// <param name="height">New Height</param>
|
/// <param name="height">New Height</param>
|
||||||
public virtual void ApplySize(int width, int height)
|
public virtual void ApplySize(int width, int height)
|
||||||
{
|
{
|
||||||
bounds.X = pageX * width;
|
situation.X = pageX * width;
|
||||||
bounds.Y = pageY * height;
|
situation.Y = pageY * height;
|
||||||
bounds.Width = width;
|
situation.Width = width;
|
||||||
bounds.Height = height;
|
situation.Height = height;
|
||||||
requiresSizeUpdate = false;
|
requiresSizeUpdate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user