From e6c22e2287c842711f4c76005882544468243b7b Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Sat, 10 Mar 2018 21:59:20 +0300 Subject: [PATCH 01/15] Taking screenshot support initial commit --- osu.Game/Configuration/OsuConfigManager.cs | 5 ++- .../Input/Bindings/GlobalActionContainer.cs | 4 ++ osu.Game/OsuGame.cs | 42 +++++++++++++++++++ .../Sections/Graphics/DetailSettings.cs | 8 +++- osu.Game/osu.Game.csproj | 1 + 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 3d927ef67c..dd17f2c4aa 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -82,6 +82,8 @@ namespace osu.Game.Configuration Set(OsuSetting.ReleaseStream, ReleaseStream.Lazer); Set(OsuSetting.Version, string.Empty); + + Set(OsuSetting.ScreenshotFormat, ScreenshotFormat.Png); } public OsuConfigManager(Storage storage) : base(storage) @@ -125,6 +127,7 @@ namespace osu.Game.Configuration Version, ShowConvertedBeatmaps, SpeedChangeVisualisation, - Skin + Skin, + ScreenshotFormat } } diff --git a/osu.Game/Input/Bindings/GlobalActionContainer.cs b/osu.Game/Input/Bindings/GlobalActionContainer.cs index 17ec2af4b9..f6263a05c2 100644 --- a/osu.Game/Input/Bindings/GlobalActionContainer.cs +++ b/osu.Game/Input/Bindings/GlobalActionContainer.cs @@ -26,6 +26,8 @@ namespace osu.Game.Input.Bindings { new KeyBinding(InputKey.F8, GlobalAction.ToggleChat), new KeyBinding(InputKey.F9, GlobalAction.ToggleSocial), + new KeyBinding(InputKey.F12,GlobalAction.TakeScreenshot), + new KeyBinding(new[] { InputKey.Control, InputKey.Alt, InputKey.R }, GlobalAction.ResetInputSettings), new KeyBinding(new[] { InputKey.Control, InputKey.T }, GlobalAction.ToggleToolbar), new KeyBinding(new[] { InputKey.Control, InputKey.O }, GlobalAction.ToggleSettings), @@ -66,6 +68,8 @@ namespace osu.Game.Input.Bindings DecreaseVolume, [Description("Toggle mute")] ToggleMute, + [Description("Take screenshot")] + TakeScreenshot, // In-Game Keybindings [Description("Skip Cutscene")] diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index e656c7256e..1078548bef 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -3,6 +3,8 @@ using System; using System.Collections.Generic; +using System.Drawing.Imaging; +using System.IO; using osu.Framework.Configuration; using osu.Framework.Screens; using osu.Game.Configuration; @@ -83,6 +85,8 @@ namespace osu.Game private Bindable configSkin; + private Bindable screenshotFormat; + private readonly string[] args; private SettingsOverlay settings; @@ -134,6 +138,8 @@ namespace osu.Game // bind config int to database SkinInfo configSkin = LocalConfig.GetBindable(OsuSetting.Skin); + screenshotFormat = LocalConfig.GetBindable(OsuSetting.ScreenshotFormat); + SkinManager.CurrentSkinInfo.ValueChanged += s => configSkin.Value = s.ID; configSkin.ValueChanged += id => SkinManager.CurrentSkinInfo.Value = SkinManager.Query(s => s.ID == id) ?? SkinInfo.Default; configSkin.TriggerChange(); @@ -432,11 +438,47 @@ namespace osu.Game case GlobalAction.ToggleDirect: direct.ToggleVisibility(); return true; + case GlobalAction.TakeScreenshot: + if (Window.ScreenshotTakenAction == null) + Window.ScreenshotTakenAction = (screenshotBitmap) => + { + var fileName = getScreenshotFileName(screenshotFormat); + + switch (screenshotFormat.Value) + { + case ScreenshotFormat.Bmp: + screenshotBitmap.Save(fileName, ImageFormat.Bmp); + break; + case ScreenshotFormat.Png: + screenshotBitmap.Save(fileName, ImageFormat.Png); + break; + case ScreenshotFormat.Jpg: + screenshotBitmap.Save(fileName, ImageFormat.Jpeg); + break; + default: + throw new ArgumentOutOfRangeException(nameof(screenshotFormat)); + } + }; + + RequestScreenshot(); + return true; } return false; } + private string getScreenshotFileName(ScreenshotFormat screenshotFormat) + { + // TODO Change screenshots location + var baseDirectory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); + var screenshotsDirectory = baseDirectory.CreateSubdirectory("Screenshots"); + + var screenshotExtension = screenshotFormat.ToString().ToLower(); + var screenshots = screenshotsDirectory.GetFiles($"*.{screenshotExtension}"); + + return Path.Combine(screenshotsDirectory.FullName, $"screenshot{screenshots.Length + 1}.{screenshotExtension}"); + } + private readonly BindableDouble inactiveVolumeAdjust = new BindableDouble(); protected override void OnDeactivated() diff --git a/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs b/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs index b9d76c05f0..3f4fc96d31 100644 --- a/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Allocation; +using osu.Framework.Graphics; using osu.Game.Configuration; namespace osu.Game.Overlays.Settings.Sections.Graphics @@ -12,7 +13,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics [BackgroundDependencyLoader] private void load(OsuConfigManager config) { - Children = new[] + Children = new Drawable[] { new SettingsCheckbox { @@ -24,6 +25,11 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics LabelText = "Rotate cursor when dragging", Bindable = config.GetBindable(OsuSetting.CursorRotation) }, + new SettingsEnumDropdown() + { + LabelText = "Screenshot format", + Bindable = config.GetBindable(OsuSetting.ScreenshotFormat) + } }; } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index d10f0085cc..fdda575a6c 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -187,6 +187,7 @@ $(SolutionDir)\packages\System.Diagnostics.DiagnosticSource.4.4.1\lib\net46\System.Diagnostics.DiagnosticSource.dll + $(SolutionDir)\packages\System.Interactive.Async.3.1.1\lib\net46\System.Interactive.Async.dll From 0e69ab161549dd32e0e2144bf49b11da21a4a165 Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Wed, 14 Mar 2018 00:17:12 +0300 Subject: [PATCH 02/15] Introduce ScreenshotManager class --- osu.Game/Graphics/ScreenshotManager.cs | 50 ++++++++++++++++++++++++++ osu.Game/OsuGame.cs | 47 ++++-------------------- osu.Game/osu.Game.csproj | 1 + 3 files changed, 57 insertions(+), 41 deletions(-) create mode 100644 osu.Game/Graphics/ScreenshotManager.cs diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs new file mode 100644 index 0000000000..7304d653cd --- /dev/null +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -0,0 +1,50 @@ +using System; +using System.Drawing.Imaging; +using System.IO; +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Platform; +using osu.Game.Configuration; + +namespace osu.Game.Graphics +{ + public class ScreenshotManager : Drawable + { + private Bindable screenshotFormat; + private GameHost host; + private Storage storage; + + [BackgroundDependencyLoader] + private void load(GameHost host, OsuConfigManager config, Storage storage) + { + this.host = host; + this.storage = storage.GetStorageForDirectory(@"screenshots"); + + screenshotFormat = config.GetBindable(OsuSetting.ScreenshotFormat); + } + + public void TakeScreenshot() + { + host.TakeScreenshot(screenshotBitmap => + { + var stream = storage.GetStream($"{DateTime.Now:yyyyMMddTHHmmss}.{screenshotFormat.ToString().ToLower()}", FileAccess.Write); + + switch (screenshotFormat.Value) + { + case ScreenshotFormat.Bmp: + screenshotBitmap.Save(stream, ImageFormat.Bmp); + break; + case ScreenshotFormat.Png: + screenshotBitmap.Save(stream, ImageFormat.Png); + break; + case ScreenshotFormat.Jpg: + screenshotBitmap.Save(stream, ImageFormat.Jpeg); + break; + default: + throw new ArgumentOutOfRangeException(nameof(screenshotFormat)); + } + }); + } + } +} diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 1078548bef..18ea093e97 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -3,8 +3,6 @@ using System; using System.Collections.Generic; -using System.Drawing.Imaging; -using System.IO; using osu.Framework.Configuration; using osu.Framework.Screens; using osu.Game.Configuration; @@ -83,9 +81,9 @@ namespace osu.Game private Bindable configRuleset; public Bindable Ruleset = new Bindable(); - private Bindable configSkin; + private ScreenshotManager screenshotManager; - private Bindable screenshotFormat; + private Bindable configSkin; private readonly string[] args; @@ -137,9 +135,6 @@ namespace osu.Game // bind config int to database SkinInfo configSkin = LocalConfig.GetBindable(OsuSetting.Skin); - - screenshotFormat = LocalConfig.GetBindable(OsuSetting.ScreenshotFormat); - SkinManager.CurrentSkinInfo.ValueChanged += s => configSkin.Value = s.ID; configSkin.ValueChanged += id => SkinManager.CurrentSkinInfo.Value = SkinManager.Query(s => s.ID == id) ?? SkinInfo.Default; configSkin.TriggerChange(); @@ -216,6 +211,9 @@ namespace osu.Game BeatmapManager.GetStableStorage = GetStorageForStableInstall; + screenshotManager = new ScreenshotManager(); + Add(screenshotManager); + AddRange(new Drawable[] { new VolumeControlReceptor @@ -439,46 +437,13 @@ namespace osu.Game direct.ToggleVisibility(); return true; case GlobalAction.TakeScreenshot: - if (Window.ScreenshotTakenAction == null) - Window.ScreenshotTakenAction = (screenshotBitmap) => - { - var fileName = getScreenshotFileName(screenshotFormat); - - switch (screenshotFormat.Value) - { - case ScreenshotFormat.Bmp: - screenshotBitmap.Save(fileName, ImageFormat.Bmp); - break; - case ScreenshotFormat.Png: - screenshotBitmap.Save(fileName, ImageFormat.Png); - break; - case ScreenshotFormat.Jpg: - screenshotBitmap.Save(fileName, ImageFormat.Jpeg); - break; - default: - throw new ArgumentOutOfRangeException(nameof(screenshotFormat)); - } - }; - - RequestScreenshot(); + screenshotManager.TakeScreenshot(); return true; } return false; } - private string getScreenshotFileName(ScreenshotFormat screenshotFormat) - { - // TODO Change screenshots location - var baseDirectory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); - var screenshotsDirectory = baseDirectory.CreateSubdirectory("Screenshots"); - - var screenshotExtension = screenshotFormat.ToString().ToLower(); - var screenshots = screenshotsDirectory.GetFiles($"*.{screenshotExtension}"); - - return Path.Combine(screenshotsDirectory.FullName, $"screenshot{screenshots.Length + 1}.{screenshotExtension}"); - } - private readonly BindableDouble inactiveVolumeAdjust = new BindableDouble(); protected override void OnDeactivated() diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index fdda575a6c..7576dd6f0c 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -288,6 +288,7 @@ + From 25f738c4aeeb154c62d20202850bedeba14e33e0 Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Wed, 14 Mar 2018 12:57:55 +0300 Subject: [PATCH 03/15] Do not support bmp screenshots --- osu.Game/Configuration/OsuConfigManager.cs | 2 +- osu.Game/Configuration/ScreenshotFormat.cs | 1 - osu.Game/Graphics/ScreenshotManager.cs | 3 --- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index dd17f2c4aa..70260b349e 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -83,7 +83,7 @@ namespace osu.Game.Configuration Set(OsuSetting.Version, string.Empty); - Set(OsuSetting.ScreenshotFormat, ScreenshotFormat.Png); + Set(OsuSetting.ScreenshotFormat, ScreenshotFormat.Jpg); } public OsuConfigManager(Storage storage) : base(storage) diff --git a/osu.Game/Configuration/ScreenshotFormat.cs b/osu.Game/Configuration/ScreenshotFormat.cs index 1bc3013af9..b9309fae3a 100644 --- a/osu.Game/Configuration/ScreenshotFormat.cs +++ b/osu.Game/Configuration/ScreenshotFormat.cs @@ -7,7 +7,6 @@ namespace osu.Game.Configuration { public enum ScreenshotFormat { - Bmp = 0, // TODO: Figure out the best way to hide this from the dropdown [Description("JPG (web-friendly)")] Jpg = 1, [Description("PNG (lossless)")] diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index 7304d653cd..e7f21d11fa 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -32,9 +32,6 @@ namespace osu.Game.Graphics switch (screenshotFormat.Value) { - case ScreenshotFormat.Bmp: - screenshotBitmap.Save(stream, ImageFormat.Bmp); - break; case ScreenshotFormat.Png: screenshotBitmap.Save(stream, ImageFormat.Png); break; From 5a1af062d31c01dd9ac1830fa75c584e8f7f4b6e Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Wed, 14 Mar 2018 22:55:24 +0300 Subject: [PATCH 04/15] Handle GlobalAction.TakeScreenshot in ScreenshotManager --- osu.Game/Graphics/ScreenshotManager.cs | 21 +++++++++++++++++++-- osu.Game/OsuGame.cs | 7 +------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index e7f21d11fa..8e0c2cce50 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -3,13 +3,16 @@ using System.Drawing.Imaging; using System.IO; using osu.Framework.Allocation; using osu.Framework.Configuration; -using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Input; +using osu.Framework.Input.Bindings; using osu.Framework.Platform; using osu.Game.Configuration; +using osu.Game.Input.Bindings; namespace osu.Game.Graphics { - public class ScreenshotManager : Drawable + public class ScreenshotManager : Container, IKeyBindingHandler, IHandleGlobalInput { private Bindable screenshotFormat; private GameHost host; @@ -24,6 +27,20 @@ namespace osu.Game.Graphics screenshotFormat = config.GetBindable(OsuSetting.ScreenshotFormat); } + public bool OnPressed(GlobalAction action) + { + switch (action) + { + case GlobalAction.TakeScreenshot: + TakeScreenshot(); + return true; + } + + return false; + } + + public bool OnReleased(GlobalAction action) => false; + public void TakeScreenshot() { host.TakeScreenshot(screenshotBitmap => diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 18ea093e97..44946dd23d 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -211,9 +211,6 @@ namespace osu.Game BeatmapManager.GetStableStorage = GetStorageForStableInstall; - screenshotManager = new ScreenshotManager(); - Add(screenshotManager); - AddRange(new Drawable[] { new VolumeControlReceptor @@ -223,6 +220,7 @@ namespace osu.Game }, mainContent = new Container { RelativeSizeAxes = Axes.Both }, overlayContent = new Container { RelativeSizeAxes = Axes.Both, Depth = float.MinValue }, + screenshotManager = new ScreenshotManager() }); loadComponentSingleFile(screenStack = new Loader(), d => @@ -436,9 +434,6 @@ namespace osu.Game case GlobalAction.ToggleDirect: direct.ToggleVisibility(); return true; - case GlobalAction.TakeScreenshot: - screenshotManager.TakeScreenshot(); - return true; } return false; From 604e725f3fba86cc5d65d3a37ebc9fa61c5f8d4b Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Fri, 16 Mar 2018 20:42:05 +0300 Subject: [PATCH 05/15] Remove redundant code --- osu.Game/Input/Bindings/GlobalActionContainer.cs | 5 +++-- osu.Game/OsuGame.cs | 4 +--- .../Overlays/Settings/Sections/Graphics/DetailSettings.cs | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Input/Bindings/GlobalActionContainer.cs b/osu.Game/Input/Bindings/GlobalActionContainer.cs index f6263a05c2..97e473a797 100644 --- a/osu.Game/Input/Bindings/GlobalActionContainer.cs +++ b/osu.Game/Input/Bindings/GlobalActionContainer.cs @@ -68,13 +68,14 @@ namespace osu.Game.Input.Bindings DecreaseVolume, [Description("Toggle mute")] ToggleMute, - [Description("Take screenshot")] - TakeScreenshot, // In-Game Keybindings [Description("Skip Cutscene")] SkipCutscene, [Description("Quick Retry (Hold)")] QuickRetry, + + [Description("Take screenshot")] + TakeScreenshot } } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 44946dd23d..ba21dc3349 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -81,8 +81,6 @@ namespace osu.Game private Bindable configRuleset; public Bindable Ruleset = new Bindable(); - private ScreenshotManager screenshotManager; - private Bindable configSkin; private readonly string[] args; @@ -220,7 +218,7 @@ namespace osu.Game }, mainContent = new Container { RelativeSizeAxes = Axes.Both }, overlayContent = new Container { RelativeSizeAxes = Axes.Both, Depth = float.MinValue }, - screenshotManager = new ScreenshotManager() + new ScreenshotManager() }); loadComponentSingleFile(screenStack = new Loader(), d => diff --git a/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs b/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs index 3f4fc96d31..fa57a85454 100644 --- a/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs @@ -1,5 +1,6 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Configuration; @@ -25,7 +26,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics LabelText = "Rotate cursor when dragging", Bindable = config.GetBindable(OsuSetting.CursorRotation) }, - new SettingsEnumDropdown() + new SettingsEnumDropdown { LabelText = "Screenshot format", Bindable = config.GetBindable(OsuSetting.ScreenshotFormat) From 8429408974a8d89e07279b22cb8c5007b91eb81c Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Fri, 16 Mar 2018 21:05:25 +0300 Subject: [PATCH 06/15] Change screenshot file name --- osu.Game/Graphics/ScreenshotManager.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index 8e0c2cce50..f1477f6b6c 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -45,7 +45,7 @@ namespace osu.Game.Graphics { host.TakeScreenshot(screenshotBitmap => { - var stream = storage.GetStream($"{DateTime.Now:yyyyMMddTHHmmss}.{screenshotFormat.ToString().ToLower()}", FileAccess.Write); + var stream = getFileStream(); switch (screenshotFormat.Value) { @@ -60,5 +60,23 @@ namespace osu.Game.Graphics } }); } + + private Stream getFileStream() + { + var fileExt = screenshotFormat.ToString().ToLower(); + + var withoutIndex = $"Screenshot.{fileExt}"; + if (!storage.Exists(withoutIndex)) + return storage.GetStream(withoutIndex, FileAccess.Write); + + for (ulong i = 1; i < ulong.MaxValue; i++) + { + var indexedName = $"Screenshot-{i}.{fileExt}"; + if (!storage.Exists(indexedName)) + return storage.GetStream(indexedName, FileAccess.Write); + } + + throw new Exception($"Failed to get stream for saving {fileExt} file"); + } } } From 245200d3eed14db452976108d28f1068cb66d85d Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Fri, 16 Mar 2018 21:25:00 +0300 Subject: [PATCH 07/15] Add simple screenshot notification --- osu.Game/Graphics/ScreenshotManager.cs | 19 +++++++++++++------ osu.Game/OsuGame.cs | 3 ++- 2 files changed, 15 insertions(+), 7 deletions(-) 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) From ee73bd4568494c26df000b80a0f94ccf91e62383 Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Mon, 19 Mar 2018 22:39:00 +0300 Subject: [PATCH 08/15] Update ScreenshotManager inline with framework changes --- osu.Game/Graphics/ScreenshotManager.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index ae1aebfbc1..8028b744c9 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -36,7 +36,7 @@ namespace osu.Game.Graphics switch (action) { case GlobalAction.TakeScreenshot: - TakeScreenshot(); + TakeScreenshotAsync(); return true; } @@ -45,9 +45,9 @@ namespace osu.Game.Graphics public bool OnReleased(GlobalAction action) => false; - public void TakeScreenshot() + public async void TakeScreenshotAsync() { - host.TakeScreenshot(screenshotBitmap => + using (var bitmap = await host.TakeScreenshotAsync()) { var fileName = getFileName(); var stream = storage.GetStream(fileName, FileAccess.Write); @@ -55,17 +55,17 @@ namespace osu.Game.Graphics switch (screenshotFormat.Value) { case ScreenshotFormat.Png: - screenshotBitmap.Save(stream, ImageFormat.Png); + bitmap.Save(stream, ImageFormat.Png); break; case ScreenshotFormat.Jpg: - screenshotBitmap.Save(stream, ImageFormat.Jpeg); + bitmap.Save(stream, ImageFormat.Jpeg); break; default: throw new ArgumentOutOfRangeException(nameof(screenshotFormat)); } notificationOverlay.Post(new SimpleNotification { Text = $"{fileName} saved" }); - }); + } } private string getFileName() From ccdd11d7b22be419ab34230150c342e4e1550c08 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 21 Mar 2018 12:29:44 +0900 Subject: [PATCH 09/15] Add missing licence header --- osu.Game/Graphics/ScreenshotManager.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index 8028b744c9..3dc4fec63a 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; using System.Drawing.Imaging; using System.IO; using osu.Framework.Allocation; @@ -43,7 +46,10 @@ namespace osu.Game.Graphics return false; } - public bool OnReleased(GlobalAction action) => false; + public bool OnReleased(GlobalAction action) + { + return false; + } public async void TakeScreenshotAsync() { From 357a3c535e95c37387d08e6936451c0e3c683a9d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 21 Mar 2018 12:29:49 +0900 Subject: [PATCH 10/15] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index d29c8365ba..140f9c4ccf 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit d29c8365ba3cf7924b57cf22341f4af55658764c +Subproject commit 140f9c4ccfc8a6ea464ee29ebfb4f6fdc66b0db7 From 4991f2ad2e28ea4bcb295b8da4518a1ffd6e8355 Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Wed, 21 Mar 2018 18:27:08 +0300 Subject: [PATCH 11/15] Change filename format --- osu.Game/Graphics/ScreenshotManager.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index 3dc4fec63a..4c9e9756df 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -76,15 +76,16 @@ namespace osu.Game.Graphics private string getFileName() { + var dt = DateTime.Now; var fileExt = screenshotFormat.ToString().ToLower(); - var withoutIndex = $"Screenshot.{fileExt}"; + var withoutIndex = $"osu_{dt:yyyy-MM-dd_HH-mm-ss}.{fileExt}"; if (!storage.Exists(withoutIndex)) return withoutIndex; for (ulong i = 1; i < ulong.MaxValue; i++) { - var indexedName = $"Screenshot-{i}.{fileExt}"; + var indexedName = $"osu_{dt:yyyy-MM-dd_HH-mm-ss}-{i}.{fileExt}"; if (!storage.Exists(indexedName)) return indexedName; } From 9e080028ff2d6953fddbeb2a98f52c677b03a8ad Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 22 Mar 2018 20:35:07 +0900 Subject: [PATCH 12/15] Add shutter sound --- osu-resources | 2 +- osu.Game/Graphics/ScreenshotManager.cs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/osu-resources b/osu-resources index 7bb0782200..6e145ed502 160000 --- a/osu-resources +++ b/osu-resources @@ -1 +1 @@ -Subproject commit 7bb0782200abadf73b79ed1a3bc1d5b926c6a81e +Subproject commit 6e145ed50274539ee827fdc3d1fda1e130b070fd diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index 4c9e9756df..412ec18412 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -5,6 +5,8 @@ using System; using System.Drawing.Imaging; using System.IO; using osu.Framework.Allocation; +using osu.Framework.Audio; +using osu.Framework.Audio.Sample; using osu.Framework.Configuration; using osu.Framework.Graphics.Containers; using osu.Framework.Input; @@ -24,14 +26,18 @@ namespace osu.Game.Graphics private Storage storage; private NotificationOverlay notificationOverlay; + private SampleChannel shutter; + [BackgroundDependencyLoader] - private void load(GameHost host, OsuConfigManager config, Storage storage, NotificationOverlay notificationOverlay) + private void load(GameHost host, OsuConfigManager config, Storage storage, NotificationOverlay notificationOverlay, AudioManager audio) { this.host = host; this.storage = storage.GetStorageForDirectory(@"screenshots"); this.notificationOverlay = notificationOverlay; screenshotFormat = config.GetBindable(OsuSetting.ScreenshotFormat); + + shutter = audio.Sample.Get("UI/shutter"); } public bool OnPressed(GlobalAction action) @@ -39,6 +45,7 @@ namespace osu.Game.Graphics switch (action) { case GlobalAction.TakeScreenshot: + shutter.Play(); TakeScreenshotAsync(); return true; } From 94847e4a233eee9ddef6cfb97ac4ff1ccc897509 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 22 Mar 2018 20:44:00 +0900 Subject: [PATCH 13/15] Allow clicking notification to open screenshot folder --- osu.Game/Graphics/ScreenshotManager.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index 412ec18412..c1df7999ad 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -53,10 +53,7 @@ namespace osu.Game.Graphics return false; } - public bool OnReleased(GlobalAction action) - { - return false; - } + public bool OnReleased(GlobalAction action) => false; public async void TakeScreenshotAsync() { @@ -77,7 +74,15 @@ namespace osu.Game.Graphics throw new ArgumentOutOfRangeException(nameof(screenshotFormat)); } - notificationOverlay.Post(new SimpleNotification { Text = $"{fileName} saved" }); + notificationOverlay.Post(new SimpleNotification + { + Text = $"{fileName} saved!", + Activated = () => + { + storage.OpenInNativeExplorer(); + return true; + } + }); } } From e41993ac44fb88f5174c7a1c5bf323b8cc98fbc4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 22 Mar 2018 20:45:26 +0900 Subject: [PATCH 14/15] Don't bother with an exception that will never happen Wasn't being caught anyways --- osu.Game/Graphics/ScreenshotManager.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index c1df7999ad..b0cd997837 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -60,6 +60,8 @@ namespace osu.Game.Graphics using (var bitmap = await host.TakeScreenshotAsync()) { var fileName = getFileName(); + if (fileName == null) return; + var stream = storage.GetStream(fileName, FileAccess.Write); switch (screenshotFormat.Value) @@ -102,7 +104,7 @@ namespace osu.Game.Graphics return indexedName; } - throw new Exception($"Failed to find suitable file name for saving {fileExt} image"); + return null; } } } From 1d3c9098b8884b889089ebf4337d0008e189c190 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 22 Mar 2018 21:42:57 +0900 Subject: [PATCH 15/15] Load component asynchronously --- osu.Game/OsuGame.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 268cca5957..89447b8ed6 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -239,6 +239,7 @@ namespace osu.Game loadComponentSingleFile(volume = new VolumeOverlay(), overlayContent.Add); loadComponentSingleFile(onscreenDisplay = new OnScreenDisplay(), Add); + loadComponentSingleFile(new ScreenshotManager(), Add); //overlay elements loadComponentSingleFile(direct = new DirectOverlay { Depth = -1 }, mainContent.Add); @@ -285,8 +286,6 @@ 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)