Merge pull request #24284 from ILW8/tourney-dangerous-action-confirm

Add confirmation dialog when performing dangerous actions in tournament client
This commit is contained in:
Bartłomiej Dach 2023-07-25 18:22:17 +02:00 committed by GitHub
commit 2c0e419d86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 218 additions and 18 deletions

View File

@ -1,23 +1,100 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation; using System;
using System.Linq;
using Newtonsoft.Json;
using NUnit.Framework;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Cursor;
using osu.Game.Tournament.Screens.Editors; using osu.Game.Tournament.Screens.Editors;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Dialog;
using osu.Game.Tournament.Screens.Editors.Components;
using osuTK;
using osuTK.Input;
namespace osu.Game.Tournament.Tests.Screens namespace osu.Game.Tournament.Tests.Screens
{ {
public partial class TestSceneLadderEditorScreen : TournamentScreenTestScene public partial class TestSceneLadderEditorScreen : TournamentScreenTestScene
{ {
[BackgroundDependencyLoader] private LadderEditorScreen ladderEditorScreen = null!;
private void load() private OsuContextMenuContainer? osuContextMenuContainer;
[SetUp]
public void Setup() => Schedule(() =>
{ {
Add(new OsuContextMenuContainer ladderEditorScreen = new LadderEditorScreen();
Add(osuContextMenuContainer = new OsuContextMenuContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = new LadderEditorScreen() Child = ladderEditorScreen = new LadderEditorScreen()
}); });
});
[Test]
public void TestResetBracketTeamsCancelled()
{
Bindable<string> matchBeforeReset = new Bindable<string>();
AddStep("save current match state", () =>
{
matchBeforeReset.Value = JsonConvert.SerializeObject(Ladder.CurrentMatch.Value);
});
AddStep("pull up context menu", () =>
{
InputManager.MoveMouseTo(ladderEditorScreen);
InputManager.Click(MouseButton.Right);
});
AddStep("click Reset teams button", () =>
{
InputManager.MoveMouseTo(osuContextMenuContainer.ChildrenOfType<DrawableOsuMenuItem>().Last(p =>
((OsuMenuItem)p.Item).Type == MenuItemType.Destructive), new Vector2(5, 0));
InputManager.Click(MouseButton.Left);
});
AddAssert("dialog displayed", () => DialogOverlay.CurrentDialog is LadderResetTeamsDialog);
AddStep("click cancel", () =>
{
InputManager.MoveMouseTo(DialogOverlay.CurrentDialog.ChildrenOfType<PopupDialogButton>().Last());
InputManager.Click(MouseButton.Left);
});
AddUntilStep("dialog dismissed", () => DialogOverlay.CurrentDialog is not LadderResetTeamsDialog);
AddAssert("assert ladder teams unchanged", () => string.Equals(matchBeforeReset.Value, JsonConvert.SerializeObject(Ladder.CurrentMatch.Value), StringComparison.Ordinal));
}
[Test]
public void TestResetBracketTeams()
{
AddStep("pull up context menu", () =>
{
InputManager.MoveMouseTo(ladderEditorScreen);
InputManager.Click(MouseButton.Right);
});
AddStep("click Reset teams button", () =>
{
InputManager.MoveMouseTo(osuContextMenuContainer.ChildrenOfType<DrawableOsuMenuItem>().Last(p =>
((OsuMenuItem)p.Item).Type == MenuItemType.Destructive), new Vector2(5, 0));
InputManager.Click(MouseButton.Left);
});
AddAssert("dialog displayed", () => DialogOverlay.CurrentDialog is LadderResetTeamsDialog);
AddStep("click confirmation", () =>
{
InputManager.MoveMouseTo(DialogOverlay.CurrentDialog.ChildrenOfType<PopupDialogButton>().First());
InputManager.PressButton(MouseButton.Left);
});
AddUntilStep("dialog dismissed", () => DialogOverlay.CurrentDialog is not LadderResetTeamsDialog);
AddStep("release mouse button", () => InputManager.ReleaseButton(MouseButton.Left));
AddAssert("assert ladder teams reset", () => Ladder.CurrentMatch.Value.Team1.Value == null && Ladder.CurrentMatch.Value.Team2.Value == null);
} }
} }
} }

View File

@ -1,13 +1,15 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Game.Tournament.Screens.Editors; using osu.Game.Tournament.Screens.Editors;
namespace osu.Game.Tournament.Tests.Screens namespace osu.Game.Tournament.Tests.Screens
{ {
public partial class TestSceneRoundEditorScreen : TournamentScreenTestScene public partial class TestSceneRoundEditorScreen : TournamentScreenTestScene
{ {
public TestSceneRoundEditorScreen() [BackgroundDependencyLoader]
private void load()
{ {
Add(new RoundEditorScreen Add(new RoundEditorScreen
{ {

View File

@ -12,7 +12,8 @@ namespace osu.Game.Tournament.Tests.Screens
[Cached] [Cached]
private readonly LadderInfo ladder = new LadderInfo(); private readonly LadderInfo ladder = new LadderInfo();
public TestSceneSeedingEditorScreen() [BackgroundDependencyLoader]
private void load()
{ {
var match = CreateSampleMatch(); var match = CreateSampleMatch();

View File

@ -1,13 +1,15 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Game.Tournament.Screens.Editors; using osu.Game.Tournament.Screens.Editors;
namespace osu.Game.Tournament.Tests.Screens namespace osu.Game.Tournament.Tests.Screens
{ {
public partial class TestSceneTeamEditorScreen : TournamentScreenTestScene public partial class TestSceneTeamEditorScreen : TournamentScreenTestScene
{ {
public TestSceneTeamEditorScreen() [BackgroundDependencyLoader]
private void load()
{ {
Add(new TeamEditorScreen Add(new TeamEditorScreen
{ {

View File

@ -8,6 +8,7 @@ using osu.Framework.Platform;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Overlays;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Tests.Visual; using osu.Game.Tests.Visual;
using osu.Game.Tournament.IO; using osu.Game.Tournament.IO;
@ -16,8 +17,11 @@ using osu.Game.Tournament.Models;
namespace osu.Game.Tournament.Tests namespace osu.Game.Tournament.Tests
{ {
public abstract partial class TournamentTestScene : OsuTestScene public abstract partial class TournamentTestScene : OsuManualInputManagerTestScene
{ {
[Cached(typeof(IDialogOverlay))]
protected readonly DialogOverlay DialogOverlay = new DialogOverlay { Depth = float.MinValue };
[Cached] [Cached]
protected LadderInfo Ladder { get; private set; } = new LadderInfo(); protected LadderInfo Ladder { get; private set; } = new LadderInfo();
@ -43,6 +47,8 @@ namespace osu.Game.Tournament.Tests
Ruleset.BindTo(Ladder.Ruleset); Ruleset.BindTo(Ladder.Ruleset);
Dependencies.CacheAs(new StableInfo(storage)); Dependencies.CacheAs(new StableInfo(storage));
Add(DialogOverlay);
} }
[SetUpSteps] [SetUpSteps]

View File

@ -0,0 +1,20 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
using osu.Game.Tournament.Models;
namespace osu.Game.Tournament.Screens.Editors.Components
{
public partial class DeleteRoundDialog : DangerousActionDialog
{
public DeleteRoundDialog(TournamentRound round, Action action)
{
HeaderText = round.Name.Value.Length > 0 ? $@"Delete round ""{round.Name.Value}""?" : @"Delete unnamed round?";
Icon = FontAwesome.Solid.Trash;
DangerousAction = action;
}
}
}

View File

@ -0,0 +1,22 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
using osu.Game.Tournament.Models;
namespace osu.Game.Tournament.Screens.Editors.Components
{
public partial class DeleteTeamDialog : DangerousActionDialog
{
public DeleteTeamDialog(TournamentTeam team, Action action)
{
HeaderText = team.FullName.Value.Length > 0 ? $@"Delete team ""{team.FullName.Value}""?" :
team.Acronym.Value.Length > 0 ? $@"Delete team ""{team.Acronym.Value}""?" :
@"Delete unnamed team?";
Icon = FontAwesome.Solid.Trash;
DangerousAction = action;
}
}
}

View File

@ -0,0 +1,19 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
namespace osu.Game.Tournament.Screens.Editors.Components
{
public partial class LadderResetTeamsDialog : DangerousActionDialog
{
public LadderResetTeamsDialog(Action action)
{
HeaderText = @"Reset teams?";
Icon = FontAwesome.Solid.Undo;
DangerousAction = action;
}
}
}

View File

@ -0,0 +1,19 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
namespace osu.Game.Tournament.Screens.Editors.Components
{
public partial class TournamentClearAllDialog : DangerousActionDialog
{
public TournamentClearAllDialog(Action action)
{
HeaderText = @"Clear all?";
Icon = FontAwesome.Solid.Trash;
DangerousAction = action;
}
}
}

View File

@ -6,6 +6,7 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -16,7 +17,9 @@ using osu.Framework.Input.States;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Edit.Compose.Components; using osu.Game.Screens.Edit.Compose.Components;
using osu.Game.Tournament.Components; using osu.Game.Tournament.Components;
using osu.Game.Overlays;
using osu.Game.Tournament.Models; using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Editors.Components;
using osu.Game.Tournament.Screens.Ladder; using osu.Game.Tournament.Screens.Ladder;
using osu.Game.Tournament.Screens.Ladder.Components; using osu.Game.Tournament.Screens.Ladder.Components;
using osuTK; using osuTK;
@ -34,6 +37,10 @@ namespace osu.Game.Tournament.Screens.Editors
private WarningBox rightClickMessage; private WarningBox rightClickMessage;
[Resolved(canBeNull: true)]
[CanBeNull]
private IDialogOverlay dialogOverlay { get; set; }
protected override bool DrawLoserPaths => true; protected override bool DrawLoserPaths => true;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -87,8 +94,11 @@ namespace osu.Game.Tournament.Screens.Editors
}), }),
new OsuMenuItem("Reset teams", MenuItemType.Destructive, () => new OsuMenuItem("Reset teams", MenuItemType.Destructive, () =>
{ {
foreach (var p in MatchesContainer) dialogOverlay?.Push(new LadderResetTeamsDialog(() =>
p.Match.Reset(); {
foreach (var p in MatchesContainer)
p.Match.Reset();
}));
}) })
}; };
} }

View File

@ -11,9 +11,11 @@ using osu.Game.Graphics;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings;
using osu.Game.Tournament.Components; using osu.Game.Tournament.Components;
using osu.Game.Tournament.Models; using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Editors.Components;
using osuTK; using osuTK;
namespace osu.Game.Tournament.Screens.Editors namespace osu.Game.Tournament.Screens.Editors
@ -29,6 +31,9 @@ namespace osu.Game.Tournament.Screens.Editors
[Resolved] [Resolved]
private LadderInfo ladderInfo { get; set; } = null!; private LadderInfo ladderInfo { get; set; } = null!;
[Resolved]
private IDialogOverlay? dialogOverlay { get; set; }
public RoundRow(TournamentRound round) public RoundRow(TournamentRound round)
{ {
Model = round; Model = round;
@ -99,11 +104,11 @@ namespace osu.Game.Tournament.Screens.Editors
RelativeSizeAxes = Axes.None, RelativeSizeAxes = Axes.None,
Width = 150, Width = 150,
Text = "Delete Round", Text = "Delete Round",
Action = () => Action = () => dialogOverlay?.Push(new DeleteRoundDialog(Model, () =>
{ {
Expire(); Expire();
ladderInfo.Rounds.Remove(Model); ladderInfo.Rounds.Remove(Model);
}, }))
} }
}; };

View File

@ -11,8 +11,10 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Overlays;
using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings;
using osu.Game.Tournament.Models; using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Editors.Components;
using osu.Game.Tournament.Screens.Drawings.Components; using osu.Game.Tournament.Screens.Drawings.Components;
using osu.Game.Users; using osu.Game.Users;
using osuTK; using osuTK;
@ -61,6 +63,9 @@ namespace osu.Game.Tournament.Screens.Editors
[Resolved] [Resolved]
private TournamentSceneManager? sceneManager { get; set; } private TournamentSceneManager? sceneManager { get; set; }
[Resolved]
private IDialogOverlay? dialogOverlay { get; set; }
[Resolved] [Resolved]
private LadderInfo ladderInfo { get; set; } = null!; private LadderInfo ladderInfo { get; set; } = null!;
@ -157,11 +162,11 @@ namespace osu.Game.Tournament.Screens.Editors
Text = "Delete Team", Text = "Delete Team",
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
Action = () => Action = () => dialogOverlay?.Push(new DeleteTeamDialog(Model, () =>
{ {
Expire(); Expire();
ladderInfo.Teams.Remove(Model); ladderInfo.Teams.Remove(Model);
}, })),
}, },
} }
}, },

View File

@ -13,7 +13,9 @@ using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Overlays;
using osu.Game.Tournament.Components; using osu.Game.Tournament.Components;
using osu.Game.Tournament.Screens.Editors.Components;
using osuTK; using osuTK;
namespace osu.Game.Tournament.Screens.Editors namespace osu.Game.Tournament.Screens.Editors
@ -24,6 +26,9 @@ namespace osu.Game.Tournament.Screens.Editors
{ {
protected abstract BindableList<TModel> Storage { get; } protected abstract BindableList<TModel> Storage { get; }
[Resolved]
private IDialogOverlay? dialogOverlay { get; set; }
private FillFlowContainer<TDrawable> flow = null!; private FillFlowContainer<TDrawable> flow = null!;
[Resolved] [Resolved]
@ -79,7 +84,10 @@ namespace osu.Game.Tournament.Screens.Editors
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
BackgroundColour = colours.Pink3, BackgroundColour = colours.Pink3,
Text = "Clear all", Text = "Clear all",
Action = Storage.Clear Action = () =>
{
dialogOverlay?.Push(new TournamentClearAllDialog(() => Storage.Clear()));
}
}, },
} }
} }

View File

@ -17,6 +17,7 @@ using osu.Framework.Platform;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Tournament.Models; using osu.Game.Tournament.Models;
using osuTK.Graphics; using osuTK.Graphics;
@ -41,6 +42,9 @@ namespace osu.Game.Tournament
private LoadingSpinner loadingSpinner; private LoadingSpinner loadingSpinner;
[Cached(typeof(IDialogOverlay))]
private readonly DialogOverlay dialogOverlay = new DialogOverlay();
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(FrameworkConfigManager frameworkConfig, GameHost host) private void load(FrameworkConfigManager frameworkConfig, GameHost host)
{ {
@ -95,12 +99,12 @@ namespace osu.Game.Tournament
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = new TournamentSceneManager() Child = new TournamentSceneManager()
} },
dialogOverlay
}, drawables => }, drawables =>
{ {
loadingSpinner.Hide(); loadingSpinner.Hide();
loadingSpinner.Expire(); loadingSpinner.Expire();
AddRange(drawables); AddRange(drawables);
windowSize.BindValueChanged(size => ScheduleAfterChildren(() => windowSize.BindValueChanged(size => ScheduleAfterChildren(() =>