1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:17:23 +08:00

Add base cursor class to retrieve true visibility state

This commit is contained in:
Dean Herbert 2019-03-25 20:25:16 +09:00
parent 06d4856e17
commit a23dfb58ad
8 changed files with 41 additions and 15 deletions

View File

@ -9,6 +9,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
using osu.Game.Graphics.Cursor;
using osu.Game.Rulesets.Osu.UI.Cursor;
using osu.Game.Rulesets.UI;
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Osu.Tests
@ -27,7 +28,7 @@ namespace osu.Game.Rulesets.Osu.Tests
[BackgroundDependencyLoader]
private void load()
{
Add(cursorContainer = new GameplayCursorContainer { RelativeSizeAxes = Axes.Both });
Add(cursorContainer = new OsuCursorContainer { RelativeSizeAxes = Axes.Both });
}
}
}

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics.Cursor;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.UI;
@ -20,7 +19,7 @@ namespace osu.Game.Rulesets.Osu.Edit
private class OsuPlayfieldNoCursor : OsuPlayfield
{
protected override CursorContainer CreateCursor() => null;
protected override GameplayCursorContainer CreateCursor() => null;
}
}
}

View File

@ -3,12 +3,12 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Input.Bindings;
using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Osu.UI.Cursor
{
public class GameplayCursorContainer : CursorContainer, IKeyBindingHandler<OsuAction>
public class OsuCursorContainer : GameplayCursorContainer, IKeyBindingHandler<OsuAction>
{
protected override Drawable CreateCursor() => new OsuCursor();
@ -16,7 +16,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
private readonly Container<Drawable> fadeContainer;
public GameplayCursorContainer()
public OsuCursorContainer()
{
InternalChild = fadeContainer = new Container
{

View File

@ -10,7 +10,6 @@ using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables.Connections;
using osu.Game.Rulesets.UI;
using System.Linq;
using osu.Framework.Graphics.Cursor;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Osu.UI.Cursor;
@ -24,7 +23,7 @@ namespace osu.Game.Rulesets.Osu.UI
public static readonly Vector2 BASE_SIZE = new Vector2(512, 384);
protected override CursorContainer CreateCursor() => new GameplayCursorContainer();
protected override GameplayCursorContainer CreateCursor() => new OsuCursorContainer();
public OsuPlayfield()
{

View File

@ -9,6 +9,7 @@ using osu.Framework.Graphics.Cursor;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Osu.UI.Cursor;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using osuTK;
using osuTK.Graphics;
@ -37,7 +38,7 @@ namespace osu.Game.Rulesets.Osu.UI
clickToResumeCursor.ShowAt(GameplayCursor.ActiveCursor.Position);
if (localCursorContainer == null)
Add(localCursorContainer = new GameplayCursorContainer());
Add(localCursorContainer = new OsuCursorContainer());
}
public override void Hide()

View File

@ -178,7 +178,7 @@ namespace osu.Game.Rulesets.UI
public override void RequestResume(Action continueResume)
{
if (ResumeOverlay != null && (Cursor == null || Contains(Cursor.ActiveCursor.ScreenSpaceDrawQuad.Centre)))
if (ResumeOverlay != null && (Cursor == null || ((GameplayCursorContainer)Cursor).LastFrameState == Visibility.Visible && Contains(Cursor.ActiveCursor.ScreenSpaceDrawQuad.Centre)))
{
ResumeOverlay.GameplayCursor = Cursor;
ResumeOverlay.ResumeAction = continueResume;
@ -284,7 +284,9 @@ namespace osu.Game.Rulesets.UI
protected override bool OnHover(HoverEvent e) => true; // required for IProvideCursor
public override CursorContainer Cursor => Playfield.Cursor;
CursorContainer IProvideCursor.Cursor => Playfield.Cursor;
public override GameplayCursorContainer Cursor => Playfield.Cursor;
public bool ProvidingUserCursor => Playfield.Cursor != null && !HasReplayLoaded.Value;
@ -354,7 +356,7 @@ namespace osu.Game.Rulesets.UI
/// <summary>
/// The cursor being displayed by the <see cref="Playfield"/>. May be null if no cursor is provided.
/// </summary>
public abstract CursorContainer Cursor { get; }
public abstract GameplayCursorContainer Cursor { get; }
/// <summary>
/// Sets a replay to be used, overriding local input.

View File

@ -0,0 +1,25 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
namespace osu.Game.Rulesets.UI
{
public class GameplayCursorContainer : CursorContainer
{
/// <summary>
/// Because Show/Hide are executed by a parent, <see cref="State"/> is updated immediately even if the cursor
/// is in a non-updating state (via <see cref="FrameStabilityContainer"/> limitations).
///
/// This holds the true visibility value.
/// </summary>
public Visibility LastFrameState;
protected override void Update()
{
base.Update();
LastFrameState = State;
}
}
}

View File

@ -10,7 +10,6 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mods;
using osuTK;
@ -90,14 +89,14 @@ namespace osu.Game.Rulesets.UI
/// <summary>
/// The cursor currently being used by this <see cref="Playfield"/>. May be null if no cursor is provided.
/// </summary>
public CursorContainer Cursor { get; private set; }
public GameplayCursorContainer Cursor { get; private set; }
/// <summary>
/// Provide an optional cursor which is to be used for gameplay.
/// If providing a cursor, <see cref="CursorTargetContainer"/> must also point to a valid target container.
/// </summary>
/// <returns>The cursor, or null if a cursor is not rqeuired.</returns>
protected virtual CursorContainer CreateCursor() => null;
protected virtual GameplayCursorContainer CreateCursor() => null;
/// <summary>
/// Registers a <see cref="Playfield"/> as a nested <see cref="Playfield"/>.