From 0f10ce3a079fd9a999d51ba86599dcb995bc0564 Mon Sep 17 00:00:00 2001 From: Recrown Date: Mon, 12 Nov 2018 00:33:40 -0600 Subject: [PATCH] book and page now use the new camera system; added functionality to camera; progress on mainscreen; --- .../Zer01HD/Game/Screens/MainScreen.cs | 11 +++- .../Zer01HD/Utilities/Camera/Camera2D.cs | 7 +++ .../Zer01HD/Utilities/UI/Book/Book.cs | 52 +++++++++++++++---- .../Zer01HD/Utilities/UI/Book/Page.cs | 7 +-- .../Utilities/UI/Modular/UIModuleGroup.cs | 1 + 5 files changed, 62 insertions(+), 16 deletions(-) diff --git a/RhythmBullet/Zer01HD/Game/Screens/MainScreen.cs b/RhythmBullet/Zer01HD/Game/Screens/MainScreen.cs index 1bb2986..ca43ef7 100644 --- a/RhythmBullet/Zer01HD/Game/Screens/MainScreen.cs +++ b/RhythmBullet/Zer01HD/Game/Screens/MainScreen.cs @@ -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("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); + } } } diff --git a/RhythmBullet/Zer01HD/Utilities/Camera/Camera2D.cs b/RhythmBullet/Zer01HD/Utilities/Camera/Camera2D.cs index 75e1da4..4c302d3 100644 --- a/RhythmBullet/Zer01HD/Utilities/Camera/Camera2D.cs +++ b/RhythmBullet/Zer01HD/Utilities/Camera/Camera2D.cs @@ -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); + } } } diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs b/RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs index e08fb8c..3454a41 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs @@ -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 pages = new Dictionary(); - 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); } } } diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs b/RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs index e26abcc..4d7a03a 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs @@ -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; - } } } diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs index c606dc3..883b3e0 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs @@ -16,6 +16,7 @@ namespace RhythmBullet.Zer01HD.UI.Modular List modules = new List(); Rectangle scissorBounds; RasterizerState scissorRasterizer = new RasterizerState(); + public UIModuleGroup(bool crop = false) { if (crop)