mirror of
https://github.com/ppy/osu.git
synced 2025-02-14 00:53:19 +08:00
Merge pull request #2199 from UselessToucan/take_screenshot
Add the ability to take in-game screenshots
This commit is contained in:
commit
72531229fe
@ -1 +1 @@
|
|||||||
Subproject commit 7bb0782200abadf73b79ed1a3bc1d5b926c6a81e
|
Subproject commit 6e145ed50274539ee827fdc3d1fda1e130b070fd
|
@ -82,6 +82,8 @@ namespace osu.Game.Configuration
|
|||||||
Set(OsuSetting.ReleaseStream, ReleaseStream.Lazer);
|
Set(OsuSetting.ReleaseStream, ReleaseStream.Lazer);
|
||||||
|
|
||||||
Set(OsuSetting.Version, string.Empty);
|
Set(OsuSetting.Version, string.Empty);
|
||||||
|
|
||||||
|
Set(OsuSetting.ScreenshotFormat, ScreenshotFormat.Jpg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OsuConfigManager(Storage storage) : base(storage)
|
public OsuConfigManager(Storage storage) : base(storage)
|
||||||
@ -125,6 +127,7 @@ namespace osu.Game.Configuration
|
|||||||
Version,
|
Version,
|
||||||
ShowConvertedBeatmaps,
|
ShowConvertedBeatmaps,
|
||||||
SpeedChangeVisualisation,
|
SpeedChangeVisualisation,
|
||||||
Skin
|
Skin,
|
||||||
|
ScreenshotFormat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ namespace osu.Game.Configuration
|
|||||||
{
|
{
|
||||||
public enum ScreenshotFormat
|
public enum ScreenshotFormat
|
||||||
{
|
{
|
||||||
Bmp = 0, // TODO: Figure out the best way to hide this from the dropdown
|
|
||||||
[Description("JPG (web-friendly)")]
|
[Description("JPG (web-friendly)")]
|
||||||
Jpg = 1,
|
Jpg = 1,
|
||||||
[Description("PNG (lossless)")]
|
[Description("PNG (lossless)")]
|
||||||
|
110
osu.Game/Graphics/ScreenshotManager.cs
Normal file
110
osu.Game/Graphics/ScreenshotManager.cs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// 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;
|
||||||
|
using osu.Framework.Audio;
|
||||||
|
using osu.Framework.Audio.Sample;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
|
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;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Overlays.Notifications;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics
|
||||||
|
{
|
||||||
|
public class ScreenshotManager : Container, IKeyBindingHandler<GlobalAction>, IHandleGlobalInput
|
||||||
|
{
|
||||||
|
private Bindable<ScreenshotFormat> screenshotFormat;
|
||||||
|
private GameHost host;
|
||||||
|
private Storage storage;
|
||||||
|
private NotificationOverlay notificationOverlay;
|
||||||
|
|
||||||
|
private SampleChannel shutter;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
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<ScreenshotFormat>(OsuSetting.ScreenshotFormat);
|
||||||
|
|
||||||
|
shutter = audio.Sample.Get("UI/shutter");
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnPressed(GlobalAction action)
|
||||||
|
{
|
||||||
|
switch (action)
|
||||||
|
{
|
||||||
|
case GlobalAction.TakeScreenshot:
|
||||||
|
shutter.Play();
|
||||||
|
TakeScreenshotAsync();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnReleased(GlobalAction action) => false;
|
||||||
|
|
||||||
|
public async void TakeScreenshotAsync()
|
||||||
|
{
|
||||||
|
using (var bitmap = await host.TakeScreenshotAsync())
|
||||||
|
{
|
||||||
|
var fileName = getFileName();
|
||||||
|
if (fileName == null) return;
|
||||||
|
|
||||||
|
var stream = storage.GetStream(fileName, FileAccess.Write);
|
||||||
|
|
||||||
|
switch (screenshotFormat.Value)
|
||||||
|
{
|
||||||
|
case ScreenshotFormat.Png:
|
||||||
|
bitmap.Save(stream, ImageFormat.Png);
|
||||||
|
break;
|
||||||
|
case ScreenshotFormat.Jpg:
|
||||||
|
bitmap.Save(stream, ImageFormat.Jpeg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(screenshotFormat));
|
||||||
|
}
|
||||||
|
|
||||||
|
notificationOverlay.Post(new SimpleNotification
|
||||||
|
{
|
||||||
|
Text = $"{fileName} saved!",
|
||||||
|
Activated = () =>
|
||||||
|
{
|
||||||
|
storage.OpenInNativeExplorer();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string getFileName()
|
||||||
|
{
|
||||||
|
var dt = DateTime.Now;
|
||||||
|
var fileExt = screenshotFormat.ToString().ToLower();
|
||||||
|
|
||||||
|
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 = $"osu_{dt:yyyy-MM-dd_HH-mm-ss}-{i}.{fileExt}";
|
||||||
|
if (!storage.Exists(indexedName))
|
||||||
|
return indexedName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -26,6 +26,8 @@ namespace osu.Game.Input.Bindings
|
|||||||
{
|
{
|
||||||
new KeyBinding(InputKey.F8, GlobalAction.ToggleChat),
|
new KeyBinding(InputKey.F8, GlobalAction.ToggleChat),
|
||||||
new KeyBinding(InputKey.F9, GlobalAction.ToggleSocial),
|
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.Alt, InputKey.R }, GlobalAction.ResetInputSettings),
|
||||||
new KeyBinding(new[] { InputKey.Control, InputKey.T }, GlobalAction.ToggleToolbar),
|
new KeyBinding(new[] { InputKey.Control, InputKey.T }, GlobalAction.ToggleToolbar),
|
||||||
new KeyBinding(new[] { InputKey.Control, InputKey.O }, GlobalAction.ToggleSettings),
|
new KeyBinding(new[] { InputKey.Control, InputKey.O }, GlobalAction.ToggleSettings),
|
||||||
@ -72,5 +74,8 @@ namespace osu.Game.Input.Bindings
|
|||||||
SkipCutscene,
|
SkipCutscene,
|
||||||
[Description("Quick Retry (Hold)")]
|
[Description("Quick Retry (Hold)")]
|
||||||
QuickRetry,
|
QuickRetry,
|
||||||
|
|
||||||
|
[Description("Take screenshot")]
|
||||||
|
TakeScreenshot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,6 @@ namespace osu.Game
|
|||||||
|
|
||||||
// bind config int to database SkinInfo
|
// bind config int to database SkinInfo
|
||||||
configSkin = LocalConfig.GetBindable<int>(OsuSetting.Skin);
|
configSkin = LocalConfig.GetBindable<int>(OsuSetting.Skin);
|
||||||
|
|
||||||
SkinManager.CurrentSkinInfo.ValueChanged += s => configSkin.Value = s.ID;
|
SkinManager.CurrentSkinInfo.ValueChanged += s => configSkin.Value = s.ID;
|
||||||
configSkin.ValueChanged += id => SkinManager.CurrentSkinInfo.Value = SkinManager.Query(s => s.ID == id) ?? SkinInfo.Default;
|
configSkin.ValueChanged += id => SkinManager.CurrentSkinInfo.Value = SkinManager.Query(s => s.ID == id) ?? SkinInfo.Default;
|
||||||
configSkin.TriggerChange();
|
configSkin.TriggerChange();
|
||||||
@ -240,6 +239,7 @@ namespace osu.Game
|
|||||||
|
|
||||||
loadComponentSingleFile(volume = new VolumeOverlay(), overlayContent.Add);
|
loadComponentSingleFile(volume = new VolumeOverlay(), overlayContent.Add);
|
||||||
loadComponentSingleFile(onscreenDisplay = new OnScreenDisplay(), Add);
|
loadComponentSingleFile(onscreenDisplay = new OnScreenDisplay(), Add);
|
||||||
|
loadComponentSingleFile(new ScreenshotManager(), Add);
|
||||||
|
|
||||||
//overlay elements
|
//overlay elements
|
||||||
loadComponentSingleFile(direct = new DirectOverlay { Depth = -1 }, mainContent.Add);
|
loadComponentSingleFile(direct = new DirectOverlay { Depth = -1 }, mainContent.Add);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings.Sections.Graphics
|
namespace osu.Game.Overlays.Settings.Sections.Graphics
|
||||||
@ -12,7 +14,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuConfigManager config)
|
private void load(OsuConfigManager config)
|
||||||
{
|
{
|
||||||
Children = new[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new SettingsCheckbox
|
new SettingsCheckbox
|
||||||
{
|
{
|
||||||
@ -24,6 +26,11 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|||||||
LabelText = "Rotate cursor when dragging",
|
LabelText = "Rotate cursor when dragging",
|
||||||
Bindable = config.GetBindable<bool>(OsuSetting.CursorRotation)
|
Bindable = config.GetBindable<bool>(OsuSetting.CursorRotation)
|
||||||
},
|
},
|
||||||
|
new SettingsEnumDropdown<ScreenshotFormat>
|
||||||
|
{
|
||||||
|
LabelText = "Screenshot format",
|
||||||
|
Bindable = config.GetBindable<ScreenshotFormat>(OsuSetting.ScreenshotFormat)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,6 +187,7 @@
|
|||||||
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
<HintPath>$(SolutionDir)\packages\System.Diagnostics.DiagnosticSource.4.4.1\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
|
<HintPath>$(SolutionDir)\packages\System.Diagnostics.DiagnosticSource.4.4.1\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Interactive.Async, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
|
<Reference Include="System.Interactive.Async, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
|
||||||
<HintPath>$(SolutionDir)\packages\System.Interactive.Async.3.1.1\lib\net46\System.Interactive.Async.dll</HintPath>
|
<HintPath>$(SolutionDir)\packages\System.Interactive.Async.3.1.1\lib\net46\System.Interactive.Async.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
@ -290,6 +291,7 @@
|
|||||||
<Compile Include="Database\SingletonContextFactory.cs" />
|
<Compile Include="Database\SingletonContextFactory.cs" />
|
||||||
<Compile Include="Graphics\Containers\LinkFlowContainer.cs" />
|
<Compile Include="Graphics\Containers\LinkFlowContainer.cs" />
|
||||||
<Compile Include="Graphics\DrawableDate.cs" />
|
<Compile Include="Graphics\DrawableDate.cs" />
|
||||||
|
<Compile Include="Graphics\ScreenshotManager.cs" />
|
||||||
<Compile Include="Graphics\Textures\LargeTextureStore.cs" />
|
<Compile Include="Graphics\Textures\LargeTextureStore.cs" />
|
||||||
<Compile Include="IO\Archives\ArchiveReader.cs" />
|
<Compile Include="IO\Archives\ArchiveReader.cs" />
|
||||||
<Compile Include="IO\Archives\LegacyFilesystemReader.cs" />
|
<Compile Include="IO\Archives\LegacyFilesystemReader.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user