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 @@ protected override void InitialiseDefaults() 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 @@ public enum OsuSetting 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 @@ public GlobalActionContainer(OsuGameBase game) { 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 @@ public enum GlobalAction 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 @@ private Intro intro private Bindable configSkin; + private Bindable screenshotFormat; + private readonly string[] args; private SettingsOverlay settings; @@ -134,6 +138,8 @@ private void load(FrameworkConfigManager frameworkConfig) // 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 @@ public bool OnPressed(GlobalAction action) 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 @@ public class DetailSettings : SettingsSubsection [BackgroundDependencyLoader] private void load(OsuConfigManager config) { - Children = new[] + Children = new Drawable[] { new SettingsCheckbox { @@ -24,6 +25,11 @@ private void load(OsuConfigManager config) 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