mirror of
https://github.com/ppy/osu.git
synced 2024-11-12 10:17:32 +08:00
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:
commit
2c0e419d86
@ -1,23 +1,100 @@
|
||||
// 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 osu.Framework.Allocation;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics.Cursor;
|
||||
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
|
||||
{
|
||||
public partial class TestSceneLadderEditorScreen : TournamentScreenTestScene
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
private LadderEditorScreen ladderEditorScreen = null!;
|
||||
private OsuContextMenuContainer? osuContextMenuContainer;
|
||||
|
||||
[SetUp]
|
||||
public void Setup() => Schedule(() =>
|
||||
{
|
||||
Add(new OsuContextMenuContainer
|
||||
ladderEditorScreen = new LadderEditorScreen();
|
||||
Add(osuContextMenuContainer = new OsuContextMenuContainer
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,15 @@
|
||||
// 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 osu.Framework.Allocation;
|
||||
using osu.Game.Tournament.Screens.Editors;
|
||||
|
||||
namespace osu.Game.Tournament.Tests.Screens
|
||||
{
|
||||
public partial class TestSceneRoundEditorScreen : TournamentScreenTestScene
|
||||
{
|
||||
public TestSceneRoundEditorScreen()
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Add(new RoundEditorScreen
|
||||
{
|
||||
|
@ -12,7 +12,8 @@ namespace osu.Game.Tournament.Tests.Screens
|
||||
[Cached]
|
||||
private readonly LadderInfo ladder = new LadderInfo();
|
||||
|
||||
public TestSceneSeedingEditorScreen()
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
var match = CreateSampleMatch();
|
||||
|
||||
|
@ -1,13 +1,15 @@
|
||||
// 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 osu.Framework.Allocation;
|
||||
using osu.Game.Tournament.Screens.Editors;
|
||||
|
||||
namespace osu.Game.Tournament.Tests.Screens
|
||||
{
|
||||
public partial class TestSceneTeamEditorScreen : TournamentScreenTestScene
|
||||
{
|
||||
public TestSceneTeamEditorScreen()
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Add(new TeamEditorScreen
|
||||
{
|
||||
|
@ -8,6 +8,7 @@ using osu.Framework.Platform;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Tests.Visual;
|
||||
using osu.Game.Tournament.IO;
|
||||
@ -16,8 +17,11 @@ using osu.Game.Tournament.Models;
|
||||
|
||||
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]
|
||||
protected LadderInfo Ladder { get; private set; } = new LadderInfo();
|
||||
|
||||
@ -43,6 +47,8 @@ namespace osu.Game.Tournament.Tests
|
||||
|
||||
Ruleset.BindTo(Ladder.Ruleset);
|
||||
Dependencies.CacheAs(new StableInfo(storage));
|
||||
|
||||
Add(DialogOverlay);
|
||||
}
|
||||
|
||||
[SetUpSteps]
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -16,7 +17,9 @@ using osu.Framework.Input.States;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Screens.Edit.Compose.Components;
|
||||
using osu.Game.Tournament.Components;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Tournament.Models;
|
||||
using osu.Game.Tournament.Screens.Editors.Components;
|
||||
using osu.Game.Tournament.Screens.Ladder;
|
||||
using osu.Game.Tournament.Screens.Ladder.Components;
|
||||
using osuTK;
|
||||
@ -34,6 +37,10 @@ namespace osu.Game.Tournament.Screens.Editors
|
||||
|
||||
private WarningBox rightClickMessage;
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
[CanBeNull]
|
||||
private IDialogOverlay dialogOverlay { get; set; }
|
||||
|
||||
protected override bool DrawLoserPaths => true;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -86,9 +93,12 @@ namespace osu.Game.Tournament.Screens.Editors
|
||||
editorInfo.Selected.Value = newMatch;
|
||||
}),
|
||||
new OsuMenuItem("Reset teams", MenuItemType.Destructive, () =>
|
||||
{
|
||||
dialogOverlay?.Push(new LadderResetTeamsDialog(() =>
|
||||
{
|
||||
foreach (var p in MatchesContainer)
|
||||
p.Match.Reset();
|
||||
}));
|
||||
})
|
||||
};
|
||||
}
|
||||
|
@ -11,9 +11,11 @@ using osu.Game.Graphics;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Settings;
|
||||
using osu.Game.Tournament.Components;
|
||||
using osu.Game.Tournament.Models;
|
||||
using osu.Game.Tournament.Screens.Editors.Components;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Tournament.Screens.Editors
|
||||
@ -29,6 +31,9 @@ namespace osu.Game.Tournament.Screens.Editors
|
||||
[Resolved]
|
||||
private LadderInfo ladderInfo { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private IDialogOverlay? dialogOverlay { get; set; }
|
||||
|
||||
public RoundRow(TournamentRound round)
|
||||
{
|
||||
Model = round;
|
||||
@ -99,11 +104,11 @@ namespace osu.Game.Tournament.Screens.Editors
|
||||
RelativeSizeAxes = Axes.None,
|
||||
Width = 150,
|
||||
Text = "Delete Round",
|
||||
Action = () =>
|
||||
Action = () => dialogOverlay?.Push(new DeleteRoundDialog(Model, () =>
|
||||
{
|
||||
Expire();
|
||||
ladderInfo.Rounds.Remove(Model);
|
||||
},
|
||||
}))
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -11,8 +11,10 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Settings;
|
||||
using osu.Game.Tournament.Models;
|
||||
using osu.Game.Tournament.Screens.Editors.Components;
|
||||
using osu.Game.Tournament.Screens.Drawings.Components;
|
||||
using osu.Game.Users;
|
||||
using osuTK;
|
||||
@ -61,6 +63,9 @@ namespace osu.Game.Tournament.Screens.Editors
|
||||
[Resolved]
|
||||
private TournamentSceneManager? sceneManager { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private IDialogOverlay? dialogOverlay { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private LadderInfo ladderInfo { get; set; } = null!;
|
||||
|
||||
@ -157,11 +162,11 @@ namespace osu.Game.Tournament.Screens.Editors
|
||||
Text = "Delete Team",
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
Action = () =>
|
||||
Action = () => dialogOverlay?.Push(new DeleteTeamDialog(Model, () =>
|
||||
{
|
||||
Expire();
|
||||
ladderInfo.Teams.Remove(Model);
|
||||
},
|
||||
})),
|
||||
},
|
||||
}
|
||||
},
|
||||
|
@ -13,7 +13,9 @@ using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Tournament.Components;
|
||||
using osu.Game.Tournament.Screens.Editors.Components;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Tournament.Screens.Editors
|
||||
@ -24,6 +26,9 @@ namespace osu.Game.Tournament.Screens.Editors
|
||||
{
|
||||
protected abstract BindableList<TModel> Storage { get; }
|
||||
|
||||
[Resolved]
|
||||
private IDialogOverlay? dialogOverlay { get; set; }
|
||||
|
||||
private FillFlowContainer<TDrawable> flow = null!;
|
||||
|
||||
[Resolved]
|
||||
@ -79,7 +84,10 @@ namespace osu.Game.Tournament.Screens.Editors
|
||||
RelativeSizeAxes = Axes.X,
|
||||
BackgroundColour = colours.Pink3,
|
||||
Text = "Clear all",
|
||||
Action = Storage.Clear
|
||||
Action = () =>
|
||||
{
|
||||
dialogOverlay?.Push(new TournamentClearAllDialog(() => Storage.Clear()));
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ using osu.Framework.Platform;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Cursor;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Tournament.Models;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@ -41,6 +42,9 @@ namespace osu.Game.Tournament
|
||||
|
||||
private LoadingSpinner loadingSpinner;
|
||||
|
||||
[Cached(typeof(IDialogOverlay))]
|
||||
private readonly DialogOverlay dialogOverlay = new DialogOverlay();
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(FrameworkConfigManager frameworkConfig, GameHost host)
|
||||
{
|
||||
@ -95,12 +99,12 @@ namespace osu.Game.Tournament
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new TournamentSceneManager()
|
||||
}
|
||||
},
|
||||
dialogOverlay
|
||||
}, drawables =>
|
||||
{
|
||||
loadingSpinner.Hide();
|
||||
loadingSpinner.Expire();
|
||||
|
||||
AddRange(drawables);
|
||||
|
||||
windowSize.BindValueChanged(size => ScheduleAfterChildren(() =>
|
||||
|
Loading…
Reference in New Issue
Block a user