1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 17:17:26 +08:00
osu-lazer/osu.Game/Overlays/Mods/DeselectAllModsButton.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.7 KiB
C#
Raw Normal View History

// 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.
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
using osu.Game.Localisation;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Overlays.Mods
{
public partial class DeselectAllModsButton : ShearedButton, IKeyBindingHandler<GlobalAction>
{
private readonly Bindable<IReadOnlyList<Mod>> selectedMods = new Bindable<IReadOnlyList<Mod>>();
private readonly ShearedSearchTextBox searchTextBox;
public DeselectAllModsButton(ModSelectOverlay modSelectOverlay)
: base(ModSelectOverlay.BUTTON_WIDTH)
{
Text = CommonStrings.DeselectAll;
Action = modSelectOverlay.DeselectAll;
searchTextBox = modSelectOverlay.SearchTextBox;
selectedMods.BindTo(modSelectOverlay.SelectedMods);
}
protected override void LoadComplete()
{
base.LoadComplete();
selectedMods.BindValueChanged(_ => updateEnabledState(), true);
}
private void updateEnabledState()
{
Enabled.Value = selectedMods.Value.Any();
}
2023-05-11 00:43:58 +08:00
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (e.Repeat || e.Action != GlobalAction.DeselectAllMods || searchTextBox.HasFocus)
return false;
TriggerClick();
return true;
}
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
}
}