From c4871bbbf33326f26a65eeefd0995cfe60159acc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 2 Mar 2017 17:08:00 +0900 Subject: [PATCH] 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. --- osu.Game/Overlays/Dialog/PopupDialog.cs | 44 ++++++++++--------------- osu.Game/Overlays/DialogOverlay.cs | 30 +++++++++-------- 2 files changed, 35 insertions(+), 39 deletions(-) diff --git a/osu.Game/Overlays/Dialog/PopupDialog.cs b/osu.Game/Overlays/Dialog/PopupDialog.cs index f1575f21cd..07aea4965c 100644 --- a/osu.Game/Overlays/Dialog/PopupDialog.cs +++ b/osu.Game/Overlays/Dialog/PopupDialog.cs @@ -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()?.FirstOrDefault()?.TriggerClick(); - triggeredButton = true; - return true; - } + Buttons.OfType().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) { diff --git a/osu.Game/Overlays/DialogOverlay.cs b/osu.Game/Overlays/DialogOverlay.cs index c4a6103a85..31dbd4390f 100644 --- a/osu.Game/Overlays/DialogOverlay.cs +++ b/osu.Game/Overlays/DialogOverlay.cs @@ -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()