1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-22 00:43:25 +08:00

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

This commit is contained in:
DrabWeb 2017-03-01 18:41:00 -04:00
parent d5d8352b62
commit befdf68abe
3 changed files with 44 additions and 31 deletions

View File

@ -18,8 +18,8 @@ namespace osu.Game.Overlays.Dialog
{ {
public class PopupDialog : FocusedOverlayContainer public class PopupDialog : FocusedOverlayContainer
{ {
private const float enter_duration = 500; public static readonly float ENTER_DURATION = 500;
private const float exit_duration = 200; public static readonly float EXIT_DURATION = 200;
private readonly Vector2 ringSize = new Vector2(100f); private readonly Vector2 ringSize = new Vector2(100f);
private readonly Vector2 ringMinifiedSize = new Vector2(20f); private readonly Vector2 ringMinifiedSize = new Vector2(20f);
private readonly Vector2 buttonsEnterSpacing = new Vector2(0f, 50f); private readonly Vector2 buttonsEnterSpacing = new Vector2(0f, 50f);
@ -92,27 +92,35 @@ 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(Framework.Input.InputState state, Framework.Input.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 (args.Key == Key.Enter) if (!triggeredButton)
{ {
Buttons.OfType<PopupDialogOkButton>()?.FirstOrDefault()?.TriggerClick(); if (args.Key == Key.Enter)
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);
return true; triggeredButton = true;
} return true;
else if (k >= Key.Keypad1 && k <= Key.Keypad9) }
{ else if (k >= Key.Keypad1 && k <= Key.Keypad9)
pressButtonAtIndex(k - Key.Keypad1); {
return true; pressButtonAtIndex(k - Key.Keypad1);
triggeredButton = true;
return true;
}
} }
return base.OnKeyDown(state, args); return base.OnKeyDown(state, args);
@ -122,6 +130,8 @@ 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)
{ {
@ -130,17 +140,17 @@ namespace osu.Game.Overlays.Dialog
ring.ResizeTo(ringMinifiedSize); ring.ResizeTo(ringMinifiedSize);
} }
content.FadeIn(enter_duration, EasingTypes.OutQuint); content.FadeIn(ENTER_DURATION, EasingTypes.OutQuint);
ring.ResizeTo(ringSize, enter_duration, EasingTypes.OutQuint); ring.ResizeTo(ringSize, ENTER_DURATION, EasingTypes.OutQuint);
buttonsContainer.TransformSpacingTo(Vector2.Zero, enter_duration, EasingTypes.OutQuint); buttonsContainer.TransformSpacingTo(Vector2.Zero, ENTER_DURATION, EasingTypes.OutQuint);
buttonsContainer.MoveToY(0, enter_duration, EasingTypes.OutQuint); buttonsContainer.MoveToY(0, ENTER_DURATION, EasingTypes.OutQuint);
} }
protected override void PopOut() protected override void PopOut()
{ {
base.PopOut(); base.PopOut();
content.FadeOut(exit_duration, EasingTypes.InSine); content.FadeOut(EXIT_DURATION, EasingTypes.InSine);
} }
public PopupDialog() public PopupDialog()

View File

@ -15,7 +15,6 @@ namespace osu.Game.Overlays
{ {
private Container dialogContainer; private Container dialogContainer;
private PopupDialog currentDialog; private PopupDialog currentDialog;
private Container darken;
public void Push(PopupDialog dialog) public void Push(PopupDialog dialog)
{ {
@ -25,26 +24,30 @@ namespace osu.Game.Overlays
dialog.Show(); dialog.Show();
dialog.StateChanged += delegate (OverlayContainer c, Visibility v) dialog.StateChanged += delegate (OverlayContainer c, Visibility v)
{ {
if (v == Visibility.Hidden && c == currentDialog) if (v == Visibility.Hidden)
State = Visibility.Hidden; {
c.Delay(PopupDialog.EXIT_DURATION);
c.Expire();
if (c == currentDialog)
State = Visibility.Hidden;
}
}; };
var lastDialog = currentDialog; var lastDialog = currentDialog;
currentDialog = dialog; currentDialog = dialog;
lastDialog?.Hide(); lastDialog?.Hide();
lastDialog?.Expire();
} }
protected override void PopIn() protected override void PopIn()
{ {
base.PopIn(); base.PopIn();
darken.FadeIn(500, EasingTypes.OutQuint); FadeIn(PopupDialog.ENTER_DURATION, EasingTypes.OutQuint);
} }
protected override void PopOut() protected override void PopOut()
{ {
base.PopOut(); base.PopOut();
darken.FadeOut(200, EasingTypes.InSine); FadeOut(PopupDialog.EXIT_DURATION, EasingTypes.InSine);
} }
public DialogOverlay() public DialogOverlay()
@ -53,7 +56,7 @@ namespace osu.Game.Overlays
Children = new Drawable[] Children = new Drawable[]
{ {
darken = new Container new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Children = new Drawable[] Children = new Drawable[]

View File

@ -59,7 +59,7 @@ namespace osu.Game.Screens.Select
FilterControl filter; FilterControl filter;
[BackgroundDependencyLoader(permitNulls: true)] [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) OsuGame osuGame, OsuColour colours)
{ {
const float carousel_width = 640; const float carousel_width = 640;
@ -144,7 +144,7 @@ namespace osu.Game.Screens.Select
database.BeatmapSetRemoved += onBeatmapSetRemoved; database.BeatmapSetRemoved += onBeatmapSetRemoved;
trackManager = audio.Track; trackManager = audio.Track;
//dialogOverlay = dialog; dialogOverlay = dialog;
sampleChangeDifficulty = audio.Sample.Get(@"SongSelect/select-difficulty"); sampleChangeDifficulty = audio.Sample.Get(@"SongSelect/select-difficulty");
sampleChangeBeatmap = audio.Sample.Get(@"SongSelect/select-expand"); sampleChangeBeatmap = audio.Sample.Get(@"SongSelect/select-expand");