From 53000e6a6c0cfb9e51c773e359d6634c679ed853 Mon Sep 17 00:00:00 2001 From: Recrown Date: Mon, 15 Apr 2019 20:25:36 -0500 Subject: [PATCH] Fading now works. --- .../SpecialTypes/TextureAtlas.cs | 2 +- .../UI/Modular/Modules/UIScrollable.cs | 43 +++++++++++++------ TestGame/TestGame.cs | 2 +- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/RecrownedAthenaeum/SpecialTypes/TextureAtlas.cs b/RecrownedAthenaeum/SpecialTypes/TextureAtlas.cs index be7ea6e..fcc5893 100644 --- a/RecrownedAthenaeum/SpecialTypes/TextureAtlas.cs +++ b/RecrownedAthenaeum/SpecialTypes/TextureAtlas.cs @@ -174,7 +174,7 @@ namespace RecrownedAthenaeum.SpecialTypes if (ninepatch != null) { - ninepatch.Draw(batch, Color.White, destination); + ninepatch.Draw(batch, color, destination); } else { diff --git a/RecrownedAthenaeum/UI/Modular/Modules/UIScrollable.cs b/RecrownedAthenaeum/UI/Modular/Modules/UIScrollable.cs index ecd64ed..c283b20 100644 --- a/RecrownedAthenaeum/UI/Modular/Modules/UIScrollable.cs +++ b/RecrownedAthenaeum/UI/Modular/Modules/UIScrollable.cs @@ -17,7 +17,8 @@ namespace RecrownedAthenaeum.UI.Modular.Modules { UIModuleGroup group; - float opacityOfBar; + Color scrollBarColor; + float opacityOfBar = 1; bool showingBars; int shiftX, shiftY; int furthestX; @@ -30,7 +31,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules /// /// How fast the bars fade away in opacity (0 to 254) per second. /// - public float barFadeSpeed; + public float barFadeSpeed = 250; ISpecialDrawable horizontalScrollBar, verticalScrollBar; ISpecialDrawable background, horizontalBarTrack, verticalBarTrack; @@ -58,8 +59,12 @@ namespace RecrownedAthenaeum.UI.Modular.Modules set { hideScrollBars = value; - WidthOrXChange(); - HeightOrYChange(); + WidthOrXChange(true); + HeightOrYChange(true); + if (!value) + { + opacityOfBar = 1f; + } } } @@ -151,9 +156,10 @@ namespace RecrownedAthenaeum.UI.Modular.Modules { if (!showingBars) { - if (opacityOfBar <= 0) + if (opacityOfBar > 0f) { - opacityOfBar -= (barFadeSpeed / 255f) * gameTime.ElapsedGameTime.Seconds; + opacityOfBar -= (barFadeSpeed / 255f) * (float)gameTime.ElapsedGameTime.TotalSeconds; + scrollBarColor = color * opacityOfBar; } } else @@ -183,11 +189,11 @@ namespace RecrownedAthenaeum.UI.Modular.Modules if (horScrollAvailable) { - horizontalScrollBar.Draw(spriteBatch, horizontalScrollBarBounds, color); + horizontalScrollBar.Draw(spriteBatch, horizontalScrollBarBounds, scrollBarColor); } if (vertScrollAvailable) { - horizontalScrollBar.Draw(spriteBatch, verticalScrollBarBounds, color); + horizontalScrollBar.Draw(spriteBatch, verticalScrollBarBounds, scrollBarColor); } base.Draw(spriteBatch); } @@ -269,15 +275,21 @@ namespace RecrownedAthenaeum.UI.Modular.Modules } else { horScrollAvailable = false; } - + verticalScrollBarBounds.X = X; if (!hideScrollBars) { - verticalScrollBarBounds.X = X; + group.Width -= VerticalBarThickness; if (!verticalBarLeftPosition) { verticalScrollBarBounds.X += group.Width; } - group.Width -= VerticalBarThickness; + } + else + { + if (!verticalBarLeftPosition) + { + verticalScrollBarBounds.X += group.Width - verticalScrollBarBounds.Width; + } } } } @@ -296,9 +308,9 @@ namespace RecrownedAthenaeum.UI.Modular.Modules } else { vertScrollAvailable = false; } + horizontalScrollBarBounds.Y = Y; if (!hideScrollBars) { - horizontalScrollBarBounds.Y = Y; group.Height -= HorizontalBarThickness; if (!horizontalBarTopPosition) { @@ -309,6 +321,13 @@ namespace RecrownedAthenaeum.UI.Modular.Modules group.Y += horizontalScrollBarBounds.Height; } } + else + { + if (!horizontalBarTopPosition) + { + horizontalScrollBarBounds.Y += group.Height - horizontalScrollBarBounds.Height; + } + } } } diff --git a/TestGame/TestGame.cs b/TestGame/TestGame.cs index 912ccb7..55c8892 100644 --- a/TestGame/TestGame.cs +++ b/TestGame/TestGame.cs @@ -63,7 +63,7 @@ namespace TestGame uIScrollable = new UIScrollable(skin); uIScrollable.Width = 256; uIScrollable.Height = 256; - uIScrollable.HideScrollBars = false; + uIScrollable.HideScrollBars = true; logoImage = new Image(logo); uIScrollable.AddModules(logoImage);