1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 15:33:21 +08:00

Fix "options" button behaving weirdly when clicking on it while open

This commit is contained in:
Salman Ahmed 2024-05-10 08:25:16 +03:00
parent b6d6a8940b
commit 09c52f03d8
2 changed files with 25 additions and 24 deletions

View File

@ -188,9 +188,9 @@ namespace osu.Game.Screens.Select.FooterV2
protected override void UpdateState(ValueChangedEvent<Visibility> 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);
}
}
}

View File

@ -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();
/// <summary>
/// True if the next click is for hiding the popover.
/// </summary>
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);