mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 03:15:45 +08:00
Remove hardcoded key param from AddButton
This commit is contained in:
parent
368aca015a
commit
1a8a7ae7f8
@ -5,7 +5,6 @@ using System.ComponentModel;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Screens.Select.Options;
|
||||
using osuTK.Graphics;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.SongSelect
|
||||
{
|
||||
@ -16,10 +15,10 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
{
|
||||
var overlay = new BeatmapOptionsOverlay();
|
||||
|
||||
overlay.AddButton(@"Remove", @"from unplayed", FontAwesome.Regular.TimesCircle, Color4.Purple, null, Key.Number1);
|
||||
overlay.AddButton(@"Clear", @"local scores", FontAwesome.Solid.Eraser, Color4.Purple, null, Key.Number2);
|
||||
overlay.AddButton(@"Delete", @"all difficulties", FontAwesome.Solid.Trash, Color4.Pink, null, Key.Number3);
|
||||
overlay.AddButton(@"Edit", @"beatmap", FontAwesome.Solid.PencilAlt, Color4.Yellow, null, Key.Number4);
|
||||
overlay.AddButton(@"Remove", @"from unplayed", FontAwesome.Regular.TimesCircle, Color4.Purple, null);
|
||||
overlay.AddButton(@"Clear", @"local scores", FontAwesome.Solid.Eraser, Color4.Purple, null);
|
||||
overlay.AddButton(@"Delete", @"all difficulties", FontAwesome.Solid.Trash, Color4.Pink, null);
|
||||
overlay.AddButton(@"Edit", @"beatmap", FontAwesome.Solid.PencilAlt, Color4.Yellow, null);
|
||||
|
||||
Add(overlay);
|
||||
|
||||
|
@ -52,8 +52,6 @@ namespace osu.Game.Screens.Select.Options
|
||||
set => secondLine.Text = value;
|
||||
}
|
||||
|
||||
public Key? HotKey;
|
||||
|
||||
protected override bool OnMouseDown(MouseDownEvent e)
|
||||
{
|
||||
flash.FadeTo(0.1f, 1000, Easing.OutQuint);
|
||||
@ -75,17 +73,6 @@ namespace osu.Game.Screens.Select.Options
|
||||
return base.OnClick(e);
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(KeyDownEvent e)
|
||||
{
|
||||
if (!e.Repeat && e.Key == HotKey)
|
||||
{
|
||||
Click();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => box.ReceivePositionalInputAt(screenSpacePos);
|
||||
|
||||
public BeatmapOptionsButton()
|
||||
|
@ -11,6 +11,8 @@ using osuTK;
|
||||
using osuTK.Graphics;
|
||||
using osuTK.Input;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Framework.Input.Events;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Screens.Select.Options
|
||||
{
|
||||
@ -60,9 +62,8 @@ namespace osu.Game.Screens.Select.Options
|
||||
/// <param name="secondLine">Text in the second line.</param>
|
||||
/// <param name="colour">Colour of the button.</param>
|
||||
/// <param name="icon">Icon of the button.</param>
|
||||
/// <param name="hotkey">Hotkey of the button.</param>
|
||||
/// <param name="action">Binding the button does.</param>
|
||||
public void AddButton(string firstLine, string secondLine, IconUsage icon, Color4 colour, Action action, Key? hotkey = null)
|
||||
public void AddButton(string firstLine, string secondLine, IconUsage icon, Color4 colour, Action action)
|
||||
{
|
||||
var button = new BeatmapOptionsButton
|
||||
{
|
||||
@ -75,7 +76,6 @@ namespace osu.Game.Screens.Select.Options
|
||||
Hide();
|
||||
action?.Invoke();
|
||||
},
|
||||
HotKey = hotkey
|
||||
};
|
||||
|
||||
buttonsContainer.Add(button);
|
||||
@ -107,5 +107,24 @@ namespace osu.Game.Screens.Select.Options
|
||||
|
||||
this.FadeOut(transition_duration, Easing.InQuint);
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(KeyDownEvent e)
|
||||
{
|
||||
if (!e.Repeat && e.Key >= Key.Number1 && e.Key <= Key.Number9)
|
||||
{
|
||||
int requested = e.Key - Key.Number1;
|
||||
|
||||
// go reverse as buttonsContainer is a ReverseChildIDFillFlowContainer
|
||||
BeatmapOptionsButton found = buttonsContainer.Children.ElementAtOrDefault((buttonsContainer.Children.Count - 1) - requested);
|
||||
|
||||
if (found != null)
|
||||
{
|
||||
found.Click();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return base.OnKeyDown(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ namespace osu.Game.Screens.Select
|
||||
{
|
||||
ValidForResume = false;
|
||||
Edit();
|
||||
}, Key.Number4);
|
||||
});
|
||||
|
||||
((PlayBeatmapDetailArea)BeatmapDetails).Leaderboard.ScoreSelected += PresentScore;
|
||||
}
|
||||
|
@ -275,9 +275,9 @@ namespace osu.Game.Screens.Select
|
||||
Footer.AddButton(new FooterButtonRandom { Action = triggerRandom });
|
||||
Footer.AddButton(new FooterButtonOptions(), BeatmapOptions);
|
||||
|
||||
BeatmapOptions.AddButton(@"Remove", @"from unplayed", FontAwesome.Regular.TimesCircle, colours.Purple, null, Key.Number1);
|
||||
BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.Solid.Eraser, colours.Purple, () => clearScores(Beatmap.Value.BeatmapInfo), Key.Number2);
|
||||
BeatmapOptions.AddButton(@"Delete", @"all difficulties", FontAwesome.Solid.Trash, colours.Pink, () => delete(Beatmap.Value.BeatmapSetInfo), Key.Number3);
|
||||
BeatmapOptions.AddButton(@"Remove", @"from unplayed", FontAwesome.Regular.TimesCircle, colours.Purple, null);
|
||||
BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.Solid.Eraser, colours.Purple, () => clearScores(Beatmap.Value.BeatmapInfo));
|
||||
BeatmapOptions.AddButton(@"Delete", @"all difficulties", FontAwesome.Solid.Trash, colours.Pink, () => delete(Beatmap.Value.BeatmapSetInfo));
|
||||
}
|
||||
|
||||
dialogOverlay = dialog;
|
||||
|
Loading…
Reference in New Issue
Block a user