rhythmbullet/RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs

87 lines
2.8 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.Zer01HD.Game.Screens;
using RhythmBullet.Zer01HD.Utilities.UI;
using System;
using System.Diagnostics;
namespace RhythmBullet.Zer01HD.Game
{
class LoadingScreen : Screen
{
Texture2D texture;
Color color;
Rectangle rectangleBounds;
float proportion = 0.5f;
bool recorded;
float rR, rG, rB;
float progR, progG, progB;
float progC = 254;
public LoadingScreen(Texture2D texture, Rectangle dimensions) : base(true)
{
color = Color.White;
this.texture = texture;
rectangleBounds = new Rectangle(0, 0, (int)(dimensions.Height * proportion), (int)(dimensions.Height * proportion));
rectangleBounds.X = (dimensions.Width - rectangleBounds.Width) / 2;
rectangleBounds.Y = (dimensions.Height - rectangleBounds.Height) / 2;
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
public override void EnteringTransition(double delta, bool assetsLoaded, ref Color BGColor)
{
float deltaf = (float)delta;
if (progR < 254 || progG < 254 || progB < 254)
{
if (!recorded)
{
rR = (Color.White.R - BGColor.R) / 2.5f;
rG = (Color.White.G - BGColor.G) / 2.5f;
rB = (Color.White.B - BGColor.B) / 2.5f;
recorded = true;
}
progR += rR * deltaf;
progR = Math.Min(progR, 254);
progG += rG * deltaf;
progG = Math.Min(progG, 254);
progB += rB * deltaf;
progB = Math.Min(progB, 254);
BGColor.R = (byte)progR;
BGColor.G = (byte)progG;
BGColor.B = (byte)progB;
}
else if (progC > 0)
{
float rate = deltaf * 255 / 1.5f;
progC -= rate;
progC = Math.Max(progC, 0);
color.R = (byte)progC;
color.G = (byte)progC;
color.B = (byte)progC;
color.A = (byte)progC;
}
else if (assetsLoaded)
{
DoneTransition();
StartExitTransition();
}
base.EnteringTransition(delta, assetsLoaded, ref BGColor);
}
public override Screen ExitingTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
{
return new MainScreen();
}
public override void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, rectangleBounds, color);
base.Draw(spriteBatch);
}
}
}