updated transition system to be more intuitive
This commit is contained in:
parent
04f8fbd8cd
commit
f3a3d31ad8
@ -54,8 +54,8 @@
|
|||||||
<Compile Include="Zer01HD\Utilities\Input\InputUtilities.cs" />
|
<Compile Include="Zer01HD\Utilities\Input\InputUtilities.cs" />
|
||||||
<Compile Include="Zer01HD\Utilities\Persistence\Preferences.cs" />
|
<Compile Include="Zer01HD\Utilities\Persistence\Preferences.cs" />
|
||||||
<Compile Include="Zer01HD\Utilities\UI\Interactive\BasicButton.cs" />
|
<Compile Include="Zer01HD\Utilities\UI\Interactive\BasicButton.cs" />
|
||||||
<Compile Include="Zer01HD\Utilities\UI\ScreenSystem\ITransition.cs" />
|
<Compile Include="Zer01HD\Utilities\ScreenSystem\ITransition.cs" />
|
||||||
<Compile Include="Zer01HD\Utilities\UI\ScreenSystem\LoadingScreen.cs" />
|
<Compile Include="Zer01HD\Utilities\ScreenSystem\LoadingScreen.cs" />
|
||||||
<Compile Include="Zer01HD\Game\Screens\MainScreen.cs" />
|
<Compile Include="Zer01HD\Game\Screens\MainScreen.cs" />
|
||||||
<Compile Include="Zer01HD\Utilities\UI\Modular\UIModule.cs" />
|
<Compile Include="Zer01HD\Utilities\UI\Modular\UIModule.cs" />
|
||||||
<Compile Include="Zer01HD\Utilities\UI\Modular\UIModuleGroup.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\Page.cs" />
|
||||||
<Compile Include="Zer01HD\Utilities\UI\Book\Book.cs" />
|
<Compile Include="Zer01HD\Utilities\UI\Book\Book.cs" />
|
||||||
<Compile Include="Zer01HD\Utilities\UI\Modular\Text.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\Utilities\ContentSystem\ContentLoad.cs" />
|
||||||
<Compile Include="Zer01HD\Game\ContentResolvers\FontContentResolver.cs" />
|
<Compile Include="Zer01HD\Game\ContentResolvers\FontContentResolver.cs" />
|
||||||
<Compile Include="Zer01HD\Game\ContentResolvers\ResolutionContentResolver.cs" />
|
<Compile Include="Zer01HD\Game\ContentResolvers\ResolutionContentResolver.cs" />
|
||||||
|
@ -32,6 +32,33 @@ namespace RhythmBullet
|
|||||||
private RenderTarget2D previousScreenRenderTarget;
|
private RenderTarget2D previousScreenRenderTarget;
|
||||||
private Screen currentScreen;
|
private Screen currentScreen;
|
||||||
private bool resizing;
|
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()
|
public RhythmBulletGame()
|
||||||
{
|
{
|
||||||
graphics = new GraphicsDeviceManager(this);
|
graphics = new GraphicsDeviceManager(this);
|
||||||
@ -84,7 +111,7 @@ namespace RhythmBullet
|
|||||||
protected override void UnloadContent()
|
protected override void UnloadContent()
|
||||||
{
|
{
|
||||||
Assets.UnloadAll();
|
Assets.UnloadAll();
|
||||||
previousScreenRenderTarget.Dispose();
|
previousScreenRenderTarget?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -123,7 +150,7 @@ namespace RhythmBullet
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Changing to default screen.");
|
Debug.WriteLine("Changing to default screen.");
|
||||||
Screen = previousScreen != null ? previousScreen : new MainScreen(graphics.GraphicsDevice, Assets);
|
Screen = previousScreen != null ? previousScreen : new MainScreen(Assets);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -188,32 +215,5 @@ namespace RhythmBullet
|
|||||||
Assets.Queue<Texture2D>("default_cover", false);
|
Assets.Queue<Texture2D>("default_cover", false);
|
||||||
Assets.Queue<Texture2D>("backgrounds/mainBG");
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,18 +16,19 @@ namespace RhythmBullet.Zer01HD.Game.Screens
|
|||||||
{
|
{
|
||||||
class MainScreen : Screen
|
class MainScreen : Screen
|
||||||
{
|
{
|
||||||
|
FadeAwayTransition fat;
|
||||||
Texture2D background;
|
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");
|
background = assets.Get<Texture2D>("backgrounds/mainBG");
|
||||||
|
fat = new FadeAwayTransition(1.25f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Show()
|
public override void Show()
|
||||||
{
|
{
|
||||||
|
Transitions.Add(fat);
|
||||||
base.Show();
|
base.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,30 +13,31 @@ namespace RhythmBullet.Zer01HD.Game.Screens.Transitions
|
|||||||
{
|
{
|
||||||
internal class FadeAwayTransition : IDisposable, ITransition
|
internal class FadeAwayTransition : IDisposable, ITransition
|
||||||
{
|
{
|
||||||
private const float TIME_REQUIRED = 2f;
|
private float time;
|
||||||
public Texture2D curtain;
|
public Texture2D curtain;
|
||||||
public Rectangle curtainSize;
|
public Rectangle curtainSize;
|
||||||
private Color color;
|
private Color color;
|
||||||
private float progR, progG, progB, progA;
|
private float progR, progG, progB, progA;
|
||||||
private float rR, rG, rB, rA;
|
private float rR, rG, rB, rA;
|
||||||
|
|
||||||
internal FadeAwayTransition()
|
internal FadeAwayTransition(float time)
|
||||||
{
|
{
|
||||||
color = Color.White;
|
this.time = time;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InitiateTransition(Rectangle dimensions)
|
public void InitiateTransition(Rectangle dimensions)
|
||||||
{
|
{
|
||||||
curtainSize = 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)
|
private bool Fade(float deltaf)
|
||||||
|
@ -23,13 +23,23 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem
|
|||||||
|
|
||||||
public LoadingScreen(Texture2D texture, float proportion, bool rotate = false) : base(true)
|
public LoadingScreen(Texture2D texture, float proportion, bool rotate = false) : base(true)
|
||||||
{
|
{
|
||||||
color = Color.White;
|
|
||||||
this.texture = texture;
|
this.texture = texture;
|
||||||
this.proportion = proportion;
|
this.proportion = proportion;
|
||||||
this.rotate = rotate;
|
this.rotate = rotate;
|
||||||
Transitions.Add(this);
|
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)
|
void DoRotate(float deltaf)
|
||||||
{
|
{
|
||||||
rotation += (2f / 3f) * (float)Math.PI * deltaf;
|
rotation += (2f / 3f) * (float)Math.PI * deltaf;
|
||||||
@ -41,18 +51,9 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem
|
|||||||
|
|
||||||
public void DrawTransition(SpriteBatch spriteBatch)
|
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)
|
public bool EnteringTransition(double delta, bool assetsLoaded)
|
||||||
{
|
{
|
@ -15,20 +15,22 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem
|
|||||||
public List<ITransition> Transitions;
|
public List<ITransition> Transitions;
|
||||||
public bool UseRenderTargetForExitTransition;
|
public bool UseRenderTargetForExitTransition;
|
||||||
public Color BackgroundColor;
|
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)
|
public Screen(bool useEnterTransition = false)
|
||||||
{
|
{
|
||||||
State = useEnterTransition ? ScreenState.EnterTransition : ScreenState.Normal;
|
State = useEnterTransition ? ScreenState.EnterTransition : ScreenState.Normal;
|
||||||
Transitions = new List<ITransition>();
|
Transitions = new List<ITransition>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initiate(Rectangle screenSize)
|
public void Initiate(GraphicsDevice graphicsDevice, Rectangle screenSize)
|
||||||
{
|
{
|
||||||
Initiated = true;
|
|
||||||
this.ScreenSize = screenSize;
|
this.ScreenSize = screenSize;
|
||||||
foreach (ITransition transition in Transitions)
|
GraphicsDevice = graphicsDevice;
|
||||||
{
|
Initiated = true;
|
||||||
transition.InitiateTransition(screenSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Update(GameTime gameTime)
|
public virtual void Update(GameTime gameTime)
|
||||||
@ -98,7 +100,10 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem
|
|||||||
|
|
||||||
public virtual void Show()
|
public virtual void Show()
|
||||||
{
|
{
|
||||||
|
foreach (ITransition transition in Transitions)
|
||||||
|
{
|
||||||
|
transition.InitiateTransition(ScreenSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Hide()
|
public virtual void Hide()
|
||||||
@ -126,17 +131,5 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem
|
|||||||
transition.UpdatePreviousScreenFrame(previousScreenFrame);
|
transition.UpdatePreviousScreenFrame(previousScreenFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Screen NextScreen
|
|
||||||
{ get; protected set; }
|
|
||||||
|
|
||||||
public Rectangle ScreenSize
|
|
||||||
{ get; protected set; }
|
|
||||||
|
|
||||||
public bool Initiated
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
private set;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user