diff --git a/osu.Desktop.VisualTests/Tests/TestCasePopupDialog.cs b/osu.Desktop.VisualTests/Tests/TestCaseDialogManager.cs similarity index 80% rename from osu.Desktop.VisualTests/Tests/TestCasePopupDialog.cs rename to osu.Desktop.VisualTests/Tests/TestCaseDialogManager.cs index 425899661e..068b2dbb64 100644 --- a/osu.Desktop.VisualTests/Tests/TestCasePopupDialog.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseDialogManager.cs @@ -4,21 +4,25 @@ using osu.Framework.Graphics; using osu.Framework.Screens.Testing; using osu.Game.Graphics; +using osu.Game.Overlays; using osu.Game.Overlays.Dialog; namespace osu.Desktop.VisualTests.Tests { - public class TestCasePopupDialog : TestCase + public class TestCaseDialogManager : TestCase { - public override string Name => @"Popup Dialog"; + public override string Name => @"Dialog Manager"; - public override string Description => @"With various dialogs"; + public override string Description => @"Display dialogs"; public override void Reset() { base.Reset(); - var firstDialog = new PopupDialog + var manager = new DialogManager(); + Add(manager); + + AddButton("dialog #1", () => manager.Push(new PopupDialog { RelativeSizeAxes = Axes.Both, Icon = FontAwesome.fa_trash_o, @@ -37,8 +41,9 @@ namespace osu.Desktop.VisualTests.Tests Action = () => System.Console.WriteLine(@"Cancel"), }, }, - }; - var secondDialog = new PopupDialog + })); + + AddButton("dialog #2", () => manager.Push(new PopupDialog { RelativeSizeAxes = Axes.Both, Icon = FontAwesome.fa_gear, @@ -71,13 +76,7 @@ namespace osu.Desktop.VisualTests.Tests Text = @"Cancel", }, }, - }; - - Add(firstDialog); - Add(secondDialog); - - AddButton("dialog #1", firstDialog.ToggleVisibility); - AddButton("dialog #2", secondDialog.ToggleVisibility); + })); } } } diff --git a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj index 1a6cecb0d3..2d65228e40 100644 --- a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj +++ b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj @@ -194,7 +194,7 @@ - + diff --git a/osu.Game/Overlays/Dialog/PopupDialog.cs b/osu.Game/Overlays/Dialog/PopupDialog.cs index 9d54817c07..416b71b795 100644 --- a/osu.Game/Overlays/Dialog/PopupDialog.cs +++ b/osu.Game/Overlays/Dialog/PopupDialog.cs @@ -153,6 +153,7 @@ namespace osu.Game.Overlays.Dialog Anchor = Anchor.BottomCentre, Origin = Anchor.BottomCentre, Width = 0.4f, + Alpha = 0f, Children = new Drawable[] { new Container diff --git a/osu.Game/Overlays/DialogManager.cs b/osu.Game/Overlays/DialogManager.cs new file mode 100644 index 0000000000..3a9cf12b4f --- /dev/null +++ b/osu.Game/Overlays/DialogManager.cs @@ -0,0 +1,75 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transforms; +using osu.Game.Graphics; +using osu.Game.Overlays.Dialog; +using OpenTK.Graphics; + +namespace osu.Game.Overlays +{ + public class DialogManager : FocusedOverlayContainer + { + private Container dialogContainer; + private PopupDialog currentDialog; + private Container darken; + + public void Push(PopupDialog dialog) + { + State = Visibility.Visible; + + dialogContainer.Add(dialog); + dialog.Show(); + dialog.StateChanged += delegate (OverlayContainer c, Visibility v) + { + if (v == Visibility.Hidden && c == currentDialog) + State = Visibility.Hidden; + }; + + var oldDialog = currentDialog; + currentDialog = dialog; + oldDialog?.Hide(); + oldDialog?.Expire(); + } + + protected override void PopIn() + { + base.PopIn(); + darken.FadeIn(500, EasingTypes.OutQuint); + } + + protected override void PopOut() + { + base.PopOut(); + darken.FadeOut(200, EasingTypes.InSine); + } + + public DialogManager() + { + RelativeSizeAxes = Axes.Both; + + Children = new Drawable[] + { + darken = new Container + { + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black.Opacity(0.5f), + }, + }, + }, + dialogContainer = new Container + { + RelativeSizeAxes = Axes.Both, + }, + }; + } + } +} diff --git a/osu.Game/Screens/Select/BeatmapDeleteDialog.cs b/osu.Game/Screens/Select/BeatmapDeleteDialog.cs index dfec2ea9f8..e03bed8d79 100644 --- a/osu.Game/Screens/Select/BeatmapDeleteDialog.cs +++ b/osu.Game/Screens/Select/BeatmapDeleteDialog.cs @@ -12,24 +12,11 @@ namespace osu.Game { public Action OnDelete; - private WorkingBeatmap beatmap; - public WorkingBeatmap Beatmap - { - get - { - return beatmap; - } - set - { - beatmap = value; - BodyText = $@"{beatmap?.Beatmap?.Metadata?.Artist} - {beatmap?.Beatmap?.Metadata?.Title}"; - } - } - - public BeatmapDeleteDialog() + public BeatmapDeleteDialog(WorkingBeatmap beatmap) { Icon = FontAwesome.fa_trash_o; HeaderText = @"Confirm deletion of"; + BodyText = $@"{beatmap?.Beatmap?.Metadata?.Artist} - {beatmap?.Beatmap?.Metadata?.Title}"; Buttons = new PopupDialogButton[] { new PopupDialogOkButton @@ -37,10 +24,7 @@ namespace osu.Game Text = @"Yes. Totally. Delete it.", Action = () => { - if (Beatmap != null) - { - OnDelete?.Invoke(Beatmap); - } + OnDelete?.Invoke(beatmap); }, }, new PopupDialogCancelButton diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index e2f15ac845..cd96070e32 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -50,8 +50,6 @@ namespace osu.Game.Screens.Select private List beatmapGroups; - private BeatmapDeleteDialog deleteDialog; - private Footer footer; OsuScreen player; @@ -125,15 +123,6 @@ namespace osu.Game.Screens.Select })).LoadAsync(Game, l => Push(player)); } }, - deleteDialog = new BeatmapDeleteDialog - { - RelativeSizeAxes = Axes.Both, - OnDelete = (b) => - { - b.Dispose(); - database.Delete(b.BeatmapSetInfo); - }, - }, }; footer.AddButton(@"mods", colours.Yellow, null); @@ -291,7 +280,6 @@ namespace osu.Game.Screens.Select //todo: change background in selectionChanged instead; support per-difficulty backgrounds. changeBackground(beatmap); carousel.SelectBeatmap(beatmap?.BeatmapInfo); - deleteDialog.Beatmap = beatmap; } /// @@ -396,7 +384,7 @@ namespace osu.Game.Screens.Select case Key.Delete: if (state.Keyboard.ShiftPressed) { - deleteDialog.Show(); + // TODO: Delete beatmap dialog here return true; } else diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 324382f383..3c5b612c79 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -286,6 +286,7 @@ +