Merge branch 'master' into cursor-skinning

This commit is contained in:
Dan Balasescu 2018-03-23 19:13:56 +09:00 committed by GitHub
commit 1b74b4e5df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 137 additions and 16 deletions

@ -1 +1 @@
Subproject commit 7bb0782200abadf73b79ed1a3bc1d5b926c6a81e
Subproject commit 6e145ed50274539ee827fdc3d1fda1e130b070fd

View File

@ -82,6 +82,8 @@ protected override void InitialiseDefaults()
Set(OsuSetting.ReleaseStream, ReleaseStream.Lazer);
Set(OsuSetting.Version, string.Empty);
Set(OsuSetting.ScreenshotFormat, ScreenshotFormat.Jpg);
}
public OsuConfigManager(Storage storage) : base(storage)
@ -125,6 +127,7 @@ public enum OsuSetting
Version,
ShowConvertedBeatmaps,
SpeedChangeVisualisation,
Skin
Skin,
ScreenshotFormat
}
}

View File

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

View 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;
}
}
}

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),
@ -72,5 +74,8 @@ public enum GlobalAction
SkipCutscene,
[Description("Quick Retry (Hold)")]
QuickRetry,
[Description("Take screenshot")]
TakeScreenshot
}
}

View File

@ -133,7 +133,6 @@ private void load(FrameworkConfigManager frameworkConfig)
// bind config int to database SkinInfo
configSkin = LocalConfig.GetBindable<int>(OsuSetting.Skin);
SkinManager.CurrentSkinInfo.ValueChanged += s => configSkin.Value = s.ID;
configSkin.ValueChanged += id => SkinManager.CurrentSkinInfo.Value = SkinManager.Query(s => s.ID == id) ?? SkinInfo.Default;
configSkin.TriggerChange();
@ -240,6 +239,7 @@ protected override void LoadComplete()
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);

View File

@ -110,17 +110,7 @@ private void load()
private int runningDepth;
private void notificationClosed()
{
Schedule(() =>
{
// hide ourselves if all notifications have been dismissed.
if (totalCount == 0)
State = Visibility.Hidden;
});
updateCounts();
}
private void notificationClosed() => updateCounts();
private readonly Scheduler postScheduler = new Scheduler();
@ -141,6 +131,8 @@ public void Post(Notification notification) => postScheduler.Add(() =>
var section = sections.Children.FirstOrDefault(s => s.AcceptTypes.Any(accept => accept.IsAssignableFrom(ourType)));
section?.Add(notification, notification.DisplayOnTop ? -runningDepth : runningDepth);
State = Visibility.Visible;
updateCounts();
});

View File

@ -1,6 +1,8 @@
// 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 +14,7 @@ public class DetailSettings : SettingsSubsection
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
Children = new[]
Children = new Drawable[]
{
new SettingsCheckbox
{
@ -24,6 +26,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

@ -328,7 +328,10 @@ private void select(CarouselItem item)
public void FlushPendingFilterOperations()
{
if (FilterTask?.Completed == false)
{
applyActiveCriteria(false, false);
Update();
}
}
public void Filter(FilterCriteria newCriteria, bool debounce = true)

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>
@ -290,6 +291,7 @@
<Compile Include="Database\SingletonContextFactory.cs" />
<Compile Include="Graphics\Containers\LinkFlowContainer.cs" />
<Compile Include="Graphics\DrawableDate.cs" />
<Compile Include="Graphics\ScreenshotManager.cs" />
<Compile Include="Graphics\Textures\LargeTextureStore.cs" />
<Compile Include="IO\Archives\ArchiveReader.cs" />
<Compile Include="IO\Archives\LegacyFilesystemReader.cs" />