From f9f31ca092b10ba89d4fce001ea056318258eb10 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 16 Mar 2017 23:58:36 +0900 Subject: [PATCH] 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;