diff --git a/RhythmBullet/RhythmBullet.csproj b/RhythmBullet/RhythmBullet.csproj index 1c078e2..e325f64 100644 --- a/RhythmBullet/RhythmBullet.csproj +++ b/RhythmBullet/RhythmBullet.csproj @@ -61,7 +61,7 @@ - + diff --git a/RhythmBullet/Zer01HD/Audio/Visualizer/HorizontalVisualizer.cs b/RhythmBullet/Zer01HD/Audio/Visualizer/HorizontalVisualizer.cs index 0e786b3..3d4c180 100644 --- a/RhythmBullet/Zer01HD/Audio/Visualizer/HorizontalVisualizer.cs +++ b/RhythmBullet/Zer01HD/Audio/Visualizer/HorizontalVisualizer.cs @@ -46,14 +46,14 @@ namespace RhythmBullet.Zer01HD.Audio.Visualizer { for (int i = 0; i < BAR_COUNT; i++) { - bar.X = (i * (bar.Width + spaceBetweenBars)) + Bounds.X; - bar.Y = Bounds.Y; + bar.X = (i * (bar.Width + spaceBetweenBars)) + bounds.X; + bar.Y = bounds.Y; bar.Height = barValue[i]; - batch.Draw(barTexture, bar, Color); + batch.Draw(barTexture, bar, color); bar.Height = -barValue[BAR_COUNT - i - 1]; - batch.Draw(barTexture, bar, Color); + batch.Draw(barTexture, bar, color); } base.Draw(batch); } diff --git a/RhythmBullet/Zer01HD/Screens/MainMenu/MainPage.cs b/RhythmBullet/Zer01HD/Screens/MainMenu/MainPage.cs index 0c8328c..c216d60 100644 --- a/RhythmBullet/Zer01HD/Screens/MainMenu/MainPage.cs +++ b/RhythmBullet/Zer01HD/Screens/MainMenu/MainPage.cs @@ -18,8 +18,8 @@ namespace RhythmBullet.Zer01HD.Screens.MainMenu 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); + title.bounds.X = (int)((width - title.bounds.Width) / 2f); + title.bounds.Y = (int)((height - title.bounds.Height) / 2f); base.ApplySize(width, height); } diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs b/RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs index b6b87fa..ac005e2 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Book/Book.cs @@ -42,7 +42,7 @@ namespace RhythmBullet.Zer01HD.UI.Book if (targetPage != null) { Vector2 position; - Rectangle targetBounds = targetPage.Bounds; + Rectangle targetBounds = targetPage.bounds; position.X = targetBounds.X + (targetBounds.Width * 0.5f); position.Y = targetBounds.Y + (targetBounds.Height * 0.5f); camera.LinearInterpolationToPosition(0.4f, position, (float)gameTime.ElapsedGameTime.TotalSeconds); @@ -85,7 +85,7 @@ namespace RhythmBullet.Zer01HD.UI.Book public void GoToPage(Page page) { - Rectangle targetBounds = page.Bounds; + Rectangle targetBounds = page.bounds; camera.Position.X = targetBounds.X + (targetBounds.Width * 0.5f); camera.Position.Y = targetBounds.Y + (targetBounds.Height * 0.5f); } diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs b/RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs index b1209d4..d4f7645 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Book/Page.cs @@ -25,10 +25,10 @@ namespace RhythmBullet.Zer01HD.UI.Book public virtual void ApplySize(int width, int height) { - Bounds.X = pageX * width; - Bounds.Y = pageY * height; - Bounds.Width = width; - Bounds.Height = height; + bounds.X = pageX * width; + bounds.Y = pageY * height; + bounds.Width = width; + bounds.Height = height; NeedsSizeUpdate = false; } } diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Modular/Modules/Image.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/Modules/Image.cs index 1076530..9827f75 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Modular/Modules/Image.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Modular/Modules/Image.cs @@ -16,12 +16,12 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.Modular.Modules { get { - return (float)Bounds.Width / Texture.Width; + return (float)bounds.Width / Texture.Width; } set { - Bounds.Width = (int)(Texture.Width * value); + bounds.Width = (int)(Texture.Width * value); } } @@ -29,12 +29,12 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.Modular.Modules { get { - return (float)Bounds.Height / Texture.Height; + return (float)bounds.Height / Texture.Height; } set { - Bounds.Height = (int)(Texture.Height * value); + bounds.Height = (int)(Texture.Height * value); } } @@ -42,20 +42,20 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.Modular.Modules { set { - Bounds.Height = (int)(Texture.Height * value); - Bounds.Width = (int)(Texture.Width * value); + bounds.Height = (int)(Texture.Height * value); + bounds.Width = (int)(Texture.Width * value); } } public Image(Texture2D texture) { Texture = texture ?? throw new ArgumentException("Image requires a texture."); - Bounds = texture.Bounds; + bounds = texture.Bounds; } public override void Draw(SpriteBatch batch) { - batch.Draw(Texture, Bounds, Color); + batch.Draw(Texture, bounds, color); base.Draw(batch); } } diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Interactive/BasicButton.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/Modules/Interactive/BasicButton.cs similarity index 77% rename from RhythmBullet/Zer01HD/Utilities/UI/Interactive/BasicButton.cs rename to RhythmBullet/Zer01HD/Utilities/UI/Modular/Modules/Interactive/BasicButton.cs index a72c963..dd8165d 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Interactive/BasicButton.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Modular/Modules/Interactive/BasicButton.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace RhythmBullet.Zer01HD.Utilities.UI.Interactive +namespace RhythmBullet.Zer01HD.Utilities.UI.Modular.Modules.Interactive { public delegate bool Clicked(); @@ -20,11 +20,9 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.Interactive } - - public sealed override bool MouseStateChanged(MouseState state) { - if (InputUtilities.MouseWithinBoundries(Bounds)) + if (InputUtilities.MouseWithinBoundries(bounds)) { if (InputUtilities.MouseClicked()) { @@ -39,6 +37,11 @@ namespace RhythmBullet.Zer01HD.Utilities.UI.Interactive return base.MouseStateChanged(state); } + public sealed override bool KeyboardStateChanged(KeyboardState state) + { + return base.KeyboardStateChanged(state); + } + protected void OnClick() { Listeners?.Invoke(); diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Modular/Modules/Text.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/Modules/Text.cs index 57e6227..9d1c6bd 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Modular/Modules/Text.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Modular/Modules/Text.cs @@ -14,31 +14,99 @@ namespace RhythmBullet.Zer01HD.UI.Modular.Modules private SpriteFont font; private float scale; private Vector2 position; + private string text; + private Vector2 textSize; + public bool autoWrap; + public bool autoScale; public string DisplayedText { get { - return DisplayedText; + return text; } set { - Vector2 size = font.MeasureString(value); - Bounds.Width = (int) size.X; - scale = Bounds.Height / size.Y; + textSize = font.MeasureString(value); + text = value; } } public Text(string displayedText, SpriteFont font, int height) { - Bounds.Height = height; + bounds.Height = height; this.font = font; } + public override void Update(GameTime gameTime) + { + position.X = bounds.X; + position.Y = bounds.Y; + + if (autoWrap) + { + AttemptToWrapText(); + } + + if (autoScale) + { + AttemptToScaleFont(); + } + + base.Update(gameTime); + } + public override void Draw(SpriteBatch batch) { - position.X = Bounds.X; - position.Y = Bounds.Y; - batch.DrawString(font, DisplayedText, position, Color); + batch.DrawString(font, DisplayedText, position, color, 0f, origin, scale, SpriteEffects.None, 0f); base.Draw(batch); } + + public void AttemptToScaleFont() + { + if (textSize.X * scale > bounds.Width || textSize.X * scale < bounds.Width) + { + scale = bounds.Width / textSize.X; + } + + if (textSize.Y * scale > bounds.Height || textSize.Y *scale > bounds.Height) + { + scale = bounds.Height / textSize.Y; + } + } + + public void RemoveLineBreaks() + { + DisplayedText = DisplayedText.Replace("\n", " "); + + } + + public void AttemptToWrapText(bool unwrap = false) + { + if (unwrap) RemoveLineBreaks(); + if (textSize.X * scale > bounds.Width) + { + text = text.Replace("\n", " "); + string[] words = text.Split(' '); + StringBuilder stringBuilder = new StringBuilder(); + float currentScaledLineWidth = 0f; + + for (int w = 0; w < words.Length; w++) + { + string word = words[w]; + float scaledWidth = font.MeasureString(word).X * scale; + + if (currentScaledLineWidth + scaledWidth <= bounds.Width) + { + stringBuilder.Append(word); + currentScaledLineWidth += scaledWidth; + } + else + { + stringBuilder.AppendLine(); + currentScaledLineWidth = 0; + } + } + DisplayedText = stringBuilder.ToString(); + } + } } } diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModule.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModule.cs index 80bdc99..f959a8d 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModule.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModule.cs @@ -13,10 +13,11 @@ namespace RhythmBullet.Zer01HD.UI.Modular { public class UIModule : IInputListener { - public Rectangle Bounds; + public Rectangle bounds; + public Vector2 origin; public UIModuleGroup Parent; public string Name; - public Color Color = Color.White; + public Color color = Color.White; public virtual void Update(GameTime gameTime) { diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs index 01fdb87..55f6aed 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs @@ -34,23 +34,23 @@ namespace RhythmBullet.Zer01HD.UI.Modular { batch.End(); batch.Begin(SpriteSortMode.Deferred, null, null, null, scissorRasterizer, null, Camera?.TransformMatrix); - scissorBounds.Width = Bounds.Width; - scissorBounds.Height = Bounds.Height; - scissorBounds.X = Bounds.X; - scissorBounds.Y = Bounds.Y; + scissorBounds.Width = bounds.Width; + scissorBounds.Height = bounds.Height; + scissorBounds.X = bounds.X; + scissorBounds.Y = bounds.Y; Rectangle scissor = scissorBounds; scissorBounds = batch.GraphicsDevice.ScissorRectangle; batch.GraphicsDevice.ScissorRectangle = scissor; } foreach (UIModule module in modules) { - int offsetX = module.Bounds.X; - int offsetY = module.Bounds.Y; - module.Bounds.X = Bounds.X + offsetX; - module.Bounds.Y = Bounds.Y + offsetY; + int offsetX = module.bounds.X; + int offsetY = module.bounds.Y; + module.bounds.X = bounds.X + offsetX; + module.bounds.Y = bounds.Y + offsetY; module.Draw(batch); - module.Bounds.X = offsetX; - module.Bounds.Y = offsetY; + module.bounds.X = offsetX; + module.bounds.Y = offsetY; } if (scissorBounds != null)