mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 13:22:55 +08:00
Merge pull request #13627 from Joehuu/fix-multiplayer-exit-logic
Fix multiplayer leave dialog not working on all exit operations
This commit is contained in:
commit
151dfdfb79
@ -55,7 +55,12 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
[Test]
|
||||
public void TestExitWithoutSave()
|
||||
{
|
||||
AddStep("exit without save", () => Editor.Exit());
|
||||
AddStep("exit without save", () =>
|
||||
{
|
||||
Editor.Exit();
|
||||
DialogOverlay.CurrentDialog.PerformOkAction();
|
||||
});
|
||||
|
||||
AddUntilStep("wait for exit", () => !Editor.IsCurrentScreen());
|
||||
AddAssert("new beatmap not persisted", () => beatmapManager.QueryBeatmapSet(s => s.ID == EditorBeatmap.BeatmapInfo.BeatmapSet.ID)?.DeletePending == true);
|
||||
}
|
||||
|
@ -6,15 +6,20 @@ using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Rulesets.Osu.Mods;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Screens.OnlinePlay.Match.Components;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
||||
using osu.Game.Tests.Resources;
|
||||
@ -159,6 +164,50 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
AddUntilStep("play started", () => !multiplayerScreen.IsCurrentScreen());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLeaveNavigation()
|
||||
{
|
||||
loadMultiplayer();
|
||||
|
||||
createRoom(() => new Room
|
||||
{
|
||||
Name = { Value = "Test Room" },
|
||||
Playlist =
|
||||
{
|
||||
new PlaylistItem
|
||||
{
|
||||
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
||||
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
||||
AllowedMods = { new OsuModHidden() }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AddStep("open mod overlay", () => this.ChildrenOfType<PurpleTriangleButton>().ElementAt(2).Click());
|
||||
|
||||
AddStep("invoke on back button", () => multiplayerScreen.OnBackButton());
|
||||
|
||||
AddAssert("mod overlay is hidden", () => this.ChildrenOfType<LocalPlayerModSelectOverlay>().Single().State.Value == Visibility.Hidden);
|
||||
|
||||
AddAssert("dialog overlay is hidden", () => DialogOverlay.State.Value == Visibility.Hidden);
|
||||
|
||||
testLeave("lounge tab item", () => this.ChildrenOfType<BreadcrumbControl<IScreen>.BreadcrumbTabItem>().First().Click());
|
||||
|
||||
testLeave("back button", () => multiplayerScreen.OnBackButton());
|
||||
|
||||
// mimics home button and OS window close
|
||||
testLeave("forced exit", () => multiplayerScreen.Exit());
|
||||
|
||||
void testLeave(string actionName, Action action)
|
||||
{
|
||||
AddStep($"leave via {actionName}", action);
|
||||
|
||||
AddAssert("dialog overlay is visible", () => DialogOverlay.State.Value == Visibility.Visible);
|
||||
|
||||
AddStep("close dialog overlay", () => InputManager.Key(Key.Escape));
|
||||
}
|
||||
}
|
||||
|
||||
private void createRoom(Func<Room> room)
|
||||
{
|
||||
AddStep("open room", () =>
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System.Linq;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Screens;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
@ -19,8 +20,13 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
if (stack.CurrentScreen != null)
|
||||
onPushed(null, stack.CurrentScreen);
|
||||
}
|
||||
|
||||
Current.ValueChanged += current => current.NewValue.MakeCurrent();
|
||||
protected override void SelectTab(TabItem<IScreen> tab)
|
||||
{
|
||||
// override base method to prevent current item from being changed on click.
|
||||
// depend on screen push/exit to change current item instead.
|
||||
tab.Value.MakeCurrent();
|
||||
}
|
||||
|
||||
private void onPushed(IScreen lastScreen, IScreen newScreen)
|
||||
|
@ -305,18 +305,34 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnBackButton();
|
||||
}
|
||||
|
||||
public override bool OnExiting(IScreen next)
|
||||
{
|
||||
if (client.Room == null)
|
||||
{
|
||||
// room has not been created yet; exit immediately.
|
||||
return base.OnExiting(next);
|
||||
}
|
||||
|
||||
if (!exitConfirmed && dialogOverlay != null)
|
||||
{
|
||||
dialogOverlay.Push(new ConfirmDialog("Are you sure you want to leave this multiplayer match?", () =>
|
||||
if (dialogOverlay.CurrentDialog is ConfirmDialog confirmDialog)
|
||||
confirmDialog.PerformOkAction();
|
||||
else
|
||||
{
|
||||
exitConfirmed = true;
|
||||
this.Exit();
|
||||
}));
|
||||
dialogOverlay.Push(new ConfirmDialog("Are you sure you want to leave this multiplayer match?", () =>
|
||||
{
|
||||
exitConfirmed = true;
|
||||
this.Exit();
|
||||
}));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnBackButton();
|
||||
return base.OnExiting(next);
|
||||
}
|
||||
|
||||
private ModSettingChangeTracker modSettingChangeTracker;
|
||||
|
@ -240,13 +240,15 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
|
||||
public override bool OnExiting(IScreen next)
|
||||
{
|
||||
if (screenStack.CurrentScreen?.OnExiting(next) == true)
|
||||
return true;
|
||||
|
||||
RoomManager.PartRoom();
|
||||
|
||||
waves.Hide();
|
||||
|
||||
this.Delay(WaveContainer.DISAPPEAR_DURATION).FadeOut();
|
||||
|
||||
screenStack.CurrentScreen?.OnExiting(next);
|
||||
base.OnExiting(next);
|
||||
return false;
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
// 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.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Screens;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
@ -19,12 +21,16 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
|
||||
[Cached]
|
||||
protected DialogOverlay DialogOverlay { get; private set; }
|
||||
|
||||
protected ScreenTestScene()
|
||||
{
|
||||
base.Content.AddRange(new Drawable[]
|
||||
{
|
||||
Stack = new OsuScreenStack { RelativeSizeAxes = Axes.Both },
|
||||
content = new Container { RelativeSizeAxes = Axes.Both }
|
||||
content = new Container { RelativeSizeAxes = Axes.Both },
|
||||
DialogOverlay = new DialogOverlay()
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user