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> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Zer01HD\Game\Screens\Transitions\FadeInTransition.cs" />
<Compile Include="Zer01HD\Utilities\ContentSystem\NormalContentResolver.cs" /> <Compile Include="Zer01HD\Utilities\ContentSystem\NormalContentResolver.cs" />
<Compile Include="Zer01HD\Utilities\Persistence\Preferences.cs" /> <Compile Include="Zer01HD\Utilities\Persistence\Preferences.cs" />
<Compile Include="Zer01HD\Utilities\Renderer\ScaledRenderer.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\Utilities\UI\LoadingScreen.cs" />
<Compile Include="Zer01HD\Game\Screens\MainScreen.cs" /> <Compile Include="Zer01HD\Game\Screens\MainScreen.cs" />
<Compile Include="Zer01HD\Utilities\UI\Modular\Module.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;
using RhythmBullet.Zer01HD.Game.ContentResolvers; using RhythmBullet.Zer01HD.Game.ContentResolvers;
using RhythmBullet.Zer01HD.Game.Preferences; using RhythmBullet.Zer01HD.Game.Preferences;
using RhythmBullet.Zer01HD.Game.Screens;
using RhythmBullet.Zer01HD.UI; using RhythmBullet.Zer01HD.UI;
using RhythmBullet.Zer01HD.Utilities; using RhythmBullet.Zer01HD.Utilities;
using RhythmBullet.Zer01HD.Utilities.ContentSystem; using RhythmBullet.Zer01HD.Utilities.ContentSystem;
@ -29,6 +30,7 @@ namespace RhythmBullet
public readonly ContentSystem Assets; public readonly ContentSystem Assets;
readonly ResolutionContentResolver resolutionContentResolver; readonly ResolutionContentResolver resolutionContentResolver;
public PreferencesManager preferencesManager; public PreferencesManager preferencesManager;
private Screen previousScreen;
private Screen currentScreen; private Screen currentScreen;
private bool resizing; private bool resizing;
public RhythmBulletGame() public RhythmBulletGame()
@ -60,6 +62,7 @@ namespace RhythmBullet
{ {
if (currentScreen != null) if (currentScreen != null)
{ {
previousScreen = value;
Screen.Hide(); Screen.Hide();
} }
currentScreen = value; currentScreen = value;
@ -91,7 +94,7 @@ namespace RhythmBullet
// Create a new SpriteBatch, which can be used to draw textures. // Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice); spriteBatch = new SpriteBatch(GraphicsDevice);
QueueContent(); 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> /// <summary>
@ -113,20 +116,21 @@ namespace RhythmBullet
if (!Assets.Done) if (!Assets.Done)
{ {
Assets.Update(); Assets.Update();
} else if (resizing) }
else if (resizing)
{ {
resizing = false; resizing = false;
PostResize(); PostResize();
} }
switch (Screen.State) { switch (Screen.State)
{
case ScreenState.EnterTransition: case ScreenState.EnterTransition:
Screen.EnteringTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor); Screen.EnteringTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor);
break; break;
case ScreenState.ExitTransition: case ScreenState.ExitTransition:
Screen transitionScreen = Screen.ExitingTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor); if (Screen.ExitingTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor))
if (transitionScreen != null)
{ {
Screen = transitionScreen; Screen = previousScreen != null ? previousScreen : new MainScreen(graphics.GraphicsDevice, BackgroundColor);
} }
break; break;
case ScreenState.Normal: case ScreenState.Normal:
@ -162,7 +166,7 @@ namespace RhythmBullet
Assets.UnloadAll(); Assets.UnloadAll();
QueueContent(); QueueContent();
Screen.AssetLoadStateChange(true); 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() private void PostResize()
@ -173,21 +177,9 @@ namespace RhythmBullet
private void QueueContent() private void QueueContent()
{ {
Assets.Queue<Texture2D>("Tech-Circle1");
Assets.Queue<Texture2D>("polyjet-standard");
Assets.Queue<Texture2D>("cybercircle3B");
Assets.Queue<Texture2D>("title"); Assets.Queue<Texture2D>("title");
Assets.Queue<Texture2D>("cybercircle1");
Assets.Queue<Texture2D>("default_cover", false); 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>("backgrounds/mainBG");
Assets.Queue<Texture2D>("magic1");
} }
} }
} }

View File

@ -1,5 +1,6 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.Zer01HD.Game.Screens.Transitions;
using RhythmBullet.Zer01HD.UI; using RhythmBullet.Zer01HD.UI;
using RhythmBullet.Zer01HD.Utilities.UI; using RhythmBullet.Zer01HD.Utilities.UI;
using System; using System;
@ -12,14 +13,16 @@ namespace RhythmBullet.Zer01HD.Game.Screens
{ {
class MainScreen : Screen 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) public override void EnteringTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
{ {
fadeInTransition.Fade((float)delta);
base.EnteringTransition(delta, assetsLoaded, ref backgroundColor); 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) if (progR > 0 || progG > 0 || progB > 0)
{ {
@ -53,9 +53,18 @@ namespace RhythmBullet.Zer01HD.Game.Screens.Transitions
color.G = (byte)progG; color.G = (byte)progG;
color.B = (byte)progB; color.B = (byte)progB;
color.A = (byte)progA; 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() public void Dispose()
{ {

View File

@ -9,21 +9,30 @@ namespace RhythmBullet.Zer01HD.Game
{ {
class LoadingScreen : Screen class LoadingScreen : Screen
{ {
Texture2D texture; readonly Texture2D texture;
Color color; Color color;
Rectangle rectangleBounds; Rectangle textureBounds;
float proportion = 0.5f; readonly float proportion;
bool recorded; bool recorded;
float rR, rG, rB; float rR, rG, rB;
float progR, progG, progB; float progR, progG, progB;
float progC = 254; 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; color = Color.White;
this.texture = texture; this.texture = texture;
rectangleBounds = new Rectangle(0, 0, (int)(dimensions.Height * proportion), (int)(dimensions.Height * proportion)); this.proportion = proportion;
rectangleBounds.X = (dimensions.Width - rectangleBounds.Width) / 2; this.rotate = rotate;
rectangleBounds.Y = (dimensions.Height - rectangleBounds.Height) / 2; 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) 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) public override void EnteringTransition(double delta, bool assetsLoaded, ref Color BGColor)
{ {
float deltaf = (float)delta;
if (rotate)
{
DoRotate(deltaf);
}
if (assetsLoaded) if (assetsLoaded)
{ {
float deltaf = (float)delta;
if (progR < 254 || progG < 254 || progB < 254) if (progR < 254 || progG < 254 || progB < 254)
{ {
if (!recorded) if (!recorded)
{ {
rR = (Color.White.R - BGColor.R) / 3f; rR = (Color.White.R - BGColor.R) / 2f;
rG = (Color.White.G - BGColor.G) / 3f; rG = (Color.White.G - BGColor.G) / 2f;
rB = (Color.White.B - BGColor.B) / 3f; rB = (Color.White.B - BGColor.B) / 2f;
recorded = true; recorded = true;
} }
progR += rR * deltaf; progR += rR * deltaf;
@ -55,9 +68,24 @@ namespace RhythmBullet.Zer01HD.Game
BGColor.G = (byte)progG; BGColor.G = (byte)progG;
BGColor.B = (byte)progB; BGColor.B = (byte)progB;
} }
else if (progC > 0) else
{ {
float rate = deltaf * 255 / 1.5f; 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 -= rate;
progC = Math.Max(progC, 0); progC = Math.Max(progC, 0);
color.R = (byte)progC; color.R = (byte)progC;
@ -67,22 +95,23 @@ namespace RhythmBullet.Zer01HD.Game
} }
else else
{ {
DoneTransition(); return true;
StartExitTransition(); }
return false;
} }
} void DoRotate(float deltaf)
base.EnteringTransition(delta, assetsLoaded, ref BGColor);
}
public override Screen ExitingTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
{ {
return new MainScreen(); rotation += (2f / 3f) * (float)Math.PI * deltaf;
if (rotation >= 2 * Math.PI)
{
rotation = 0;
}
} }
public override void Draw(SpriteBatch spriteBatch) 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); 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() public virtual void Show()
@ -67,7 +67,7 @@ namespace RhythmBullet.Zer01HD.Utilities.UI
} }
} }
public void DoneTransition() public void DoneEnterTransition()
{ {
state = ScreenState.Normal; state = ScreenState.Normal;
} }