From befdf68abec79c1d1a08678c03ee8cd3fc891397 Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Wed, 1 Mar 2017 18:41:00 -0400 Subject: [PATCH] Made DialogOverlay use PopupDialog's direct valfixed last dialogs not expiring, DialogOverlay actually hides now, fixed an issue where multiple buttons could be pressed at once --- osu.Game/Overlays/Dialog/PopupDialog.cs | 54 ++++++++++++++--------- osu.Game/Overlays/DialogOverlay.cs | 17 ++++--- osu.Game/Screens/Select/PlaySongSelect.cs | 4 +- 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/osu.Game/Overlays/Dialog/PopupDialog.cs b/osu.Game/Overlays/Dialog/PopupDialog.cs index 4c95b53822..587deda932 100644 --- a/osu.Game/Overlays/Dialog/PopupDialog.cs +++ b/osu.Game/Overlays/Dialog/PopupDialog.cs @@ -18,8 +18,8 @@ namespace osu.Game.Overlays.Dialog { public class PopupDialog : FocusedOverlayContainer { - private const float enter_duration = 500; - private const float exit_duration = 200; + public static readonly float ENTER_DURATION = 500; + public static readonly float EXIT_DURATION = 200; private readonly Vector2 ringSize = new Vector2(100f); private readonly Vector2 ringMinifiedSize = new Vector2(20f); private readonly Vector2 buttonsEnterSpacing = new Vector2(0f, 50f); @@ -92,27 +92,35 @@ 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) { if (args.Repeat) return false; - if (args.Key == Key.Enter) + if (!triggeredButton) { - Buttons.OfType()?.FirstOrDefault()?.TriggerClick(); - return true; - } + if (args.Key == Key.Enter) + { + Buttons.OfType()?.FirstOrDefault()?.TriggerClick(); + 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; - } - else if (k >= Key.Keypad1 && k <= Key.Keypad9) - { - pressButtonAtIndex(k - Key.Keypad1); - 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; + } } return base.OnKeyDown(state, args); @@ -122,6 +130,8 @@ namespace osu.Game.Overlays.Dialog { base.PopIn(); + triggeredButton = false; + // Reset various animations but only if the dialog animation fully completed if (content.Alpha == 0) { @@ -130,17 +140,17 @@ namespace osu.Game.Overlays.Dialog ring.ResizeTo(ringMinifiedSize); } - content.FadeIn(enter_duration, EasingTypes.OutQuint); - ring.ResizeTo(ringSize, enter_duration, EasingTypes.OutQuint); - buttonsContainer.TransformSpacingTo(Vector2.Zero, enter_duration, EasingTypes.OutQuint); - buttonsContainer.MoveToY(0, enter_duration, EasingTypes.OutQuint); + content.FadeIn(ENTER_DURATION, EasingTypes.OutQuint); + ring.ResizeTo(ringSize, ENTER_DURATION, EasingTypes.OutQuint); + buttonsContainer.TransformSpacingTo(Vector2.Zero, ENTER_DURATION, EasingTypes.OutQuint); + buttonsContainer.MoveToY(0, ENTER_DURATION, EasingTypes.OutQuint); } protected override void PopOut() { base.PopOut(); - content.FadeOut(exit_duration, EasingTypes.InSine); + content.FadeOut(EXIT_DURATION, EasingTypes.InSine); } public PopupDialog() diff --git a/osu.Game/Overlays/DialogOverlay.cs b/osu.Game/Overlays/DialogOverlay.cs index 7434eed852..c4a6103a85 100644 --- a/osu.Game/Overlays/DialogOverlay.cs +++ b/osu.Game/Overlays/DialogOverlay.cs @@ -15,7 +15,6 @@ namespace osu.Game.Overlays { private Container dialogContainer; private PopupDialog currentDialog; - private Container darken; public void Push(PopupDialog dialog) { @@ -25,26 +24,30 @@ namespace osu.Game.Overlays dialog.Show(); dialog.StateChanged += delegate (OverlayContainer c, Visibility v) { - if (v == Visibility.Hidden && c == currentDialog) - State = Visibility.Hidden; + if (v == Visibility.Hidden) + { + c.Delay(PopupDialog.EXIT_DURATION); + c.Expire(); + if (c == currentDialog) + State = Visibility.Hidden; + } }; var lastDialog = currentDialog; currentDialog = dialog; lastDialog?.Hide(); - lastDialog?.Expire(); } protected override void PopIn() { base.PopIn(); - darken.FadeIn(500, EasingTypes.OutQuint); + FadeIn(PopupDialog.ENTER_DURATION, EasingTypes.OutQuint); } protected override void PopOut() { base.PopOut(); - darken.FadeOut(200, EasingTypes.InSine); + FadeOut(PopupDialog.EXIT_DURATION, EasingTypes.InSine); } public DialogOverlay() @@ -53,7 +56,7 @@ namespace osu.Game.Overlays Children = new Drawable[] { - darken = new Container + new Container { RelativeSizeAxes = Axes.Both, Children = new Drawable[] diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index 867db8df09..06dc321f3b 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -59,7 +59,7 @@ namespace osu.Game.Screens.Select FilterControl filter; [BackgroundDependencyLoader(permitNulls: true)] - private void load(BeatmapDatabase beatmaps, AudioManager audio, /*DialogOverlay dialog,*/ Framework.Game game, + private void load(BeatmapDatabase beatmaps, AudioManager audio, DialogOverlay dialog, Framework.Game game, OsuGame osuGame, OsuColour colours) { const float carousel_width = 640; @@ -144,7 +144,7 @@ namespace osu.Game.Screens.Select database.BeatmapSetRemoved += onBeatmapSetRemoved; trackManager = audio.Track; - //dialogOverlay = dialog; + dialogOverlay = dialog; sampleChangeDifficulty = audio.Sample.Get(@"SongSelect/select-difficulty"); sampleChangeBeatmap = audio.Sample.Get(@"SongSelect/select-expand");