mirror of
https://github.com/ppy/osu.git
synced 2025-02-04 23:43:00 +08:00
Add simple screenshot notification
This commit is contained in:
parent
8429408974
commit
245200d3ee
@ -9,6 +9,8 @@ using osu.Framework.Input.Bindings;
|
|||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Overlays.Notifications;
|
||||||
|
|
||||||
namespace osu.Game.Graphics
|
namespace osu.Game.Graphics
|
||||||
{
|
{
|
||||||
@ -17,12 +19,14 @@ namespace osu.Game.Graphics
|
|||||||
private Bindable<ScreenshotFormat> screenshotFormat;
|
private Bindable<ScreenshotFormat> screenshotFormat;
|
||||||
private GameHost host;
|
private GameHost host;
|
||||||
private Storage storage;
|
private Storage storage;
|
||||||
|
private NotificationOverlay notificationOverlay;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(GameHost host, OsuConfigManager config, Storage storage)
|
private void load(GameHost host, OsuConfigManager config, Storage storage, NotificationOverlay notificationOverlay)
|
||||||
{
|
{
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.storage = storage.GetStorageForDirectory(@"screenshots");
|
this.storage = storage.GetStorageForDirectory(@"screenshots");
|
||||||
|
this.notificationOverlay = notificationOverlay;
|
||||||
|
|
||||||
screenshotFormat = config.GetBindable<ScreenshotFormat>(OsuSetting.ScreenshotFormat);
|
screenshotFormat = config.GetBindable<ScreenshotFormat>(OsuSetting.ScreenshotFormat);
|
||||||
}
|
}
|
||||||
@ -45,7 +49,8 @@ namespace osu.Game.Graphics
|
|||||||
{
|
{
|
||||||
host.TakeScreenshot(screenshotBitmap =>
|
host.TakeScreenshot(screenshotBitmap =>
|
||||||
{
|
{
|
||||||
var stream = getFileStream();
|
var fileName = getFileName();
|
||||||
|
var stream = storage.GetStream(fileName, FileAccess.Write);
|
||||||
|
|
||||||
switch (screenshotFormat.Value)
|
switch (screenshotFormat.Value)
|
||||||
{
|
{
|
||||||
@ -58,25 +63,27 @@ namespace osu.Game.Graphics
|
|||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException(nameof(screenshotFormat));
|
throw new ArgumentOutOfRangeException(nameof(screenshotFormat));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notificationOverlay.Post(new SimpleNotification { Text = $"{fileName} saved" });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Stream getFileStream()
|
private string getFileName()
|
||||||
{
|
{
|
||||||
var fileExt = screenshotFormat.ToString().ToLower();
|
var fileExt = screenshotFormat.ToString().ToLower();
|
||||||
|
|
||||||
var withoutIndex = $"Screenshot.{fileExt}";
|
var withoutIndex = $"Screenshot.{fileExt}";
|
||||||
if (!storage.Exists(withoutIndex))
|
if (!storage.Exists(withoutIndex))
|
||||||
return storage.GetStream(withoutIndex, FileAccess.Write);
|
return withoutIndex;
|
||||||
|
|
||||||
for (ulong i = 1; i < ulong.MaxValue; i++)
|
for (ulong i = 1; i < ulong.MaxValue; i++)
|
||||||
{
|
{
|
||||||
var indexedName = $"Screenshot-{i}.{fileExt}";
|
var indexedName = $"Screenshot-{i}.{fileExt}";
|
||||||
if (!storage.Exists(indexedName))
|
if (!storage.Exists(indexedName))
|
||||||
return storage.GetStream(indexedName, FileAccess.Write);
|
return indexedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception($"Failed to get stream for saving {fileExt} file");
|
throw new Exception($"Failed to find suitable file name for saving {fileExt} image");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,6 @@ namespace osu.Game
|
|||||||
},
|
},
|
||||||
mainContent = new Container { RelativeSizeAxes = Axes.Both },
|
mainContent = new Container { RelativeSizeAxes = Axes.Both },
|
||||||
overlayContent = new Container { RelativeSizeAxes = Axes.Both, Depth = float.MinValue },
|
overlayContent = new Container { RelativeSizeAxes = Axes.Both, Depth = float.MinValue },
|
||||||
new ScreenshotManager()
|
|
||||||
});
|
});
|
||||||
|
|
||||||
loadComponentSingleFile(screenStack = new Loader(), d =>
|
loadComponentSingleFile(screenStack = new Loader(), d =>
|
||||||
@ -286,6 +285,8 @@ namespace osu.Game
|
|||||||
dependencies.Cache(notifications);
|
dependencies.Cache(notifications);
|
||||||
dependencies.Cache(dialogOverlay);
|
dependencies.Cache(dialogOverlay);
|
||||||
|
|
||||||
|
Add(new ScreenshotManager());
|
||||||
|
|
||||||
// ensure only one of these overlays are open at once.
|
// ensure only one of these overlays are open at once.
|
||||||
var singleDisplayOverlays = new OverlayContainer[] { chat, social, direct };
|
var singleDisplayOverlays = new OverlayContainer[] { chat, social, direct };
|
||||||
foreach (var overlay in singleDisplayOverlays)
|
foreach (var overlay in singleDisplayOverlays)
|
||||||
|
Loading…
Reference in New Issue
Block a user