updated transition system to be more intuitive

This commit is contained in:
Harrison Deng 2018-11-11 12:45:37 -06:00
parent 04f8fbd8cd
commit f3a3d31ad8
7 changed files with 74 additions and 78 deletions

View File

@ -54,8 +54,8 @@
<Compile Include="Zer01HD\Utilities\Input\InputUtilities.cs" />
<Compile Include="Zer01HD\Utilities\Persistence\Preferences.cs" />
<Compile Include="Zer01HD\Utilities\UI\Interactive\BasicButton.cs" />
<Compile Include="Zer01HD\Utilities\UI\ScreenSystem\ITransition.cs" />
<Compile Include="Zer01HD\Utilities\UI\ScreenSystem\LoadingScreen.cs" />
<Compile Include="Zer01HD\Utilities\ScreenSystem\ITransition.cs" />
<Compile Include="Zer01HD\Utilities\ScreenSystem\LoadingScreen.cs" />
<Compile Include="Zer01HD\Game\Screens\MainScreen.cs" />
<Compile Include="Zer01HD\Utilities\UI\Modular\UIModule.cs" />
<Compile Include="Zer01HD\Utilities\UI\Modular\UIModuleGroup.cs" />
@ -65,7 +65,7 @@
<Compile Include="Zer01HD\Utilities\UI\Book\Page.cs" />
<Compile Include="Zer01HD\Utilities\UI\Book\Book.cs" />
<Compile Include="Zer01HD\Utilities\UI\Modular\Text.cs" />
<Compile Include="Zer01HD\Utilities\UI\ScreenSystem\Screen.cs" />
<Compile Include="Zer01HD\Utilities\ScreenSystem\Screen.cs" />
<Compile Include="Zer01HD\Utilities\ContentSystem\ContentLoad.cs" />
<Compile Include="Zer01HD\Game\ContentResolvers\FontContentResolver.cs" />
<Compile Include="Zer01HD\Game\ContentResolvers\ResolutionContentResolver.cs" />

View File

@ -32,6 +32,33 @@ namespace RhythmBullet
private RenderTarget2D previousScreenRenderTarget;
private Screen currentScreen;
private bool resizing;
public Screen Screen
{
get
{
return currentScreen;
}
set
{
previousScreen = currentScreen;
currentScreen = value;
if (!Screen.Initiated)
{
Screen.Initiate(graphics.GraphicsDevice, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
}
if (previousScreen != null && previousScreenRenderTarget == null && previousScreen.UseRenderTargetForExitTransition)
{
previousScreenRenderTarget = new RenderTarget2D(graphics.GraphicsDevice, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
}
graphics.GraphicsDevice.SetRenderTarget(previousScreenRenderTarget);
graphics.GraphicsDevice.Clear(Color.Black);
Debug.WriteLine("Showing " + value.GetType().Name);
Debug.WriteLine("Previous screen is " + previousScreen?.GetType().Name);
Screen.Show();
}
}
public RhythmBulletGame()
{
graphics = new GraphicsDeviceManager(this);
@ -84,7 +111,7 @@ namespace RhythmBullet
protected override void UnloadContent()
{
Assets.UnloadAll();
previousScreenRenderTarget.Dispose();
previousScreenRenderTarget?.Dispose();
}
/// <summary>
@ -123,7 +150,7 @@ namespace RhythmBullet
else
{
Debug.WriteLine("Changing to default screen.");
Screen = previousScreen != null ? previousScreen : new MainScreen(graphics.GraphicsDevice, Assets);
Screen = previousScreen != null ? previousScreen : new MainScreen(Assets);
}
}
break;
@ -188,32 +215,5 @@ namespace RhythmBullet
Assets.Queue<Texture2D>("default_cover", false);
Assets.Queue<Texture2D>("backgrounds/mainBG");
}
public Screen Screen
{
get
{
return currentScreen;
}
set
{
previousScreen = currentScreen;
currentScreen = value;
if (!Screen.Initiated)
{
Screen.Initiate(new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
}
if (previousScreen != null && previousScreenRenderTarget == null && previousScreen.UseRenderTargetForExitTransition)
{
previousScreenRenderTarget = new RenderTarget2D(graphics.GraphicsDevice, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
}
graphics.GraphicsDevice.SetRenderTarget(previousScreenRenderTarget);
graphics.GraphicsDevice.Clear(Color.Black);
Debug.WriteLine("Showing " + value.GetType().Name);
Debug.WriteLine("Previous screen is " + previousScreen?.GetType().Name);
Screen.Show();
}
}
}
}

View File

@ -16,18 +16,19 @@ namespace RhythmBullet.Zer01HD.Game.Screens
{
class MainScreen : Screen
{
FadeAwayTransition fat;
Texture2D background;
Viewport viewport;
public MainScreen(GraphicsDevice graphicsDevice, ContentSystem assets) : base(true)
public MainScreen(ContentSystem assets) : base(true)
{
FadeAwayTransition fadeAwayTransition = new FadeAwayTransition();
Transitions.Add(fadeAwayTransition);
graphicsDevice.Clear(Color.White);
background = assets.Get<Texture2D>("backgrounds/mainBG");
fat = new FadeAwayTransition(1.25f);
}
public override void Show()
{
Transitions.Add(fat);
base.Show();
}

View File

@ -13,30 +13,31 @@ namespace RhythmBullet.Zer01HD.Game.Screens.Transitions
{
internal class FadeAwayTransition : IDisposable, ITransition
{
private const float TIME_REQUIRED = 2f;
private float time;
public Texture2D curtain;
public Rectangle curtainSize;
private Color color;
private float progR, progG, progB, progA;
private float rR, rG, rB, rA;
internal FadeAwayTransition()
internal FadeAwayTransition(float time)
{
color = Color.White;
rR = (0 - 254) / TIME_REQUIRED;
rG = (0 - 254) / TIME_REQUIRED;
rB = (0 - 254) / TIME_REQUIRED;
rA = (0 - 254) / TIME_REQUIRED;
progA = color.A;
progR = color.R;
progG = color.G;
progB = color.B;
this.time = time;
}
public void InitiateTransition(Rectangle dimensions)
{
curtainSize = dimensions;
color = Color.White;
rR = (0 - 254) / time;
rG = (0 - 254) / time;
rB = (0 - 254) / time;
rA = (0 - 254) / time;
progA = color.A;
progR = color.R;
progG = color.G;
progB = color.B;
}
private bool Fade(float deltaf)

View File

@ -23,13 +23,23 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem
public LoadingScreen(Texture2D texture, float proportion, bool rotate = false) : base(true)
{
color = Color.White;
this.texture = texture;
this.proportion = proportion;
this.rotate = rotate;
Transitions.Add(this);
}
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;
}
void DoRotate(float deltaf)
{
rotation += (2f / 3f) * (float)Math.PI * deltaf;
@ -41,18 +51,9 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem
public void DrawTransition(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, textureBounds, null, Color.White, rotation, origin, SpriteEffects.None, 0f);
spriteBatch.Draw(texture, textureBounds, null, color, rotation, origin, SpriteEffects.None, 0f);
}
public void InitiateTransition(Rectangle dimensions)
{
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;
}
public bool EnteringTransition(double delta, bool assetsLoaded)
{

View File

@ -15,20 +15,22 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem
public List<ITransition> Transitions;
public bool UseRenderTargetForExitTransition;
public Color BackgroundColor;
public GraphicsDevice GraphicsDevice { get; private set; }
public Screen NextScreen { get; protected set; }
public Rectangle ScreenSize { get; protected set; }
public bool Initiated { get; private set; }
public Screen(bool useEnterTransition = false)
{
State = useEnterTransition ? ScreenState.EnterTransition : ScreenState.Normal;
Transitions = new List<ITransition>();
}
public void Initiate(Rectangle screenSize)
public void Initiate(GraphicsDevice graphicsDevice, Rectangle screenSize)
{
Initiated = true;
this.ScreenSize = screenSize;
foreach (ITransition transition in Transitions)
{
transition.InitiateTransition(screenSize);
}
GraphicsDevice = graphicsDevice;
Initiated = true;
}
public virtual void Update(GameTime gameTime)
@ -98,7 +100,10 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem
public virtual void Show()
{
foreach (ITransition transition in Transitions)
{
transition.InitiateTransition(ScreenSize);
}
}
public virtual void Hide()
@ -126,17 +131,5 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem
transition.UpdatePreviousScreenFrame(previousScreenFrame);
}
}
public Screen NextScreen
{ get; protected set; }
public Rectangle ScreenSize
{ get; protected set; }
public bool Initiated
{
get;
private set;
}
}
}