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-09-15 18:15:32 +00:00
|
|
|
|
Dictionary<string, Page> pages = new Dictionary<string, Page>();
|
2018-11-12 06:33:40 +00:00
|
|
|
|
|
|
|
|
|
public Book(Camera2D camera)
|
|
|
|
|
{
|
|
|
|
|
this.camera = camera;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Draw(SpriteBatch batch)
|
2018-09-15 18:15:32 +00:00
|
|
|
|
{
|
2018-11-12 06:33:40 +00:00
|
|
|
|
for (int page = 0; page < pages.Count; page++)
|
|
|
|
|
{
|
2018-11-13 00:34:11 +00:00
|
|
|
|
pages.ElementAt(page).Value.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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int page = 0; page < pages.Count; page++)
|
|
|
|
|
{
|
|
|
|
|
pages.ElementAt(page).Value.Update(gameTime);
|
|
|
|
|
}
|
2018-09-15 18:15:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddPage(Page page)
|
|
|
|
|
{
|
|
|
|
|
pages.Add(page.Name, page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|