A lot more protection from outsiders

This commit is contained in:
smoogipoo 2018-04-13 21:12:33 +09:00
parent cd594ce12b
commit 34adb2527c
3 changed files with 27 additions and 21 deletions

View File

@ -21,16 +21,15 @@ public class CursorOverrideContainer : Container, IProvideCursor
/// Whether any cursors can be displayed.
/// </summary>
internal bool CanShowCursor = true;
internal readonly MenuCursor MenuCursor;
public CursorContainer Cursor => MenuCursor;
public CursorContainer Cursor { get; }
public bool ProvidingUserCursor => true;
public CursorOverrideContainer()
{
AddRangeInternal(new Drawable[]
{
MenuCursor = new MenuCursor { State = Visibility.Hidden },
Cursor = new MenuCursor { State = Visibility.Hidden },
content = new Container { RelativeSizeAxes = Axes.Both }
});
}

View File

@ -12,14 +12,15 @@
using osu.Game.Configuration;
using System;
using System.Diagnostics;
using JetBrains.Annotations;
using osu.Framework.Graphics.Textures;
namespace osu.Game.Graphics.Cursor
{
public class MenuCursor : CursorContainer
{
public bool ShowCursor = true;
public override bool IsPresent => ShowCursor && base.IsPresent;
private readonly IBindable<bool> screenshotCursorVisibility = new Bindable<bool>(true);
public override bool IsPresent => screenshotCursorVisibility.Value && base.IsPresent;
protected override Drawable CreateCursor() => new Cursor();
@ -28,6 +29,17 @@ public class MenuCursor : CursorContainer
private bool startRotation;
private ScreenshotManager screenshotManager;
[BackgroundDependencyLoader(true)]
private void load([NotNull] OsuConfigManager config, [CanBeNull] ScreenshotManager screenshotManager)
{
cursorRotate = config.GetBindable<bool>(OsuSetting.CursorRotation);
if (screenshotManager != null)
screenshotCursorVisibility.BindTo(screenshotManager.CursorVisibility);
}
protected override bool OnMouseMove(InputState state)
{
if (cursorRotate && dragging)
@ -107,12 +119,6 @@ protected override void PopOut()
ActiveCursor.ScaleTo(0.6f, 250, Easing.In);
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
cursorRotate = config.GetBindable<bool>(OsuSetting.CursorRotation);
}
public class Cursor : Container
{
private Container cursorContainer;

View File

@ -16,7 +16,6 @@
using osu.Framework.Platform;
using osu.Framework.Threading;
using osu.Game.Configuration;
using osu.Game.Graphics.Cursor;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
@ -25,6 +24,14 @@ namespace osu.Game.Graphics
{
public class ScreenshotManager : Container, IKeyBindingHandler<GlobalAction>, IHandleGlobalInput
{
private readonly BindableBool cursorVisibility = new BindableBool(true);
/// <summary>
/// Invoked when screenshots are or have finished being taken, to control whether cursors should be visible.
/// If cursors should not be visible, cursors have 3 frames to hide themselves.
/// </summary>
public IBindable<bool> CursorVisibility => cursorVisibility;
private Bindable<ScreenshotFormat> screenshotFormat;
private Bindable<bool> captureMenuCursor;
@ -33,12 +40,6 @@ public class ScreenshotManager : Container, IKeyBindingHandler<GlobalAction>, IH
private NotificationOverlay notificationOverlay;
private SampleChannel shutter;
private readonly MenuCursor menuCursor;
public ScreenshotManager(MenuCursor menuCursor)
{
this.menuCursor = menuCursor;
}
[BackgroundDependencyLoader]
private void load(GameHost host, OsuConfigManager config, Storage storage, NotificationOverlay notificationOverlay, AudioManager audio)
@ -76,7 +77,7 @@ public async Task TakeScreenshotAsync() => await Task.Run(async () =>
if (!captureMenuCursor.Value)
{
menuCursor.ShowCursor = false;
cursorVisibility.Value = false;
// We need to wait for at most 3 draw nodes to be drawn, following which we can be assured at least one DrawNode has been generated/drawn with the set value
const int frames_to_wait = 3;
@ -126,8 +127,8 @@ protected override void Update()
{
base.Update();
if (Interlocked.CompareExchange(ref screenShotTasks, 0, 0) == 0)
menuCursor.ShowCursor = true;
if (cursorVisibility == false && Interlocked.CompareExchange(ref screenShotTasks, 0, 0) == 0)
cursorVisibility.Value = true;
}
private string getFileName()