From a44cfe29013a6b92eefdc20766257e0422c0ad2a Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 12 Oct 2022 17:50:31 +0300 Subject: [PATCH] Hide menu cursor when user is idle --- osu.Game/Graphics/Cursor/MenuCursorContainer.cs | 9 +++++++++ osu.Game/OsuGame.cs | 8 ++++++-- osu.Game/OsuGameBase.cs | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/Cursor/MenuCursorContainer.cs b/osu.Game/Graphics/Cursor/MenuCursorContainer.cs index 9f876a5e2d..cc747f00d5 100644 --- a/osu.Game/Graphics/Cursor/MenuCursorContainer.cs +++ b/osu.Game/Graphics/Cursor/MenuCursorContainer.cs @@ -49,7 +49,11 @@ namespace osu.Game.Graphics.Cursor [Resolved] private OsuUserInputManager inputManager { get; set; } = null!; + [Resolved] + private OsuGame? game { get; set; } + private readonly IBindable mouseInputSource = new BindableBool(); + private readonly IBindable isIdle = new BindableBool(); private readonly Bindable internalState = new Bindable(); @@ -62,6 +66,11 @@ namespace osu.Game.Graphics.Cursor mouseInputSource.BindTo(inputManager.IsMouseInputSource); mouseInputSource.BindValueChanged(_ => updateInternalVisibility(), true); + if (game != null) + { + isIdle.BindTo(game.IsIdle); + isIdle.BindValueChanged(_ => updateInternalVisibility()); + } } private void updateInternalVisibility() diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 1716e48395..b3eaf5cd01 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -70,6 +70,7 @@ namespace osu.Game /// The full osu! experience. Builds on top of to add menus and binding logic /// for initial components that are generally retrieved via DI. /// + [Cached(typeof(OsuGame))] public class OsuGame : OsuGameBase, IKeyBindingHandler, ILocalUserPlayInfo, IPerformFromScreenRunner, IOverlayManager, ILinkHandler { /// @@ -136,6 +137,11 @@ namespace osu.Game private IdleTracker idleTracker; + /// + /// Whether the user is currently in an idle state. + /// + public IBindable IsIdle => idleTracker.IsIdle; + /// /// Whether overlays should be able to be opened game-wide. Value is sourced from the current active screen. /// @@ -266,8 +272,6 @@ namespace osu.Game [BackgroundDependencyLoader] private void load() { - dependencies.CacheAs(this); - SentryLogger.AttachUser(API.LocalUser); dependencies.Cache(osuLogo = new OsuLogo { Alpha = 0 }); diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 478f154d58..7d9ed7bf3e 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -62,6 +62,7 @@ namespace osu.Game /// Unlike , this class will not load any kind of UI, allowing it to be used /// for provide dependencies to test cases without interfering with them. /// + [Cached(typeof(OsuGameBase))] public partial class OsuGameBase : Framework.Game, ICanAcceptFiles, IBeatSyncProvider { public static readonly string[] VIDEO_EXTENSIONS = { ".mp4", ".mov", ".avi", ".flv" }; @@ -253,7 +254,6 @@ namespace osu.Game largeStore.AddTextureSource(Host.CreateTextureLoaderStore(new OnlineStore())); dependencies.Cache(largeStore); - dependencies.CacheAs(this); dependencies.CacheAs(LocalConfig); InitialiseFonts();