1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 04:52:57 +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.Game.IO;
using osu.Game.IPC;
using osu.Game.Online.Multiplayer;
using osu.Game.Utils;
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()
{
base.LoadComplete();

View File

@ -3,6 +3,7 @@
#nullable disable
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Moq;
@ -250,6 +251,8 @@ namespace osu.Game.Tests.Visual.Menus
}
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.BeatmapListing;
using osu.Game.Overlays.Mods;
using osu.Game.Overlays.Notifications;
using osu.Game.Overlays.Toolbar;
using osu.Game.Rulesets.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));
}
[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]
public void TestExitGameFromSongSelect()
{
@ -699,7 +738,7 @@ namespace osu.Game.Tests.Visual.Navigation
}
[Test]
public void TestRapidBackButtonExit()
public void TestExitWithHoldDisabled()
{
AddStep("set hold delay to 0", () => Game.LocalConfig.SetValue(OsuSetting.UIHoldActivationDelay, 0.0));
@ -711,7 +750,7 @@ namespace osu.Game.Tests.Visual.Navigation
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()

View File

@ -214,6 +214,8 @@ namespace osu.Game.Tests.Visual.UserInterface
}
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.

View File

@ -8,11 +8,11 @@ using osu.Game.Screens.Menu;
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
public TestSceneHoldToConfirmOverlay()
public TestSceneHoldToExitGameOverlay()
{
bool fired = false;
@ -25,7 +25,7 @@ namespace osu.Game.Tests.Visual.UserInterface
Alpha = 0,
};
var overlay = new TestHoldToConfirmOverlay
var overlay = new TestHoldToExitGameOverlay
{
Action = () =>
{
@ -57,7 +57,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddUntilStep("wait until fired again", () => overlay.Fired);
}
private partial class TestHoldToConfirmOverlay : ExitConfirmOverlay
private partial class TestHoldToExitGameOverlay : HoldToExitGameOverlay
{
public void Begin() => BeginConfirm();
}

View File

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

View File

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

View File

@ -515,6 +515,12 @@ namespace osu.Game
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)
{
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.
// 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.Bindables;
using osu.Game.Overlays.Notifications;
@ -28,5 +30,20 @@ namespace osu.Game.Overlays
/// Current number of unread notifications.
/// </summary>
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.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
@ -33,6 +35,9 @@ namespace osu.Game.Overlays
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!;
[Resolved]

View File

@ -28,6 +28,11 @@ namespace osu.Game.Overlays
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;
private FillFlowContainer<Notification> toastFlow = null!;

View File

@ -19,6 +19,11 @@ namespace osu.Game.Overlays.Notifications
{
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 FlowContainer<Notification> notifications = null!;

View File

@ -67,10 +67,17 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
if (r.NewValue == RendererType.Automatic && automaticRendererInUse)
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.

View File

@ -2,38 +2,80 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Game.Localisation;
using osu.Game.Overlays;
using osu.Game.Overlays.Dialog;
namespace osu.Game.Screens.Menu
{
public partial class ConfirmExitDialog : PopupDialog
{
private readonly Action onConfirm;
private readonly Action? onCancel;
/// <summary>
/// Construct a new exit confirmation dialog.
/// </summary>
/// <param name="onConfirm">An action to perform on confirmation.</param>
/// <param name="onCancel">An optional action to perform on cancel.</param>
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!?";
BodyText = "Last chance to turn back";
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!",
Action = onConfirm
},
new PopupDialogCancelButton
new PopupDialogDangerousButton
{
Text = @"Let me out!",
Action = onConfirm
},
new PopupDialogCancelButton
{
Text = CommonStrings.Back,
Action = onCancel
},
};
}
else
{
BodyText = "Last chance to turn back";
Buttons = new PopupDialogButton[]
{
Text = @"Just a little more...",
Action = onCancel
},
};
new PopupDialogOkButton
{
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
{
public partial class ExitConfirmOverlay : HoldToConfirmOverlay, IKeyBindingHandler<GlobalAction>
public partial class HoldToExitGameOverlay : HoldToConfirmOverlay, IKeyBindingHandler<GlobalAction>
{
protected override bool AllowMultipleFires => true;
public void Abort() => AbortConfirm();
public ExitConfirmOverlay()
public HoldToExitGameOverlay()
: base(0.7f)
{
}

View File

@ -54,14 +54,20 @@ namespace osu.Game.Screens.Menu
private GameHost host { get; set; }
[Resolved]
private MusicController musicController { get; set; }
private INotificationOverlay notifications { get; set; }
[Resolved(canBeNull: true)]
private LoginOverlay login { get; set; }
[Resolved]
private MusicController musicController { get; set; }
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private Storage storage { get; set; }
[Resolved(canBeNull: true)]
private LoginOverlay login { get; set; }
[Resolved(canBeNull: true)]
private IDialogOverlay dialogOverlay { get; set; }
@ -72,7 +78,10 @@ namespace osu.Game.Screens.Menu
private Bindable<double> holdDelay;
private Bindable<bool> loginDisplayed;
private ExitConfirmOverlay exitConfirmOverlay;
private HoldToExitGameOverlay holdToExitGameOverlay;
private bool exitConfirmedViaDialog;
private bool exitConfirmedViaHoldOrClick;
private ParallaxContainer buttonsContainer;
private SongTicker songTicker;
@ -85,14 +94,12 @@ namespace osu.Game.Screens.Menu
if (host.CanExit)
{
AddInternal(exitConfirmOverlay = new ExitConfirmOverlay
AddInternal(holdToExitGameOverlay = new HoldToExitGameOverlay
{
Action = () =>
{
if (holdDelay.Value > 0)
confirmAndExit();
else
this.Exit();
exitConfirmedViaHoldOrClick = holdDelay.Value > 0;
this.Exit();
}
});
}
@ -114,7 +121,11 @@ namespace osu.Game.Screens.Menu
OnSolo = loadSoloSongSelect,
OnMultiplayer = () => this.Push(new Multiplayer()),
OnPlaylists = () => this.Push(new Playlists()),
OnExit = confirmAndExit,
OnExit = () =>
{
exitConfirmedViaHoldOrClick = true;
this.Exit();
}
}
}
},
@ -125,7 +136,7 @@ namespace osu.Game.Screens.Menu
Origin = Anchor.TopRight,
Margin = new MarginPadding { Right = 15, Top = 5 }
},
exitConfirmOverlay?.CreateProxy() ?? Empty()
holdToExitGameOverlay?.CreateProxy() ?? Empty()
});
Buttons.StateChanged += state =>
@ -149,19 +160,8 @@ namespace osu.Game.Screens.Menu
preloadSongSelect();
}
[Resolved(canBeNull: true)]
private IPerformFromScreenRunner performer { get; set; }
public void ReturnToOsuLogo() => Buttons.State = ButtonSystemState.Initial;
private void confirmAndExit()
{
if (exitConfirmed) return;
exitConfirmed = true;
performer?.PerformFromScreen(menu => menu.Exit());
}
private void preloadSongSelect()
{
if (songSelect == null)
@ -177,9 +177,6 @@ namespace osu.Game.Screens.Menu
return s;
}
[Resolved]
private Storage storage { get; set; }
public override void OnEntering(ScreenTransitionEvent e)
{
base.OnEntering(e);
@ -201,8 +198,6 @@ namespace osu.Game.Screens.Menu
dialogOverlay?.Push(new StorageErrorDialog(osuStorage, osuStorage.Error));
}
private bool exitConfirmed;
protected override void LogoArriving(OsuLogo logo, bool resuming)
{
base.LogoArriving(logo, resuming);
@ -279,12 +274,29 @@ namespace osu.Game.Screens.Menu
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)
exitDialog.PerformOkAction();
else
dialogOverlay.Push(new ConfirmExitDialog(confirmAndExit, () => exitConfirmOverlay.Abort()));
{
dialogOverlay.Push(new ConfirmExitDialog(() =>
{
exitConfirmedViaDialog = true;
this.Exit();
}, () =>
{
holdToExitGameOverlay.Abort();
}));
}
return true;
}