refactoring to comply with c# conventions
This commit is contained in:
31
RhythmBullet/Screens/MainMenu/MainPage.cs
Normal file
31
RhythmBullet/Screens/MainMenu/MainPage.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RhythmBullet.UI.Book;
|
||||
using RhythmBullet.Utilities.ContentSystem;
|
||||
using RhythmBullet.Utilities.UI.Modular.Modules;
|
||||
|
||||
namespace RhythmBullet.Screens.MainMenu
|
||||
{
|
||||
internal class MainPage : Page
|
||||
{
|
||||
Image title;
|
||||
internal MainPage(ContentManagerController assets) : base(0, 0)
|
||||
{
|
||||
title = new Image(assets.Get<Texture2D>("title"));
|
||||
AddModule(title);
|
||||
}
|
||||
|
||||
public override void ApplySize(int width, int height)
|
||||
{
|
||||
title.Scale = (width - 40) / title.Texture.Width;
|
||||
title.bounds.X = (int)((width - title.bounds.Width) / 2f);
|
||||
title.bounds.Y = (int)((height - title.bounds.Height) / 2f);
|
||||
base.ApplySize(width, height);
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch batch)
|
||||
{
|
||||
base.Draw(batch);
|
||||
}
|
||||
}
|
||||
}
|
58
RhythmBullet/Screens/MainMenu/MainScreen.cs
Normal file
58
RhythmBullet/Screens/MainMenu/MainScreen.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using RhythmBullet.Screens.Transitions;
|
||||
using RhythmBullet.UI.Book;
|
||||
using RhythmBullet.Utilities.Camera;
|
||||
using RhythmBullet.Utilities.ContentSystem;
|
||||
using RhythmBullet.Utilities.ScreenSystem;
|
||||
using System;
|
||||
|
||||
namespace RhythmBullet.Screens.MainMenu
|
||||
{
|
||||
class MainScreen : Screen
|
||||
{
|
||||
ContentManagerController assets;
|
||||
FadeAwayTransition fat;
|
||||
Texture2D background;
|
||||
Book book;
|
||||
MainPage mainPage;
|
||||
|
||||
public MainScreen(ContentManagerController assets) : base(true)
|
||||
{
|
||||
this.assets = assets;
|
||||
background = assets.Get<Texture2D>("backgrounds/mainBG");
|
||||
fat = new FadeAwayTransition(1.5f);
|
||||
book = new Book();
|
||||
mainPage = new MainPage(assets);
|
||||
book.AddPages(mainPage);
|
||||
}
|
||||
|
||||
public override void Initiate(GraphicsDevice graphicsDevice, Rectangle screenSize, Camera2D camera)
|
||||
{
|
||||
book.Initiate(camera, screenSize);
|
||||
base.Initiate(graphicsDevice, screenSize, camera);
|
||||
}
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
Transitions.Add(fat);
|
||||
base.Show();
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
spriteBatch.Draw(background, ScreenSize, Color.White);
|
||||
book.Draw(spriteBatch);
|
||||
base.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
book.Update(gameTime);
|
||||
base.Update(gameTime);
|
||||
}
|
||||
}
|
||||
}
|
92
RhythmBullet/Screens/Transitions/FadeAwayTransition.cs
Normal file
92
RhythmBullet/Screens/Transitions/FadeAwayTransition.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RhythmBullet.Utilities.UI;
|
||||
using RhythmBullet.Utilities.ScreenSystem;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Screens.Transitions
|
||||
{
|
||||
internal class FadeAwayTransition : IDisposable, ITransition
|
||||
{
|
||||
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(float time)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (progR > 0 || progG > 0 || progB > 0)
|
||||
{
|
||||
progR += rR * deltaf;
|
||||
progR = Math.Max(progR, 0);
|
||||
progG += rG * deltaf;
|
||||
progG = Math.Max(progG, 0);
|
||||
progB += rB * deltaf;
|
||||
progB = Math.Max(progB, 0);
|
||||
progA += rA * deltaf;
|
||||
progA = Math.Max(progA, 0);
|
||||
color.R = (byte)progR;
|
||||
color.G = (byte)progG;
|
||||
color.B = (byte)progB;
|
||||
color.A = (byte)progA;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void DrawTransition(SpriteBatch batch)
|
||||
{
|
||||
if (curtain != null)
|
||||
{
|
||||
batch.Draw(curtain, curtainSize, color);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
curtain.Dispose();
|
||||
}
|
||||
|
||||
public bool EnteringTransition(double delta, bool assetsLoaded)
|
||||
{
|
||||
return Fade((float)delta);
|
||||
}
|
||||
|
||||
public bool ExitingTransition(double delta, bool assetsLoaded)
|
||||
{
|
||||
return Fade((float)delta);
|
||||
}
|
||||
|
||||
public void UpdatePreviousScreenFrame(RenderTarget2D previousScreenFrame)
|
||||
{
|
||||
curtain = previousScreenFrame;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user