mirror of
https://github.com/osukey/osukey.git
synced 2025-05-17 03:27:21 +09: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.Primitives;
|
||||||
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;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Backgrounds;
|
using osu.Game.Graphics.Backgrounds;
|
||||||
|
|
||||||
@ -92,35 +93,28 @@ namespace osu.Game.Overlays.Dialog
|
|||||||
Buttons[index].TriggerClick();
|
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(InputState state, KeyDownEventArgs args)
|
||||||
|
|
||||||
protected override bool OnKeyDown(Framework.Input.InputState state, Framework.Input.KeyDownEventArgs args)
|
|
||||||
{
|
{
|
||||||
if (args.Repeat) return false;
|
if (args.Repeat) return false;
|
||||||
|
|
||||||
if (!triggeredButton)
|
if (args.Key == Key.Enter)
|
||||||
{
|
{
|
||||||
if (args.Key == Key.Enter)
|
Buttons.OfType<PopupDialogOkButton>().FirstOrDefault()?.TriggerClick();
|
||||||
{
|
return true;
|
||||||
Buttons.OfType<PopupDialogOkButton>()?.FirstOrDefault()?.TriggerClick();
|
}
|
||||||
triggeredButton = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// press button at number if 1-9 on number row or keypad are pressed
|
// press button at number if 1-9 on number row or keypad are pressed
|
||||||
var k = args.Key;
|
var k = args.Key;
|
||||||
if (k >= Key.Number1 && k <= Key.Number9)
|
if (k >= Key.Number1 && k <= Key.Number9)
|
||||||
{
|
{
|
||||||
pressButtonAtIndex(k - Key.Number1);
|
pressButtonAtIndex(k - Key.Number1);
|
||||||
triggeredButton = true;
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
else if (k >= Key.Keypad1 && k <= Key.Keypad9)
|
if (k >= Key.Keypad1 && k <= Key.Keypad9)
|
||||||
{
|
{
|
||||||
pressButtonAtIndex(k - Key.Keypad1);
|
pressButtonAtIndex(k - Key.Keypad1);
|
||||||
triggeredButton = true;
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.OnKeyDown(state, args);
|
return base.OnKeyDown(state, args);
|
||||||
@ -130,8 +124,6 @@ namespace osu.Game.Overlays.Dialog
|
|||||||
{
|
{
|
||||||
base.PopIn();
|
base.PopIn();
|
||||||
|
|
||||||
triggeredButton = false;
|
|
||||||
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
|
@ -18,24 +18,28 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
public void Push(PopupDialog dialog)
|
public void Push(PopupDialog dialog)
|
||||||
{
|
{
|
||||||
|
if (dialog == currentDialog) return;
|
||||||
|
|
||||||
State = Visibility.Visible;
|
State = Visibility.Visible;
|
||||||
|
|
||||||
dialogContainer.Add(dialog);
|
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;
|
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()
|
protected override void PopIn()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user