refactor and better screen mechanism (probably)
This commit is contained in:
@@ -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
|
@@ -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);
|
||||
|
@@ -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)
|
||||
|
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user