refactor and better screen mechanism (probably)

This commit is contained in:
Harrison Deng 2018-11-17 23:27:05 -06:00
parent 8377bb5ae8
commit 1195b8228a
15 changed files with 89 additions and 71 deletions

View File

@ -700,3 +700,15 @@
/processorParam:TextureFormat=Color
/build:loading_ring.png
#begin cursor.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:cursor.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

View File

@ -47,8 +47,8 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Compile Include="Zer01HD\Game\Screens\MainMenu\MainPage.cs" />
<Compile Include="Zer01HD\Game\Screens\Transitions\FadeAwayTransition.cs" />
<Compile Include="Zer01HD\Screens\MainMenu\MainPage.cs" />
<Compile Include="Zer01HD\Screens\Transitions\FadeAwayTransition.cs" />
<Compile Include="Zer01HD\Utilities\Camera\Camera2D.cs" />
<Compile Include="Zer01HD\Utilities\ContentSystem\NormalContentResolver.cs" />
<Compile Include="Zer01HD\Utilities\Input\IInputListener.cs" />
@ -59,7 +59,7 @@
<Compile Include="Zer01HD\Utilities\UI\Interactive\BasicButton.cs" />
<Compile Include="Zer01HD\Utilities\ScreenSystem\ITransition.cs" />
<Compile Include="Zer01HD\Utilities\ScreenSystem\LoadingScreen.cs" />
<Compile Include="Zer01HD\Game\Screens\MainMenu\MainScreen.cs" />
<Compile Include="Zer01HD\Screens\MainMenu\MainScreen.cs" />
<Compile Include="Zer01HD\Utilities\UI\Modular\Modules\Image.cs" />
<Compile Include="Zer01HD\Utilities\UI\Modular\UIModule.cs" />
<Compile Include="Zer01HD\Utilities\UI\Modular\UIModuleGroup.cs" />
@ -71,13 +71,13 @@
<Compile Include="Zer01HD\Utilities\UI\Modular\Modules\Text.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" />
<Compile Include="Zer01HD\Utilities\ContentSystem\ContentSystem.cs" />
<Compile Include="Zer01HD\ContentResolvers\FontContentResolver.cs" />
<Compile Include="Zer01HD\ContentResolvers\ResolutionContentResolver.cs" />
<Compile Include="Zer01HD\Utilities\ContentSystem\ContentManagerController.cs" />
<Compile Include="Zer01HD\Utilities\ContentSystem\IContentPathModifier.cs" />
<Compile Include="Zer01HD\Utilities\ParticleSystem\Particle.cs" />
<Compile Include="Zer01HD\Game\Preferences\Controls.cs" />
<Compile Include="Zer01HD\Game\Preferences\General.cs" />
<Compile Include="Zer01HD\Preferences\Controls.cs" />
<Compile Include="Zer01HD\Preferences\General.cs" />
<Compile Include="Zer01HD\Utilities\Persistence\PreferencesManager.cs" />
<Compile Include="Zer01HD\Utilities\DataTypes\Resolution.cs" />
</ItemGroup>

View File

@ -1,14 +1,15 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using RhythmBullet.Zer01HD.Game.ContentResolvers;
using RhythmBullet.Zer01HD.Game.Preferences;
using RhythmBullet.Zer01HD.Game.Screens.MainMenu;
using RhythmBullet.Zer01HD.ContentResolvers;
using RhythmBullet.Zer01HD.Preferences;
using RhythmBullet.Zer01HD.Screens.MainMenu;
using RhythmBullet.Zer01HD.Utilities;
using RhythmBullet.Zer01HD.Utilities.Camera;
using RhythmBullet.Zer01HD.Utilities.ContentSystem;
using RhythmBullet.Zer01HD.Utilities.DataTypes;
using RhythmBullet.Zer01HD.Utilities.Input;
using RhythmBullet.Zer01HD.Utilities.Persistence;
using RhythmBullet.Zer01HD.Utilities.ScreenSystem;
using System;
using System.Diagnostics;
@ -26,18 +27,19 @@ namespace RhythmBullet
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public readonly ContentSystem Assets;
public readonly ContentManagerController Assets;
readonly ResolutionContentResolver resolutionContentResolver;
public PreferencesManager preferencesManager;
private ScreenManager screenManager;
public Camera2D Camera { get; private set; }
private bool resizing;
private bool initialLoadComplete;
private MainScreen mainScreen;
public RhythmBulletGame()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
Assets = new ContentSystem(Content);
Assets = new ContentManagerController(Content);
resolutionContentResolver = new ResolutionContentResolver();
FontContentResolver fcr = new FontContentResolver(resolutionContentResolver);
@ -77,9 +79,9 @@ namespace RhythmBullet
spriteBatch = new SpriteBatch(GraphicsDevice);
Camera = new Camera2D(graphics.GraphicsDevice);
screenManager = new ScreenManager(graphics, Camera);
screenManager.RequireNextScreenEvent += ExitTransitionComplete;
screenManager.RequireNextScreenEvent += RequireNextScreen;
QueueContent();
screenManager.Screen = new LoadingScreen(Content.Load<Texture2D>("RhythmBullet"), 0.7f);
screenManager.Screen = new LoadingScreen(this, Content.Load<Texture2D>("RhythmBullet"), 0.7f);
}
/// <summary>
@ -106,6 +108,11 @@ namespace RhythmBullet
{
resizing = false;
PostResize();
} else if (!initialLoadComplete)
{
Console.WriteLine("Initial load complete.");
initialLoadComplete = true;
mainScreen = new MainScreen(Assets);
}
screenManager.UpdateCurrentScreen(gameTime, Assets.Done);
@ -135,7 +142,7 @@ namespace RhythmBullet
resizing = true;
Assets.UnloadAll();
QueueContent();
screenManager.Resize(Content.Load<Texture2D>("loading_ring"));
screenManager.Resize(new LoadingScreen(this, Content.Load<Texture2D>("loading_ring"), 0.4f));
}
private void PostResize()
@ -146,14 +153,15 @@ namespace RhythmBullet
private void QueueContent()
{
Assets.Queue<Texture2D>("cursor", false);
Assets.Queue<Texture2D>("title");
Assets.Queue<Texture2D>("default_cover", false);
Assets.Queue<Texture2D>("backgrounds/mainBG");
}
private void ExitTransitionComplete(Screen Screen)
private void RequireNextScreen(Screen Screen)
{
Screen.NextScreen = new MainScreen(Assets);
Screen.NextScreen = mainScreen;
}
}
}

View File

@ -5,7 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.Game.ContentResolvers
namespace RhythmBullet.Zer01HD.ContentResolvers
{
class FontContentResolver : IContentPathModifier
{

View File

@ -1,4 +1,4 @@
using RhythmBullet.Zer01HD.Game.Preferences;
using RhythmBullet.Zer01HD.Preferences;
using RhythmBullet.Zer01HD.Utilities;
using RhythmBullet.Zer01HD.Utilities.ContentSystem;
using RhythmBullet.Zer01HD.Utilities.DataTypes;
@ -8,7 +8,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.Game.ContentResolvers
namespace RhythmBullet.Zer01HD.ContentResolvers
{
class ResolutionContentResolver : IContentPathModifier
{

View File

@ -1,7 +1,7 @@
using Microsoft.Xna.Framework.Input;
using RhythmBullet.Zer01HD.Utilities.Persistence;
namespace RhythmBullet.Zer01HD.Game.Preferences
namespace RhythmBullet.Zer01HD.Preferences
{
public class Controls : Utilities.Persistence.Preferences
{

View File

@ -3,7 +3,7 @@ using System.Xml.Serialization;
using RhythmBullet.Zer01HD.Utilities.DataTypes;
using RhythmBullet.Zer01HD.Utilities.Persistence;
namespace RhythmBullet.Zer01HD.Game.Preferences
namespace RhythmBullet.Zer01HD.Preferences
{
public class General : Utilities.Persistence.Preferences
{

View File

@ -4,12 +4,12 @@ using RhythmBullet.Zer01HD.UI.Book;
using RhythmBullet.Zer01HD.Utilities.ContentSystem;
using RhythmBullet.Zer01HD.Utilities.UI.Modular.Modules;
namespace RhythmBullet.Zer01HD.Game.Screens.MainMenu
namespace RhythmBullet.Zer01HD.Screens.MainMenu
{
internal class MainPage : Page
{
Image title;
internal MainPage(ContentSystem assets) : base(0, 0)
internal MainPage(ContentManagerController assets) : base(0, 0)
{
title = new Image(assets.Get<Texture2D>("title"));
AddModule(title);

View File

@ -1,29 +1,28 @@
using Microsoft.Xna.Framework;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.Zer01HD.Game.Screens.Transitions;
using RhythmBullet.Zer01HD.UI;
using RhythmBullet.Zer01HD.Utilities.ContentSystem;
using RhythmBullet.Zer01HD.Utilities.UI;
using RhythmBullet.Zer01HD.Utilities.ScreenSystem;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework.Input;
using RhythmBullet.Zer01HD.Screens.Transitions;
using RhythmBullet.Zer01HD.UI.Book;
using RhythmBullet.Zer01HD.Utilities.Camera;
using RhythmBullet.Zer01HD.Utilities.ContentSystem;
using RhythmBullet.Zer01HD.Utilities.ScreenSystem;
using System;
namespace RhythmBullet.Zer01HD.Game.Screens.MainMenu
namespace RhythmBullet.Zer01HD.Screens.MainMenu
{
class MainScreen : Screen
{
ContentManagerController assets;
FadeAwayTransition fat;
Texture2D background;
Book book;
MainPage mainPage;
public MainScreen(ContentSystem assets) : base(true)
public MainScreen(ContentManagerController assets) : base(true)
{
this.assets = assets;
background = assets.Get<Texture2D>("backgrounds/mainBG");
fat = new FadeAwayTransition(1.5f);
book = new Book();
@ -39,13 +38,13 @@ namespace RhythmBullet.Zer01HD.Game.Screens.MainMenu
public override void Show()
{
Mouse.SetCursor(MouseCursor.FromTexture2D(assets.Get<Texture2D>("cursor"), 256, 256));
Transitions.Add(fat);
base.Show();
}
public override void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(background, ScreenSize, Color.White);
book.Draw(spriteBatch);
base.Draw(spriteBatch);

View File

@ -9,7 +9,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.Game.Screens.Transitions
namespace RhythmBullet.Zer01HD.Screens.Transitions
{
internal class FadeAwayTransition : IDisposable, ITransition
{

View File

@ -11,18 +11,17 @@ using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
{
public delegate void ContentSystemUpdate(String fileName, float completed);
public class ContentSystem
public class ContentManagerController
{
public event ContentSystemUpdate ContentSystemListeners;
Thread thread;
readonly ContentManager contentManager;
readonly Queue<LoadableContent> queue;
Dictionary<string, IDisposable> assets;
public readonly Dictionary<Type, IContentPathModifier> contentPathModifier;
volatile float progress;
public ContentSystem(ContentManager contentManager)
volatile bool running;
public ContentManagerController(ContentManager contentManager)
{
this.contentManager = contentManager;
assets = new Dictionary<string, IDisposable>();
@ -46,6 +45,7 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
public T Get<T>(string assetName)
{
Console.WriteLine("Attempt get");
lock (queue)
{
return (T)assets[assetName];
@ -83,6 +83,7 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
private void LoadBatch()
{
running = true;
int totalTasks = queue.Count;
int tasksCompleted = 0;
while (queue.Count != 0)
@ -93,9 +94,9 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
Load(content.assetName, content.type, content.usePathModifier);
tasksCompleted++;
progress = (float)tasksCompleted / totalTasks;
OnProgress(content.assetName, progress);
}
}
running = false;
}
/// <summary>
/// Removes the asset from the list of assets in the system.
@ -143,15 +144,10 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
{
get
{
return queue.Count == 0;
return !running && queue.Count == 0;
}
}
protected virtual void OnProgress(string fileName, float progress)
{
ContentSystemListeners?.Invoke(fileName, progress);
}
public float Progress
{
get

View File

@ -1,14 +1,11 @@
using RhythmBullet.Zer01HD.Utilities.Persistence;
using RhythmBullet.Zer01HD.Preferences;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace RhythmBullet.Zer01HD.Utilities
namespace RhythmBullet.Zer01HD.Utilities.Persistence
{
public class PreferencesManager
{
@ -21,12 +18,13 @@ namespace RhythmBullet.Zer01HD.Utilities
this.savePath = savePath;
Directory.CreateDirectory(savePath);
preferenceList = new Dictionary<Type, Preferences>();
Debug.WriteLine("Preference manager setting up...");
Type[] preferenceTypes = new Type[preferences.Length];
for (int prefID = 0; prefID < preferences.Length; prefID++)
{
preferenceList.Add(preferences[prefID].GetType(), preferences[prefID]);
preferenceTypes[prefID] = preferences[prefID].GetType();
Debug.WriteLine(preferences[prefID] + " added to list of preferences");
}
xmlSerializer = new XmlSerializer(typeof(Preferences), preferenceTypes);

View File

@ -1,15 +1,17 @@

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Diagnostics;
namespace RhythmBullet.Zer01HD.Utilities.ScreenSystem
{
class LoadingScreen : Screen, ITransition
public class LoadingScreen : Screen, ITransition
{
private const float ENTER_TIME = 2f;
private const float EXIT_TIME = 1f;
Game game;
readonly Texture2D texture;
Color color;
Rectangle textureBounds;
@ -22,12 +24,14 @@ namespace RhythmBullet.Zer01HD.Utilities.ScreenSystem
readonly bool rotate;
Vector2 origin;
public LoadingScreen(Texture2D texture, float proportion, bool rotate = false) : base(true)
public LoadingScreen(Game game, Texture2D screenImage, float proportion, bool rotate = false) : base(true)
{
this.texture = texture;
this.game = game;
this.texture = screenImage;
this.proportion = proportion;
this.rotate = rotate;
Transitions.Add(this);
game.IsMouseVisible = false;
}
public void InitiateTransition(Rectangle dimensions)

View File

@ -10,16 +10,17 @@ using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.Utilities.ScreenSystem
{
public delegate void RequireNextScreen(Screen screen);
public delegate void FirstScreenChange(Screen screen);
public class ScreenManager : IDisposable
{
public event RequireNextScreen RequireNextScreenEvent;
public event FirstScreenChange RequireNextScreenEvent;
private GraphicsDeviceManager graphics;
private Screen previousScreen;
private RenderTarget2D previousScreenRenderTarget;
private Screen currentScreen;
private Camera2D camera;
private bool firstScreenChangeComplete;
public Screen Screen
{
get
@ -42,7 +43,6 @@ namespace RhythmBullet.Zer01HD.Utilities.ScreenSystem
graphics.GraphicsDevice.Clear(Color.Black);
Debug.WriteLine("Showing " + value.GetType().Name);
Debug.WriteLine("Previous screen is " + previousScreen?.GetType().Name);
Screen.Show();
}
}
@ -67,9 +67,10 @@ namespace RhythmBullet.Zer01HD.Utilities.ScreenSystem
case ScreenState.ExitTransition:
if (Screen.UseRenderTargetForExitTransition || Screen.UpdateTransition(gameTime.ElapsedGameTime.TotalSeconds, assetsDone))
{
if (Screen.NextScreen == null)
if (!firstScreenChangeComplete)
{
OnRequireNextScreen(Screen);
firstScreenChangeComplete = true;
OnFirstScreenChange(Screen);
}
if (Screen.NextScreen != null)
{
@ -109,10 +110,10 @@ namespace RhythmBullet.Zer01HD.Utilities.ScreenSystem
spriteBatch.End();
}
public void Resize(Texture2D loadingScreenSymbol)
public void Resize(LoadingScreen loadingScreen)
{
Screen.AssetLoadStateChange(true);
Screen = new LoadingScreen(loadingScreenSymbol, 0.3f, true);
Screen = loadingScreen;
previousScreenRenderTarget.Dispose();
previousScreenRenderTarget = null;
}
@ -122,7 +123,7 @@ namespace RhythmBullet.Zer01HD.Utilities.ScreenSystem
Screen.AssetLoadStateChange(false);
}
public void OnRequireNextScreen(Screen screen)
public void OnFirstScreenChange(Screen screen)
{
RequireNextScreenEvent?.Invoke(screen);
}