From 09c52f03d8ea7ed896721a9ce629ec58d8d67e0c Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 10 May 2024 08:25:16 +0300 Subject: [PATCH] Fix "options" button behaving weirdly when clicking on it while open --- .../Select/FooterV2/BeatmapOptionsPopover.cs | 6 +-- .../Select/FooterV2/FooterButtonOptionsV2.cs | 43 ++++++++++--------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs b/osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs index f81036f745..648f536bb1 100644 --- a/osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs +++ b/osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs @@ -188,9 +188,9 @@ namespace osu.Game.Screens.Select.FooterV2 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 a1559d32dc..2ed8480b46 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 @@ namespace osu.Game.Screens.Select.FooterV2 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; + protected override void Flash() + { + if (hidingFromClick) + return; - case Visibility.Visible: - this.ShowPopover(); - break; - } - }); + base.Flash(); } public Popover GetPopover() => new BeatmapOptionsPopover(this);