mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 14:46:38 +09:00
Introduce ScreenshotManager class
This commit is contained in:
@ -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<int> configRuleset;
|
||||
public Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
|
||||
|
||||
private Bindable<int> configSkin;
|
||||
private ScreenshotManager screenshotManager;
|
||||
|
||||
private Bindable<ScreenshotFormat> screenshotFormat;
|
||||
private Bindable<int> configSkin;
|
||||
|
||||
private readonly string[] args;
|
||||
|
||||
@ -137,9 +135,6 @@ namespace osu.Game
|
||||
|
||||
// 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();
|
||||
@ -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()
|
||||
|
Reference in New Issue
Block a user