mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 08:55:35 +08:00
Enter key presses first OK button, 1-9 presses button at number
This commit is contained in:
parent
e8cae3b45e
commit
0ce8fff666
@ -1,23 +1,22 @@
|
|||||||
// 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 System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using osu.Framework.Allocation;
|
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.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Graphics.Transforms;
|
using osu.Framework.Graphics.Transforms;
|
||||||
using osu.Framework.MathUtils;
|
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Backgrounds;
|
using osu.Game.Graphics.Backgrounds;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Dialog
|
namespace osu.Game.Overlays.Dialog
|
||||||
{
|
{
|
||||||
public class PopupDialog : OverlayContainer
|
public class PopupDialog : FocusedOverlayContainer
|
||||||
{
|
{
|
||||||
private const float enter_duration = 500;
|
private const float enter_duration = 500;
|
||||||
private const float exit_duration = 200;
|
private const float exit_duration = 200;
|
||||||
@ -87,8 +86,52 @@ namespace osu.Game.Overlays.Dialog
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PopupDialogOkButton okButton
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
foreach (PopupDialogButton b in Buttons)
|
||||||
|
{
|
||||||
|
if (b is PopupDialogOkButton)
|
||||||
|
return (PopupDialogOkButton)b;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pressButtonAtIndex(int index)
|
||||||
|
{
|
||||||
|
if (index < Buttons.Length)
|
||||||
|
{
|
||||||
|
Buttons[index].TriggerClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnKeyDown(Framework.Input.InputState state, Framework.Input.KeyDownEventArgs args)
|
||||||
|
{
|
||||||
|
if (args.Repeat) return false;
|
||||||
|
|
||||||
|
if (args.Key == Key.Enter)
|
||||||
|
{
|
||||||
|
okButton?.TriggerClick();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// press button at number if 1-9 on number row or keypad are pressed
|
||||||
|
int k = (int)args.Key;
|
||||||
|
if (k >= (int)Key.Number1 && k <= (int)Key.Number9)
|
||||||
|
pressButtonAtIndex(k - (int)Key.Number1);
|
||||||
|
else if (k >= (int)Key.Keypad1 && k <= (int)Key.Keypad9)
|
||||||
|
pressButtonAtIndex(k - (int)Key.Keypad1);
|
||||||
|
|
||||||
|
return base.OnKeyDown(state, args);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void PopIn()
|
protected override void PopIn()
|
||||||
{
|
{
|
||||||
|
base.PopIn();
|
||||||
|
|
||||||
// Reset various animations but only if the dialog animation fully completed
|
// Reset various animations but only if the dialog animation fully completed
|
||||||
if (content.Alpha == 0)
|
if (content.Alpha == 0)
|
||||||
{
|
{
|
||||||
@ -105,6 +148,8 @@ namespace osu.Game.Overlays.Dialog
|
|||||||
|
|
||||||
protected override void PopOut()
|
protected override void PopOut()
|
||||||
{
|
{
|
||||||
|
base.PopOut();
|
||||||
|
|
||||||
content.FadeOut(exit_duration, EasingTypes.InSine);
|
content.FadeOut(exit_duration, EasingTypes.InSine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user