From b6d6a8940bfb15313b8787185f45463391a79f1f Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 10 May 2024 08:24:39 +0300 Subject: [PATCH 1/3] Improve animation of new song select footer buttons --- .../Screens/Select/FooterV2/FooterButtonV2.cs | 64 +++++++++---------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/osu.Game/Screens/Select/FooterV2/FooterButtonV2.cs b/osu.Game/Screens/Select/FooterV2/FooterButtonV2.cs index 2c841f6ae6d0..21337327fa06 100644 --- a/osu.Game/Screens/Select/FooterV2/FooterButtonV2.cs +++ b/osu.Game/Screens/Select/FooterV2/FooterButtonV2.cs @@ -24,8 +24,6 @@ namespace osu.Game.Screens.Select.FooterV2 { public partial class FooterButtonV2 : OsuClickableContainer, IKeyBindingHandler { - private const int transition_length = 500; - // This should be 12 by design, but an extra allowance is added due to the corner radius specification. private const float shear_width = 13.5f; @@ -68,6 +66,7 @@ protected LocalisableString Text protected Container TextContainer; private readonly Box bar; private readonly Box backgroundBox; + private readonly Box flashLayer; public FooterButtonV2() { @@ -137,8 +136,15 @@ public FooterButtonV2() { RelativeSizeAxes = Axes.Both, } - } - } + }, + flashLayer = new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Colour4.White.Opacity(0.9f), + Blending = BlendingParameters.Additive, + Alpha = 0, + }, + }, }; } @@ -154,26 +160,20 @@ protected override void LoadComplete() public GlobalAction? Hotkey; - private bool handlingMouse; - - protected override bool OnHover(HoverEvent e) + protected override bool OnClick(ClickEvent e) { - updateDisplay(); - return true; - } + if (Enabled.Value) + Flash(); - protected override bool OnMouseDown(MouseDownEvent e) - { - handlingMouse = true; - updateDisplay(); - return base.OnMouseDown(e); + return base.OnClick(e); } - protected override void OnMouseUp(MouseUpEvent e) + protected virtual void Flash() => flashLayer.FadeOutFromOne(800, Easing.OutQuint); + + protected override bool OnHover(HoverEvent e) { - handlingMouse = false; updateDisplay(); - base.OnMouseUp(e); + return true; } protected override void OnHoverLost(HoverLostEvent e) => updateDisplay(); @@ -190,27 +190,23 @@ public virtual bool OnPressed(KeyBindingPressEvent e) private void updateDisplay() { - Color4 backgroundColour = colourProvider.Background3; + Color4 backgroundColour = OverlayState.Value == Visibility.Visible ? buttonAccentColour : colourProvider.Background3; + Color4 textColour = OverlayState.Value == Visibility.Visible ? colourProvider.Background6 : colourProvider.Content1; + Color4 accentColour = OverlayState.Value == Visibility.Visible ? colourProvider.Background6 : buttonAccentColour; if (!Enabled.Value) - { - backgroundColour = colourProvider.Background3.Darken(0.4f); - } - else - { - if (OverlayState.Value == Visibility.Visible) - backgroundColour = buttonAccentColour.Darken(0.5f); + backgroundColour = backgroundColour.Darken(1f); + else if (IsHovered) + backgroundColour = backgroundColour.Lighten(0.2f); - if (IsHovered) - { - backgroundColour = backgroundColour.Lighten(0.3f); + backgroundBox.FadeColour(backgroundColour, 150, Easing.OutQuint); - if (handlingMouse) - backgroundColour = backgroundColour.Lighten(0.3f); - } - } + if (!Enabled.Value) + textColour = textColour.Opacity(0.6f); - backgroundBox.FadeColour(backgroundColour, transition_length, Easing.OutQuint); + text.FadeColour(textColour, 150, Easing.OutQuint); + icon.FadeColour(accentColour, 150, Easing.OutQuint); + bar.FadeColour(accentColour, 150, Easing.OutQuint); } } } From 09c52f03d8ea7ed896721a9ce629ec58d8d67e0c Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 10 May 2024 08:25:16 +0300 Subject: [PATCH 2/3] Fix "options" button behaving weirdly when clicking on it while open --- .../Select/FooterV2/BeatmapOptionsPopover.cs | 6 +-- .../Select/FooterV2/FooterButtonOptionsV2.cs | 45 ++++++++++--------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs b/osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs index f81036f74585..648f536bb186 100644 --- a/osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs +++ b/osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs @@ -188,9 +188,9 @@ protected override bool OnKeyDown(KeyDownEvent e) protected override void UpdateState(ValueChangedEvent state) { base.UpdateState(state); - - if (state.NewValue == Visibility.Hidden) - footerButton.IsActive.Value = false; + // intentionally scheduling to let the button have a chance whether the popover will hide from clicking the button or clicking outside + // see the "hidingFromClick" field in FooterButtonOptionsV2. + Schedule(() => footerButton.OverlayState.Value = state.NewValue); } } } diff --git a/osu.Game/Screens/Select/FooterV2/FooterButtonOptionsV2.cs b/osu.Game/Screens/Select/FooterV2/FooterButtonOptionsV2.cs index a1559d32dc96..2ed8480b460d 100644 --- a/osu.Game/Screens/Select/FooterV2/FooterButtonOptionsV2.cs +++ b/osu.Game/Screens/Select/FooterV2/FooterButtonOptionsV2.cs @@ -2,12 +2,12 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Extensions; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; +using osu.Framework.Input.Events; using osu.Game.Graphics; using osu.Game.Input.Bindings; @@ -15,7 +15,10 @@ namespace osu.Game.Screens.Select.FooterV2 { public partial class FooterButtonOptionsV2 : FooterButtonV2, IHasPopover { - public readonly BindableBool IsActive = new BindableBool(); + /// + /// True if the next click is for hiding the popover. + /// + private bool hidingFromClick; [BackgroundDependencyLoader] private void load(OsuColour colour) @@ -25,31 +28,29 @@ private void load(OsuColour colour) AccentColour = colour.Purple1; Hotkey = GlobalAction.ToggleBeatmapOptions; - Action = () => IsActive.Toggle(); + Action = () => + { + if (OverlayState.Value == Visibility.Hidden && !hidingFromClick) + this.ShowPopover(); + + hidingFromClick = false; + }; } - protected override void LoadComplete() + protected override bool OnMouseDown(MouseDownEvent e) { - base.LoadComplete(); + if (OverlayState.Value == Visibility.Visible) + hidingFromClick = true; - IsActive.BindValueChanged(active => - { - OverlayState.Value = active.NewValue ? Visibility.Visible : Visibility.Hidden; - }); + return base.OnMouseDown(e); + } - OverlayState.BindValueChanged(state => - { - switch (state.NewValue) - { - case Visibility.Hidden: - this.HidePopover(); - break; - - case Visibility.Visible: - this.ShowPopover(); - break; - } - }); + protected override void Flash() + { + if (hidingFromClick) + return; + + base.Flash(); } public Popover GetPopover() => new BeatmapOptionsPopover(this); From fa6ccc854d5324d08baf4e6ee77ce7373d75ef0a Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sun, 12 May 2024 05:24:20 +0300 Subject: [PATCH 3/3] Revert behavioural changes on options button --- .../Select/FooterV2/BeatmapOptionsPopover.cs | 4 +-- .../Select/FooterV2/FooterButtonOptionsV2.cs | 31 +------------------ 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs b/osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs index 648f536bb186..d98164c3068c 100644 --- a/osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs +++ b/osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs @@ -188,9 +188,7 @@ protected override bool OnKeyDown(KeyDownEvent e) protected override void UpdateState(ValueChangedEvent state) { base.UpdateState(state); - // intentionally scheduling to let the button have a chance whether the popover will hide from clicking the button or clicking outside - // see the "hidingFromClick" field in FooterButtonOptionsV2. - Schedule(() => footerButton.OverlayState.Value = state.NewValue); + footerButton.OverlayState.Value = state.NewValue; } } } diff --git a/osu.Game/Screens/Select/FooterV2/FooterButtonOptionsV2.cs b/osu.Game/Screens/Select/FooterV2/FooterButtonOptionsV2.cs index 2ed8480b460d..555215056a39 100644 --- a/osu.Game/Screens/Select/FooterV2/FooterButtonOptionsV2.cs +++ b/osu.Game/Screens/Select/FooterV2/FooterButtonOptionsV2.cs @@ -3,11 +3,9 @@ using osu.Framework.Allocation; using osu.Framework.Extensions; -using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; -using osu.Framework.Input.Events; using osu.Game.Graphics; using osu.Game.Input.Bindings; @@ -15,11 +13,6 @@ namespace osu.Game.Screens.Select.FooterV2 { public partial class FooterButtonOptionsV2 : FooterButtonV2, IHasPopover { - /// - /// True if the next click is for hiding the popover. - /// - private bool hidingFromClick; - [BackgroundDependencyLoader] private void load(OsuColour colour) { @@ -28,29 +21,7 @@ private void load(OsuColour colour) AccentColour = colour.Purple1; Hotkey = GlobalAction.ToggleBeatmapOptions; - Action = () => - { - if (OverlayState.Value == Visibility.Hidden && !hidingFromClick) - this.ShowPopover(); - - hidingFromClick = false; - }; - } - - protected override bool OnMouseDown(MouseDownEvent e) - { - if (OverlayState.Value == Visibility.Visible) - hidingFromClick = true; - - return base.OnMouseDown(e); - } - - protected override void Flash() - { - if (hidingFromClick) - return; - - base.Flash(); + Action = this.ShowPopover; } public Popover GetPopover() => new BeatmapOptionsPopover(this);