2019-01-24 16:43:03 +08:00
|
|
|
// 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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2022-07-26 13:07:33 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Input;
|
2020-09-07 14:18:15 +08:00
|
|
|
using osu.Framework.Input.StateChanges;
|
2022-07-26 13:07:33 +08:00
|
|
|
using osu.Game.Configuration;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Cursor
|
|
|
|
{
|
|
|
|
/// <summary>
|
2022-07-26 13:11:52 +08:00
|
|
|
/// A container which provides the main <see cref="Cursor.MenuCursor"/>.
|
|
|
|
/// Also handles cases where a more localised cursor is provided by another component (via <see cref="IProvideCursor"/>).
|
2018-04-13 17:19:50 +08:00
|
|
|
/// </summary>
|
2022-07-26 13:11:52 +08:00
|
|
|
public class GlobalCursorDisplay : Container, IProvideCursor
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
2022-07-26 13:11:52 +08:00
|
|
|
/// Control whether any cursor should be displayed.
|
2018-04-13 17:19:50 +08:00
|
|
|
/// </summary>
|
2022-07-26 13:11:52 +08:00
|
|
|
internal bool ShowCursor = true;
|
|
|
|
|
|
|
|
public CursorContainer MenuCursor { get; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
public bool ProvidingUserCursor => true;
|
|
|
|
|
2022-07-26 13:11:52 +08:00
|
|
|
protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both };
|
|
|
|
|
|
|
|
private Bindable<bool> showDuringTouch = null!;
|
|
|
|
|
|
|
|
private InputManager inputManager = null!;
|
|
|
|
|
|
|
|
private IProvideCursor? currentOverrideProvider;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuConfigManager config { get; set; } = null!;
|
|
|
|
|
|
|
|
public GlobalCursorDisplay()
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
{
|
2022-07-26 13:11:52 +08:00
|
|
|
MenuCursor = new MenuCursor { State = { Value = Visibility.Hidden } },
|
|
|
|
Content = new Container { RelativeSizeAxes = Axes.Both }
|
2018-04-13 17:19:50 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2022-07-26 13:07:33 +08:00
|
|
|
|
2022-07-26 13:11:52 +08:00
|
|
|
inputManager = GetContainingInputManager();
|
2022-07-26 13:07:33 +08:00
|
|
|
showDuringTouch = config.GetBindable<bool>(OsuSetting.GameplayCursorDuringTouch);
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2020-09-07 14:31:05 +08:00
|
|
|
var lastMouseSource = inputManager.CurrentState.Mouse.LastSource;
|
2022-07-26 13:07:33 +08:00
|
|
|
bool hasValidInput = lastMouseSource != null && (showDuringTouch.Value || lastMouseSource is not ISourcedFromTouch);
|
2020-09-07 14:18:15 +08:00
|
|
|
|
2022-07-26 13:11:52 +08:00
|
|
|
if (!hasValidInput || !ShowCursor)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2022-07-26 13:11:52 +08:00
|
|
|
currentOverrideProvider?.MenuCursor?.Hide();
|
|
|
|
currentOverrideProvider = null;
|
2018-04-13 17:19:50 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-26 13:11:52 +08:00
|
|
|
IProvideCursor newOverrideProvider = this;
|
2020-07-19 10:37:10 +08:00
|
|
|
|
|
|
|
foreach (var d in inputManager.HoveredDrawables)
|
|
|
|
{
|
2020-07-24 09:41:09 +08:00
|
|
|
if (d is IProvideCursor p && p.ProvidingUserCursor)
|
|
|
|
{
|
2022-07-26 13:11:52 +08:00
|
|
|
newOverrideProvider = p;
|
2020-07-24 09:41:09 +08:00
|
|
|
break;
|
|
|
|
}
|
2020-07-19 10:37:10 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2022-07-26 13:11:52 +08:00
|
|
|
if (currentOverrideProvider == newOverrideProvider)
|
2018-04-13 17:19:50 +08:00
|
|
|
return;
|
|
|
|
|
2022-07-26 13:11:52 +08:00
|
|
|
currentOverrideProvider?.MenuCursor?.Hide();
|
|
|
|
newOverrideProvider.MenuCursor?.Show();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2022-07-26 13:11:52 +08:00
|
|
|
currentOverrideProvider = newOverrideProvider;
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|