rhythmbullet/RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs

80 lines
2.1 KiB
C#
Raw Normal View History

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.Zer01HD.Utilities.Camera;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.UI.Book
{
class Book
{
Camera2D camera;
Page targetPage;
Dictionary<string, Page> pages = new Dictionary<string, Page>();
public Book(Camera2D camera)
{
this.camera = camera;
}
public void Draw(SpriteBatch batch)
{
for (int page = 0; page < pages.Count; page++)
{
pages.ElementAt(page).Value.Draw(batch);
}
}
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);
}
}
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);
}
public void LerpToPage(Page page)
{
targetPage = page;
}
public void GoToPage(Page page)
{
Rectangle targetBounds = page.Bounds;
camera.Position.X = targetBounds.X + (targetBounds.Width * 0.5f);
camera.Position.Y = targetBounds.Y + (targetBounds.Height * 0.5f);
}
}
}