loading screen now has the option to rotate image; change in how transitions are handled

This commit is contained in:
Harrison Deng 2018-11-01 21:20:46 -05:00
parent 1879bb0e4c
commit 9da8233eda
6 changed files with 88 additions and 53 deletions

View File

@ -47,9 +47,11 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Compile Include="Zer01HD\Game\Screens\Transitions\FadeInTransition.cs" />
<Compile Include="Zer01HD\Utilities\ContentSystem\NormalContentResolver.cs" />
<Compile Include="Zer01HD\Utilities\Persistence\Preferences.cs" />
<Compile Include="Zer01HD\Utilities\Renderer\ScaledRenderer.cs" />
<Compile Include="Zer01HD\Utilities\UI\Interactive\BasicButton.cs" />
<Compile Include="Zer01HD\Utilities\UI\LoadingScreen.cs" />
<Compile Include="Zer01HD\Game\Screens\MainScreen.cs" />
<Compile Include="Zer01HD\Utilities\UI\Modular\Module.cs" />

View File

@ -4,6 +4,7 @@ using Microsoft.Xna.Framework.Input;
using RhythmBullet.Zer01HD.Game;
using RhythmBullet.Zer01HD.Game.ContentResolvers;
using RhythmBullet.Zer01HD.Game.Preferences;
using RhythmBullet.Zer01HD.Game.Screens;
using RhythmBullet.Zer01HD.UI;
using RhythmBullet.Zer01HD.Utilities;
using RhythmBullet.Zer01HD.Utilities.ContentSystem;
@ -29,6 +30,7 @@ namespace RhythmBullet
public readonly ContentSystem Assets;
readonly ResolutionContentResolver resolutionContentResolver;
public PreferencesManager preferencesManager;
private Screen previousScreen;
private Screen currentScreen;
private bool resizing;
public RhythmBulletGame()
@ -60,6 +62,7 @@ namespace RhythmBullet
{
if (currentScreen != null)
{
previousScreen = value;
Screen.Hide();
}
currentScreen = value;
@ -91,7 +94,7 @@ namespace RhythmBullet
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
QueueContent();
Screen = new LoadingScreen(Content.Load<Texture2D>("RhythmBullet"), new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
Screen = new LoadingScreen(Content.Load<Texture2D>("RhythmBullet"), 0.5f, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
}
/// <summary>
@ -113,20 +116,21 @@ namespace RhythmBullet
if (!Assets.Done)
{
Assets.Update();
} else if (resizing)
}
else if (resizing)
{
resizing = false;
PostResize();
}
switch (Screen.State) {
switch (Screen.State)
{
case ScreenState.EnterTransition:
Screen.EnteringTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor);
break;
case ScreenState.ExitTransition:
Screen transitionScreen = Screen.ExitingTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor);
if (transitionScreen != null)
if (Screen.ExitingTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor))
{
Screen = transitionScreen;
Screen = previousScreen != null ? previousScreen : new MainScreen(graphics.GraphicsDevice, BackgroundColor);
}
break;
case ScreenState.Normal:
@ -162,7 +166,7 @@ namespace RhythmBullet
Assets.UnloadAll();
QueueContent();
Screen.AssetLoadStateChange(true);
Screen = new LoadingScreen(Content.Load<Texture2D>("RhythmBullet"), new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
Screen = new LoadingScreen(Content.Load<Texture2D>("loading_ring"), 0.4f, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
}
private void PostResize()
@ -173,21 +177,9 @@ namespace RhythmBullet
private void QueueContent()
{
Assets.Queue<Texture2D>("Tech-Circle1");
Assets.Queue<Texture2D>("polyjet-standard");
Assets.Queue<Texture2D>("cybercircle3B");
Assets.Queue<Texture2D>("title");
Assets.Queue<Texture2D>("cybercircle1");
Assets.Queue<Texture2D>("default_cover", false);
Assets.Queue<Texture2D>("laser");
Assets.Queue<Texture2D>("pellet");
Assets.Queue<Texture2D>("shard");
Assets.Queue<Texture2D>("bar");
Assets.Queue<Texture2D>("flake");
Assets.Queue<Texture2D>("void_circle");
Assets.Queue<Texture2D>("tpSelector");
Assets.Queue<Texture2D>("backgrounds/mainBG");
Assets.Queue<Texture2D>("magic1");
}
}
}

View File

@ -1,5 +1,6 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.Zer01HD.Game.Screens.Transitions;
using RhythmBullet.Zer01HD.UI;
using RhythmBullet.Zer01HD.Utilities.UI;
using System;
@ -12,14 +13,16 @@ namespace RhythmBullet.Zer01HD.Game.Screens
{
class MainScreen : Screen
{
FadeInTransition fadeInTransition;
public MainScreen() : base(true)
public MainScreen(GraphicsDevice graphicsDevice, Color transitionFromColor) : base(true)
{
fadeInTransition = new FadeInTransition(graphicsDevice, transitionFromColor, ScreenSize);
}
public override void EnteringTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
{
fadeInTransition.Fade((float)delta);
base.EnteringTransition(delta, assetsLoaded, ref backgroundColor);
}
}

View File

@ -28,7 +28,7 @@ namespace RhythmBullet.Zer01HD.Game.Screens.Transitions
}
internal void Fade(SpriteBatch batch, float deltaf)
internal bool Fade(float deltaf)
{
if (progR > 0 || progG > 0 || progB > 0)
{
@ -53,8 +53,17 @@ namespace RhythmBullet.Zer01HD.Game.Screens.Transitions
color.G = (byte)progG;
color.B = (byte)progB;
color.A = (byte)progA;
return false;
}
return true;
}
internal void Draw(SpriteBatch batch)
{
if (curtain != null)
{
batch.Draw(curtain, curtainSize, color);
}
batch.Draw(curtain, curtainSize, color);
}
public void Dispose()

View File

@ -9,21 +9,30 @@ namespace RhythmBullet.Zer01HD.Game
{
class LoadingScreen : Screen
{
Texture2D texture;
readonly Texture2D texture;
Color color;
Rectangle rectangleBounds;
float proportion = 0.5f;
Rectangle textureBounds;
readonly float proportion;
bool recorded;
float rR, rG, rB;
float progR, progG, progB;
float progC = 254;
public LoadingScreen(Texture2D texture, Rectangle dimensions) : base(true)
float rotation;
readonly bool rotate;
Vector2 origin;
public LoadingScreen(Texture2D texture, float proportion, Rectangle dimensions, bool rotate = false) : 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;
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)
@ -33,16 +42,20 @@ namespace RhythmBullet.Zer01HD.Game
public override void EnteringTransition(double delta, bool assetsLoaded, ref Color BGColor)
{
float deltaf = (float)delta;
if (rotate)
{
DoRotate(deltaf);
}
if (assetsLoaded)
{
float deltaf = (float)delta;
if (progR < 254 || progG < 254 || progB < 254)
{
if (!recorded)
{
rR = (Color.White.R - BGColor.R) / 3f;
rG = (Color.White.G - BGColor.G) / 3f;
rB = (Color.White.B - BGColor.B) / 3f;
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;
@ -55,34 +68,50 @@ namespace RhythmBullet.Zer01HD.Game
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
{
DoneTransition();
DoneEnterTransition();
StartExitTransition();
}
}
base.EnteringTransition(delta, assetsLoaded, ref BGColor);
}
public override Screen ExitingTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
public override bool ExitingTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
{
return new MainScreen();
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;
}
}
public override void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, rectangleBounds, color);
spriteBatch.Draw(texture, textureBounds, null, color, rotation, origin, SpriteEffects.None, 0f);
base.Draw(spriteBatch);
}

View File

@ -39,9 +39,9 @@ namespace RhythmBullet.Zer01HD.Utilities.UI
}
public virtual Screen ExitingTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
public virtual bool ExitingTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
{
return null;
return true;
}
public virtual void Show()
@ -67,7 +67,7 @@ namespace RhythmBullet.Zer01HD.Utilities.UI
}
}
public void DoneTransition()
public void DoneEnterTransition()
{
state = ScreenState.Normal;
}