1
0
mirror of https://github.com/ppy/osu.git synced 2026-06-13 15:24:36 +08:00
Files
osu-lazer/osu.Game/Screens/Select/FooterButtonOptions.cs
T
Jerry 4b698128ae Fix options menu not toggling off when pressing f3 again (#37648)
Previously pressing f3 again when the options menu was open would just
open it again. This code changes the Action from always showing the
popover to closing it if it is already open.

As noted in the original issue, framework changes were also required for
this to work. You can find the separate pr
[here](https://github.com/ppy/osu-framework/pull/6743).

Was unsure if tests were necessary for a fix with minimal changes like
this, please let me know if you would like me to add some!

Fixes issue #36331

Co-authored-by: Bartłomiej Dach <dach.bartlomiej@gmail.com>
2026-06-09 15:02:24 +02:00

74 lines
2.2 KiB
C#

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// 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;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Input.Bindings;
using osu.Game.Localisation;
using osu.Game.Overlays;
using osu.Game.Screens.Footer;
namespace osu.Game.Screens.Select
{
public partial class FooterButtonOptions : ScreenFooterButton, IHasPopover
{
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
[Resolved]
private IBindable<WorkingBeatmap> workingBeatmap { get; set; } = null!;
[Resolved]
private ISongSelect? songSelect { get; set; }
[Resolved]
private RealmAccess realm { get; set; } = null!;
private Live<BeatmapInfo> beatmap = null!;
[BackgroundDependencyLoader]
private void load(OsuColour colour)
{
Text = SongSelectStrings.Options;
Icon = FontAwesome.Solid.Cog;
AccentColour = colour.Purple1;
Hotkey = GlobalAction.ToggleBeatmapOptions;
Action = () =>
{
if (this.FindClosestParent<PopoverContainer>()?.CurrentTarget == this)
this.HidePopover();
else
this.ShowPopover();
};
}
protected override void LoadComplete()
{
base.LoadComplete();
workingBeatmap.BindValueChanged(_ => beatmapChanged(), true);
}
private void beatmapChanged()
{
this.HidePopover();
Enabled.Value = !workingBeatmap.IsDefault;
if (!workingBeatmap.IsDefault)
beatmap = realm.Run(r => r.Find<BeatmapInfo>(workingBeatmap.Value.BeatmapInfo.ID)!.ToLive(realm));
}
public Framework.Graphics.UserInterface.Popover GetPopover() => new Popover(this, beatmap.Value.Detach())
{
ColourProvider = colourProvider,
SongSelect = songSelect
};
}
}