From 892659de0f22b4bc584dc98a096c32a696d7c893 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 27 Jun 2024 08:15:12 +0300 Subject: [PATCH 01/10] Adjust footer design to display well with the rest of the game --- osu.Game/Screens/Footer/ScreenBackButton.cs | 9 +++------ osu.Game/Screens/Footer/ScreenFooter.cs | 4 ++-- osu.Game/Screens/Footer/ScreenFooterButton.cs | 15 +++++++-------- .../SelectV2/Footer/ScreenFooterButtonMods.cs | 12 +++++------- .../SelectV2/Footer/ScreenFooterButtonRandom.cs | 6 +++--- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/osu.Game/Screens/Footer/ScreenBackButton.cs b/osu.Game/Screens/Footer/ScreenBackButton.cs index c5e613ea51b5..bf29186bb1b5 100644 --- a/osu.Game/Screens/Footer/ScreenBackButton.cs +++ b/osu.Game/Screens/Footer/ScreenBackButton.cs @@ -17,13 +17,10 @@ namespace osu.Game.Screens.Footer { public partial class ScreenBackButton : ShearedButton { - // todo: see https://github.com/ppy/osu-framework/issues/3271 - private const float torus_scale_factor = 1.2f; - public const float BUTTON_WIDTH = 240; public ScreenBackButton() - : base(BUTTON_WIDTH, 70) + : base(BUTTON_WIDTH) { } @@ -42,14 +39,14 @@ private void load() { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Size = new Vector2(20f), + Size = new Vector2(17f), Icon = FontAwesome.Solid.ChevronLeft, }, new OsuSpriteText { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Font = OsuFont.TorusAlternate.With(size: 20 * torus_scale_factor), + Font = OsuFont.TorusAlternate.With(size: 17), Text = CommonStrings.Back, UseFullGlyphHeight = false, } diff --git a/osu.Game/Screens/Footer/ScreenFooter.cs b/osu.Game/Screens/Footer/ScreenFooter.cs index 594cb3b9c9f5..c7090ba34455 100644 --- a/osu.Game/Screens/Footer/ScreenFooter.cs +++ b/osu.Game/Screens/Footer/ScreenFooter.cs @@ -24,7 +24,7 @@ public partial class ScreenFooter : OverlayContainer private const int padding = 60; private const float delay_per_button = 30; - public const int HEIGHT = 60; + public const int HEIGHT = 50; private readonly List overlays = new List(); @@ -73,7 +73,7 @@ private void load() }, backButton = new ScreenBackButton { - Margin = new MarginPadding { Bottom = 10f, Left = 12f }, + Margin = new MarginPadding { Bottom = 15f, Left = 12f }, Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, Action = () => OnBack?.Invoke(), diff --git a/osu.Game/Screens/Footer/ScreenFooterButton.cs b/osu.Game/Screens/Footer/ScreenFooterButton.cs index 1e5576e47a71..cd1de2454b3c 100644 --- a/osu.Game/Screens/Footer/ScreenFooterButton.cs +++ b/osu.Game/Screens/Footer/ScreenFooterButton.cs @@ -28,8 +28,8 @@ public partial class ScreenFooterButton : OsuClickableContainer, IKeyBindingHand private const float shear = OsuGame.SHEAR; protected const int CORNER_RADIUS = 10; - protected const int BUTTON_HEIGHT = 90; - protected const int BUTTON_WIDTH = 140; + protected const int BUTTON_HEIGHT = 75; + protected const int BUTTON_WIDTH = 116; public Bindable OverlayState = new Bindable(); @@ -116,19 +116,18 @@ public ScreenFooterButton(OverlayContainer? overlay = null) { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, - Y = 42, + Y = 35, AutoSizeAxes = Axes.Both, Child = text = new OsuSpriteText { - // figma design says the size is 16, but due to the issues with font sizes 19 matches better - Font = OsuFont.TorusAlternate.With(size: 19), + Font = OsuFont.TorusAlternate.With(size: 16), AlwaysPresent = true } }, icon = new SpriteIcon { - Y = 12, - Size = new Vector2(20), + Y = 10, + Size = new Vector2(16), Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre }, @@ -140,7 +139,7 @@ public ScreenFooterButton(OverlayContainer? overlay = null) Anchor = Anchor.BottomCentre, Origin = Anchor.Centre, Y = -CORNER_RADIUS, - Size = new Vector2(120, 6), + Size = new Vector2(100, 5), Masking = true, CornerRadius = 3, Child = bar = new Box diff --git a/osu.Game/Screens/SelectV2/Footer/ScreenFooterButtonMods.cs b/osu.Game/Screens/SelectV2/Footer/ScreenFooterButtonMods.cs index 841f0297e851..0992203dbc3c 100644 --- a/osu.Game/Screens/SelectV2/Footer/ScreenFooterButtonMods.cs +++ b/osu.Game/Screens/SelectV2/Footer/ScreenFooterButtonMods.cs @@ -32,9 +32,7 @@ namespace osu.Game.Screens.SelectV2.Footer { public partial class ScreenFooterButtonMods : ScreenFooterButton, IHasCurrentValue> { - // todo: see https://github.com/ppy/osu-framework/issues/3271 - private const float torus_scale_factor = 1.2f; - private const float bar_height = 37f; + private const float bar_height = 30f; private const float mod_display_portion = 0.65f; private readonly BindableWithCurrent> current = new BindableWithCurrent>(Array.Empty()); @@ -112,7 +110,7 @@ private void load() Origin = Anchor.Centre, Shear = -BUTTON_SHEAR, UseFullGlyphHeight = false, - Font = OsuFont.Torus.With(size: 14 * torus_scale_factor, weight: FontWeight.Bold) + Font = OsuFont.Torus.With(size: 14f, weight: FontWeight.Bold) } }, new Container @@ -133,7 +131,7 @@ private void load() Anchor = Anchor.Centre, Origin = Anchor.Centre, Shear = -BUTTON_SHEAR, - Scale = new Vector2(0.6f), + Scale = new Vector2(0.5f), Current = { BindTarget = Current }, ExpansionMode = ExpansionMode.AlwaysContracted, }, @@ -142,7 +140,7 @@ private void load() Anchor = Anchor.Centre, Origin = Anchor.Centre, Shear = -BUTTON_SHEAR, - Font = OsuFont.Torus.With(size: 14 * torus_scale_factor, weight: FontWeight.Bold), + Font = OsuFont.Torus.With(size: 14f, weight: FontWeight.Bold), Mods = { BindTarget = Current }, } } @@ -335,7 +333,7 @@ private void load(OsuColour colours) Text = ModSelectOverlayStrings.Unranked.ToUpper(), Margin = new MarginPadding { Horizontal = 15 }, UseFullGlyphHeight = false, - Font = OsuFont.Torus.With(size: 14 * torus_scale_factor, weight: FontWeight.Bold), + Font = OsuFont.Torus.With(size: 14f, weight: FontWeight.Bold), Colour = Color4.Black, } }; diff --git a/osu.Game/Screens/SelectV2/Footer/ScreenFooterButtonRandom.cs b/osu.Game/Screens/SelectV2/Footer/ScreenFooterButtonRandom.cs index e8e850a9cebf..dbdb6fe79bd8 100644 --- a/osu.Game/Screens/SelectV2/Footer/ScreenFooterButtonRandom.cs +++ b/osu.Game/Screens/SelectV2/Footer/ScreenFooterButtonRandom.cs @@ -42,7 +42,7 @@ private void load(OsuColour colour) { randomSpriteText = new OsuSpriteText { - Font = OsuFont.TorusAlternate.With(size: 19), + Font = OsuFont.TorusAlternate.With(size: 16), AlwaysPresent = true, Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, @@ -50,7 +50,7 @@ private void load(OsuColour colour) }, rewindSpriteText = new OsuSpriteText { - Font = OsuFont.TorusAlternate.With(size: 19), + Font = OsuFont.TorusAlternate.With(size: 16), AlwaysPresent = true, Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, @@ -75,7 +75,7 @@ private void load(OsuColour colour) AlwaysPresent = true, // make sure the button is sized large enough to always show this Anchor = Anchor.BottomCentre, Origin = Anchor.BottomCentre, - Font = OsuFont.TorusAlternate.With(size: 19), + Font = OsuFont.TorusAlternate.With(size: 16), }); fallingRewind.FadeOutFromOne(fade_time, Easing.In); From 68b8a4fb2ac3b06904695d0884717669a968e265 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 29 Jun 2024 08:35:48 +0300 Subject: [PATCH 02/10] Use `ScreenFooter` for displaying footer buttons from overlays --- .../Overlays/Mods/ShearedOverlayContainer.cs | 40 +++++++-- osu.Game/Screens/Footer/ScreenFooter.cs | 83 +++++++++++++++++-- osu.Game/Screens/Footer/ScreenFooterButton.cs | 10 ++- 3 files changed, 116 insertions(+), 17 deletions(-) diff --git a/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs b/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs index acdd1db728ca..fab2fccb353e 100644 --- a/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs +++ b/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs @@ -3,6 +3,7 @@ #nullable disable +using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -11,19 +12,20 @@ using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; +using osu.Game.Screens.Footer; namespace osu.Game.Overlays.Mods { /// - /// A sheared overlay which provides a header and footer and basic animations. - /// Exposes , and as valid targets for content. + /// A sheared overlay which provides a header and basic animations. + /// Exposes and as valid targets for content. /// public abstract partial class ShearedOverlayContainer : OsuFocusedOverlayContainer { - protected const float PADDING = 14; + public const float PADDING = 14; [Cached] - protected readonly OverlayColourProvider ColourProvider; + public readonly OverlayColourProvider ColourProvider; /// /// The overlay's header. @@ -35,6 +37,13 @@ public abstract partial class ShearedOverlayContainer : OsuFocusedOverlayContain /// protected Container Footer { get; private set; } + [Resolved(canBeNull: true)] + [CanBeNull] + private ScreenFooter footer { get; set; } + + // todo: very temporary property that will be removed once ModSelectOverlay and FirstRunSetupOverlay are updated to use new footer. + public virtual bool UseNewFooter => false; + /// /// A container containing all content, including the header and footer. /// May be used for overlay-wide animations. @@ -65,7 +74,7 @@ protected ShearedOverlayContainer(OverlayColourScheme colourScheme) [BackgroundDependencyLoader] private void load() { - const float footer_height = 50; + const float footer_height = ScreenFooter.HEIGHT; Child = TopLevelContent = new Container { @@ -113,6 +122,11 @@ private void load() }; } + /// + /// Creates content to be displayed on the game-wide footer. + /// + public virtual Drawable CreateFooterContent() => Empty(); + protected override bool OnClick(ClickEvent e) { if (State.Value == Visibility.Visible) @@ -131,7 +145,13 @@ protected override void PopIn() this.FadeIn(fade_in_duration, Easing.OutQuint); Header.MoveToY(0, fade_in_duration, Easing.OutQuint); - Footer.MoveToY(0, fade_in_duration, Easing.OutQuint); + + if (UseNewFooter && footer != null) + { + footer.SetOverlayContent(this); + } + else + Footer.MoveToY(0, fade_in_duration, Easing.OutQuint); } protected override void PopOut() @@ -142,7 +162,13 @@ protected override void PopOut() this.FadeOut(fade_out_duration, Easing.OutQuint); Header.MoveToY(-Header.DrawHeight, fade_out_duration, Easing.OutQuint); - Footer.MoveToY(Footer.DrawHeight, fade_out_duration, Easing.OutQuint); + + if (UseNewFooter && footer != null) + { + footer.ClearOverlayContent(); + } + else + Footer.MoveToY(Footer.DrawHeight, fade_out_duration, Easing.OutQuint); } } } diff --git a/osu.Game/Screens/Footer/ScreenFooter.cs b/osu.Game/Screens/Footer/ScreenFooter.cs index c7090ba34455..7779b6a4e5ba 100644 --- a/osu.Game/Screens/Footer/ScreenFooter.cs +++ b/osu.Game/Screens/Footer/ScreenFooter.cs @@ -115,8 +115,11 @@ protected override void PopOut() public void SetButtons(IReadOnlyList buttons) { + temporarilyHiddenButtons.Clear(); overlays.Clear(); + ClearOverlayContent(); + var oldButtons = buttonsFlow.ToArray(); for (int i = 0; i < oldButtons.Length; i++) @@ -127,9 +130,9 @@ public void SetButtons(IReadOnlyList buttons) removedButtonsContainer.Add(oldButton); if (buttons.Count > 0) - makeButtonDisappearToRightAndExpire(oldButton, i, oldButtons.Length); + makeButtonDisappearToRight(oldButton, i, oldButtons.Length, true); else - makeButtonDisappearToBottomAndExpire(oldButton, i, oldButtons.Length); + makeButtonDisappearToBottom(oldButton, i, oldButtons.Length, true); } for (int i = 0; i < buttons.Count; i++) @@ -158,17 +161,85 @@ public void SetButtons(IReadOnlyList buttons) } } + private ShearedOverlayContainer? activeOverlay; + private Container? contentContainer; + private readonly List temporarilyHiddenButtons = new List(); + + public void SetOverlayContent(ShearedOverlayContainer overlay) + { + if (contentContainer != null) + { + throw new InvalidOperationException(@"Cannot set overlay content while one is already present. " + + $@"The previous overlay whose content is {contentContainer.Child.GetType().Name} should be hidden first."); + } + + activeOverlay = overlay; + + Debug.Assert(temporarilyHiddenButtons.Count == 0); + + var targetButton = buttonsFlow.SingleOrDefault(b => b.Overlay == overlay); + + temporarilyHiddenButtons.AddRange(targetButton != null + ? buttonsFlow.SkipWhile(b => b != targetButton).Skip(1) + : buttonsFlow); + + for (int i = 0; i < temporarilyHiddenButtons.Count; i++) + makeButtonDisappearToBottom(temporarilyHiddenButtons[i], 0, 0, false); + + var fallbackPosition = buttonsFlow.Any() + ? buttonsFlow.ToSpaceOfOtherDrawable(Vector2.Zero, this) + : BackButton.ToSpaceOfOtherDrawable(BackButton.LayoutRectangle.TopRight + new Vector2(5f, 0f), this); + + var targetPosition = targetButton?.ToSpaceOfOtherDrawable(targetButton.LayoutRectangle.TopRight, this) ?? fallbackPosition; + + var content = overlay.CreateFooterContent(); + + Add(contentContainer = new Container + { + Y = -15f, + RelativeSizeAxes = Axes.Both, + Padding = new MarginPadding { Left = targetPosition.X }, + Child = content, + }); + + if (temporarilyHiddenButtons.Count > 0) + this.Delay(60).Schedule(() => content.Show()); + else + content.Show(); + } + + public void ClearOverlayContent() + { + if (contentContainer == null) + return; + + contentContainer.Child.Hide(); + + double timeUntilRun = contentContainer.Child.LatestTransformEndTime - Time.Current; + + Container expireTarget = contentContainer; + contentContainer = null; + activeOverlay = null; + + for (int i = 0; i < temporarilyHiddenButtons.Count; i++) + makeButtonAppearFromBottom(temporarilyHiddenButtons[i], 0); + + temporarilyHiddenButtons.Clear(); + + expireTarget.Delay(timeUntilRun).Expire(); + } + private void makeButtonAppearFromLeft(ScreenFooterButton button, int index, int count, float startDelay) => button.AppearFromLeft(startDelay + (count - index) * delay_per_button); private void makeButtonAppearFromBottom(ScreenFooterButton button, int index) => button.AppearFromBottom(index * delay_per_button); - private void makeButtonDisappearToRightAndExpire(ScreenFooterButton button, int index, int count) - => button.DisappearToRightAndExpire((count - index) * delay_per_button); + private void makeButtonDisappearToRight(ScreenFooterButton button, int index, int count, bool expire) + => button.DisappearToRight((count - index) * delay_per_button, expire); - private void makeButtonDisappearToBottomAndExpire(ScreenFooterButton button, int index, int count) - => button.DisappearToBottomAndExpire((count - index) * delay_per_button); + private void makeButtonDisappearToBottom(ScreenFooterButton button, int index, int count, bool expire) + => button.DisappearToBottom((count - index) * delay_per_button, expire); private void showOverlay(OverlayContainer overlay) { diff --git a/osu.Game/Screens/Footer/ScreenFooterButton.cs b/osu.Game/Screens/Footer/ScreenFooterButton.cs index cd1de2454b3c..c1dbbb071d26 100644 --- a/osu.Game/Screens/Footer/ScreenFooterButton.cs +++ b/osu.Game/Screens/Footer/ScreenFooterButton.cs @@ -243,22 +243,24 @@ public void AppearFromBottom(double delay) .FadeIn(240, Easing.OutCubic); } - public void DisappearToRightAndExpire(double delay) + public void DisappearToRight(double delay, bool expire) { Content.Delay(delay) .FadeOut(240, Easing.InOutCubic) .MoveToX(300f, 360, Easing.InOutCubic); - this.Delay(Content.LatestTransformEndTime - Time.Current).Expire(); + if (expire) + this.Delay(Content.LatestTransformEndTime - Time.Current).Expire(); } - public void DisappearToBottomAndExpire(double delay) + public void DisappearToBottom(double delay, bool expire) { Content.Delay(delay) .FadeOut(240, Easing.InOutCubic) .MoveToY(100f, 240, Easing.InOutCubic); - this.Delay(Content.LatestTransformEndTime - Time.Current).Expire(); + if (expire) + this.Delay(Content.LatestTransformEndTime - Time.Current).Expire(); } } } From 916d0bfcc26f6de154dc729b5b8cfef0debf6d02 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 29 Jun 2024 08:39:34 +0300 Subject: [PATCH 03/10] Temporarily show screen footer if hidden while overlay is present --- osu.Game/Overlays/Mods/ShearedOverlayContainer.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs b/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs index fab2fccb353e..d3b1b9244b54 100644 --- a/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs +++ b/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs @@ -138,6 +138,8 @@ protected override bool OnClick(ClickEvent e) return base.OnClick(e); } + private bool hideFooterOnPopOut; + protected override void PopIn() { const double fade_in_duration = 400; @@ -149,6 +151,12 @@ protected override void PopIn() if (UseNewFooter && footer != null) { footer.SetOverlayContent(this); + + if (footer.State.Value == Visibility.Hidden) + { + footer.Show(); + hideFooterOnPopOut = true; + } } else Footer.MoveToY(0, fade_in_duration, Easing.OutQuint); @@ -166,6 +174,12 @@ protected override void PopOut() if (UseNewFooter && footer != null) { footer.ClearOverlayContent(); + + if (hideFooterOnPopOut) + { + footer.Hide(); + hideFooterOnPopOut = false; + } } else Footer.MoveToY(Footer.DrawHeight, fade_out_duration, Easing.OutQuint); From 2319fa11ec640f3922590e9f10e2858d6ebb9168 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 29 Jun 2024 08:42:17 +0300 Subject: [PATCH 04/10] Support performing custom overlay-specific action with back button --- .../Overlays/Mods/ShearedOverlayContainer.cs | 6 ++++ osu.Game/Screens/Footer/ScreenFooter.cs | 31 +++++++++++++------ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs b/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs index d3b1b9244b54..c9c3c6240414 100644 --- a/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs +++ b/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs @@ -127,6 +127,12 @@ private void load() /// public virtual Drawable CreateFooterContent() => Empty(); + /// + /// Invoked when the back button in the footer is pressed. + /// + /// Whether the back button should not close the overlay. + public virtual bool OnBackButton() => false; + protected override bool OnClick(ClickEvent e) { if (State.Value == Visibility.Visible) diff --git a/osu.Game/Screens/Footer/ScreenFooter.cs b/osu.Game/Screens/Footer/ScreenFooter.cs index 7779b6a4e5ba..d6c98d1c6409 100644 --- a/osu.Game/Screens/Footer/ScreenFooter.cs +++ b/osu.Game/Screens/Footer/ScreenFooter.cs @@ -28,7 +28,7 @@ public partial class ScreenFooter : OverlayContainer private readonly List overlays = new List(); - private ScreenBackButton backButton = null!; + private Box background = null!; private FillFlowContainer buttonsFlow = null!; private Container removedButtonsContainer = null!; private LogoTrackingContainer logoTrackingContainer = null!; @@ -36,6 +36,8 @@ public partial class ScreenFooter : OverlayContainer [Cached] private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine); + public ScreenBackButton BackButton { get; private set; } = null!; + public Action? OnBack; public ScreenFooter(BackReceptor? receptor = null) @@ -48,7 +50,7 @@ public ScreenFooter(BackReceptor? receptor = null) if (receptor == null) Add(receptor = new BackReceptor()); - receptor.OnBackPressed = () => backButton.TriggerClick(); + receptor.OnBackPressed = () => BackButton.TriggerClick(); } [BackgroundDependencyLoader] @@ -71,12 +73,12 @@ private void load() Spacing = new Vector2(7, 0), AutoSizeAxes = Axes.Both }, - backButton = new ScreenBackButton + BackButton = new ScreenBackButton { Margin = new MarginPadding { Bottom = 15f, Left = 12f }, Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, - Action = () => OnBack?.Invoke(), + Action = onBackPressed, }, removedButtonsContainer = new Container { @@ -243,13 +245,24 @@ private void makeButtonDisappearToBottom(ScreenFooterButton button, int index, i private void showOverlay(OverlayContainer overlay) { - foreach (var o in overlays) + foreach (var o in overlays.Where(o => o != overlay)) + o.Hide(); + + overlay.ToggleVisibility(); + } + + private void onBackPressed() + { + if (activeOverlay != null) { - if (o == overlay) - o.ToggleVisibility(); - else - o.Hide(); + if (activeOverlay.OnBackButton()) + return; + + activeOverlay.Hide(); + return; } + + OnBack?.Invoke(); } public partial class BackReceptor : Drawable, IKeyBindingHandler From b8816bfc28f2ccc527f6d6ae9650749777cbe637 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 29 Jun 2024 09:59:40 +0300 Subject: [PATCH 05/10] Update colour scheme of footer in line with visible overlay --- osu.Game/Overlays/OverlayColourProvider.cs | 16 +++++++++++++--- osu.Game/Screens/Footer/ScreenFooter.cs | 17 ++++++++++++++++- osu.Game/Screens/Footer/ScreenFooterButton.cs | 10 +++++----- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/osu.Game/Overlays/OverlayColourProvider.cs b/osu.Game/Overlays/OverlayColourProvider.cs index a4f6527024eb..06b42eafc0d5 100644 --- a/osu.Game/Overlays/OverlayColourProvider.cs +++ b/osu.Game/Overlays/OverlayColourProvider.cs @@ -9,11 +9,11 @@ namespace osu.Game.Overlays { public class OverlayColourProvider { - private readonly OverlayColourScheme colourScheme; + public OverlayColourScheme ColourScheme { get; private set; } public OverlayColourProvider(OverlayColourScheme colourScheme) { - this.colourScheme = colourScheme; + ColourScheme = colourScheme; } // Note that the following five colours are also defined in `OsuColour` as `{colourScheme}{0,1,2,3,4}`. @@ -47,7 +47,17 @@ public OverlayColourProvider(OverlayColourScheme colourScheme) public Color4 Background5 => getColour(0.1f, 0.15f); public Color4 Background6 => getColour(0.1f, 0.1f); - private Color4 getColour(float saturation, float lightness) => Color4.FromHsl(new Vector4(getBaseHue(colourScheme), saturation, lightness, 1)); + /// + /// Changes the value of to a different colour scheme. + /// Note that this does not trigger any kind of signal to any drawable that received colours from here, all drawables need to be updated manually. + /// + /// The proposed colour scheme. + public void ChangeColourScheme(OverlayColourScheme colourScheme) + { + ColourScheme = colourScheme; + } + + private Color4 getColour(float saturation, float lightness) => Color4.FromHsl(new Vector4(getBaseHue(ColourScheme), saturation, lightness, 1)); // See https://github.com/ppy/osu-web/blob/5a536d217a21582aad999db50a981003d3ad5659/app/helpers.php#L1620-L1628 private static float getBaseHue(OverlayColourScheme colourScheme) diff --git a/osu.Game/Screens/Footer/ScreenFooter.cs b/osu.Game/Screens/Footer/ScreenFooter.cs index d6c98d1c6409..cef891f8c052 100644 --- a/osu.Game/Screens/Footer/ScreenFooter.cs +++ b/osu.Game/Screens/Footer/ScreenFooter.cs @@ -14,6 +14,7 @@ using osu.Game.Graphics.Containers; using osu.Game.Input.Bindings; using osu.Game.Overlays; +using osu.Game.Overlays.Mods; using osu.Game.Screens.Menu; using osuTK; @@ -58,7 +59,7 @@ private void load() { InternalChildren = new Drawable[] { - new Box + background = new Box { RelativeSizeAxes = Axes.Both, Colour = colourProvider.Background5 @@ -194,6 +195,8 @@ public void SetOverlayContent(ShearedOverlayContainer overlay) var targetPosition = targetButton?.ToSpaceOfOtherDrawable(targetButton.LayoutRectangle.TopRight, this) ?? fallbackPosition; + updateColourScheme(overlay.ColourProvider.ColourScheme); + var content = overlay.CreateFooterContent(); Add(contentContainer = new Container @@ -229,6 +232,18 @@ public void ClearOverlayContent() temporarilyHiddenButtons.Clear(); expireTarget.Delay(timeUntilRun).Expire(); + + updateColourScheme(OverlayColourScheme.Aquamarine); + } + + private void updateColourScheme(OverlayColourScheme colourScheme) + { + colourProvider.ChangeColourScheme(colourScheme); + + background.FadeColour(colourProvider.Background5, 150, Easing.OutQuint); + + foreach (var button in buttonsFlow) + button.UpdateDisplay(); } private void makeButtonAppearFromLeft(ScreenFooterButton button, int index, int count, float startDelay) diff --git a/osu.Game/Screens/Footer/ScreenFooterButton.cs b/osu.Game/Screens/Footer/ScreenFooterButton.cs index c1dbbb071d26..0be7ef95b5cb 100644 --- a/osu.Game/Screens/Footer/ScreenFooterButton.cs +++ b/osu.Game/Screens/Footer/ScreenFooterButton.cs @@ -166,8 +166,8 @@ protected override void LoadComplete() if (Overlay != null) OverlayState.BindTo(Overlay.State); - OverlayState.BindValueChanged(_ => updateDisplay()); - Enabled.BindValueChanged(_ => updateDisplay(), true); + OverlayState.BindValueChanged(_ => UpdateDisplay()); + Enabled.BindValueChanged(_ => UpdateDisplay(), true); FinishTransforms(true); } @@ -186,11 +186,11 @@ protected override bool OnClick(ClickEvent e) protected override bool OnHover(HoverEvent e) { - updateDisplay(); + UpdateDisplay(); return true; } - protected override void OnHoverLost(HoverLostEvent e) => updateDisplay(); + protected override void OnHoverLost(HoverLostEvent e) => UpdateDisplay(); public virtual bool OnPressed(KeyBindingPressEvent e) { @@ -202,7 +202,7 @@ public virtual bool OnPressed(KeyBindingPressEvent e) public virtual void OnReleased(KeyBindingReleaseEvent e) { } - private void updateDisplay() + public void UpdateDisplay() { Color4 backgroundColour = OverlayState.Value == Visibility.Visible ? buttonAccentColour : colourProvider.Background3; Color4 textColour = OverlayState.Value == Visibility.Visible ? colourProvider.Background6 : colourProvider.Content1; From fb77260afc617d2e0f3039987e8168a862535bd6 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 29 Jun 2024 10:06:49 +0300 Subject: [PATCH 06/10] Fix footer buttons receiving input while put away from screen --- osu.Game/Screens/Footer/ScreenFooterButton.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Screens/Footer/ScreenFooterButton.cs b/osu.Game/Screens/Footer/ScreenFooterButton.cs index 0be7ef95b5cb..b39e1e11c3f8 100644 --- a/osu.Game/Screens/Footer/ScreenFooterButton.cs +++ b/osu.Game/Screens/Footer/ScreenFooterButton.cs @@ -172,6 +172,9 @@ protected override void LoadComplete() FinishTransforms(true); } + // use Content for tracking input as some buttons might be temporarily hidden with DisappearToBottom, and they become hidden by moving Content away from screen. + public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Content.ReceivePositionalInputAt(screenSpacePos); + public GlobalAction? Hotkey; protected override bool OnClick(ClickEvent e) From 56d1255f8ae819f6cd74d8fe8f61aa975ac32cde Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sun, 30 Jun 2024 06:15:50 +0300 Subject: [PATCH 07/10] Fix footer button transforms getting interrupted by consecutive method calls --- osu.Game/Screens/Footer/ScreenFooterButton.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osu.Game/Screens/Footer/ScreenFooterButton.cs b/osu.Game/Screens/Footer/ScreenFooterButton.cs index b39e1e11c3f8..a88ba1aead4d 100644 --- a/osu.Game/Screens/Footer/ScreenFooterButton.cs +++ b/osu.Game/Screens/Footer/ScreenFooterButton.cs @@ -230,6 +230,7 @@ public void UpdateDisplay() public void AppearFromLeft(double delay) { + Content.FinishTransforms(); Content.MoveToX(-300f) .FadeOut() .Delay(delay) @@ -239,6 +240,7 @@ public void AppearFromLeft(double delay) public void AppearFromBottom(double delay) { + Content.FinishTransforms(); Content.MoveToY(100f) .FadeOut() .Delay(delay) @@ -248,6 +250,7 @@ public void AppearFromBottom(double delay) public void DisappearToRight(double delay, bool expire) { + Content.FinishTransforms(); Content.Delay(delay) .FadeOut(240, Easing.InOutCubic) .MoveToX(300f, 360, Easing.InOutCubic); @@ -258,6 +261,7 @@ public void DisappearToRight(double delay, bool expire) public void DisappearToBottom(double delay, bool expire) { + Content.FinishTransforms(); Content.Delay(delay) .FadeOut(240, Easing.InOutCubic) .MoveToY(100f, 240, Easing.InOutCubic); From 900d15e777fab79d533ea7b31dcfeaac5f410d4a Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 29 Jun 2024 10:19:58 +0300 Subject: [PATCH 08/10] Add test coverage --- .../UserInterface/TestSceneScreenFooter.cs | 176 ++++++++++++++++-- osu.Game/Screens/Footer/ScreenFooterButton.cs | 4 +- 2 files changed, 167 insertions(+), 13 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneScreenFooter.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneScreenFooter.cs index dabb2e7f5012..70c3664b9a29 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneScreenFooter.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneScreenFooter.cs @@ -2,10 +2,16 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Linq; using NUnit.Framework; +using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; +using osu.Framework.Graphics.Sprites; using osu.Framework.Testing; +using osu.Game.Graphics; +using osu.Game.Graphics.UserInterface; using osu.Game.Overlays; using osu.Game.Overlays.Mods; using osu.Game.Screens.Footer; @@ -15,25 +21,31 @@ namespace osu.Game.Tests.Visual.UserInterface { public partial class TestSceneScreenFooter : OsuManualInputManagerTestScene { + private DependencyProvidingContainer contentContainer = null!; private ScreenFooter screenFooter = null!; private TestModSelectOverlay overlay = null!; [SetUp] public void SetUp() => Schedule(() => { - Children = new Drawable[] + screenFooter = new ScreenFooter(); + + Child = contentContainer = new DependencyProvidingContainer { - overlay = new TestModSelectOverlay + RelativeSizeAxes = Axes.Both, + CachedDependencies = new (Type, object)[] { - Padding = new MarginPadding - { - Bottom = ScreenFooter.HEIGHT - } + (typeof(ScreenFooter), screenFooter) }, - new PopoverContainer + Children = new Drawable[] { - RelativeSizeAxes = Axes.Both, - Child = screenFooter = new ScreenFooter(), + overlay = new TestModSelectOverlay(), + new PopoverContainer + { + RelativeSizeAxes = Axes.Both, + Depth = float.MinValue, + Child = screenFooter, + }, }, }; @@ -82,13 +94,155 @@ public void TestReplaceButtons() })); } + [Test] + public void TestExternalOverlayContent() + { + TestShearedOverlayContainer externalOverlay = null!; + + AddStep("add overlay", () => contentContainer.Add(externalOverlay = new TestShearedOverlayContainer())); + AddStep("set buttons", () => screenFooter.SetButtons(new[] + { + new ScreenFooterButton(externalOverlay) + { + AccentColour = Dependencies.Get().Orange1, + Icon = FontAwesome.Solid.Toolbox, + Text = "One", + }, + new ScreenFooterButton { Text = "Two", Action = () => { } }, + new ScreenFooterButton { Text = "Three", Action = () => { } }, + })); + AddWaitStep("wait for transition", 3); + + AddStep("show overlay", () => externalOverlay.Show()); + AddAssert("content displayed in footer", () => screenFooter.ChildrenOfType().Single().IsPresent); + AddUntilStep("other buttons hidden", () => screenFooter.ChildrenOfType().Skip(1).All(b => b.Child.Parent!.Y > 0)); + + AddStep("hide overlay", () => externalOverlay.Hide()); + AddUntilStep("content hidden from footer", () => screenFooter.ChildrenOfType().SingleOrDefault()?.IsPresent != true); + AddUntilStep("other buttons returned", () => screenFooter.ChildrenOfType().Skip(1).All(b => b.ChildrenOfType().First().Y == 0)); + } + + [Test] + public void TestTemporarilyShowFooter() + { + TestShearedOverlayContainer externalOverlay = null!; + + AddStep("hide footer", () => screenFooter.Hide()); + AddStep("remove buttons", () => screenFooter.SetButtons(Array.Empty())); + + AddStep("add external overlay", () => contentContainer.Add(externalOverlay = new TestShearedOverlayContainer())); + AddStep("show external overlay", () => externalOverlay.Show()); + AddAssert("footer shown", () => screenFooter.State.Value == Visibility.Visible); + AddAssert("content displayed in footer", () => screenFooter.ChildrenOfType().Single().IsPresent); + + AddStep("hide external overlay", () => externalOverlay.Hide()); + AddAssert("footer hidden", () => screenFooter.State.Value == Visibility.Hidden); + AddUntilStep("content hidden from footer", () => screenFooter.ChildrenOfType().SingleOrDefault()?.IsPresent != true); + + AddStep("show footer", () => screenFooter.Show()); + AddAssert("content still hidden from footer", () => screenFooter.ChildrenOfType().SingleOrDefault()?.IsPresent != true); + + AddStep("show external overlay", () => externalOverlay.Show()); + AddAssert("footer still visible", () => screenFooter.State.Value == Visibility.Visible); + + AddStep("hide external overlay", () => externalOverlay.Hide()); + AddAssert("footer still visible", () => screenFooter.State.Value == Visibility.Visible); + + AddStep("hide footer", () => screenFooter.Hide()); + AddStep("show external overlay", () => externalOverlay.Show()); + } + + [Test] + public void TestBackButton() + { + TestShearedOverlayContainer externalOverlay = null!; + + AddStep("hide footer", () => screenFooter.Hide()); + AddStep("remove buttons", () => screenFooter.SetButtons(Array.Empty())); + + AddStep("add external overlay", () => contentContainer.Add(externalOverlay = new TestShearedOverlayContainer())); + AddStep("show external overlay", () => externalOverlay.Show()); + AddAssert("footer shown", () => screenFooter.State.Value == Visibility.Visible); + + AddStep("press back", () => this.ChildrenOfType().Single().TriggerClick()); + AddAssert("overlay hidden", () => externalOverlay.State.Value == Visibility.Hidden); + AddAssert("footer hidden", () => screenFooter.State.Value == Visibility.Hidden); + + AddStep("show external overlay", () => externalOverlay.Show()); + AddStep("set block count", () => externalOverlay.BackButtonCount = 1); + AddStep("press back", () => this.ChildrenOfType().Single().TriggerClick()); + AddAssert("overlay still visible", () => externalOverlay.State.Value == Visibility.Visible); + AddAssert("footer still shown", () => screenFooter.State.Value == Visibility.Visible); + AddStep("press back again", () => this.ChildrenOfType().Single().TriggerClick()); + AddAssert("overlay hidden", () => externalOverlay.State.Value == Visibility.Hidden); + AddAssert("footer hidden", () => screenFooter.State.Value == Visibility.Hidden); + } + private partial class TestModSelectOverlay : UserModSelectOverlay { protected override bool ShowPresets => true; + } - public TestModSelectOverlay() - : base(OverlayColourScheme.Aquamarine) + private partial class TestShearedOverlayContainer : ShearedOverlayContainer + { + public override bool UseNewFooter => true; + + public TestShearedOverlayContainer() + : base(OverlayColourScheme.Orange) + { + } + + [BackgroundDependencyLoader] + private void load() { + Header.Title = "Test overlay"; + Header.Description = "An overlay that is made purely for testing purposes."; + } + + public int BackButtonCount; + + public override bool OnBackButton() + { + if (BackButtonCount > 0) + { + BackButtonCount--; + return true; + } + + return false; + } + + public override Drawable CreateFooterContent() => new TestFooterContent(); + + public partial class TestFooterContent : VisibilityContainer + { + [BackgroundDependencyLoader] + private void load() + { + RelativeSizeAxes = Axes.Both; + + InternalChild = new FillFlowContainer + { + AutoSizeAxes = Axes.Both, + Children = new[] + { + new ShearedButton(200) { Text = "Action #1", Action = () => { } }, + new ShearedButton(140) { Text = "Action #2", Action = () => { } }, + } + }; + } + + protected override void PopIn() + { + this.MoveToY(0, 400, Easing.OutQuint) + .FadeIn(400, Easing.OutQuint); + } + + protected override void PopOut() + { + this.MoveToY(-20f, 200, Easing.OutQuint) + .FadeOut(200, Easing.OutQuint); + } } } } diff --git a/osu.Game/Screens/Footer/ScreenFooterButton.cs b/osu.Game/Screens/Footer/ScreenFooterButton.cs index a88ba1aead4d..6515203ca015 100644 --- a/osu.Game/Screens/Footer/ScreenFooterButton.cs +++ b/osu.Game/Screens/Footer/ScreenFooterButton.cs @@ -40,7 +40,7 @@ public partial class ScreenFooterButton : OsuClickableContainer, IKeyBindingHand private Colour4 buttonAccentColour; - protected Colour4 AccentColour + public Colour4 AccentColour { set { @@ -50,7 +50,7 @@ protected Colour4 AccentColour } } - protected IconUsage Icon + public IconUsage Icon { set => icon.Icon = value; } From 4e1240c349169b3493d799f85427f65a1c53717b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 10 Jul 2024 13:54:27 +0900 Subject: [PATCH 09/10] Migrate `ShearedOverlayContainer` to NRT --- .../Overlays/Mods/ShearedOverlayContainer.cs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs b/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs index c9c3c6240414..d3326cb86bd4 100644 --- a/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs +++ b/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs @@ -1,9 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - -using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -30,16 +27,15 @@ public abstract partial class ShearedOverlayContainer : OsuFocusedOverlayContain /// /// The overlay's header. /// - protected ShearedOverlayHeader Header { get; private set; } + protected ShearedOverlayHeader Header { get; private set; } = null!; /// /// The overlay's footer. /// - protected Container Footer { get; private set; } + protected Container Footer { get; private set; } = null!; - [Resolved(canBeNull: true)] - [CanBeNull] - private ScreenFooter footer { get; set; } + [Resolved] + private ScreenFooter? footer { get; set; } // todo: very temporary property that will be removed once ModSelectOverlay and FirstRunSetupOverlay are updated to use new footer. public virtual bool UseNewFooter => false; @@ -48,17 +44,17 @@ public abstract partial class ShearedOverlayContainer : OsuFocusedOverlayContain /// A container containing all content, including the header and footer. /// May be used for overlay-wide animations. /// - protected Container TopLevelContent { get; private set; } + protected Container TopLevelContent { get; private set; } = null!; /// /// A container for content that is to be displayed between the header and footer. /// - protected Container MainAreaContent { get; private set; } + protected Container MainAreaContent { get; private set; } = null!; /// /// A container for content that is to be displayed inside the footer. /// - protected Container FooterContent { get; private set; } + protected Container FooterContent { get; private set; } = null!; protected override bool StartHidden => true; From f2810193588f55ebc91f17ce4e39a68be7ca54fc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 10 Jul 2024 13:58:50 +0900 Subject: [PATCH 10/10] Rename method to match provided argument --- osu.Game/Overlays/Mods/ShearedOverlayContainer.cs | 4 ++-- osu.Game/Screens/Footer/ScreenFooter.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs b/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs index d3326cb86bd4..aed9b395f668 100644 --- a/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs +++ b/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs @@ -152,7 +152,7 @@ protected override void PopIn() if (UseNewFooter && footer != null) { - footer.SetOverlayContent(this); + footer.SetActiveOverlayContainer(this); if (footer.State.Value == Visibility.Hidden) { @@ -175,7 +175,7 @@ protected override void PopOut() if (UseNewFooter && footer != null) { - footer.ClearOverlayContent(); + footer.ClearActiveOverlayContainer(); if (hideFooterOnPopOut) { diff --git a/osu.Game/Screens/Footer/ScreenFooter.cs b/osu.Game/Screens/Footer/ScreenFooter.cs index cef891f8c052..f9a6d54b9679 100644 --- a/osu.Game/Screens/Footer/ScreenFooter.cs +++ b/osu.Game/Screens/Footer/ScreenFooter.cs @@ -121,7 +121,7 @@ public void SetButtons(IReadOnlyList buttons) temporarilyHiddenButtons.Clear(); overlays.Clear(); - ClearOverlayContent(); + ClearActiveOverlayContainer(); var oldButtons = buttonsFlow.ToArray(); @@ -168,7 +168,7 @@ public void SetButtons(IReadOnlyList buttons) private Container? contentContainer; private readonly List temporarilyHiddenButtons = new List(); - public void SetOverlayContent(ShearedOverlayContainer overlay) + public void SetActiveOverlayContainer(ShearedOverlayContainer overlay) { if (contentContainer != null) { @@ -213,7 +213,7 @@ public void SetOverlayContent(ShearedOverlayContainer overlay) content.Show(); } - public void ClearOverlayContent() + public void ClearActiveOverlayContainer() { if (contentContainer == null) return;