screens update normal logic during transition now; added comments; book now has an initiate function; image has more functions; minor improvements on module system;
This commit is contained in:
parent
e00f89325d
commit
507cde744d
@ -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<ITransition>();
|
||||
}
|
||||
|
||||
public void Initiate(GraphicsDevice graphicsDevice, Rectangle screenSize, Camera2D camera)
|
||||
/// <summary>
|
||||
/// Called only once after initialization to give required parameters.
|
||||
/// </summary>
|
||||
/// <param name="graphicsDevice"></param>
|
||||
/// <param name="screenSize"></param>
|
||||
/// <param name="camera"></param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the screen is shown.
|
||||
/// </summary>
|
||||
public virtual void Show()
|
||||
{
|
||||
foreach (ITransition transition in Transitions)
|
||||
|
@ -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)
|
||||
|
@ -13,18 +13,27 @@ namespace RhythmBullet.Zer01HD.UI.Book
|
||||
{
|
||||
Camera2D camera;
|
||||
Page targetPage;
|
||||
Rectangle dimensions;
|
||||
Dictionary<string, Page> pages = new Dictionary<string, Page>();
|
||||
|
||||
public Book(Camera2D camera)
|
||||
/// <summary>
|
||||
/// Should be called whenever a valid camera and dimensions for the book exist.
|
||||
/// Initializes book with given parameters.
|
||||
/// </summary>
|
||||
/// <param name="camera">Camera game is currently using.</param>
|
||||
/// <param name="dimensions">Dimensions of the book and the dimensions the pages will use.</param>
|
||||
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)
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user