diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneFooterButtonMods.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneFooterButtonMods.cs index 6eb621ca3b..63197ed26a 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneFooterButtonMods.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneFooterButtonMods.cs @@ -16,7 +16,8 @@ namespace osu.Game.Tests.Visual.UserInterface { public override IReadOnlyList RequiredTypes => new[] { - typeof(FooterButtonMods) + typeof(FooterButtonMods), + typeof(FooterButton) }; private readonly TestFooterButtonMods footerButtonMods; diff --git a/osu.Game/Screens/Play/HUD/ModDisplay.cs b/osu.Game/Screens/Play/HUD/ModDisplay.cs index 0f3c92a962..00edd4db99 100644 --- a/osu.Game/Screens/Play/HUD/ModDisplay.cs +++ b/osu.Game/Screens/Play/HUD/ModDisplay.cs @@ -41,7 +41,7 @@ namespace osu.Game.Screens.Play.HUD } } - private readonly FillFlowContainer iconsContainer; + protected readonly FillFlowContainer IconsContainer; private readonly OsuSpriteText unrankedText; public ModDisplay() @@ -50,7 +50,7 @@ namespace osu.Game.Screens.Play.HUD Children = new Drawable[] { - iconsContainer = new ReverseChildIDFillFlowContainer + IconsContainer = new ReverseChildIDFillFlowContainer { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, @@ -69,11 +69,11 @@ namespace osu.Game.Screens.Play.HUD Current.ValueChanged += mods => { - iconsContainer.Clear(); + IconsContainer.Clear(); foreach (Mod mod in mods.NewValue) { - iconsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.6f) }); + IconsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.6f) }); } if (IsLoaded) @@ -92,7 +92,7 @@ namespace osu.Game.Screens.Play.HUD base.LoadComplete(); appearTransform(); - iconsContainer.FadeInFromZero(fade_duration, Easing.OutQuint); + IconsContainer.FadeInFromZero(fade_duration, Easing.OutQuint); } private void appearTransform() @@ -104,17 +104,17 @@ namespace osu.Game.Screens.Play.HUD expand(); - using (iconsContainer.BeginDelayedSequence(1200)) + using (IconsContainer.BeginDelayedSequence(1200)) contract(); } private void expand() { if (AllowExpand) - iconsContainer.TransformSpacingTo(new Vector2(5, 0), 500, Easing.OutQuint); + IconsContainer.TransformSpacingTo(new Vector2(5, 0), 500, Easing.OutQuint); } - private void contract() => iconsContainer.TransformSpacingTo(new Vector2(-25, 0), 500, Easing.OutQuint); + private void contract() => IconsContainer.TransformSpacingTo(new Vector2(-25, 0), 500, Easing.OutQuint); protected override bool OnHover(HoverEvent e) { diff --git a/osu.Game/Screens/Select/FooterButton.cs b/osu.Game/Screens/Select/FooterButton.cs index 4dcab60548..35970cd960 100644 --- a/osu.Game/Screens/Select/FooterButton.cs +++ b/osu.Game/Screens/Select/FooterButton.cs @@ -56,6 +56,7 @@ namespace osu.Game.Screens.Select } } + protected FillFlowContainer ButtonContentContainer; protected readonly Container TextContainer; protected readonly SpriteText SpriteText; private readonly Box box; @@ -80,15 +81,36 @@ namespace osu.Game.Screens.Select EdgeSmoothness = new Vector2(2, 0), RelativeSizeAxes = Axes.X, }, - TextContainer = new Container + new Container { - Size = new Vector2(100 - SHEAR_WIDTH, 50), - Shear = -SHEAR, - Child = SpriteText = new OsuSpriteText + AutoSizeAxes = Axes.Both, + Children = new Drawable[] { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - } + ButtonContentContainer = new FillFlowContainer + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Direction = FillDirection.Horizontal, + Shear = -SHEAR, + AutoSizeAxes = Axes.X, + Height = 50, + Spacing = new Vector2(15, 0), + Children = new Drawable[] + { + TextContainer = new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + AutoSizeAxes = Axes.Both, + Child = SpriteText = new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } + }, + }, + }, + }, }, }; } @@ -97,6 +119,19 @@ namespace osu.Game.Screens.Select public Action HoverLost; public Key? Hotkey; + protected override void UpdateAfterChildren() + { + base.UpdateAfterChildren(); + + float horizontalMargin = (100 - TextContainer.Width) / 2; + ButtonContentContainer.Padding = new MarginPadding + { + Left = horizontalMargin, + // right side margin offset to compensate for shear + Right = horizontalMargin - SHEAR_WIDTH / 2 + }; + } + protected override bool OnHover(HoverEvent e) { Hovered?.Invoke(); diff --git a/osu.Game/Screens/Select/FooterButtonMods.cs b/osu.Game/Screens/Select/FooterButtonMods.cs index 8419ee0c2a..4f2369847f 100644 --- a/osu.Game/Screens/Select/FooterButtonMods.cs +++ b/osu.Game/Screens/Select/FooterButtonMods.cs @@ -3,7 +3,6 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Game.Screens.Play.HUD; using osu.Game.Rulesets.Mods; using System.Collections.Generic; @@ -34,31 +33,18 @@ namespace osu.Game.Screens.Select public FooterButtonMods() { - Add(new FillFlowContainer + ButtonContentContainer.Add(modDisplay = new FooterModDisplay { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Direction = FillDirection.Horizontal, - Shear = -SHEAR, - Children = new Drawable[] - { - modDisplay = new FooterModDisplay - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - DisplayUnrankedText = false, - Scale = new Vector2(0.8f) - }, - MultiplierText = new OsuSpriteText - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Font = OsuFont.GetFont(weight: FontWeight.Bold), - Margin = new MarginPadding { Right = 10 } - } - }, - AutoSizeAxes = Axes.Both, - Margin = new MarginPadding { Left = 70 } + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + DisplayUnrankedText = false, + Scale = new Vector2(0.8f) + }); + ButtonContentContainer.Add(MultiplierText = new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.GetFont(weight: FontWeight.Bold), }); } @@ -92,6 +78,11 @@ namespace osu.Game.Screens.Select MultiplierText.FadeColour(lowMultiplierColour, 200); else MultiplierText.FadeColour(Color4.White, 200); + + if (Current.Value?.Count > 0) + modDisplay.FadeIn(); + else + modDisplay.FadeOut(); } private class FooterModDisplay : ModDisplay @@ -101,6 +92,7 @@ namespace osu.Game.Screens.Select public FooterModDisplay() { AllowExpand = false; + IconsContainer.Margin = new MarginPadding(); } } } diff --git a/osu.Game/Screens/Select/FooterButtonRandom.cs b/osu.Game/Screens/Select/FooterButtonRandom.cs index 9bc5181f6f..a42e6721db 100644 --- a/osu.Game/Screens/Select/FooterButtonRandom.cs +++ b/osu.Game/Screens/Select/FooterButtonRandom.cs @@ -24,8 +24,11 @@ namespace osu.Game.Screens.Select Anchor = Anchor.Centre, Origin = Anchor.Centre, Text = @"rewind", - Alpha = 0 + Alpha = 0, }); + + // force both text sprites to always be present to avoid width flickering while they're being swapped out + SpriteText.AlwaysPresent = secondaryText.AlwaysPresent = true; } [BackgroundDependencyLoader]