From 782ca31f15c2cbc6264a88b4cddf390c094d1f3e Mon Sep 17 00:00:00 2001 From: Recrown Date: Sat, 9 Mar 2019 00:55:44 -0600 Subject: [PATCH] Implement module var name refactor and added way to keep insertion order. --- RecrownedAthenaeum/UI/BookSystem/Book.cs | 53 ++++++++++++++++++++++-- RecrownedAthenaeum/UI/BookSystem/Page.cs | 8 ++-- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/RecrownedAthenaeum/UI/BookSystem/Book.cs b/RecrownedAthenaeum/UI/BookSystem/Book.cs index 9b7e38a..ef41f96 100644 --- a/RecrownedAthenaeum/UI/BookSystem/Book.cs +++ b/RecrownedAthenaeum/UI/BookSystem/Book.cs @@ -1,7 +1,9 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; using RecrownedAthenaeum.Camera; using RecrownedAthenaeum.ContentSystem; +using RecrownedAthenaeum.Input; using RecrownedAthenaeum.UI.SkinSystem; using System.Collections.Generic; using System.Linq; @@ -11,7 +13,7 @@ namespace RecrownedAthenaeum.UI.BookSystem /// /// Contains the pages. /// - public class Book + public class Book : IInputListener { readonly ContentManagerController assets; readonly ISkin skin; @@ -19,6 +21,7 @@ namespace RecrownedAthenaeum.UI.BookSystem Page targetPage; Rectangle dimensions; Dictionary pages = new Dictionary(); + List orderedPages = new List(); /// /// Creates a book. @@ -52,7 +55,7 @@ namespace RecrownedAthenaeum.UI.BookSystem { for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++) { - Page page = pages.ElementAt(pageIndex).Value; + Page page = orderedPages[pageIndex]; page.Draw(batch); } } @@ -66,7 +69,7 @@ namespace RecrownedAthenaeum.UI.BookSystem if (targetPage != null) { Vector2 position; - Rectangle targetBounds = targetPage.bounds; + Rectangle targetBounds = targetPage.situation; position.X = targetBounds.X + (targetBounds.Width * 0.5f); position.Y = targetBounds.Y + (targetBounds.Height * 0.5f); camera.LinearInterpolationToPosition(0.4f, position, (float)gameTime.ElapsedGameTime.TotalSeconds); @@ -94,6 +97,7 @@ namespace RecrownedAthenaeum.UI.BookSystem { page.camera = camera; page.Initialize(assets, skin); + orderedPages.Add(page); this.pages.Add(page.Name, page); } } @@ -113,9 +117,20 @@ namespace RecrownedAthenaeum.UI.BookSystem /// Name of page to remove. public void RemovePage(string name) { + orderedPages.Remove(pages[name]); pages.Remove(name); } + + /// + /// Removes all pages. + /// + public void ClearPages() + { + orderedPages.Clear(); + pages.Clear(); + } + /// /// Perform a step of linear interpolation to the given page. /// @@ -131,9 +146,39 @@ namespace RecrownedAthenaeum.UI.BookSystem /// Page to go to. public void GoToPage(Page page) { - Rectangle targetBounds = page.bounds; + Rectangle targetBounds = page.situation; camera.position.X = targetBounds.X + (targetBounds.Width * 0.5f); camera.position.Y = targetBounds.Y + (targetBounds.Height * 0.5f); } + + /// + /// Passes the new keyboard state down to each page in order of when it was added. + /// + /// + /// True if the state change should to trigger further input listeners. + public bool KeyboardStateChanged(KeyboardState state) + { + for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++) + { + Page page = orderedPages[pageIndex]; + if (!page.KeyboardStateChanged(state)) return false; + } + return true; + } + + /// + /// Passes the new mouse state down to each page in order of when it was added. + /// + /// + /// True if the state change should to trigger further input listeners. + public bool MouseStateChanged(MouseState state) + { + for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++) + { + Page page = orderedPages[pageIndex]; + if (!page.MouseStateChanged(state)) return false; + } + return true; + } } } diff --git a/RecrownedAthenaeum/UI/BookSystem/Page.cs b/RecrownedAthenaeum/UI/BookSystem/Page.cs index 29e78fb..710b616 100644 --- a/RecrownedAthenaeum/UI/BookSystem/Page.cs +++ b/RecrownedAthenaeum/UI/BookSystem/Page.cs @@ -35,10 +35,10 @@ namespace RecrownedAthenaeum.UI.BookSystem /// New Height public virtual void ApplySize(int width, int height) { - bounds.X = pageX * width; - bounds.Y = pageY * height; - bounds.Width = width; - bounds.Height = height; + situation.X = pageX * width; + situation.Y = pageY * height; + situation.Width = width; + situation.Height = height; requiresSizeUpdate = false; }