Taking screenshot support initial commit

This commit is contained in:
TocoToucan 2018-03-10 21:59:20 +03:00
parent a9327eac8f
commit e6c22e2287
5 changed files with 58 additions and 2 deletions

View File

@ -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
}
}

View File

@ -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")]

View File

@ -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<int> configSkin;
private Bindable<ScreenshotFormat> 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<int>(OsuSetting.Skin);
screenshotFormat = LocalConfig.GetBindable<ScreenshotFormat>(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()

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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<bool>(OsuSetting.CursorRotation)
},
new SettingsEnumDropdown<ScreenshotFormat>()
{
LabelText = "Screenshot format",
Bindable = config.GetBindable<ScreenshotFormat>(OsuSetting.ScreenshotFormat)
}
};
}
}

View File

@ -187,6 +187,7 @@
<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>
</Reference>
<Reference Include="System.Drawing" />
<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>
</Reference>