From 292de44a0b2fc0164a91dd2d6cd6c96309ffe38f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 16 Mar 2017 22:41:07 +0900 Subject: [PATCH 1/6] WIP menu cursor. --- osu.Game.Modes.Osu/UI/OsuPlayfield.cs | 3 +- osu.Game/Graphics/Cursor/GameplayCursor.cs | 129 +++++++++++++++++++++ osu.Game/Graphics/Cursor/MenuCursor.cs | 106 +++++++++++++++++ osu.Game/OsuGameBase.cs | 2 +- osu.Game/osu.Game.csproj | 3 +- 5 files changed, 239 insertions(+), 4 deletions(-) create mode 100644 osu.Game/Graphics/Cursor/GameplayCursor.cs create mode 100644 osu.Game/Graphics/Cursor/MenuCursor.cs diff --git a/osu.Game.Modes.Osu/UI/OsuPlayfield.cs b/osu.Game.Modes.Osu/UI/OsuPlayfield.cs index 7f7ec2d161..5caaaafb13 100644 --- a/osu.Game.Modes.Osu/UI/OsuPlayfield.cs +++ b/osu.Game.Modes.Osu/UI/OsuPlayfield.cs @@ -12,7 +12,6 @@ using osu.Game.Modes.UI; using System.Linq; using osu.Game.Graphics.Cursor; using osu.Game.Modes.Osu.Judgements; -using OpenTK.Graphics; namespace osu.Game.Modes.Osu.UI { @@ -63,7 +62,7 @@ namespace osu.Game.Modes.Osu.UI protected override void LoadComplete() { base.LoadComplete(); - AddInternal(new OsuCursorContainer { Colour = Color4.LightYellow }); + AddInternal(new GameplayCursor()); } public override void Add(DrawableHitObject h) diff --git a/osu.Game/Graphics/Cursor/GameplayCursor.cs b/osu.Game/Graphics/Cursor/GameplayCursor.cs new file mode 100644 index 0000000000..df31017734 --- /dev/null +++ b/osu.Game/Graphics/Cursor/GameplayCursor.cs @@ -0,0 +1,129 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transforms; +using osu.Framework.Input; +using osu.Game.Configuration; +using System; + +namespace osu.Game.Graphics.Cursor +{ + public class GameplayCursor : CursorContainer + { + protected override Drawable CreateCursor() => new OsuCursor(); + + public GameplayCursor() + { + Add(new CursorTrail { Depth = 1 }); + } + + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) + { + ActiveCursor.Scale = new Vector2(1); + ActiveCursor.ScaleTo(1.2f, 100, EasingTypes.OutQuad); + return base.OnMouseDown(state, args); + } + + protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) + { + if (!state.Mouse.HasMainButtonPressed) + ActiveCursor.ScaleTo(1, 200, EasingTypes.OutQuad); + return base.OnMouseUp(state, args); + } + + public class OsuCursor : Container + { + private Container cursorContainer; + private Bindable cursorScale; + + public OsuCursor() + { + Origin = Anchor.Centre; + Size = new Vector2(42); + } + + [BackgroundDependencyLoader] + private void load(OsuConfigManager config) + { + cursorScale = config.GetBindable(OsuConfig.CursorSize); + + Children = new Drawable[] + { + cursorContainer = new CircularContainer + { + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + Scale = new Vector2((float)cursorScale), + Masking = true, + BorderThickness = Size.X / 6, + BorderColour = Color4.White, + EdgeEffect = new EdgeEffect { + Type = EdgeEffectType.Shadow, + Colour = Color4.Pink.Opacity(0.5f), + Radius = 5, + }, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Alpha = 0, + AlwaysPresent = true, + }, + new CircularContainer + { + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + Masking = true, + BorderThickness = Size.X / 3, + BorderColour = Color4.White.Opacity(0.5f), + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Alpha = 0, + AlwaysPresent = true, + }, + }, + }, + new CircularContainer + { + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + Scale = new Vector2(0.1f), + Masking = true, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.White, + }, + }, + }, + } + }, + }; + cursorScale.ValueChanged += scaleChanged; + } + + private void scaleChanged(object sender, EventArgs e) + { + cursorContainer.Scale = new Vector2((float)cursorScale); + } + } + } +} diff --git a/osu.Game/Graphics/Cursor/MenuCursor.cs b/osu.Game/Graphics/Cursor/MenuCursor.cs new file mode 100644 index 0000000000..ffdfd37a67 --- /dev/null +++ b/osu.Game/Graphics/Cursor/MenuCursor.cs @@ -0,0 +1,106 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Input; +using osu.Game.Configuration; +using System; +using osu.Framework.Graphics.Textures; +using osu.Framework.Graphics.Transforms; + +namespace osu.Game.Graphics.Cursor +{ + public class MenuCursor : CursorContainer + { + protected override Drawable CreateCursor() => new Cursor(); + + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) + { + ActiveCursor.Scale = new Vector2(1); + ActiveCursor.ScaleTo(0.90f, 800, EasingTypes.OutQuint); + + ((Cursor)ActiveCursor).AdditiveLayer.Alpha = 0; + ((Cursor)ActiveCursor).AdditiveLayer.FadeInFromZero(800, EasingTypes.OutQuint); + return base.OnMouseDown(state, args); + } + + protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) + { + if (!state.Mouse.HasMainButtonPressed) + { + ((Cursor)ActiveCursor).AdditiveLayer.FadeOut(500, EasingTypes.OutQuint); + ActiveCursor.RotateTo(0, 200, EasingTypes.OutQuint); + ActiveCursor.ScaleTo(1, 500, EasingTypes.OutElastic); + } + + return base.OnMouseUp(state, args); + } + + protected override bool OnClick(InputState state) + { + ((Cursor)ActiveCursor).AdditiveLayer.FadeOutFromOne(500, EasingTypes.OutQuint); + + return base.OnClick(state); + } + + protected override bool OnDragStart(InputState state) + { + ActiveCursor.RotateTo(-30, 600, EasingTypes.OutElastic); + return base.OnDragStart(state); + } + + public class Cursor : Container + { + private Container cursorContainer; + private Bindable cursorScale; + + public Sprite AdditiveLayer; + + public Cursor() + { + Size = new Vector2(42); + } + + [BackgroundDependencyLoader] + private void load(OsuConfigManager config, TextureStore textures) + { + cursorScale = config.GetBindable(OsuConfig.CursorSize); + + Children = new Drawable[] + { + cursorContainer = new Container + { + Size = new Vector2(28), + Children = new Drawable[] + { + new Sprite + { + FillMode = FillMode.Fit, + Texture = textures.Get(@"Cursor/menu-cursor"), + }, + AdditiveLayer = new Sprite + { + FillMode = FillMode.Fit, + BlendingMode = BlendingMode.Additive, + Alpha = 0, + Texture = textures.Get(@"Cursor/menu-cursor"), + }, + } + } + }; + cursorScale.ValueChanged += scaleChanged; + } + + private void scaleChanged(object sender, EventArgs e) + { + cursorContainer.Scale = new Vector2((float)cursorScale); + } + } + } +} diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 50c8aab5ef..b815d0028f 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -137,7 +137,7 @@ namespace osu.Game { Children = new[] { - Cursor = new OsuCursorContainer { Depth = float.MinValue } + Cursor = new MenuCursor { Depth = float.MinValue } } }); } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 80d5c906e0..8b0a5fd307 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -79,6 +79,7 @@ + @@ -221,7 +222,7 @@ - + From 7110ab8e17353800220ce8ee1a770d46b5603677 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 16 Mar 2017 22:50:16 +0900 Subject: [PATCH 2/6] Stop cursor moving when paused. --- osu.Game/Screens/Play/PauseOverlay.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Screens/Play/PauseOverlay.cs b/osu.Game/Screens/Play/PauseOverlay.cs index b862adcd53..1cc6f9cf02 100644 --- a/osu.Game/Screens/Play/PauseOverlay.cs +++ b/osu.Game/Screens/Play/PauseOverlay.cs @@ -78,6 +78,8 @@ namespace osu.Game.Screens.Play // Don't let mouse down events through the overlay or people can click circles while paused. protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true; + protected override bool OnMouseMove(InputState state) => true; + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { if (args.Key == Key.Escape) From f9f31ca092b10ba89d4fce001ea056318258eb10 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 16 Mar 2017 23:58:36 +0900 Subject: [PATCH 3/6] Add statefulness to MenuCursor. --- osu.Game/Graphics/Cursor/MenuCursor.cs | 14 ++++++++++++++ osu.Game/OsuGame.cs | 22 ++++++++++++++-------- osu.Game/OsuGameBase.cs | 2 +- osu.Game/Screens/Menu/Disclaimer.cs | 2 ++ osu.Game/Screens/Menu/Intro.cs | 2 ++ osu.Game/Screens/OsuGameScreen.cs | 2 ++ osu.Game/Screens/Play/Player.cs | 6 +++++- 7 files changed, 40 insertions(+), 10 deletions(-) diff --git a/osu.Game/Graphics/Cursor/MenuCursor.cs b/osu.Game/Graphics/Cursor/MenuCursor.cs index ffdfd37a67..ada1308b3e 100644 --- a/osu.Game/Graphics/Cursor/MenuCursor.cs +++ b/osu.Game/Graphics/Cursor/MenuCursor.cs @@ -55,6 +55,20 @@ namespace osu.Game.Graphics.Cursor return base.OnDragStart(state); } + protected override void PopIn() + { + ActiveCursor.FadeTo(1, 250, EasingTypes.OutQuint); + ActiveCursor.ScaleTo(1, 1000, EasingTypes.OutElastic); + } + + protected override void PopOut() + { + ActiveCursor.FadeTo(0, 1400, EasingTypes.OutQuint); + ActiveCursor.ScaleTo(1.1f, 100, EasingTypes.Out); + ActiveCursor.Delay(100); + ActiveCursor.ScaleTo(0, 500, EasingTypes.In); + } + public class Cursor : Container { private Container cursorContainer; diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 8aa3a63d26..3896661835 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -220,7 +220,7 @@ namespace osu.Game } }; - Cursor.Alpha = 0; + Cursor.State = Visibility.Hidden; } private bool globalHotkeyPressed(InputState state, KeyDownEventArgs args) @@ -264,10 +264,20 @@ namespace osu.Game private Container overlayContent; + private OsuScreen currentScreen; + private void screenChanged(Screen newScreen) { + currentScreen = newScreen as OsuScreen; + + if (currentScreen == null) + { + Exit(); + return; + } + //central game mode change logic. - if ((newScreen as OsuScreen)?.ShowOverlays != true) + if (currentScreen.ShowOverlays != true) { Toolbar.State = Visibility.Hidden; musicController.State = Visibility.Hidden; @@ -278,13 +288,7 @@ namespace osu.Game Toolbar.State = Visibility.Visible; } - if (newScreen is MainMenu) - Cursor.FadeIn(100); - ScreenChanged?.Invoke(newScreen); - - if (newScreen == null) - Exit(); } protected override bool OnExiting() @@ -308,6 +312,8 @@ namespace osu.Game if (intro?.ChildScreen != null) intro.ChildScreen.Padding = new MarginPadding { Top = Toolbar.Position.Y + Toolbar.DrawHeight }; + + Cursor.State = currentScreen == null || currentScreen.HasLocalCursorDisplayed ? Visibility.Hidden : Visibility.Visible; } private void screenAdded(Screen newScreen) diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index b815d0028f..bfef31d14a 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -38,7 +38,7 @@ namespace osu.Game private RatioAdjust ratioContainer; - protected CursorContainer Cursor; + protected MenuCursor Cursor; public readonly Bindable Beatmap = new Bindable(); diff --git a/osu.Game/Screens/Menu/Disclaimer.cs b/osu.Game/Screens/Menu/Disclaimer.cs index 58e86bd069..6ae237f66c 100644 --- a/osu.Game/Screens/Menu/Disclaimer.cs +++ b/osu.Game/Screens/Menu/Disclaimer.cs @@ -21,6 +21,8 @@ namespace osu.Game.Screens.Menu internal override bool ShowOverlays => false; + internal override bool HasLocalCursorDisplayed => false; + public Disclaimer() { ValidForResume = false; diff --git a/osu.Game/Screens/Menu/Intro.cs b/osu.Game/Screens/Menu/Intro.cs index 6d0cd4d821..6965707bcc 100644 --- a/osu.Game/Screens/Menu/Intro.cs +++ b/osu.Game/Screens/Menu/Intro.cs @@ -28,6 +28,8 @@ namespace osu.Game.Screens.Menu private SampleChannel seeya; private Track bgm; + internal override bool HasLocalCursorDisplayed => true; + internal override bool ShowOverlays => false; protected override BackgroundScreen CreateBackground() => new BackgroundScreenEmpty(); diff --git a/osu.Game/Screens/OsuGameScreen.cs b/osu.Game/Screens/OsuGameScreen.cs index 871d3a6780..736f9f96ae 100644 --- a/osu.Game/Screens/OsuGameScreen.cs +++ b/osu.Game/Screens/OsuGameScreen.cs @@ -24,6 +24,8 @@ namespace osu.Game.Screens protected new OsuGameBase Game => base.Game as OsuGameBase; + internal virtual bool HasLocalCursorDisplayed => false; + private readonly Bindable beatmap = new Bindable(); public WorkingBeatmap Beatmap diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 674a741d8c..bd54e6e263 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -32,6 +32,10 @@ namespace osu.Game.Screens.Play internal override bool ShowOverlays => false; + internal override bool HasLocalCursorDisplayed => !hasReplayLoaded && !IsPaused; + + private bool hasReplayLoaded => hitRenderer.InputManager.ReplayInputHandler != null; + public BeatmapInfo BeatmapInfo; public bool IsPaused { get; private set; } @@ -304,7 +308,7 @@ namespace osu.Game.Screens.Play { if (pauseOverlay == null) return false; - if (hitRenderer.InputManager.ReplayInputHandler != null) + if (hasReplayLoaded) return false; if (pauseOverlay.State != Visibility.Visible && !canPause) return true; From ba67e63ffa94e3a1265b4cefa3007d169ef6b760 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 17 Mar 2017 20:53:20 +0900 Subject: [PATCH 4/6] Update resources. --- osu-resources | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-resources b/osu-resources index 4f9ed4e703..07024c119a 160000 --- a/osu-resources +++ b/osu-resources @@ -1 +1 @@ -Subproject commit 4f9ed4e703777ede98737c7e2af31efa4694c395 +Subproject commit 07024c119a76fabb7822f4b1d68a8c9ed989d41a From 317dc94b4ca0c20e429f1a8deaf2c848f5fb5cd9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 17 Mar 2017 21:04:46 +0900 Subject: [PATCH 5/6] Adjust appearance. --- osu-resources | 2 +- osu.Game/Graphics/Cursor/MenuCursor.cs | 7 ++++--- osu.Game/OsuGameBase.cs | 1 - 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/osu-resources b/osu-resources index 07024c119a..f85c594c18 160000 --- a/osu-resources +++ b/osu-resources @@ -1 +1 @@ -Subproject commit 07024c119a76fabb7822f4b1d68a8c9ed989d41a +Subproject commit f85c594c182db2b01233e29ca52639b7baa00402 diff --git a/osu.Game/Graphics/Cursor/MenuCursor.cs b/osu.Game/Graphics/Cursor/MenuCursor.cs index ada1308b3e..1447fa9417 100644 --- a/osu.Game/Graphics/Cursor/MenuCursor.cs +++ b/osu.Game/Graphics/Cursor/MenuCursor.cs @@ -82,7 +82,7 @@ namespace osu.Game.Graphics.Cursor } [BackgroundDependencyLoader] - private void load(OsuConfigManager config, TextureStore textures) + private void load(OsuConfigManager config, TextureStore textures, OsuColour colour) { cursorScale = config.GetBindable(OsuConfig.CursorSize); @@ -90,7 +90,7 @@ namespace osu.Game.Graphics.Cursor { cursorContainer = new Container { - Size = new Vector2(28), + Size = new Vector2(32), Children = new Drawable[] { new Sprite @@ -102,8 +102,9 @@ namespace osu.Game.Graphics.Cursor { FillMode = FillMode.Fit, BlendingMode = BlendingMode.Additive, + Colour = colour.Pink, Alpha = 0, - Texture = textures.Get(@"Cursor/menu-cursor"), + Texture = textures.Get(@"Cursor/menu-cursor-additive"), }, } } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index bfef31d14a..f454956de7 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -8,7 +8,6 @@ using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Cursor; using osu.Framework.IO.Stores; using osu.Framework.Platform; using osu.Game.Beatmaps; From 77067b7e64a3e419d0e431ef63f1d6455c0bfdd9 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Sat, 18 Mar 2017 02:03:44 +0900 Subject: [PATCH 6/6] Re-style. --- osu.Game/Graphics/Cursor/GameplayCursor.cs | 4 +++- osu.Game/OsuGame.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/Cursor/GameplayCursor.cs b/osu.Game/Graphics/Cursor/GameplayCursor.cs index df31017734..a544a8e1bb 100644 --- a/osu.Game/Graphics/Cursor/GameplayCursor.cs +++ b/osu.Game/Graphics/Cursor/GameplayCursor.cs @@ -67,7 +67,8 @@ namespace osu.Game.Graphics.Cursor Masking = true, BorderThickness = Size.X / 6, BorderColour = Color4.White, - EdgeEffect = new EdgeEffect { + EdgeEffect = new EdgeEffect + { Type = EdgeEffectType.Shadow, Colour = Color4.Pink.Opacity(0.5f), Radius = 5, @@ -117,6 +118,7 @@ namespace osu.Game.Graphics.Cursor } }, }; + cursorScale.ValueChanged += scaleChanged; } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 3896661835..9bd2ef9f75 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -277,7 +277,7 @@ namespace osu.Game } //central game mode change logic. - if (currentScreen.ShowOverlays != true) + if (!currentScreen.ShowOverlays) { Toolbar.State = Visibility.Hidden; musicController.State = Visibility.Hidden;