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

120 lines
3.6 KiB
C#
Raw Normal View History

2018-09-15 19:05:14 +00:00
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.Zer01HD.Game.Screens;
using RhythmBullet.Zer01HD.Utilities.UI;
2018-09-15 19:05:14 +00:00
using System;
using System.Diagnostics;
2018-09-15 19:05:14 +00:00
namespace RhythmBullet.Zer01HD.Game
{
class LoadingScreen : Screen
2018-09-15 19:05:14 +00:00
{
readonly Texture2D texture;
Color color;
Rectangle textureBounds;
readonly float proportion;
bool recorded;
float rR, rG, rB;
float progR, progG, progB;
float progC = 254;
float rotation;
readonly bool rotate;
Vector2 origin;
public LoadingScreen(Texture2D texture, float proportion, Rectangle dimensions, bool rotate = false) : base(true)
2018-09-15 19:05:14 +00:00
{
color = Color.White;
this.texture = texture;
this.proportion = proportion;
this.rotate = rotate;
textureBounds.Width = (int)(dimensions.Height * proportion);
textureBounds.Height = (int)(dimensions.Height * proportion);
textureBounds.X = (dimensions.Width) / 2;
textureBounds.Y = (dimensions.Height) / 2;
origin.X = texture.Width / 2;
origin.Y = texture.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 (rotate)
{
DoRotate(deltaf);
}
if (assetsLoaded)
{
if (progR < 254 || progG < 254 || progB < 254)
{
if (!recorded)
{
rR = (Color.White.R - BGColor.R) / 2f;
rG = (Color.White.G - BGColor.G) / 2f;
rB = (Color.White.B - BGColor.B) / 2f;
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
{
DoneEnterTransition();
StartExitTransition();
}
}
}
public override bool ExitingTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
{
float deltaf = (float)delta;
if (rotate)
{
DoRotate(deltaf);
}
if (progC > 0)
{
float rate = deltaf * 255 / 1f;
progC -= rate;
progC = Math.Max(progC, 0);
color.R = (byte)progC;
color.G = (byte)progC;
color.B = (byte)progC;
color.A = (byte)progC;
}
else
{
return true;
}
return false;
}
void DoRotate(float deltaf)
{
rotation += (2f / 3f) * (float)Math.PI * deltaf;
if (rotation >= 2 * Math.PI)
{
rotation = 0;
}
2018-09-15 19:05:14 +00:00
}
public override void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, textureBounds, null, color, rotation, origin, SpriteEffects.None, 0f);
2018-09-15 19:05:14 +00:00
base.Draw(spriteBatch);
}
2018-09-15 19:05:14 +00:00
}
}