Added DialogManager(not wired up for desktop project yet)

This commit is contained in:
DrabWeb 2017-02-28 00:59:36 -04:00
parent fbd9523596
commit 50d172be39
7 changed files with 94 additions and 46 deletions

View File

@ -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);
}));
}
}
}

View File

@ -194,7 +194,7 @@
<Compile Include="Platform\TestStorage.cs" />
<Compile Include="Tests\TestCaseOptions.cs" />
<Compile Include="Tests\TestCasePauseOverlay.cs" />
<Compile Include="Tests\TestCasePopupDialog.cs" />
<Compile Include="Tests\TestCaseDialogManager.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup />

View File

@ -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

View File

@ -0,0 +1,75 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// 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,
},
};
}
}
}

View File

@ -12,24 +12,11 @@ namespace osu.Game
{
public Action<WorkingBeatmap> 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

View File

@ -50,8 +50,6 @@ namespace osu.Game.Screens.Select
private List<BeatmapGroup> 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;
}
/// <summary>
@ -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

View File

@ -286,6 +286,7 @@
<Compile Include="Overlays\Dialog\PopupDialogOKButton.cs" />
<Compile Include="Overlays\Dialog\PopupDialogCancelButton.cs" />
<Compile Include="Screens\Select\BeatmapDeleteDialog.cs" />
<Compile Include="Overlays\DialogManager.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj">