Merge pull request #18054 from frenzibyte/fix-footer-random-jarringness

Fix footer random button autosizing to text length
This commit is contained in:
Bartłomiej Dach 2022-05-02 15:21:32 +02:00 committed by GitHub
commit b9642a13c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 9 deletions

View File

@ -5,6 +5,7 @@
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 @@ public class FooterButtonRandom : FooterButton
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 @@ private void load(OsuColour colours)
{
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 @@ private void load(OsuColour colours)
{
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 @@ public override void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
}
}
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;
}
}
}