2018-11-04 05:01:17 +00:00
|
|
|
|
|
|
|
|
|
using Microsoft.Xna.Framework;
|
2018-09-15 19:05:14 +00:00
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
using System;
|
|
|
|
|
|
2018-11-11 20:44:30 +00:00
|
|
|
|
namespace RhythmBullet.Zer01HD.Utilities.ScreenSystem
|
2018-09-15 19:05:14 +00:00
|
|
|
|
{
|
2018-11-04 05:01:17 +00:00
|
|
|
|
class LoadingScreen : Screen, ITransition
|
2018-09-15 19:05:14 +00:00
|
|
|
|
{
|
2018-11-04 05:01:17 +00:00
|
|
|
|
private const float ENTER_TIME = 2f;
|
|
|
|
|
private const float EXIT_TIME = 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;
|
|
|
|
|
|
2018-11-04 05:01:17 +00:00
|
|
|
|
public LoadingScreen(Texture2D texture, float proportion, bool rotate = false) : base(true)
|
2018-09-15 19:05:14 +00:00
|
|
|
|
{
|
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;
|
2018-11-04 05:01:17 +00:00
|
|
|
|
Transitions.Add(this);
|
2018-10-31 06:10:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-11 18:45:37 +00:00
|
|
|
|
public void InitiateTransition(Rectangle dimensions)
|
|
|
|
|
{
|
|
|
|
|
color = Color.White;
|
|
|
|
|
textureBounds.Width = (int)(ScreenSize.Height * proportion);
|
|
|
|
|
textureBounds.Height = (int)(ScreenSize.Height * proportion);
|
|
|
|
|
textureBounds.X = (ScreenSize.Width) / 2;
|
|
|
|
|
textureBounds.Y = (ScreenSize.Height) / 2;
|
|
|
|
|
origin.X = texture.Width / 2;
|
|
|
|
|
origin.Y = texture.Height / 2;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-04 05:01:17 +00:00
|
|
|
|
void DoRotate(float deltaf)
|
2018-10-31 06:10:15 +00:00
|
|
|
|
{
|
2018-11-04 05:01:17 +00:00
|
|
|
|
rotation += (2f / 3f) * (float)Math.PI * deltaf;
|
|
|
|
|
if (rotation >= 2 * Math.PI)
|
|
|
|
|
{
|
|
|
|
|
rotation = 0;
|
|
|
|
|
}
|
2018-11-01 04:58:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-04 05:01:17 +00:00
|
|
|
|
public void DrawTransition(SpriteBatch spriteBatch)
|
|
|
|
|
{
|
2018-11-11 18:45:37 +00:00
|
|
|
|
spriteBatch.Draw(texture, textureBounds, null, color, rotation, origin, SpriteEffects.None, 0f);
|
2018-11-04 05:01:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool EnteringTransition(double delta, bool assetsLoaded)
|
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-04 05:01:17 +00:00
|
|
|
|
rR = (Color.White.R - BackgroundColor.R) / ENTER_TIME;
|
|
|
|
|
rG = (Color.White.G - BackgroundColor.G) / ENTER_TIME;
|
|
|
|
|
rB = (Color.White.B - BackgroundColor.B) / ENTER_TIME;
|
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);
|
2018-11-04 05:01:17 +00:00
|
|
|
|
BackgroundColor.R = (byte)progR;
|
|
|
|
|
BackgroundColor.G = (byte)progG;
|
|
|
|
|
BackgroundColor.B = (byte)progB;
|
2018-10-31 06:10:15 +00:00
|
|
|
|
}
|
2018-11-01 05:15:29 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2018-11-03 06:08:39 +00:00
|
|
|
|
StartExitTransition(true);
|
2018-11-04 05:01:17 +00:00
|
|
|
|
return true;
|
2018-11-01 05:15:29 +00:00
|
|
|
|
}
|
2018-11-02 02:20:46 +00:00
|
|
|
|
}
|
2018-11-04 05:01:17 +00:00
|
|
|
|
return false;
|
2018-11-02 02:20:46 +00:00
|
|
|
|
}
|
2018-11-01 05:15:29 +00:00
|
|
|
|
|
2018-11-04 05:01:17 +00:00
|
|
|
|
public bool ExitingTransition(double delta, bool assetsLoaded)
|
2018-11-02 02:20:46 +00:00
|
|
|
|
{
|
|
|
|
|
float deltaf = (float)delta;
|
|
|
|
|
if (rotate)
|
|
|
|
|
{
|
|
|
|
|
DoRotate(deltaf);
|
|
|
|
|
}
|
|
|
|
|
if (progC > 0)
|
|
|
|
|
{
|
2018-11-04 05:01:17 +00:00
|
|
|
|
float rate = deltaf * 255 / EXIT_TIME;
|
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-09-15 19:05:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|