mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 02:43:19 +08:00
Tidy up code.
The triggered bool is not even necessary because input is no longer handled after the OverlayContainer's state is set to hidden.
This commit is contained in:
parent
d1cd077e0d
commit
c4871bbbf3
@ -11,6 +11,7 @@ using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Transforms;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Backgrounds;
|
||||
|
||||
@ -92,35 +93,28 @@ namespace osu.Game.Overlays.Dialog
|
||||
Buttons[index].TriggerClick();
|
||||
}
|
||||
|
||||
private bool triggeredButton = false; // used to make it so the user can't press multiple buttons at once with the keyboard
|
||||
|
||||
protected override bool OnKeyDown(Framework.Input.InputState state, Framework.Input.KeyDownEventArgs args)
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
if (args.Repeat) return false;
|
||||
|
||||
if (!triggeredButton)
|
||||
if (args.Key == Key.Enter)
|
||||
{
|
||||
if (args.Key == Key.Enter)
|
||||
{
|
||||
Buttons.OfType<PopupDialogOkButton>()?.FirstOrDefault()?.TriggerClick();
|
||||
triggeredButton = true;
|
||||
return true;
|
||||
}
|
||||
Buttons.OfType<PopupDialogOkButton>().FirstOrDefault()?.TriggerClick();
|
||||
return true;
|
||||
}
|
||||
|
||||
// press button at number if 1-9 on number row or keypad are pressed
|
||||
var k = args.Key;
|
||||
if (k >= Key.Number1 && k <= Key.Number9)
|
||||
{
|
||||
pressButtonAtIndex(k - Key.Number1);
|
||||
triggeredButton = true;
|
||||
return true;
|
||||
}
|
||||
else if (k >= Key.Keypad1 && k <= Key.Keypad9)
|
||||
{
|
||||
pressButtonAtIndex(k - Key.Keypad1);
|
||||
triggeredButton = true;
|
||||
return true;
|
||||
}
|
||||
// press button at number if 1-9 on number row or keypad are pressed
|
||||
var k = args.Key;
|
||||
if (k >= Key.Number1 && k <= Key.Number9)
|
||||
{
|
||||
pressButtonAtIndex(k - Key.Number1);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (k >= Key.Keypad1 && k <= Key.Keypad9)
|
||||
{
|
||||
pressButtonAtIndex(k - Key.Keypad1);
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnKeyDown(state, args);
|
||||
@ -130,8 +124,6 @@ namespace osu.Game.Overlays.Dialog
|
||||
{
|
||||
base.PopIn();
|
||||
|
||||
triggeredButton = false;
|
||||
|
||||
// Reset various animations but only if the dialog animation fully completed
|
||||
if (content.Alpha == 0)
|
||||
{
|
||||
|
@ -18,24 +18,28 @@ namespace osu.Game.Overlays
|
||||
|
||||
public void Push(PopupDialog dialog)
|
||||
{
|
||||
if (dialog == currentDialog) return;
|
||||
|
||||
State = Visibility.Visible;
|
||||
|
||||
dialogContainer.Add(dialog);
|
||||
dialog.Show();
|
||||
dialog.StateChanged += delegate (OverlayContainer c, Visibility v)
|
||||
{
|
||||
if (v == Visibility.Hidden)
|
||||
{
|
||||
c.Delay(PopupDialog.EXIT_DURATION);
|
||||
c.Expire();
|
||||
if (c == currentDialog)
|
||||
State = Visibility.Hidden;
|
||||
}
|
||||
};
|
||||
|
||||
var lastDialog = currentDialog;
|
||||
dialog.Show();
|
||||
dialog.StateChanged += onDialogOnStateChanged;
|
||||
|
||||
currentDialog?.Hide();
|
||||
currentDialog = dialog;
|
||||
lastDialog?.Hide();
|
||||
}
|
||||
|
||||
private void onDialogOnStateChanged(OverlayContainer dialog, Visibility v)
|
||||
{
|
||||
if (v != Visibility.Hidden) return;
|
||||
|
||||
//handle the dialog being dismissed.
|
||||
dialog.Delay(PopupDialog.EXIT_DURATION);
|
||||
dialog.Expire();
|
||||
if (dialog == currentDialog)
|
||||
State = Visibility.Hidden;
|
||||
}
|
||||
|
||||
protected override void PopIn()
|
||||
|
Loading…
Reference in New Issue
Block a user