1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 04:53:21 +08:00

Make Footer handles hotkey.

This commit is contained in:
Huo Yaoyuan 2017-03-14 16:58:34 +08:00
parent c3a0549cdd
commit 9a4247f67e
3 changed files with 37 additions and 30 deletions

View File

@ -4,11 +4,13 @@
using System;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Input;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Menu;
@ -34,7 +36,7 @@ namespace osu.Game.Screens.Select
public OsuLogo StartButton;
public void AddButton(string text, Color4 colour, Action action)
public void AddButton(string text, Color4 colour, Action action, Key? hotkey = null)
{
var button = new FooterButton
{
@ -43,6 +45,7 @@ namespace osu.Game.Screens.Select
Width = play_song_select_button_width,
SelectedColour = colour,
DeselectedColour = colour.Opacity(0.5f),
Hotkey = hotkey,
};
button.Hovered = () => updateModeLight(button);
@ -89,7 +92,7 @@ namespace osu.Game.Screens.Select
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Action = () => OnBack?.Invoke(),
Action = () => OnBack?.Invoke()
},
new FillFlowContainer
{
@ -114,5 +117,16 @@ namespace osu.Game.Screens.Select
updateModeLight();
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (!args.Repeat && args.Key == Key.Enter)
{
OnStart?.Invoke();
return true;
}
return base.OnKeyDown(state, args);
}
}
}

View File

@ -1,14 +1,15 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using System;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Input;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Screens.Select
@ -34,7 +35,7 @@ namespace osu.Game.Screens.Select
set
{
deselectedColour = value;
if(light.Colour != SelectedColour)
if (light.Colour != SelectedColour)
light.Colour = value;
}
}
@ -83,6 +84,7 @@ namespace osu.Game.Screens.Select
public Action Hovered;
public Action HoverLost;
public Key? Hotkey;
protected override bool OnHover(InputState state)
{
@ -119,5 +121,15 @@ namespace osu.Game.Screens.Select
return base.OnClick(state);
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (!args.Repeat && args.Key == Hotkey)
{
OnClick(state);
return true;
}
return base.OnKeyDown(state, args);
}
}
}

View File

@ -164,9 +164,9 @@ namespace osu.Game.Screens.Select
},
};
footer.AddButton(@"mods", colours.Yellow, modSelect.ToggleVisibility);
footer.AddButton(@"random", colours.Green, carousel.SelectRandom);
footer.AddButton(@"options", colours.Blue, beatmapOptions.ToggleVisibility);
footer.AddButton(@"mods", colours.Yellow, modSelect.ToggleVisibility, Key.F1);
footer.AddButton(@"random", colours.Green, carousel.SelectRandom, Key.F2);
footer.AddButton(@"options", colours.Blue, beatmapOptions.ToggleVisibility, Key.F3);
if (osu != null)
playMode.BindTo(osu.PlayMode);
@ -435,29 +435,10 @@ namespace osu.Game.Screens.Select
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (args.Repeat) return false;
switch (args.Key)
if (!args.Repeat && args.Key == Key.Delete && state.Keyboard.ShiftPressed)
{
case Key.F1:
modSelect.ToggleVisibility();
return true;
case Key.F2:
carousel.SelectRandom();
return true;
case Key.F3:
beatmapOptions.ToggleVisibility();
return true;
case Key.Enter:
footer.StartButton.TriggerClick();
return true;
case Key.Delete:
if (state.Keyboard.ShiftPressed)
{
promptDelete();
return true;
}
break;
promptDelete();
return true;
}
return base.OnKeyDown(state, args);