diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index f1477f6b6c..ae1aebfbc1 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -9,6 +9,8 @@ using osu.Framework.Input.Bindings; using osu.Framework.Platform; using osu.Game.Configuration; using osu.Game.Input.Bindings; +using osu.Game.Overlays; +using osu.Game.Overlays.Notifications; namespace osu.Game.Graphics { @@ -17,12 +19,14 @@ namespace osu.Game.Graphics private Bindable screenshotFormat; private GameHost host; private Storage storage; + private NotificationOverlay notificationOverlay; [BackgroundDependencyLoader] - private void load(GameHost host, OsuConfigManager config, Storage storage) + private void load(GameHost host, OsuConfigManager config, Storage storage, NotificationOverlay notificationOverlay) { this.host = host; this.storage = storage.GetStorageForDirectory(@"screenshots"); + this.notificationOverlay = notificationOverlay; screenshotFormat = config.GetBindable(OsuSetting.ScreenshotFormat); } @@ -45,7 +49,8 @@ namespace osu.Game.Graphics { host.TakeScreenshot(screenshotBitmap => { - var stream = getFileStream(); + var fileName = getFileName(); + var stream = storage.GetStream(fileName, FileAccess.Write); switch (screenshotFormat.Value) { @@ -58,25 +63,27 @@ namespace osu.Game.Graphics default: throw new ArgumentOutOfRangeException(nameof(screenshotFormat)); } + + notificationOverlay.Post(new SimpleNotification { Text = $"{fileName} saved" }); }); } - private Stream getFileStream() + private string getFileName() { var fileExt = screenshotFormat.ToString().ToLower(); var withoutIndex = $"Screenshot.{fileExt}"; if (!storage.Exists(withoutIndex)) - return storage.GetStream(withoutIndex, FileAccess.Write); + return withoutIndex; for (ulong i = 1; i < ulong.MaxValue; i++) { var indexedName = $"Screenshot-{i}.{fileExt}"; if (!storage.Exists(indexedName)) - return storage.GetStream(indexedName, FileAccess.Write); + return indexedName; } - throw new Exception($"Failed to get stream for saving {fileExt} file"); + throw new Exception($"Failed to find suitable file name for saving {fileExt} image"); } } } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index ba21dc3349..0aa915ed3f 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -218,7 +218,6 @@ namespace osu.Game }, mainContent = new Container { RelativeSizeAxes = Axes.Both }, overlayContent = new Container { RelativeSizeAxes = Axes.Both, Depth = float.MinValue }, - new ScreenshotManager() }); loadComponentSingleFile(screenStack = new Loader(), d => @@ -286,6 +285,8 @@ namespace osu.Game dependencies.Cache(notifications); dependencies.Cache(dialogOverlay); + Add(new ScreenshotManager()); + // ensure only one of these overlays are open at once. var singleDisplayOverlays = new OverlayContainer[] { chat, social, direct }; foreach (var overlay in singleDisplayOverlays)