reorganized file structure; texture and fonts now have appropriate folder resolver;
This commit is contained in:
@@ -16,7 +16,7 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
|
||||
readonly ContentManager contentManager;
|
||||
readonly Queue<ContentLoad> queue;
|
||||
Dictionary<string, IDisposable> assets;
|
||||
readonly Dictionary<Type, IContentResolver> contentResolver;
|
||||
public readonly Dictionary<Type, IContentResolver> contentResolver;
|
||||
|
||||
public ContentSystem(ContentManager contentManager)
|
||||
{
|
||||
@@ -69,7 +69,7 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
|
||||
/// <summary>
|
||||
/// Called whenever a batch of assets should be loaded from the queue. Safe to call once every frame.
|
||||
/// </summary>
|
||||
void Update()
|
||||
public void Update()
|
||||
{
|
||||
if (queue.Count > 0)
|
||||
{
|
||||
@@ -81,16 +81,45 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
|
||||
}
|
||||
}
|
||||
|
||||
void UnloadAll()
|
||||
/// <summary>
|
||||
/// Removes the asset from the list of assets in the system.
|
||||
/// Cannot remove from queue.
|
||||
/// </summary>
|
||||
/// <param name="name">the string name used to load the asset</param>
|
||||
public void Remove(string name)
|
||||
{
|
||||
if (assets.ContainsKey(name))
|
||||
{
|
||||
assets[name].Dispose();
|
||||
assets.Remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the queue.
|
||||
/// </summary>
|
||||
public void ClearQueue()
|
||||
{
|
||||
lock(queue)
|
||||
{
|
||||
queue.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unloads everything from both queue and loaded list while properly disposing of the assets loaded.
|
||||
/// </summary>
|
||||
public void UnloadAll()
|
||||
{
|
||||
foreach (KeyValuePair<string, IDisposable> asset in assets)
|
||||
{
|
||||
asset.Value.Dispose();
|
||||
assets.Remove(asset.Key);
|
||||
}
|
||||
ClearQueue();
|
||||
}
|
||||
|
||||
bool Done()
|
||||
public bool Done()
|
||||
{
|
||||
return queued;
|
||||
}
|
||||
|
@@ -6,8 +6,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
|
||||
{
|
||||
interface IContentResolver
|
||||
public interface IContentResolver
|
||||
{
|
||||
string Load(string path);
|
||||
/// <summary>
|
||||
/// Returns the complete path with the content folder as root.
|
||||
/// </summary>
|
||||
/// <param name="assetName">Is the asset's name</param>
|
||||
/// <returns></returns>
|
||||
string Load(string assetName);
|
||||
}
|
||||
}
|
||||
|
12
RhythmBullet/Zer01HD/Utilities/Preferences.cs
Normal file
12
RhythmBullet/Zer01HD/Utilities/Preferences.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.Utilities
|
||||
{
|
||||
class Preferences
|
||||
{
|
||||
}
|
||||
}
|
34
RhythmBullet/Zer01HD/Utilities/Resolution.cs
Normal file
34
RhythmBullet/Zer01HD/Utilities/Resolution.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.Game.Preferences
|
||||
{
|
||||
public class Resolution : IComparable<Resolution>
|
||||
{
|
||||
public int Width, Height;
|
||||
|
||||
public Resolution(int width, int height)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
public int CompareTo(Resolution other)
|
||||
{
|
||||
return Area() - other.Area();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Width + "x" + Height;
|
||||
}
|
||||
|
||||
public int Area()
|
||||
{
|
||||
return Width * Height;
|
||||
}
|
||||
}
|
||||
}
|
45
RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs
Normal file
45
RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.UI.Book
|
||||
{
|
||||
class Book
|
||||
{
|
||||
Viewport viewport;
|
||||
Dictionary<string, Page> pages = new Dictionary<string, Page>();
|
||||
public Book(Viewport viewport)
|
||||
{
|
||||
this.viewport = viewport;
|
||||
}
|
||||
|
||||
public void AddPage(Page page)
|
||||
{
|
||||
pages.Add(page.Name, page);
|
||||
}
|
||||
|
||||
public void RemovePage(Page page)
|
||||
{
|
||||
RemovePage(page.Name);
|
||||
}
|
||||
|
||||
public void RemovePage(string name)
|
||||
{
|
||||
pages.Remove(name);
|
||||
}
|
||||
|
||||
public void Resize(int width, int height)
|
||||
{
|
||||
viewport.Width = width;
|
||||
viewport.Height = height;
|
||||
}
|
||||
|
||||
public void DisplayPage(string name)
|
||||
{
|
||||
pages[name].DisplayWithViewport(viewport);
|
||||
}
|
||||
}
|
||||
}
|
36
RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs
Normal file
36
RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RhythmBullet.Zer01HD.UI.Modular;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.UI.Book
|
||||
{
|
||||
class Page : ModuleGroup
|
||||
{
|
||||
private readonly int pageX, pageY;
|
||||
|
||||
public Page(int pageX, int pageY, int width, int height)
|
||||
{
|
||||
this.pageX = pageX;
|
||||
this.pageY = pageY;
|
||||
ApplySize(width, height);
|
||||
}
|
||||
|
||||
public virtual void ApplySize(int width, int height)
|
||||
{
|
||||
Position.X = pageX * width;
|
||||
Position.Y = pageY * height;
|
||||
this.Width = width;
|
||||
this.Height = height;
|
||||
}
|
||||
|
||||
public void DisplayWithViewport(Viewport viewport)
|
||||
{
|
||||
viewport.X = (int) Position.X;
|
||||
viewport.Y = (int) Position.Y;
|
||||
}
|
||||
}
|
||||
}
|
28
RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs
Normal file
28
RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RhythmBullet.Zer01HD.UI;
|
||||
using RhythmBullet.Zer01HD.Utilities.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.Game
|
||||
{
|
||||
class LoadingScreen : Screen
|
||||
{
|
||||
Texture2D recrown;
|
||||
public LoadingScreen(Texture2D recrown)
|
||||
{
|
||||
this.recrown = recrown;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
spriteBatch.Draw(recrown, recrown.Bounds, Color.White);
|
||||
base.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
}
|
38
RhythmBullet/Zer01HD/Utilities/UI/Modular/Module.cs
Normal file
38
RhythmBullet/Zer01HD/Utilities/UI/Modular/Module.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.UI.Modular
|
||||
{
|
||||
public class Module
|
||||
{
|
||||
public Vector2 Position = new Vector2();
|
||||
public float Width, Height;
|
||||
public ModuleGroup Parent;
|
||||
public string Name;
|
||||
public Color Color;
|
||||
|
||||
public virtual void Update(GameTime gameTime)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void Draw(SpriteBatch batch)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void RemoveFromParent()
|
||||
{
|
||||
if (Parent == null)
|
||||
{
|
||||
throw new InvalidOperationException("Parent is null.");
|
||||
}
|
||||
Parent.RemoveModule(this);
|
||||
}
|
||||
}
|
||||
}
|
85
RhythmBullet/Zer01HD/Utilities/UI/Modular/ModuleGroup.cs
Normal file
85
RhythmBullet/Zer01HD/Utilities/UI/Modular/ModuleGroup.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.UI.Modular
|
||||
{
|
||||
public class ModuleGroup : Module
|
||||
{
|
||||
List<Module> modules = new List<Module>();
|
||||
Rectangle scissorBounds;
|
||||
RasterizerState scissorRasterizer = new RasterizerState();
|
||||
public ModuleGroup(bool crop = false)
|
||||
{
|
||||
if (crop)
|
||||
{
|
||||
scissorRasterizer.ScissorTestEnable = true;
|
||||
scissorBounds = new Rectangle();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch batch)
|
||||
{
|
||||
if (scissorBounds != null)
|
||||
{
|
||||
batch.End();
|
||||
batch.Begin(SpriteSortMode.Deferred, null, null, null, scissorRasterizer);
|
||||
scissorBounds.Width = (int) Width;
|
||||
scissorBounds.Height = (int) Height;
|
||||
scissorBounds.X = (int) Position.X;
|
||||
scissorBounds.Y = (int) Position.Y;
|
||||
Rectangle scissor = scissorBounds;
|
||||
scissorBounds = batch.GraphicsDevice.ScissorRectangle;
|
||||
batch.GraphicsDevice.ScissorRectangle = scissor;
|
||||
}
|
||||
foreach (Module module in modules)
|
||||
{
|
||||
float offsetX = module.Position.X;
|
||||
float offsetY = module.Position.Y;
|
||||
module.Position.X = Position.X + offsetX;
|
||||
module.Position.Y = Position.Y + offsetY;
|
||||
module.Draw(batch);
|
||||
module.Position.X = offsetX;
|
||||
module.Position.Y = offsetY;
|
||||
}
|
||||
|
||||
if (scissorBounds != null)
|
||||
{
|
||||
batch.GraphicsDevice.ScissorRectangle = scissorBounds;
|
||||
batch.End();
|
||||
batch.Begin();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
foreach (Module module in modules)
|
||||
{
|
||||
module.Update(gameTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddModule(params Module[] addModules)
|
||||
{
|
||||
foreach (Module module in addModules)
|
||||
{
|
||||
if (modules.Contains(module))
|
||||
{
|
||||
throw new InvalidOperationException(module.ToString() + " already exists in " + this.ToString());
|
||||
}
|
||||
module.Parent = this;
|
||||
modules.Add(module);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveModule(Module module)
|
||||
{
|
||||
module.Parent = null;
|
||||
modules.Remove(module);
|
||||
}
|
||||
}
|
||||
}
|
40
RhythmBullet/Zer01HD/Utilities/UI/Modular/Text.cs
Normal file
40
RhythmBullet/Zer01HD/Utilities/UI/Modular/Text.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.UI.Modular
|
||||
{
|
||||
class Text : Module
|
||||
{
|
||||
private SpriteFont font;
|
||||
private float scale;
|
||||
public string DisplayedText
|
||||
{
|
||||
get
|
||||
{
|
||||
return DisplayedText;
|
||||
}
|
||||
set
|
||||
{
|
||||
Vector2 size = font.MeasureString(value);
|
||||
Width = size.X;
|
||||
scale = Height / size.Y;
|
||||
}
|
||||
}
|
||||
public Text(string displayedText, SpriteFont font, int height)
|
||||
{
|
||||
this.font = font;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch batch)
|
||||
{
|
||||
batch.DrawString(font, DisplayedText, Position, Color);
|
||||
base.Draw(batch);
|
||||
}
|
||||
}
|
||||
}
|
38
RhythmBullet/Zer01HD/Utilities/UI/Screen.cs
Normal file
38
RhythmBullet/Zer01HD/Utilities/UI/Screen.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.Utilities.UI
|
||||
{
|
||||
public class Screen
|
||||
{
|
||||
public virtual void Update(GameTime gameTime)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void Show()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void Hide()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void Resize()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user