book and page now use the new camera system; added functionality to camera; progress on mainscreen;
This commit is contained in:
parent
a2defc5d11
commit
0f10ce3a07
@ -11,6 +11,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RhythmBullet.Zer01HD.UI.Book;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.Game.Screens
|
||||
{
|
||||
@ -18,11 +19,12 @@ namespace RhythmBullet.Zer01HD.Game.Screens
|
||||
{
|
||||
FadeAwayTransition fat;
|
||||
Texture2D background;
|
||||
|
||||
Book book;
|
||||
public MainScreen(ContentSystem assets) : base(true)
|
||||
{
|
||||
background = assets.Get<Texture2D>("backgrounds/mainBG");
|
||||
fat = new FadeAwayTransition(1.25f);
|
||||
book = new Book(Camera);
|
||||
}
|
||||
|
||||
public override void Show()
|
||||
@ -33,8 +35,15 @@ namespace RhythmBullet.Zer01HD.Game.Screens
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
book.Draw(spriteBatch);
|
||||
spriteBatch.Draw(background, ScreenSize, Color.White);
|
||||
base.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
book.Update(gameTime);
|
||||
base.Update(gameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,5 +31,12 @@ namespace RhythmBullet.Zer01HD.Utilities.Camera
|
||||
Matrix.CreateScale(Zoom) *
|
||||
Matrix.CreateTranslation(new Vector3(bounds.Width * 0.5f, bounds.Height * 0.5f, 0f));
|
||||
}
|
||||
|
||||
public void LinearInterpolationToPosition(float alpha, Vector2 targetPosition)
|
||||
{
|
||||
if (alpha < 0 && alpha > 1f) throw new ArgumentException("Alpha can't be greater than 1f, or less than 0.");
|
||||
Position.X = MathHelper.Lerp(Position.X, targetPosition.X, alpha);
|
||||
Position.Y = MathHelper.Lerp(Position.Y, targetPosition.Y, alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RhythmBullet.Zer01HD.Utilities.Camera;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -9,11 +11,42 @@ namespace RhythmBullet.Zer01HD.UI.Book
|
||||
{
|
||||
class Book
|
||||
{
|
||||
Viewport viewport;
|
||||
Camera2D camera;
|
||||
Page targetPage;
|
||||
Dictionary<string, Page> pages = new Dictionary<string, Page>();
|
||||
public Book(Viewport viewport)
|
||||
|
||||
public Book(Camera2D camera)
|
||||
{
|
||||
this.viewport = viewport;
|
||||
this.camera = camera;
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch batch)
|
||||
{
|
||||
for (int page = 0; page < pages.Count; page++)
|
||||
{
|
||||
pages.ElementAt(page).Value.Draw(batch, camera);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@ -31,15 +64,16 @@ namespace RhythmBullet.Zer01HD.UI.Book
|
||||
pages.Remove(name);
|
||||
}
|
||||
|
||||
public void Resize(int width, int height)
|
||||
public void LerpToPage(Page page)
|
||||
{
|
||||
viewport.Width = width;
|
||||
viewport.Height = height;
|
||||
targetPage = page;
|
||||
}
|
||||
|
||||
public void DisplayPage(string name)
|
||||
public void GoToPage(Page page)
|
||||
{
|
||||
pages[name].DisplayWithViewport(viewport);
|
||||
Rectangle targetBounds = page.Bounds;
|
||||
camera.Position.X = targetBounds.X + (targetBounds.Width * 0.5f);
|
||||
camera.Position.Y = targetBounds.Y + (targetBounds.Height * 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RhythmBullet.Zer01HD.UI.Modular;
|
||||
using RhythmBullet.Zer01HD.Utilities.Camera;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -26,11 +27,5 @@ namespace RhythmBullet.Zer01HD.UI.Book
|
||||
Bounds.Width = width;
|
||||
Bounds.Height = height;
|
||||
}
|
||||
|
||||
public void DisplayWithViewport(Viewport viewport)
|
||||
{
|
||||
viewport.X = Bounds.X;
|
||||
viewport.Y = Bounds.Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ namespace RhythmBullet.Zer01HD.UI.Modular
|
||||
List<UIModule> modules = new List<UIModule>();
|
||||
Rectangle scissorBounds;
|
||||
RasterizerState scissorRasterizer = new RasterizerState();
|
||||
|
||||
public UIModuleGroup(bool crop = false)
|
||||
{
|
||||
if (crop)
|
||||
|
Loading…
x
Reference in New Issue
Block a user