CursorOverrideContainer.ShowMenuCursor

This commit is contained in:
TocoToucan 2018-04-11 21:22:52 +03:00
parent 9225c06872
commit d7812ab12e
2 changed files with 15 additions and 10 deletions

View File

@ -21,6 +21,7 @@ namespace osu.Game.Graphics.Cursor
/// Whether any cursors can be displayed. /// Whether any cursors can be displayed.
/// </summary> /// </summary>
public bool CanShowCursor = true; public bool CanShowCursor = true;
public bool ShowMenuCursor = true;
public CursorContainer Cursor { get; } public CursorContainer Cursor { get; }
public bool ProvidingUserCursor => true; public bool ProvidingUserCursor => true;
@ -53,6 +54,14 @@ namespace osu.Game.Graphics.Cursor
return; return;
} }
if (currentTarget?.Cursor is MenuCursor)
{
if (ShowMenuCursor && currentTarget?.Cursor.State == Visibility.Hidden)
currentTarget?.Cursor?.Show();
else if (!ShowMenuCursor && currentTarget?.Cursor.State == Visibility.Visible)
currentTarget?.Cursor?.Hide();
}
var newTarget = inputManager.HoveredDrawables.OfType<IProvideCursor>().FirstOrDefault(t => t.ProvidingUserCursor) ?? this; var newTarget = inputManager.HoveredDrawables.OfType<IProvideCursor>().FirstOrDefault(t => t.ProvidingUserCursor) ?? this;
if (currentTarget == newTarget) if (currentTarget == newTarget)

View File

@ -11,7 +11,6 @@ using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Platform; using osu.Framework.Platform;
@ -33,7 +32,7 @@ namespace osu.Game.Graphics
private NotificationOverlay notificationOverlay; private NotificationOverlay notificationOverlay;
private SampleChannel shutter; private SampleChannel shutter;
private CursorContainer menuCursorContainer; private CursorOverrideContainer cursorOverrideContainer;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(GameHost host, OsuConfigManager config, Storage storage, NotificationOverlay notificationOverlay, AudioManager audio, CursorOverrideContainer cursorOverrideContainer) private void load(GameHost host, OsuConfigManager config, Storage storage, NotificationOverlay notificationOverlay, AudioManager audio, CursorOverrideContainer cursorOverrideContainer)
@ -41,7 +40,7 @@ namespace osu.Game.Graphics
this.host = host; this.host = host;
this.storage = storage.GetStorageForDirectory(@"screenshots"); this.storage = storage.GetStorageForDirectory(@"screenshots");
this.notificationOverlay = notificationOverlay; this.notificationOverlay = notificationOverlay;
menuCursorContainer = cursorOverrideContainer.Cursor; this.cursorOverrideContainer = cursorOverrideContainer;
screenshotFormat = config.GetBindable<ScreenshotFormat>(OsuSetting.ScreenshotFormat); screenshotFormat = config.GetBindable<ScreenshotFormat>(OsuSetting.ScreenshotFormat);
captureMenuCursor = config.GetBindable<bool>(OsuSetting.ScreenshotCaptureMenuCursor); captureMenuCursor = config.GetBindable<bool>(OsuSetting.ScreenshotCaptureMenuCursor);
@ -66,16 +65,14 @@ namespace osu.Game.Graphics
public async void TakeScreenshotAsync() public async void TakeScreenshotAsync()
{ {
var menuCursorWasHidden = false; if (!captureMenuCursor.Value)
if (!captureMenuCursor.Value && menuCursorContainer.State == Visibility.Visible)
{ {
menuCursorContainer.ToggleVisibility(); cursorOverrideContainer.ShowMenuCursor = false;
await Task.Run(() => await Task.Run(() =>
{ {
while (menuCursorContainer.ActiveCursor.Alpha > 0) while (cursorOverrideContainer.Cursor.ActiveCursor.Alpha > 0)
Thread.Sleep(1); Thread.Sleep(1);
}); });
menuCursorWasHidden = true;
} }
using (var bitmap = await host.TakeScreenshotAsync()) using (var bitmap = await host.TakeScreenshotAsync())
@ -108,8 +105,7 @@ namespace osu.Game.Graphics
}); });
} }
if (menuCursorWasHidden) cursorOverrideContainer.ShowMenuCursor = true;
menuCursorContainer.ToggleVisibility();
} }
private string getFileName() private string getFileName()