diff --git a/osu.Game/Graphics/UserInterface/IconButton.cs b/osu.Game/Graphics/UserInterface/IconButton.cs index c6fb3d1896..a409f954f6 100644 --- a/osu.Game/Graphics/UserInterface/IconButton.cs +++ b/osu.Game/Graphics/UserInterface/IconButton.cs @@ -9,6 +9,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Input; +using osu.Framework.Graphics.Transforms; namespace osu.Game.Graphics.UserInterface { @@ -35,37 +36,6 @@ namespace osu.Game.Graphics.UserInterface private Color4 disabledColour; - public override bool Enabled - { - get - { - return base.Enabled; - } - - set - { - if (base.Enabled == value) return; - - base.Enabled = value; - - if (!value) - { - FadeColour(disabledColour, 200, EasingTypes.OutQuint); - content.ScaleTo(1, 200, EasingTypes.OutElastic); - - if (Hovering) - OnHoverLost(new InputState()); - } - else - { - FadeColour(Color4.White, 200, EasingTypes.OutQuint); - - if (Hovering) - OnHover(new InputState()); - } - } - } - public IconButton() { AutoSizeAxes = Axes.Both; @@ -113,11 +83,44 @@ namespace osu.Game.Graphics.UserInterface hover.Colour = colours.Yellow.Opacity(0.6f); flashColour = colours.Yellow; disabledColour = colours.Gray9; + + Enabled.ValueChanged += enabledChanged; + } + + private void enabledChanged(bool newEnabled) + { + if (newEnabled) + { + // Only fade the colour to white if there is no colour transformation pending + bool colorTransformation = false; + foreach (ITransform t in Transforms) + { + if (t is TransformColour) + { + colorTransformation = true; + break; + } + } + + if(!colorTransformation) + FadeColour(Color4.White, 200, EasingTypes.OutQuint); + + if (Hovering) + OnHover(new InputState()); + } + else + { + FadeColour(disabledColour, 200, EasingTypes.OutQuint); + content.ScaleTo(1, 200, EasingTypes.OutElastic); + + if (Hovering) + OnHoverLost(new InputState()); + } } protected override bool OnHover(InputState state) { - if (!Enabled) + if (!Enabled.Value) return true; hover.FadeIn(500, EasingTypes.OutQuint); @@ -126,7 +129,7 @@ namespace osu.Game.Graphics.UserInterface protected override void OnHoverLost(InputState state) { - if (!Enabled) + if (!Enabled.Value) return; hover.FadeOut(500, EasingTypes.OutQuint); @@ -141,7 +144,7 @@ namespace osu.Game.Graphics.UserInterface protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) { - if (!Enabled) + if (!Enabled.Value) return true; content.ScaleTo(0.75f, 2000, EasingTypes.OutQuint); @@ -150,7 +153,7 @@ namespace osu.Game.Graphics.UserInterface protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) { - if (!Enabled) + if (!Enabled.Value) return true; content.ScaleTo(1, 1000, EasingTypes.OutElastic); diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 6a80840e93..4a1e54152c 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -328,7 +328,7 @@ namespace osu.Game ScreenChanged?.Invoke(newScreen); - musicController.AllowBeatmapChange = currentScreen.AllowBeatmapChange; + Beatmap.Disabled = !currentScreen.AllowBeatmapChange; } protected override bool OnExiting() diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index ed7f357855..c84201a7b7 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -59,36 +59,7 @@ namespace osu.Game.Overlays private bool showPlaylistOnceAvailable; - private bool allowBeatmapChange = true; - - public bool AllowBeatmapChange - { - get - { - return allowBeatmapChange; - } - set - { - if (allowBeatmapChange == value) return; - - allowBeatmapChange = value; - - prevButton.Enabled = allowBeatmapChange; - nextButton.Enabled = allowBeatmapChange; - playlistButton.Enabled = allowBeatmapChange; - - // Toggle the playlist's visibility if required - if (!allowBeatmapChange) - { - showPlaylistOnceAvailable = playlist.State == Visibility.Visible; - - if (showPlaylistOnceAvailable) - playlist?.Hide(); - } - else if (showPlaylistOnceAvailable && State == Visibility.Visible) - playlist?.Show(); - } - } + private bool AllowBeatmapChange => !beatmapBacking.Disabled; public MusicController() { @@ -239,7 +210,7 @@ namespace osu.Game.Overlays playlist.StateChanged += (c, s) => { - if (playlistButton.Enabled) + if (AllowBeatmapChange) playlistButton.FadeColour(s == Visibility.Visible ? colorYellow : Color4.White, 200, EasingTypes.OutQuint); }; } @@ -249,9 +220,30 @@ namespace osu.Game.Overlays beatmapBacking.ValueChanged += beatmapChanged; beatmapBacking.TriggerChange(); + beatmapBacking.DisabledChanged += beatmapDisabledChanged; + beatmapDisabledChanged(beatmapBacking.Disabled); + base.LoadComplete(); } + private void beatmapDisabledChanged(bool newBeatmapDisabled) + { + prevButton.Enabled.Value = !newBeatmapDisabled; + nextButton.Enabled.Value = !newBeatmapDisabled; + playlistButton.Enabled.Value = !newBeatmapDisabled; + + // Toggle the playlist's visibility if required + if (newBeatmapDisabled) + { + showPlaylistOnceAvailable = playlist.State == Visibility.Visible; + + if (showPlaylistOnceAvailable) + playlist?.Hide(); + } + else if (showPlaylistOnceAvailable && State == Visibility.Visible) + playlist?.Show(); + } + protected override void UpdateAfterChildren() { base.UpdateAfterChildren(); @@ -281,7 +273,8 @@ namespace osu.Game.Overlays if (track == null) { - playlist.PlayNext(); + if (AllowBeatmapChange) + playlist.PlayNext(); return; } @@ -407,7 +400,7 @@ namespace osu.Game.Overlays FadeIn(transition_length, EasingTypes.OutQuint); dragContainer.ScaleTo(1, transition_length, EasingTypes.OutElastic); - if(Alpha == 0) + if (Alpha == 0) showPlaylistOnceAvailable = false; }