diff --git a/RhythmBullet/RhythmBullet.csproj b/RhythmBullet/RhythmBullet.csproj index 9e1c598..3978012 100644 --- a/RhythmBullet/RhythmBullet.csproj +++ b/RhythmBullet/RhythmBullet.csproj @@ -42,21 +42,27 @@ app.manifest - + - - + + - - - - + + + + + + + + + + diff --git a/RhythmBullet/RhythmBulletGame.cs b/RhythmBullet/RhythmBulletGame.cs index 9b9d6ac..a84a795 100644 --- a/RhythmBullet/RhythmBulletGame.cs +++ b/RhythmBullet/RhythmBulletGame.cs @@ -2,8 +2,10 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using RhythmBullet.Zer01HD.Game; +using RhythmBullet.Zer01HD.Game.ContentResolvers; using RhythmBullet.Zer01HD.UI; using RhythmBullet.Zer01HD.Utilities.ContentSystem; +using RhythmBullet.Zer01HD.Utilities.UI; namespace RhythmBullet { @@ -15,6 +17,7 @@ namespace RhythmBullet public GraphicsDeviceManager Graphics; SpriteBatch spriteBatch; public readonly ContentSystem Assets; + private readonly ResolutionContentResolver resolutionContentResolver; private Screen currentScreen; Screen CurrentScreen { @@ -41,6 +44,10 @@ namespace RhythmBullet Window.IsBorderless = true; Content.RootDirectory = "Content"; Assets = new ContentSystem(Content); + resolutionContentResolver = new ResolutionContentResolver(); + FontContentResolver fcr = new FontContentResolver(resolutionContentResolver); + Assets.contentResolver.Add(typeof(Texture2D), resolutionContentResolver); + Assets.contentResolver.Add(typeof(SpriteFont), fcr); } /// @@ -102,11 +109,16 @@ namespace RhythmBullet base.Draw(gameTime); } - public void Resize(int width, int height) + public void Reload() { - Graphics.PreferredBackBufferWidth = width; - Graphics.PreferredBackBufferHeight = height; - + Assets.UnloadAll(); + resolutionContentResolver.Width = Graphics.PreferredBackBufferWidth; + resolutionContentResolver.Height = Graphics.PreferredBackBufferHeight; + } + + void QueueContent() + { + } } } diff --git a/RhythmBullet/Zer01HD/Game/ContentResolvers/FontContentResolver.cs b/RhythmBullet/Zer01HD/Game/ContentResolvers/FontContentResolver.cs new file mode 100644 index 0000000..1b75558 --- /dev/null +++ b/RhythmBullet/Zer01HD/Game/ContentResolvers/FontContentResolver.cs @@ -0,0 +1,24 @@ +using RhythmBullet.Zer01HD.Utilities.ContentSystem; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RhythmBullet.Zer01HD.Game.ContentResolvers +{ + class FontContentResolver : IContentResolver + { + readonly ResolutionContentResolver rcr; + + public FontContentResolver(ResolutionContentResolver rcr) + { + this.rcr = rcr; + } + + public string Load(string assetName) + { + return rcr.Load("fonts/" + assetName); + } + } +} diff --git a/RhythmBullet/Zer01HD/Game/ContentResolvers/ResolutionContentResolver.cs b/RhythmBullet/Zer01HD/Game/ContentResolvers/ResolutionContentResolver.cs new file mode 100644 index 0000000..902b600 --- /dev/null +++ b/RhythmBullet/Zer01HD/Game/ContentResolvers/ResolutionContentResolver.cs @@ -0,0 +1,109 @@ +using RhythmBullet.Zer01HD.Game.Preferences; +using RhythmBullet.Zer01HD.Utilities; +using RhythmBullet.Zer01HD.Utilities.ContentSystem; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RhythmBullet.Zer01HD.Game.ContentResolvers +{ + class ResolutionContentResolver : IContentResolver + { + int width, height; + bool updated; + Resolution bestResolution; + + public int Width + { + get + { + return width; + } + + set + { + updated = true; + width = value; + } + } + + public int Height + { + get + { + return height; + } + + set + { + updated = true; + height = value; + } + } + + Resolution[] resolutions = { + new Resolution(1920, 1080), + new Resolution(2560, 1440), + new Resolution(3840, 2160) + }; + + Resolution ChooseRounded() + { + updated = false; + Resolution best = resolutions[0]; + + int leastDifference = -1; + + int w = Width, h = Height; + + if (w > h) + { + for (int i = 0; i < resolutions.Length; i++) + { + int currentDiff = h - resolutions[i].Height; + + if (currentDiff < 0) + { + currentDiff = currentDiff * -1; + } + + if ((currentDiff < leastDifference) || leastDifference == -1) + { + best = resolutions[i]; + leastDifference = currentDiff; + } + } + } + else + { + for (int i = 0; i < resolutions.Length; i++) + { + int currentDiff = w - resolutions[i].Width; + + if (currentDiff < 0) + { + currentDiff = currentDiff * -1; + } + + if (currentDiff < leastDifference || leastDifference == -1) + { + best = resolutions[i]; + leastDifference = currentDiff; + } + } + } + return best; + } + + public string Load(string path) + { + if (updated) + { + bestResolution = ChooseRounded(); + } + return bestResolution + "/" + path; + } + } +} diff --git a/RhythmBullet/Zer01HD/Game/MainScreen/MainScreen.cs b/RhythmBullet/Zer01HD/Game/MainScreen/MainScreen.cs index e26a591..3cf7838 100644 --- a/RhythmBullet/Zer01HD/Game/MainScreen/MainScreen.cs +++ b/RhythmBullet/Zer01HD/Game/MainScreen/MainScreen.cs @@ -1,5 +1,6 @@ using Microsoft.Xna.Framework.Graphics; using RhythmBullet.Zer01HD.UI; +using RhythmBullet.Zer01HD.Utilities.UI; using System; using System.Collections.Generic; using System.Linq; diff --git a/RhythmBullet/Zer01HD/Game/Preferences/Controls.cs b/RhythmBullet/Zer01HD/Game/Preferences/Controls.cs new file mode 100644 index 0000000..ec8ca32 --- /dev/null +++ b/RhythmBullet/Zer01HD/Game/Preferences/Controls.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RhythmBullet.Zer01HD.Game.Preferences +{ + class Controls + { + } +} diff --git a/RhythmBullet/Zer01HD/Game/Preferences/General.cs b/RhythmBullet/Zer01HD/Game/Preferences/General.cs new file mode 100644 index 0000000..fc06353 --- /dev/null +++ b/RhythmBullet/Zer01HD/Game/Preferences/General.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RhythmBullet.Zer01HD.Game.Preferences +{ + class General + { + public Resolution Resolution; + public bool Fullscreen; + public float MusicVolume; + public float FXVolume; + } +} diff --git a/RhythmBullet/Zer01HD/Utilities/ContentSystem/ContentSystem.cs b/RhythmBullet/Zer01HD/Utilities/ContentSystem/ContentSystem.cs index 72c844e..062b690 100644 --- a/RhythmBullet/Zer01HD/Utilities/ContentSystem/ContentSystem.cs +++ b/RhythmBullet/Zer01HD/Utilities/ContentSystem/ContentSystem.cs @@ -16,7 +16,7 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem readonly ContentManager contentManager; readonly Queue queue; Dictionary assets; - readonly Dictionary contentResolver; + public readonly Dictionary contentResolver; public ContentSystem(ContentManager contentManager) { @@ -69,7 +69,7 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem /// /// Called whenever a batch of assets should be loaded from the queue. Safe to call once every frame. /// - void Update() + public void Update() { if (queue.Count > 0) { @@ -81,16 +81,45 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem } } - void UnloadAll() + /// + /// Removes the asset from the list of assets in the system. + /// Cannot remove from queue. + /// + /// the string name used to load the asset + public void Remove(string name) + { + if (assets.ContainsKey(name)) + { + assets[name].Dispose(); + assets.Remove(name); + } + } + + /// + /// Clears the queue. + /// + public void ClearQueue() + { + lock(queue) + { + queue.Clear(); + } + } + + /// + /// Unloads everything from both queue and loaded list while properly disposing of the assets loaded. + /// + public void UnloadAll() { foreach (KeyValuePair asset in assets) { asset.Value.Dispose(); assets.Remove(asset.Key); } + ClearQueue(); } - bool Done() + public bool Done() { return queued; } diff --git a/RhythmBullet/Zer01HD/Utilities/ContentSystem/IContentResolver.cs b/RhythmBullet/Zer01HD/Utilities/ContentSystem/IContentResolver.cs index 8835e23..631b88d 100644 --- a/RhythmBullet/Zer01HD/Utilities/ContentSystem/IContentResolver.cs +++ b/RhythmBullet/Zer01HD/Utilities/ContentSystem/IContentResolver.cs @@ -6,8 +6,13 @@ using System.Threading.Tasks; namespace RhythmBullet.Zer01HD.Utilities.ContentSystem { - interface IContentResolver + public interface IContentResolver { - string Load(string path); + /// + /// Returns the complete path with the content folder as root. + /// + /// Is the asset's name + /// + string Load(string assetName); } } diff --git a/RhythmBullet/Zer01HD/Utilities/Preferences.cs b/RhythmBullet/Zer01HD/Utilities/Preferences.cs new file mode 100644 index 0000000..4657369 --- /dev/null +++ b/RhythmBullet/Zer01HD/Utilities/Preferences.cs @@ -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 + { + } +} diff --git a/RhythmBullet/Zer01HD/Utilities/Resolution.cs b/RhythmBullet/Zer01HD/Utilities/Resolution.cs new file mode 100644 index 0000000..f10d671 --- /dev/null +++ b/RhythmBullet/Zer01HD/Utilities/Resolution.cs @@ -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 + { + 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; + } + } +} diff --git a/RhythmBullet/Zer01HD/UI/Book/Book.cs b/RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs similarity index 100% rename from RhythmBullet/Zer01HD/UI/Book/Book.cs rename to RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs diff --git a/RhythmBullet/Zer01HD/UI/Book/Page.cs b/RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs similarity index 100% rename from RhythmBullet/Zer01HD/UI/Book/Page.cs rename to RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs diff --git a/RhythmBullet/Zer01HD/Game/LoadingScreen.cs b/RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs similarity index 94% rename from RhythmBullet/Zer01HD/Game/LoadingScreen.cs rename to RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs index 0d839da..7a3d5b8 100644 --- a/RhythmBullet/Zer01HD/Game/LoadingScreen.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs @@ -2,6 +2,7 @@ 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; diff --git a/RhythmBullet/Zer01HD/UI/Modular/Module.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/Module.cs similarity index 100% rename from RhythmBullet/Zer01HD/UI/Modular/Module.cs rename to RhythmBullet/Zer01HD/Utilities/UI/Modular/Module.cs diff --git a/RhythmBullet/Zer01HD/UI/Modular/ModuleGroup.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/ModuleGroup.cs similarity index 100% rename from RhythmBullet/Zer01HD/UI/Modular/ModuleGroup.cs rename to RhythmBullet/Zer01HD/Utilities/UI/Modular/ModuleGroup.cs diff --git a/RhythmBullet/Zer01HD/UI/Modular/Text.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/Text.cs similarity index 100% rename from RhythmBullet/Zer01HD/UI/Modular/Text.cs rename to RhythmBullet/Zer01HD/Utilities/UI/Modular/Text.cs diff --git a/RhythmBullet/Zer01HD/UI/Screen.cs b/RhythmBullet/Zer01HD/Utilities/UI/Screen.cs similarity index 92% rename from RhythmBullet/Zer01HD/UI/Screen.cs rename to RhythmBullet/Zer01HD/Utilities/UI/Screen.cs index 680e259..e4b4cca 100644 --- a/RhythmBullet/Zer01HD/UI/Screen.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Screen.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace RhythmBullet.Zer01HD.UI +namespace RhythmBullet.Zer01HD.Utilities.UI { public class Screen {