Skip to content

Commit 608e380

Browse files
committed
Hide cursor when inactive in visualizer screen
1 parent d0cee98 commit 608e380

File tree

3 files changed

+63
-7
lines changed

3 files changed

+63
-7
lines changed

osu.Game.Rulesets.Sandbox/Screens/SandboxScreenWithSettings.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using osu.Framework.Graphics;
1+
using osu.Framework.Bindables;
2+
using osu.Framework.Graphics;
23
using osu.Framework.Graphics.Containers;
34
using osu.Framework.Input.Events;
45
using osu.Game.Rulesets.Sandbox.UI.Settings;
@@ -8,6 +9,7 @@ namespace osu.Game.Rulesets.Sandbox.Screens
89
public abstract class SandboxScreenWithSettings : SandboxScreen
910
{
1011
private readonly SandboxSettings settings;
12+
protected readonly BindableBool SettingsVisible = new BindableBool();
1113

1214
public SandboxScreenWithSettings()
1315
{
@@ -43,6 +45,8 @@ public SandboxScreenWithSettings()
4345
}
4446
}
4547
});
48+
49+
SettingsVisible.BindTo(settings.IsVisible);
4650
}
4751

4852
protected abstract Drawable CreateContent();
@@ -55,14 +59,14 @@ protected override bool OnMouseMove(MouseMoveEvent e)
5559
{
5660
base.OnMouseMove(e);
5761

58-
if (settings.IsVisible.Value)
62+
if (SettingsVisible.Value)
5963
return false;
6064

6165
var cursorPosition = ToLocalSpace(e.CurrentState.Mouse.Position);
6266

6367
if (cursorPosition.X > DrawWidth - 5)
6468
{
65-
settings.IsVisible.Value = true;
69+
SettingsVisible.Value = true;
6670
return true;
6771
}
6872

@@ -71,11 +75,17 @@ protected override bool OnMouseMove(MouseMoveEvent e)
7175

7276
protected override bool OnClick(ClickEvent e)
7377
{
74-
if (!settings.IsVisible.Value)
78+
if (!SettingsVisible.Value)
7579
return false;
7680

77-
settings.IsVisible.Value = false;
81+
SettingsVisible.Value = false;
7882
return true;
7983
}
84+
85+
protected override void Dispose(bool isDisposing)
86+
{
87+
SettingsVisible.UnbindFrom(settings.IsVisible);
88+
base.Dispose(isDisposing);
89+
}
8090
}
8191
}

osu.Game.Rulesets.Sandbox/Screens/Visualizer/VisualizerScreen.cs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
using osu.Framework.Bindables;
33
using osu.Framework.Graphics;
44
using osu.Framework.Graphics.Containers;
5+
using osu.Framework.Graphics.Cursor;
56
using osu.Framework.Input.Bindings;
67
using osu.Framework.Input.Events;
78
using osu.Framework.Screens;
9+
using osu.Game.Graphics.Cursor;
10+
using osu.Game.Input;
811
using osu.Game.Input.Bindings;
912
using osu.Game.Rulesets.Sandbox.Configuration;
1013
using osu.Game.Rulesets.Sandbox.Screens.Visualizer.Components;
1114
using osu.Game.Rulesets.Sandbox.Screens.Visualizer.Components.Settings;
1215
using osu.Game.Rulesets.Sandbox.UI;
1316
using osu.Game.Rulesets.Sandbox.UI.Settings;
17+
using osuTK;
1418

1519
namespace osu.Game.Rulesets.Sandbox.Screens.Visualizer
1620
{
@@ -20,12 +24,15 @@ public class VisualizerScreen : SandboxScreenWithSettings, IKeyBindingHandler<Gl
2024

2125
public override bool HideOverlaysOnEnter => true;
2226

27+
private readonly IBindable<bool> isIdle = new BindableBool();
2328
private readonly BindableBool showTip = new BindableBool();
29+
private CursorHider cursorHider;
2430

2531
[BackgroundDependencyLoader]
26-
private void load(SandboxRulesetConfigManager config)
32+
private void load(SandboxRulesetConfigManager config, IdleTracker idleTracker)
2733
{
2834
config.BindWith(SandboxRulesetSetting.ShowSettingsTip, showTip);
35+
isIdle.BindTo(idleTracker.IsIdle);
2936
}
3037

3138
protected override void LoadComplete()
@@ -38,6 +45,21 @@ protected override void LoadComplete()
3845
AddInternal(tip);
3946
tip.Show();
4047
}
48+
49+
AddInternal(cursorHider = new CursorHider());
50+
51+
isIdle.BindValueChanged(idle =>
52+
{
53+
if (idle.NewValue)
54+
{
55+
SettingsVisible.Value = false;
56+
cursorHider.Size = Vector2.One;
57+
}
58+
else
59+
{
60+
cursorHider.Size = Vector2.Zero;
61+
}
62+
});
4163
}
4264

4365
protected override Drawable CreateBackground() => new Container
@@ -74,5 +96,29 @@ public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
7496
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
7597
{
7698
}
99+
100+
private class CursorHider : CompositeDrawable, IProvideCursor
101+
{
102+
public CursorHider()
103+
{
104+
RelativeSizeAxes = Axes.Both;
105+
Size = Vector2.Zero;
106+
}
107+
108+
public CursorContainer Cursor => new EmptyCursor();
109+
110+
public bool ProvidingUserCursor => true;
111+
112+
protected override bool OnHover(HoverEvent e)
113+
{
114+
base.OnHover(e);
115+
return true;
116+
}
117+
118+
private class EmptyCursor : CursorContainer
119+
{
120+
protected override Drawable CreateCursor() => Empty();
121+
}
122+
}
77123
}
78124
}

osu.Game.Rulesets.Sandbox/osu.Game.Rulesets.Sandbox.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
<EmbeddedResource Include="Resources\**\*" />
1212
</ItemGroup>
1313
<ItemGroup>
14-
<PackageReference Include="ppy.osu.Game" Version="2021.1120.0" />
14+
<PackageReference Include="ppy.osu.Game" Version="2021.1127.0" />
1515
</ItemGroup>
1616
</Project>

0 commit comments

Comments
 (0)