2018-11-12 06:33:40 +00:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
using RhythmBullet.Zer01HD.Utilities.Camera;
|
2018-09-15 18:15:32 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace RhythmBullet.Zer01HD.UI.Book
|
|
|
|
|
{
|
|
|
|
|
class Book
|
|
|
|
|
{
|
2018-11-12 06:33:40 +00:00
|
|
|
|
Camera2D camera;
|
|
|
|
|
Page targetPage;
|
2018-11-15 07:22:19 +00:00
|
|
|
|
Rectangle dimensions;
|
2018-09-15 18:15:32 +00:00
|
|
|
|
Dictionary<string, Page> pages = new Dictionary<string, Page>();
|
2018-11-12 06:33:40 +00:00
|
|
|
|
|
2018-11-15 07:22:19 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Should be called whenever a valid camera and dimensions for the book exist.
|
|
|
|
|
/// Initializes book with given parameters.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="camera">Camera game is currently using.</param>
|
|
|
|
|
/// <param name="dimensions">Dimensions of the book and the dimensions the pages will use.</param>
|
2018-11-15 07:22:35 +00:00
|
|
|
|
public void Initiate(Camera2D camera, Rectangle dimensions)
|
2018-11-12 06:33:40 +00:00
|
|
|
|
{
|
|
|
|
|
this.camera = camera;
|
2018-11-15 07:22:19 +00:00
|
|
|
|
this.dimensions = dimensions;
|
2018-11-12 06:33:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Draw(SpriteBatch batch)
|
2018-09-15 18:15:32 +00:00
|
|
|
|
{
|
2018-11-15 07:22:19 +00:00
|
|
|
|
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
2018-11-12 06:33:40 +00:00
|
|
|
|
{
|
2018-11-15 07:22:19 +00:00
|
|
|
|
Page page = pages.ElementAt(pageIndex).Value;
|
|
|
|
|
page.Draw(batch);
|
2018-11-12 06:33:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(GameTime gameTime)
|
|
|
|
|
{
|
|
|
|
|
if (targetPage != null)
|
|
|
|
|
{
|
|
|
|
|
Vector2 position;
|
|
|
|
|
Rectangle targetBounds = targetPage.Bounds;
|
|
|
|
|
position.X = targetBounds.X + (targetBounds.Width * 0.5f);
|
|
|
|
|
position.Y = targetBounds.Y + (targetBounds.Height * 0.5f);
|
|
|
|
|
camera.LinearInterpolationToPosition(0.4f, position);
|
|
|
|
|
if (camera.Position == position)
|
|
|
|
|
{
|
|
|
|
|
targetPage = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 07:22:19 +00:00
|
|
|
|
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
2018-11-12 06:33:40 +00:00
|
|
|
|
{
|
2018-11-15 07:22:19 +00:00
|
|
|
|
Page page = pages.ElementAt(pageIndex).Value;
|
|
|
|
|
if (page.NeedsSizeUpdate) page.ApplySize(dimensions.Width, dimensions.Height);
|
|
|
|
|
page.Update(gameTime);
|
2018-11-12 06:33:40 +00:00
|
|
|
|
}
|
2018-09-15 18:15:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 07:22:19 +00:00
|
|
|
|
public void AddPages(params Page[] pages)
|
2018-09-15 18:15:32 +00:00
|
|
|
|
{
|
2018-11-15 07:22:19 +00:00
|
|
|
|
foreach (Page page in pages)
|
|
|
|
|
{
|
|
|
|
|
this.pages.Add(page.Name, page);
|
|
|
|
|
}
|
2018-09-15 18:15:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemovePage(Page page)
|
|
|
|
|
{
|
|
|
|
|
RemovePage(page.Name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemovePage(string name)
|
|
|
|
|
{
|
|
|
|
|
pages.Remove(name);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-12 06:33:40 +00:00
|
|
|
|
public void LerpToPage(Page page)
|
2018-09-15 18:15:32 +00:00
|
|
|
|
{
|
2018-11-12 06:33:40 +00:00
|
|
|
|
targetPage = page;
|
2018-09-15 18:15:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-12 06:33:40 +00:00
|
|
|
|
public void GoToPage(Page page)
|
2018-09-15 18:15:32 +00:00
|
|
|
|
{
|
2018-11-12 06:33:40 +00:00
|
|
|
|
Rectangle targetBounds = page.Bounds;
|
|
|
|
|
camera.Position.X = targetBounds.X + (targetBounds.Width * 0.5f);
|
|
|
|
|
camera.Position.Y = targetBounds.Y + (targetBounds.Height * 0.5f);
|
2018-09-15 18:15:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|