1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 22:22:54 +08:00

Merge branch 'master' into chatdisplay-fix

This commit is contained in:
Bartłomiej Dach 2023-06-25 17:39:45 +02:00
commit 88fbc3094a
No known key found for this signature in database
16 changed files with 222 additions and 55 deletions

View File

@ -17,6 +17,7 @@ using osu.Game.Updater;
using osu.Desktop.Windows; using osu.Desktop.Windows;
using osu.Game.IO; using osu.Game.IO;
using osu.Game.IPC; using osu.Game.IPC;
using osu.Game.Online.Multiplayer;
using osu.Game.Utils; using osu.Game.Utils;
using SDL2; using SDL2;
@ -108,6 +109,25 @@ namespace osu.Desktop
} }
} }
public override bool RestartAppWhenExited()
{
switch (RuntimeInfo.OS)
{
case RuntimeInfo.Platform.Windows:
Debug.Assert(OperatingSystem.IsWindows());
// Of note, this is an async method in squirrel that adds an arbitrary delay before returning
// likely to ensure the external process is in a good state.
//
// We're not waiting on that here, but the outro playing before the actual exit should be enough
// to cover this.
Squirrel.UpdateManager.RestartAppWhenExited().FireAndForget();
return true;
}
return base.RestartAppWhenExited();
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();

View File

@ -3,6 +3,7 @@
#nullable disable #nullable disable
using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using Moq; using Moq;
@ -250,6 +251,8 @@ namespace osu.Game.Tests.Visual.Menus
} }
public virtual IBindable<int> UnreadCount => null; public virtual IBindable<int> UnreadCount => null;
public IEnumerable<Notification> AllNotifications => Enumerable.Empty<Notification>();
} }
} }
} }

View File

@ -22,6 +22,7 @@ using osu.Game.Online.Leaderboards;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapListing; using osu.Game.Overlays.BeatmapListing;
using osu.Game.Overlays.Mods; using osu.Game.Overlays.Mods;
using osu.Game.Overlays.Notifications;
using osu.Game.Overlays.Toolbar; using osu.Game.Overlays.Toolbar;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
@ -683,6 +684,44 @@ namespace osu.Game.Tests.Visual.Navigation
AddStep("center cursor", () => InputManager.MoveMouseTo(Game.ScreenSpaceDrawQuad.Centre)); AddStep("center cursor", () => InputManager.MoveMouseTo(Game.ScreenSpaceDrawQuad.Centre));
} }
[Test]
public void TestExitWithOperationInProgress()
{
AddUntilStep("wait for dialog overlay", () => Game.ChildrenOfType<DialogOverlay>().SingleOrDefault() != null);
ProgressNotification progressNotification = null!;
AddStep("start ongoing operation", () =>
{
progressNotification = new ProgressNotification
{
Text = "Something is still running",
Progress = 0.5f,
State = ProgressNotificationState.Active,
};
Game.Notifications.Post(progressNotification);
});
AddStep("Hold escape", () => InputManager.PressKey(Key.Escape));
AddUntilStep("confirmation dialog shown", () => Game.ChildrenOfType<DialogOverlay>().Single().CurrentDialog is ConfirmExitDialog);
AddStep("Release escape", () => InputManager.ReleaseKey(Key.Escape));
AddStep("cancel exit", () => InputManager.Key(Key.Escape));
AddAssert("dialog dismissed", () => Game.ChildrenOfType<DialogOverlay>().Single().CurrentDialog == null);
AddStep("complete operation", () =>
{
progressNotification.Progress = 100;
progressNotification.State = ProgressNotificationState.Completed;
});
AddStep("Hold escape", () => InputManager.PressKey(Key.Escape));
AddUntilStep("Wait for intro", () => Game.ScreenStack.CurrentScreen is IntroScreen);
AddStep("Release escape", () => InputManager.ReleaseKey(Key.Escape));
AddUntilStep("Wait for game exit", () => Game.ScreenStack.CurrentScreen == null);
}
[Test] [Test]
public void TestExitGameFromSongSelect() public void TestExitGameFromSongSelect()
{ {
@ -699,7 +738,7 @@ namespace osu.Game.Tests.Visual.Navigation
} }
[Test] [Test]
public void TestRapidBackButtonExit() public void TestExitWithHoldDisabled()
{ {
AddStep("set hold delay to 0", () => Game.LocalConfig.SetValue(OsuSetting.UIHoldActivationDelay, 0.0)); AddStep("set hold delay to 0", () => Game.LocalConfig.SetValue(OsuSetting.UIHoldActivationDelay, 0.0));
@ -711,7 +750,7 @@ namespace osu.Game.Tests.Visual.Navigation
pushEscape(); pushEscape();
AddAssert("exit dialog is shown", () => Game.Dependencies.Get<IDialogOverlay>().CurrentDialog != null); AddAssert("exit dialog is shown", () => Game.Dependencies.Get<IDialogOverlay>().CurrentDialog is ConfirmExitDialog);
} }
private Func<Player> playToResults() private Func<Player> playToResults()

View File

@ -214,6 +214,8 @@ namespace osu.Game.Tests.Visual.UserInterface
} }
public virtual IBindable<int> UnreadCount => null; public virtual IBindable<int> UnreadCount => null;
public IEnumerable<Notification> AllNotifications => Enumerable.Empty<Notification>();
} }
// interface mocks break hot reload, mocking this stub implementation instead works around it. // interface mocks break hot reload, mocking this stub implementation instead works around it.

View File

@ -8,11 +8,11 @@ using osu.Game.Screens.Menu;
namespace osu.Game.Tests.Visual.UserInterface namespace osu.Game.Tests.Visual.UserInterface
{ {
public partial class TestSceneHoldToConfirmOverlay : OsuTestScene public partial class TestSceneHoldToExitGameOverlay : OsuTestScene
{ {
protected override double TimePerAction => 100; // required for the early exit test, since hold-to-confirm delay is 200ms protected override double TimePerAction => 100; // required for the early exit test, since hold-to-confirm delay is 200ms
public TestSceneHoldToConfirmOverlay() public TestSceneHoldToExitGameOverlay()
{ {
bool fired = false; bool fired = false;
@ -25,7 +25,7 @@ namespace osu.Game.Tests.Visual.UserInterface
Alpha = 0, Alpha = 0,
}; };
var overlay = new TestHoldToConfirmOverlay var overlay = new TestHoldToExitGameOverlay
{ {
Action = () => Action = () =>
{ {
@ -57,7 +57,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddUntilStep("wait until fired again", () => overlay.Fired); AddUntilStep("wait until fired again", () => overlay.Fired);
} }
private partial class TestHoldToConfirmOverlay : ExitConfirmOverlay private partial class TestHoldToExitGameOverlay : HoldToExitGameOverlay
{ {
public void Begin() => BeginConfirm(); public void Begin() => BeginConfirm();
} }

View File

@ -28,7 +28,11 @@ namespace osu.Game.Tournament.Screens.Setup
dropdown.Items = storage.ListTournaments(); dropdown.Items = storage.ListTournaments();
dropdown.Current.BindValueChanged(v => Button.Enabled.Value = v.NewValue != startupTournament, true); dropdown.Current.BindValueChanged(v => Button.Enabled.Value = v.NewValue != startupTournament, true);
Action = () => game.AttemptExit(); Action = () =>
{
game.RestartAppWhenExited();
game.AttemptExit();
};
folderButton.Action = () => storage.PresentExternally(); folderButton.Action = () => storage.PresentExternally();
ButtonText = "Close osu!"; ButtonText = "Close osu!";

View File

@ -83,7 +83,7 @@ namespace osu.Game
/// </summary> /// </summary>
protected const float SIDE_OVERLAY_OFFSET_RATIO = 0.05f; protected const float SIDE_OVERLAY_OFFSET_RATIO = 0.05f;
public Toolbar Toolbar; public Toolbar Toolbar { get; private set; }
private ChatOverlay chatOverlay; private ChatOverlay chatOverlay;
@ -778,8 +778,8 @@ namespace osu.Game
public override void AttemptExit() public override void AttemptExit()
{ {
// Using PerformFromScreen gives the user a chance to interrupt the exit process if needed. // The main menu exit implementation gives the user a chance to interrupt the exit process if needed.
PerformFromScreen(menu => menu.Exit()); PerformFromScreen(menu => menu.Exit(), new[] { typeof(MainMenu) });
} }
/// <summary> /// <summary>

View File

@ -515,6 +515,12 @@ namespace osu.Game
Scheduler.AddDelayed(AttemptExit, 2000); Scheduler.AddDelayed(AttemptExit, 2000);
} }
/// <summary>
/// If supported by the platform, the game will automatically restart after the next exit.
/// </summary>
/// <returns>Whether a restart operation was queued.</returns>
public virtual bool RestartAppWhenExited() => false;
public bool Migrate(string path) public bool Migrate(string path)
{ {
Logger.Log($@"Migrating osu! data from ""{Storage.GetFullPath(string.Empty)}"" to ""{path}""..."); Logger.Log($@"Migrating osu! data from ""{Storage.GetFullPath(string.Empty)}"" to ""{path}""...");

View File

@ -1,6 +1,8 @@
// 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 System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Overlays.Notifications; using osu.Game.Overlays.Notifications;
@ -28,5 +30,20 @@ namespace osu.Game.Overlays
/// Current number of unread notifications. /// Current number of unread notifications.
/// </summary> /// </summary>
IBindable<int> UnreadCount { get; } IBindable<int> UnreadCount { get; }
/// <summary>
/// Whether there are any ongoing operations, such as imports or downloads.
/// </summary>
public bool HasOngoingOperations => OngoingOperations.Any();
/// <summary>
/// All current displayed notifications, whether in the toast tray or a section.
/// </summary>
IEnumerable<Notification> AllNotifications { get; }
/// <summary>
/// All ongoing operations (ie. any <see cref="ProgressNotification"/> not in a completed state).
/// </summary>
public IEnumerable<ProgressNotification> OngoingOperations => AllNotifications.OfType<ProgressNotification>().Where(p => p.State != ProgressNotificationState.Completed);
} }
} }

View File

@ -1,6 +1,8 @@
// 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 System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
@ -33,6 +35,9 @@ namespace osu.Game.Overlays
public const float TRANSITION_LENGTH = 600; public const float TRANSITION_LENGTH = 600;
public IEnumerable<Notification> AllNotifications =>
IsLoaded ? toastTray.Notifications.Concat(sections.SelectMany(s => s.Notifications)) : Array.Empty<Notification>();
private FlowContainer<NotificationSection> sections = null!; private FlowContainer<NotificationSection> sections = null!;
[Resolved] [Resolved]

View File

@ -28,6 +28,11 @@ namespace osu.Game.Overlays
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => toastFlow.ReceivePositionalInputAt(screenSpacePos); public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => toastFlow.ReceivePositionalInputAt(screenSpacePos);
/// <summary>
/// All notifications currently being displayed by the toast tray.
/// </summary>
public IEnumerable<Notification> Notifications => toastFlow;
public bool IsDisplayingToasts => toastFlow.Count > 0; public bool IsDisplayingToasts => toastFlow.Count > 0;
private FillFlowContainer<Notification> toastFlow = null!; private FillFlowContainer<Notification> toastFlow = null!;

View File

@ -19,6 +19,11 @@ namespace osu.Game.Overlays.Notifications
{ {
public partial class NotificationSection : AlwaysUpdateFillFlowContainer<Drawable> public partial class NotificationSection : AlwaysUpdateFillFlowContainer<Drawable>
{ {
/// <summary>
/// All notifications currently being displayed in this section.
/// </summary>
public IEnumerable<Notification> Notifications => notifications;
private OsuSpriteText countDrawable = null!; private OsuSpriteText countDrawable = null!;
private FlowContainer<Notification> notifications = null!; private FlowContainer<Notification> notifications = null!;

View File

@ -67,10 +67,17 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
if (r.NewValue == RendererType.Automatic && automaticRendererInUse) if (r.NewValue == RendererType.Automatic && automaticRendererInUse)
return; return;
dialogOverlay?.Push(new ConfirmDialog(GraphicsSettingsStrings.ChangeRendererConfirmation, () => game?.AttemptExit(), () => if (game?.RestartAppWhenExited() == true)
{ {
renderer.Value = automaticRendererInUse ? RendererType.Automatic : host.ResolvedRenderer; game.AttemptExit();
})); }
else
{
dialogOverlay?.Push(new ConfirmDialog(GraphicsSettingsStrings.ChangeRendererConfirmation, () => game?.AttemptExit(), () =>
{
renderer.Value = automaticRendererInUse ? RendererType.Automatic : host.ResolvedRenderer;
}));
}
}); });
// TODO: remove this once we support SDL+android. // TODO: remove this once we support SDL+android.

View File

@ -2,38 +2,80 @@
// 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 System; using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Localisation;
using osu.Game.Overlays;
using osu.Game.Overlays.Dialog; using osu.Game.Overlays.Dialog;
namespace osu.Game.Screens.Menu namespace osu.Game.Screens.Menu
{ {
public partial class ConfirmExitDialog : PopupDialog public partial class ConfirmExitDialog : PopupDialog
{ {
private readonly Action onConfirm;
private readonly Action? onCancel;
/// <summary> /// <summary>
/// Construct a new exit confirmation dialog. /// Construct a new exit confirmation dialog.
/// </summary> /// </summary>
/// <param name="onConfirm">An action to perform on confirmation.</param> /// <param name="onConfirm">An action to perform on confirmation.</param>
/// <param name="onCancel">An optional action to perform on cancel.</param> /// <param name="onCancel">An optional action to perform on cancel.</param>
public ConfirmExitDialog(Action onConfirm, Action? onCancel = null) public ConfirmExitDialog(Action onConfirm, Action? onCancel = null)
{
this.onConfirm = onConfirm;
this.onCancel = onCancel;
}
[BackgroundDependencyLoader]
private void load(INotificationOverlay notifications)
{ {
HeaderText = "Are you sure you want to exit osu!?"; HeaderText = "Are you sure you want to exit osu!?";
BodyText = "Last chance to turn back";
Icon = FontAwesome.Solid.ExclamationTriangle; Icon = FontAwesome.Solid.ExclamationTriangle;
Buttons = new PopupDialogButton[] if (notifications.HasOngoingOperations)
{ {
new PopupDialogOkButton string text = "There are currently some background operations which will be aborted if you continue:\n\n";
foreach (var n in notifications.OngoingOperations)
text += $"{n.Text} ({n.Progress:0%})\n";
text += "\nLast chance to turn back";
BodyText = text;
Buttons = new PopupDialogButton[]
{ {
Text = @"Let me out!", new PopupDialogDangerousButton
Action = onConfirm {
}, Text = @"Let me out!",
new PopupDialogCancelButton Action = onConfirm
},
new PopupDialogCancelButton
{
Text = CommonStrings.Back,
Action = onCancel
},
};
}
else
{
BodyText = "Last chance to turn back";
Buttons = new PopupDialogButton[]
{ {
Text = @"Just a little more...", new PopupDialogOkButton
Action = onCancel {
}, Text = @"Let me out!",
}; Action = onConfirm
},
new PopupDialogCancelButton
{
Text = @"Just a little more...",
Action = onCancel
},
};
}
} }
} }
} }

View File

@ -8,13 +8,13 @@ using osu.Game.Overlays;
namespace osu.Game.Screens.Menu namespace osu.Game.Screens.Menu
{ {
public partial class ExitConfirmOverlay : HoldToConfirmOverlay, IKeyBindingHandler<GlobalAction> public partial class HoldToExitGameOverlay : HoldToConfirmOverlay, IKeyBindingHandler<GlobalAction>
{ {
protected override bool AllowMultipleFires => true; protected override bool AllowMultipleFires => true;
public void Abort() => AbortConfirm(); public void Abort() => AbortConfirm();
public ExitConfirmOverlay() public HoldToExitGameOverlay()
: base(0.7f) : base(0.7f)
{ {
} }

View File

@ -54,14 +54,20 @@ namespace osu.Game.Screens.Menu
private GameHost host { get; set; } private GameHost host { get; set; }
[Resolved] [Resolved]
private MusicController musicController { get; set; } private INotificationOverlay notifications { get; set; }
[Resolved(canBeNull: true)] [Resolved]
private LoginOverlay login { get; set; } private MusicController musicController { get; set; }
[Resolved] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
[Resolved]
private Storage storage { get; set; }
[Resolved(canBeNull: true)]
private LoginOverlay login { get; set; }
[Resolved(canBeNull: true)] [Resolved(canBeNull: true)]
private IDialogOverlay dialogOverlay { get; set; } private IDialogOverlay dialogOverlay { get; set; }
@ -72,7 +78,10 @@ namespace osu.Game.Screens.Menu
private Bindable<double> holdDelay; private Bindable<double> holdDelay;
private Bindable<bool> loginDisplayed; private Bindable<bool> loginDisplayed;
private ExitConfirmOverlay exitConfirmOverlay; private HoldToExitGameOverlay holdToExitGameOverlay;
private bool exitConfirmedViaDialog;
private bool exitConfirmedViaHoldOrClick;
private ParallaxContainer buttonsContainer; private ParallaxContainer buttonsContainer;
private SongTicker songTicker; private SongTicker songTicker;
@ -85,14 +94,12 @@ namespace osu.Game.Screens.Menu
if (host.CanExit) if (host.CanExit)
{ {
AddInternal(exitConfirmOverlay = new ExitConfirmOverlay AddInternal(holdToExitGameOverlay = new HoldToExitGameOverlay
{ {
Action = () => Action = () =>
{ {
if (holdDelay.Value > 0) exitConfirmedViaHoldOrClick = holdDelay.Value > 0;
confirmAndExit(); this.Exit();
else
this.Exit();
} }
}); });
} }
@ -114,7 +121,11 @@ namespace osu.Game.Screens.Menu
OnSolo = loadSoloSongSelect, OnSolo = loadSoloSongSelect,
OnMultiplayer = () => this.Push(new Multiplayer()), OnMultiplayer = () => this.Push(new Multiplayer()),
OnPlaylists = () => this.Push(new Playlists()), OnPlaylists = () => this.Push(new Playlists()),
OnExit = confirmAndExit, OnExit = () =>
{
exitConfirmedViaHoldOrClick = true;
this.Exit();
}
} }
} }
}, },
@ -125,7 +136,7 @@ namespace osu.Game.Screens.Menu
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
Margin = new MarginPadding { Right = 15, Top = 5 } Margin = new MarginPadding { Right = 15, Top = 5 }
}, },
exitConfirmOverlay?.CreateProxy() ?? Empty() holdToExitGameOverlay?.CreateProxy() ?? Empty()
}); });
Buttons.StateChanged += state => Buttons.StateChanged += state =>
@ -149,19 +160,8 @@ namespace osu.Game.Screens.Menu
preloadSongSelect(); preloadSongSelect();
} }
[Resolved(canBeNull: true)]
private IPerformFromScreenRunner performer { get; set; }
public void ReturnToOsuLogo() => Buttons.State = ButtonSystemState.Initial; public void ReturnToOsuLogo() => Buttons.State = ButtonSystemState.Initial;
private void confirmAndExit()
{
if (exitConfirmed) return;
exitConfirmed = true;
performer?.PerformFromScreen(menu => menu.Exit());
}
private void preloadSongSelect() private void preloadSongSelect()
{ {
if (songSelect == null) if (songSelect == null)
@ -177,9 +177,6 @@ namespace osu.Game.Screens.Menu
return s; return s;
} }
[Resolved]
private Storage storage { get; set; }
public override void OnEntering(ScreenTransitionEvent e) public override void OnEntering(ScreenTransitionEvent e)
{ {
base.OnEntering(e); base.OnEntering(e);
@ -201,8 +198,6 @@ namespace osu.Game.Screens.Menu
dialogOverlay?.Push(new StorageErrorDialog(osuStorage, osuStorage.Error)); dialogOverlay?.Push(new StorageErrorDialog(osuStorage, osuStorage.Error));
} }
private bool exitConfirmed;
protected override void LogoArriving(OsuLogo logo, bool resuming) protected override void LogoArriving(OsuLogo logo, bool resuming)
{ {
base.LogoArriving(logo, resuming); base.LogoArriving(logo, resuming);
@ -279,12 +274,29 @@ namespace osu.Game.Screens.Menu
public override bool OnExiting(ScreenExitEvent e) public override bool OnExiting(ScreenExitEvent e)
{ {
if (!exitConfirmed && dialogOverlay != null) bool requiresConfirmation =
// we need to have a dialog overlay to confirm in the first place.
dialogOverlay != null
// if the dialog has already displayed and been accepted by the user, we are good.
&& !exitConfirmedViaDialog
// Only require confirmation if there is either an ongoing operation or the user exited via a non-hold escape press.
&& (notifications.HasOngoingOperations || !exitConfirmedViaHoldOrClick);
if (requiresConfirmation)
{ {
if (dialogOverlay.CurrentDialog is ConfirmExitDialog exitDialog) if (dialogOverlay.CurrentDialog is ConfirmExitDialog exitDialog)
exitDialog.PerformOkAction(); exitDialog.PerformOkAction();
else else
dialogOverlay.Push(new ConfirmExitDialog(confirmAndExit, () => exitConfirmOverlay.Abort())); {
dialogOverlay.Push(new ConfirmExitDialog(() =>
{
exitConfirmedViaDialog = true;
this.Exit();
}, () =>
{
holdToExitGameOverlay.Abort();
}));
}
return true; return true;
} }