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 System;
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;
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.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
@ -34,7 +36,7 @@ namespace osu.Game.Screens.Select
public OsuLogo StartButton; 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 var button = new FooterButton
{ {
@ -43,6 +45,7 @@ namespace osu.Game.Screens.Select
Width = play_song_select_button_width, Width = play_song_select_button_width,
SelectedColour = colour, SelectedColour = colour,
DeselectedColour = colour.Opacity(0.5f), DeselectedColour = colour.Opacity(0.5f),
Hotkey = hotkey,
}; };
button.Hovered = () => updateModeLight(button); button.Hovered = () => updateModeLight(button);
@ -89,7 +92,7 @@ namespace osu.Game.Screens.Select
{ {
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
Action = () => OnBack?.Invoke(), Action = () => OnBack?.Invoke()
}, },
new FillFlowContainer new FillFlowContainer
{ {
@ -114,5 +117,16 @@ namespace osu.Game.Screens.Select
updateModeLight(); 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>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using OpenTK.Input;
using osu.Framework.Graphics; 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.Input;
using System;
using osu.Framework.Graphics.Transforms; using osu.Framework.Graphics.Transforms;
using osu.Framework.Input;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
namespace osu.Game.Screens.Select namespace osu.Game.Screens.Select
@ -34,7 +35,7 @@ namespace osu.Game.Screens.Select
set set
{ {
deselectedColour = value; deselectedColour = value;
if(light.Colour != SelectedColour) if (light.Colour != SelectedColour)
light.Colour = value; light.Colour = value;
} }
} }
@ -83,6 +84,7 @@ namespace osu.Game.Screens.Select
public Action Hovered; public Action Hovered;
public Action HoverLost; public Action HoverLost;
public Key? Hotkey;
protected override bool OnHover(InputState state) protected override bool OnHover(InputState state)
{ {
@ -119,5 +121,15 @@ namespace osu.Game.Screens.Select
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 base.OnKeyDown(state, args);
}
} }
} }

View File

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