From 18852b250965df3f8c51be41682c2fca9719f298 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 2 May 2022 15:31:47 +0300 Subject: [PATCH] Fix footer random button autosizing to text length --- osu.Game/Screens/Select/FooterButtonRandom.cs | 51 +++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/osu.Game/Screens/Select/FooterButtonRandom.cs b/osu.Game/Screens/Select/FooterButtonRandom.cs index 48d5836826..f855b80f75 100644 --- a/osu.Game/Screens/Select/FooterButtonRandom.cs +++ b/osu.Game/Screens/Select/FooterButtonRandom.cs @@ -5,6 +5,7 @@ using System; using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Input.Events; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; @@ -19,6 +20,9 @@ namespace osu.Game.Screens.Select public Action NextRandom { get; set; } public Action PreviousRandom { get; set; } + private Container persistentText; + private OsuSpriteText randomSpriteText; + private OsuSpriteText rewindSpriteText; private bool rewindSearch; [BackgroundDependencyLoader] @@ -26,7 +30,32 @@ namespace osu.Game.Screens.Select { SelectedColour = colours.Green; DeselectedColour = SelectedColour.Opacity(0.5f); - updateText(); + + TextContainer.Add(persistentText = new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + AlwaysPresent = true, + AutoSizeAxes = Axes.Both, + Children = new[] + { + randomSpriteText = new OsuSpriteText + { + AlwaysPresent = true, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Text = "random", + }, + rewindSpriteText = new OsuSpriteText + { + AlwaysPresent = true, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Text = "rewind", + Alpha = 0f, + } + } + }); Action = () => { @@ -34,22 +63,22 @@ namespace osu.Game.Screens.Select { const double fade_time = 500; - OsuSpriteText rewindSpriteText; + OsuSpriteText fallingRewind; - TextContainer.Add(rewindSpriteText = new OsuSpriteText + TextContainer.Add(fallingRewind = new OsuSpriteText { Alpha = 0, - Text = @"rewind", + Text = rewindSpriteText.Text, AlwaysPresent = true, // make sure the button is sized large enough to always show this Anchor = Anchor.Centre, Origin = Anchor.Centre, }); - rewindSpriteText.FadeOutFromOne(fade_time, Easing.In); - rewindSpriteText.MoveTo(Vector2.Zero).MoveTo(new Vector2(0, 10), fade_time, Easing.In); - rewindSpriteText.Expire(); + fallingRewind.FadeOutFromOne(fade_time, Easing.In); + fallingRewind.MoveTo(Vector2.Zero).MoveTo(new Vector2(0, 10), fade_time, Easing.In); + fallingRewind.Expire(); - SpriteText.FadeInFromZero(fade_time, Easing.In); + persistentText.FadeInFromZero(fade_time, Easing.In); PreviousRandom.Invoke(); } @@ -119,6 +148,10 @@ namespace osu.Game.Screens.Select } } - private void updateText(bool rewind = false) => Text = rewind ? "rewind" : "random"; + private void updateText(bool rewind = false) + { + randomSpriteText.Alpha = rewind ? 0 : 1; + rewindSpriteText.Alpha = rewind ? 1 : 0; + } } }