mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 09:22:54 +08:00
Auto assign hotkeys for BeatmapOptionsButton.
This commit is contained in:
parent
35a60a8f7d
commit
beb0a8ff03
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using OpenTK.Input;
|
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -49,8 +48,6 @@ namespace osu.Game.Screens.Select.Options
|
|||||||
set { secondLine.Text = value; }
|
set { secondLine.Text = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Key? HotKey;
|
|
||||||
|
|
||||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
||||||
{
|
{
|
||||||
flash.FadeTo(0.1f, 1000, EasingTypes.OutQuint);
|
flash.FadeTo(0.1f, 1000, EasingTypes.OutQuint);
|
||||||
@ -72,17 +69,6 @@ namespace osu.Game.Screens.Select.Options
|
|||||||
return base.OnClick(state);
|
return base.OnClick(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
|
||||||
{
|
|
||||||
if (!args.Repeat && args.Key == HotKey)
|
|
||||||
{
|
|
||||||
OnClick(state);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool Contains(Vector2 screenSpacePos) => box.Contains(screenSpacePos);
|
public override bool Contains(Vector2 screenSpacePos) => box.Contains(screenSpacePos);
|
||||||
|
|
||||||
public BeatmapOptionsButton()
|
public BeatmapOptionsButton()
|
||||||
|
@ -12,6 +12,7 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Graphics.Transforms;
|
using osu.Framework.Graphics.Transforms;
|
||||||
|
using osu.Framework.Input;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Select.Options
|
namespace osu.Game.Screens.Select.Options
|
||||||
@ -90,7 +91,7 @@ namespace osu.Game.Screens.Select.Options
|
|||||||
/// <para>Lower depth to be put on the left, and higher to be put on the right.</para>
|
/// <para>Lower depth to be put on the left, and higher to be put on the right.</para>
|
||||||
/// <para>Notice this is different to <see cref="Footer"/>!</para>
|
/// <para>Notice this is different to <see cref="Footer"/>!</para>
|
||||||
/// </param>
|
/// </param>
|
||||||
public void AddButton(string firstLine, string secongLine, FontAwesome icon, Color4 colour, Action action, Key? hotkey = null, float depth = 0)
|
public void AddButton(string firstLine, string secongLine, FontAwesome icon, Color4 colour, Action action, float depth = 0)
|
||||||
{
|
{
|
||||||
buttonsContainer.Add(new BeatmapOptionsButton
|
buttonsContainer.Add(new BeatmapOptionsButton
|
||||||
{
|
{
|
||||||
@ -104,10 +105,26 @@ namespace osu.Game.Screens.Select.Options
|
|||||||
Hide();
|
Hide();
|
||||||
action?.Invoke();
|
action?.Invoke();
|
||||||
},
|
},
|
||||||
HotKey = hotkey
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||||
|
{
|
||||||
|
if (args.Repeat) return false;
|
||||||
|
int index = (int)args.Key - (int)Key.Number1;
|
||||||
|
if (index >= 0 && index <= 9)
|
||||||
|
{
|
||||||
|
// Children of ButtonFlow is reversed. The same reason of depth in AddButton.
|
||||||
|
var button = buttonsContainer.Children.Reverse().ElementAtOrDefault(index);
|
||||||
|
if (button != null)
|
||||||
|
{
|
||||||
|
button.TriggerClick();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return base.OnKeyDown(state, args);
|
||||||
|
}
|
||||||
|
|
||||||
private class ButtonFlow : FillFlowContainer<BeatmapOptionsButton>
|
private class ButtonFlow : FillFlowContainer<BeatmapOptionsButton>
|
||||||
{
|
{
|
||||||
protected override IComparer<Drawable> DepthComparer => new ReverseCreationOrderDepthComparer();
|
protected override IComparer<Drawable> DepthComparer => new ReverseCreationOrderDepthComparer();
|
||||||
|
@ -31,9 +31,9 @@ namespace osu.Game.Screens.Select
|
|||||||
|
|
||||||
Footer.AddButton(@"mods", colours.Yellow, modSelect.ToggleVisibility, Key.F1, float.MaxValue);
|
Footer.AddButton(@"mods", colours.Yellow, modSelect.ToggleVisibility, Key.F1, float.MaxValue);
|
||||||
|
|
||||||
BeatmapOptions.AddButton(@"Remove", @"from unplayed", FontAwesome.fa_times_circle_o, colours.Purple, null, Key.Number1);
|
BeatmapOptions.AddButton(@"Remove", @"from unplayed", FontAwesome.fa_times_circle_o, colours.Purple, null);
|
||||||
BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.fa_eraser, colours.Purple, null, Key.Number2);
|
BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.fa_eraser, colours.Purple, null);
|
||||||
BeatmapOptions.AddButton(@"Edit", @"Beatmap", FontAwesome.fa_pencil, colours.Yellow, null, Key.Number3);
|
BeatmapOptions.AddButton(@"Edit", @"Beatmap", FontAwesome.fa_pencil, colours.Yellow, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnBeatmapChanged(WorkingBeatmap beatmap)
|
protected override void OnBeatmapChanged(WorkingBeatmap beatmap)
|
||||||
|
@ -149,7 +149,7 @@ namespace osu.Game.Screens.Select
|
|||||||
Footer.AddButton(@"random", colours.Green, SelectRandom, Key.F2);
|
Footer.AddButton(@"random", colours.Green, SelectRandom, Key.F2);
|
||||||
Footer.AddButton(@"options", colours.Blue, BeatmapOptions.ToggleVisibility, Key.F3);
|
Footer.AddButton(@"options", colours.Blue, BeatmapOptions.ToggleVisibility, Key.F3);
|
||||||
|
|
||||||
BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, promptDelete, Key.Number4, float.MaxValue);
|
BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, promptDelete, float.MaxValue);
|
||||||
|
|
||||||
if (osu != null)
|
if (osu != null)
|
||||||
playMode.BindTo(osu.PlayMode);
|
playMode.BindTo(osu.PlayMode);
|
||||||
|
Loading…
Reference in New Issue
Block a user