2018-09-15 19:05:14 +00:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2018-11-01 04:58:26 +00:00
|
|
|
|
using RhythmBullet.Zer01HD.Game.Screens;
|
2018-09-16 06:37:48 +00:00
|
|
|
|
using RhythmBullet.Zer01HD.Utilities.UI;
|
2018-09-15 19:05:14 +00:00
|
|
|
|
using System;
|
2018-10-31 06:10:15 +00:00
|
|
|
|
using System.Diagnostics;
|
2018-09-15 19:05:14 +00:00
|
|
|
|
|
|
|
|
|
namespace RhythmBullet.Zer01HD.Game
|
|
|
|
|
{
|
2018-10-31 23:21:44 +00:00
|
|
|
|
class LoadingScreen : Screen
|
2018-09-15 19:05:14 +00:00
|
|
|
|
{
|
2018-11-02 03:02:25 +00:00
|
|
|
|
private const float ENTER_RATE = 2f;
|
|
|
|
|
private const float EXIT_RATE = 1f;
|
2018-11-02 02:20:46 +00:00
|
|
|
|
readonly Texture2D texture;
|
2018-10-31 23:21:44 +00:00
|
|
|
|
Color color;
|
2018-11-02 02:20:46 +00:00
|
|
|
|
Rectangle textureBounds;
|
|
|
|
|
readonly float proportion;
|
2018-11-01 04:58:26 +00:00
|
|
|
|
bool recorded;
|
|
|
|
|
float rR, rG, rB;
|
|
|
|
|
float progR, progG, progB;
|
|
|
|
|
float progC = 254;
|
2018-11-02 02:20:46 +00:00
|
|
|
|
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
|
|
|
|
{
|
2018-10-31 23:21:44 +00:00
|
|
|
|
color = Color.White;
|
2018-11-01 04:58:26 +00:00
|
|
|
|
this.texture = texture;
|
2018-11-02 02:20:46 +00:00
|
|
|
|
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;
|
2018-10-31 06:10:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update(GameTime gameTime)
|
|
|
|
|
{
|
2018-11-01 04:58:26 +00:00
|
|
|
|
base.Update(gameTime);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-03 06:08:39 +00:00
|
|
|
|
public override void EnteringTransition(double delta, bool assetsLoaded, ref Color BGColor, RenderTarget2D previousScreenExitFrame)
|
2018-11-01 04:58:26 +00:00
|
|
|
|
{
|
2018-11-02 02:20:46 +00:00
|
|
|
|
float deltaf = (float)delta;
|
|
|
|
|
if (rotate)
|
|
|
|
|
{
|
|
|
|
|
DoRotate(deltaf);
|
|
|
|
|
}
|
2018-11-01 05:15:29 +00:00
|
|
|
|
if (assetsLoaded)
|
2018-10-31 06:10:15 +00:00
|
|
|
|
{
|
2018-11-01 05:15:29 +00:00
|
|
|
|
if (progR < 254 || progG < 254 || progB < 254)
|
2018-10-31 06:10:15 +00:00
|
|
|
|
{
|
2018-11-01 05:15:29 +00:00
|
|
|
|
if (!recorded)
|
|
|
|
|
{
|
2018-11-02 03:02:25 +00:00
|
|
|
|
rR = (Color.White.R - BGColor.R) / ENTER_RATE;
|
|
|
|
|
rG = (Color.White.G - BGColor.G) / ENTER_RATE;
|
|
|
|
|
rB = (Color.White.B - BGColor.B) / ENTER_RATE;
|
2018-11-01 05:15:29 +00:00
|
|
|
|
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;
|
2018-10-31 06:10:15 +00:00
|
|
|
|
}
|
2018-11-01 05:15:29 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2018-11-02 02:20:46 +00:00
|
|
|
|
DoneEnterTransition();
|
2018-11-03 06:08:39 +00:00
|
|
|
|
StartExitTransition(true);
|
2018-11-01 05:15:29 +00:00
|
|
|
|
}
|
2018-11-02 02:20:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-01 05:15:29 +00:00
|
|
|
|
|
2018-11-02 02:20:46 +00:00
|
|
|
|
public override bool ExitingTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
|
|
|
|
|
{
|
|
|
|
|
float deltaf = (float)delta;
|
|
|
|
|
if (rotate)
|
|
|
|
|
{
|
|
|
|
|
DoRotate(deltaf);
|
|
|
|
|
}
|
|
|
|
|
if (progC > 0)
|
|
|
|
|
{
|
2018-11-02 03:02:25 +00:00
|
|
|
|
float rate = deltaf * 255 / EXIT_RATE;
|
2018-11-02 02:20:46 +00:00
|
|
|
|
progC -= rate;
|
|
|
|
|
progC = Math.Max(progC, 0);
|
|
|
|
|
color.R = (byte)progC;
|
|
|
|
|
color.G = (byte)progC;
|
|
|
|
|
color.B = (byte)progC;
|
|
|
|
|
color.A = (byte)progC;
|
2018-11-01 04:58:26 +00:00
|
|
|
|
}
|
2018-11-02 02:20:46 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2018-11-01 04:58:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-02 02:20:46 +00:00
|
|
|
|
void DoRotate(float deltaf)
|
2018-11-01 04:58:26 +00:00
|
|
|
|
{
|
2018-11-02 02:20:46 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2018-11-02 02:20:46 +00:00
|
|
|
|
spriteBatch.Draw(texture, textureBounds, null, color, rotation, origin, SpriteEffects.None, 0f);
|
2018-09-15 19:05:14 +00:00
|
|
|
|
base.Draw(spriteBatch);
|
|
|
|
|
}
|
2018-11-01 04:58:26 +00:00
|
|
|
|
|
2018-09-15 19:05:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|