mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 14:46:38 +09:00
Rewrite the way that cursor overrides are done game-wide
This commit is contained in:
22
osu.Game/Graphics/Cursor/IProvideLocalCursor.cs
Normal file
22
osu.Game/Graphics/Cursor/IProvideLocalCursor.cs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
|
||||
namespace osu.Game.Graphics.Cursor
|
||||
{
|
||||
public interface IProvideLocalCursor : IDrawable
|
||||
{
|
||||
/// <summary>
|
||||
/// The cursor provided by this <see cref="Drawable"/>.
|
||||
/// </summary>
|
||||
CursorContainer LocalCursor { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the cursor provided by this <see cref="Drawable"/> should be displayed.
|
||||
/// If this is false, a cursor occurring earlier in the draw hierarchy will be displayed instead.
|
||||
/// </summary>
|
||||
bool ProvidesUserCursor { get; }
|
||||
}
|
||||
}
|
53
osu.Game/Graphics/Cursor/OsuCursorContainer.cs
Normal file
53
osu.Game/Graphics/Cursor/OsuCursorContainer.cs
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Linq;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Input;
|
||||
|
||||
namespace osu.Game.Graphics.Cursor
|
||||
{
|
||||
public class OsuCursorContainer : Container, IProvideLocalCursor
|
||||
{
|
||||
protected override Container<Drawable> Content => content;
|
||||
private readonly Container content;
|
||||
|
||||
public CursorContainer LocalCursor { get; }
|
||||
public bool ProvidesUserCursor => true;
|
||||
|
||||
public OsuCursorContainer()
|
||||
{
|
||||
AddRangeInternal(new Drawable[]
|
||||
{
|
||||
LocalCursor = new MenuCursor { State = Visibility.Hidden },
|
||||
content = new Container { RelativeSizeAxes = Axes.Both }
|
||||
});
|
||||
}
|
||||
|
||||
private InputManager inputManager;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
inputManager = GetContainingInputManager();
|
||||
}
|
||||
|
||||
private IProvideLocalCursor currentTarget;
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
var newTarget = inputManager.HoveredDrawables.OfType<IProvideLocalCursor>().FirstOrDefault(t => t.ProvidesUserCursor) ?? this;
|
||||
|
||||
if (currentTarget == newTarget)
|
||||
return;
|
||||
|
||||
currentTarget?.LocalCursor?.Hide();
|
||||
newTarget.LocalCursor?.Show();
|
||||
|
||||
currentTarget = newTarget;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user