From 507cde744d2e1681f042f67dcadc2861a662e13e Mon Sep 17 00:00:00 2001 From: Recrown Date: Thu, 15 Nov 2018 01:22:19 -0600 Subject: [PATCH] screens update normal logic during transition now; added comments; book now has an initiate function; image has more functions; minor improvements on module system; --- .../Zer01HD/Utilities/ScreenSystem/Screen.cs | 13 +++++- .../Utilities/ScreenSystem/ScreenManager.cs | 4 +- .../Zer01HD/Utilities/UI/Book/Book.cs | 28 +++++++++--- .../Zer01HD/Utilities/UI/Book/Page.cs | 12 ++--- .../Utilities/UI/Modular/Modules/Image.cs | 44 +++++++++++++++++-- .../Zer01HD/Utilities/UI/Modular/UIModule.cs | 2 +- .../Utilities/UI/Modular/UIModuleGroup.cs | 2 +- 7 files changed, 82 insertions(+), 23 deletions(-) diff --git a/RhythmBullet/Zer01HD/Utilities/ScreenSystem/Screen.cs b/RhythmBullet/Zer01HD/Utilities/ScreenSystem/Screen.cs index 60b9554..7268ca6 100644 --- a/RhythmBullet/Zer01HD/Utilities/ScreenSystem/Screen.cs +++ b/RhythmBullet/Zer01HD/Utilities/ScreenSystem/Screen.cs @@ -18,7 +18,7 @@ namespace RhythmBullet.Zer01HD.Utilities.ScreenSystem public Color BackgroundColor; public GraphicsDevice GraphicsDevice { get; private set; } public Screen NextScreen { get; set; } - public Rectangle ScreenSize { get; protected set; } + public Rectangle ScreenSize { get; private set; } public bool Initiated { get; private set; } public Camera2D Camera { get; private set; } public Screen(bool useEnterTransition = false) @@ -27,7 +27,13 @@ namespace RhythmBullet.Zer01HD.Utilities.ScreenSystem Transitions = new List(); } - public void Initiate(GraphicsDevice graphicsDevice, Rectangle screenSize, Camera2D camera) + /// + /// Called only once after initialization to give required parameters. + /// + /// + /// + /// + public virtual void Initiate(GraphicsDevice graphicsDevice, Rectangle screenSize, Camera2D camera) { this.Camera = camera; this.ScreenSize = screenSize; @@ -100,6 +106,9 @@ namespace RhythmBullet.Zer01HD.Utilities.ScreenSystem return complete; } + /// + /// Called when the screen is shown. + /// public virtual void Show() { foreach (ITransition transition in Transitions) diff --git a/RhythmBullet/Zer01HD/Utilities/ScreenSystem/ScreenManager.cs b/RhythmBullet/Zer01HD/Utilities/ScreenSystem/ScreenManager.cs index 87a1644..47683cf 100644 --- a/RhythmBullet/Zer01HD/Utilities/ScreenSystem/ScreenManager.cs +++ b/RhythmBullet/Zer01HD/Utilities/ScreenSystem/ScreenManager.cs @@ -87,10 +87,8 @@ namespace RhythmBullet.Zer01HD.Utilities.ScreenSystem } } break; - case ScreenState.Normal: - Screen.Update(gameTime); - break; } + Screen.Update(gameTime); } public void DrawCurrentScreen(SpriteBatch spriteBatch) diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs b/RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs index 72b0a7c..cbdc741 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs @@ -13,18 +13,27 @@ namespace RhythmBullet.Zer01HD.UI.Book { Camera2D camera; Page targetPage; + Rectangle dimensions; Dictionary pages = new Dictionary(); - public Book(Camera2D camera) + /// + /// Should be called whenever a valid camera and dimensions for the book exist. + /// Initializes book with given parameters. + /// + /// Camera game is currently using. + /// Dimensions of the book and the dimensions the pages will use. + public void Initialize(Camera2D camera, Rectangle dimensions) { this.camera = camera; + this.dimensions = dimensions; } public void Draw(SpriteBatch batch) { - for (int page = 0; page < pages.Count; page++) + for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++) { - pages.ElementAt(page).Value.Draw(batch); + Page page = pages.ElementAt(pageIndex).Value; + page.Draw(batch); } } @@ -43,15 +52,20 @@ namespace RhythmBullet.Zer01HD.UI.Book } } - for (int page = 0; page < pages.Count; page++) + for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++) { - pages.ElementAt(page).Value.Update(gameTime); + Page page = pages.ElementAt(pageIndex).Value; + if (page.NeedsSizeUpdate) page.ApplySize(dimensions.Width, dimensions.Height); + page.Update(gameTime); } } - public void AddPage(Page page) + public void AddPages(params Page[] pages) { - pages.Add(page.Name, page); + foreach (Page page in pages) + { + this.pages.Add(page.Name, page); + } } public void RemovePage(Page page) diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs b/RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs index d336957..b1209d4 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using RhythmBullet.Zer01HD.UI.Modular; using RhythmBullet.Zer01HD.Utilities.Camera; using System; @@ -12,14 +13,14 @@ namespace RhythmBullet.Zer01HD.UI.Book class Page : UIModuleGroup { private readonly int pageX, pageY; - private GraphicsDevice graphicsDevice; + public bool NeedsSizeUpdate; - public Page(int pageX, int pageY, GraphicsDevice graphicsDevice) + public Page(int pageX, int pageY) : base(false) { - this.graphicsDevice = graphicsDevice; this.pageX = pageX; this.pageY = pageY; - ApplySize(graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height); + NeedsSizeUpdate = true; + Name = ToString(); } public virtual void ApplySize(int width, int height) @@ -28,6 +29,7 @@ namespace RhythmBullet.Zer01HD.UI.Book Bounds.Y = pageY * height; Bounds.Width = width; Bounds.Height = height; + NeedsSizeUpdate = false; } } } diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Modular/Modules/Image.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/Modules/Image.cs index 4508b3f..1076530 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Modular/Modules/Image.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Modular/Modules/Image.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using RhythmBullet.Zer01HD.UI.Modular; using System; using System.Collections.Generic; @@ -10,16 +11,51 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.Modular.Modules { class Image : UIModule { - Texture2D texture; + public Texture2D Texture { get; set; } + public float ScaleX + { + get + { + return (float)Bounds.Width / Texture.Width; + } + + set + { + Bounds.Width = (int)(Texture.Width * value); + } + } + + public float ScaleY + { + get + { + return (float)Bounds.Height / Texture.Height; + } + + set + { + Bounds.Height = (int)(Texture.Height * value); + } + } + + public float Scale + { + set + { + Bounds.Height = (int)(Texture.Height * value); + Bounds.Width = (int)(Texture.Width * value); + } + } public Image(Texture2D texture) { - this.texture = texture; + Texture = texture ?? throw new ArgumentException("Image requires a texture."); + Bounds = texture.Bounds; } public override void Draw(SpriteBatch batch) { - batch.Draw(texture, Bounds, Color); + batch.Draw(Texture, Bounds, Color); base.Draw(batch); } } diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModule.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModule.cs index 84963ef..80bdc99 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModule.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModule.cs @@ -16,7 +16,7 @@ namespace RhythmBullet.Zer01HD.UI.Modular public Rectangle Bounds; public UIModuleGroup Parent; public string Name; - public Color Color; + public Color Color = Color.White; public virtual void Update(GameTime gameTime) { diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs index 5b1d9a8..01fdb87 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs @@ -18,7 +18,7 @@ namespace RhythmBullet.Zer01HD.UI.Modular RasterizerState scissorRasterizer = new RasterizerState(); public Camera2D Camera { get; set; } - public UIModuleGroup(Camera2D camera = null, bool crop = false) + public UIModuleGroup(bool crop = false, Camera2D camera = null) { Camera = camera; if (crop)