1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:47:26 +08:00

Implement OsuScreen::CanBeatmapChange and use it in the music controller

This commit is contained in:
MrTheMake 2017-06-19 14:32:53 +02:00
parent ee2c649971
commit 5450499415
5 changed files with 43 additions and 9 deletions

View File

@ -298,21 +298,22 @@ namespace osu.Game
private Container overlayContent; private Container overlayContent;
private OsuScreen currentScreen; public readonly Bindable<OsuScreen> CurrentScreen = new Bindable<OsuScreen>();
private FrameworkConfigManager frameworkConfig; private FrameworkConfigManager frameworkConfig;
private void screenChanged(Screen newScreen) private void screenChanged(Screen newScreen)
{ {
currentScreen = newScreen as OsuScreen; CurrentScreen.Value = newScreen as OsuScreen;
if (currentScreen == null) if (CurrentScreen.Value == null)
{ {
Exit(); Exit();
return; return;
} }
//central game screen change logic. //central game screen change logic.
if (!currentScreen.ShowOverlays) if (!CurrentScreen.Value.ShowOverlays)
{ {
settings.State = Visibility.Hidden; settings.State = Visibility.Hidden;
Toolbar.State = Visibility.Hidden; Toolbar.State = Visibility.Hidden;
@ -362,7 +363,7 @@ namespace osu.Game
mainContent.Padding = new MarginPadding { Top = Toolbar.Position.Y + Toolbar.DrawHeight }; mainContent.Padding = new MarginPadding { Top = Toolbar.Position.Y + Toolbar.DrawHeight };
Cursor.State = currentScreen?.HasLocalCursorDisplayed == false ? Visibility.Visible : Visibility.Hidden; Cursor.State = CurrentScreen.Value?.HasLocalCursorDisplayed == false ? Visibility.Visible : Visibility.Hidden;
} }
private void screenAdded(Screen newScreen) private void screenAdded(Screen newScreen)

View File

@ -16,13 +16,14 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Framework.Threading;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Framework.Threading;
using osu.Game.Overlays.Music; using osu.Game.Overlays.Music;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Screens;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
@ -39,7 +40,9 @@ namespace osu.Game.Overlays
private Drawable currentBackground; private Drawable currentBackground;
private DragBar progressBar; private DragBar progressBar;
private IconButton prevButton;
private IconButton playButton; private IconButton playButton;
private IconButton nextButton;
private IconButton playlistButton; private IconButton playlistButton;
private SpriteText title, artist; private SpriteText title, artist;
@ -50,9 +53,13 @@ namespace osu.Game.Overlays
private readonly Bindable<WorkingBeatmap> beatmapBacking = new Bindable<WorkingBeatmap>(); private readonly Bindable<WorkingBeatmap> beatmapBacking = new Bindable<WorkingBeatmap>();
private readonly Bindable<OsuScreen> currentScreenBacking = new Bindable<OsuScreen>();
private Container dragContainer; private Container dragContainer;
private Container playerContainer; private Container playerContainer;
private bool canChangeBeatmap;
public MusicController() public MusicController()
{ {
Width = 400; Width = 400;
@ -81,7 +88,7 @@ namespace osu.Game.Overlays
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuGameBase game, OsuColour colours, LocalisationEngine localisation) private void load(OsuGame game, OsuColour colours, LocalisationEngine localisation)
{ {
this.localisation = localisation; this.localisation = localisation;
@ -153,7 +160,7 @@ namespace osu.Game.Overlays
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Children = new[] Children = new[]
{ {
new IconButton prevButton = new IconButton
{ {
Action = prev, Action = prev,
Icon = FontAwesome.fa_step_backward, Icon = FontAwesome.fa_step_backward,
@ -165,7 +172,7 @@ namespace osu.Game.Overlays
Action = play, Action = play,
Icon = FontAwesome.fa_play_circle_o, Icon = FontAwesome.fa_play_circle_o,
}, },
new IconButton nextButton = new IconButton
{ {
Action = next, Action = next,
Icon = FontAwesome.fa_step_forward, Icon = FontAwesome.fa_step_forward,
@ -197,6 +204,7 @@ namespace osu.Game.Overlays
}; };
beatmapBacking.BindTo(game.Beatmap); beatmapBacking.BindTo(game.Beatmap);
currentScreenBacking.BindTo(game.CurrentScreen);
playlist.StateChanged += (c, s) => playlistButton.FadeColour(s == Visibility.Visible ? colours.Yellow : Color4.White, 200, EasingTypes.OutQuint); playlist.StateChanged += (c, s) => playlistButton.FadeColour(s == Visibility.Visible ? colours.Yellow : Color4.White, 200, EasingTypes.OutQuint);
} }
@ -206,9 +214,24 @@ namespace osu.Game.Overlays
beatmapBacking.ValueChanged += beatmapChanged; beatmapBacking.ValueChanged += beatmapChanged;
beatmapBacking.TriggerChange(); beatmapBacking.TriggerChange();
currentScreenBacking.ValueChanged += screenChanged;
currentScreenBacking.TriggerChange();
base.LoadComplete(); base.LoadComplete();
} }
private void screenChanged(OsuScreen newScreen)
{
canChangeBeatmap = newScreen?.CanChangeBeatmap ?? false;
prevButton.Enabled = canChangeBeatmap;
playButton.Enabled = canChangeBeatmap;
nextButton.Enabled = canChangeBeatmap;
playlistButton.Enabled = canChangeBeatmap;
progressBar.IsEnabled = canChangeBeatmap;
}
protected override void UpdateAfterChildren() protected override void UpdateAfterChildren()
{ {
base.UpdateAfterChildren(); base.UpdateAfterChildren();
@ -250,12 +273,16 @@ namespace osu.Game.Overlays
private void prev() private void prev()
{ {
if(!canChangeBeatmap) return;
queuedDirection = TransformDirection.Prev; queuedDirection = TransformDirection.Prev;
playlist.PlayPrevious(); playlist.PlayPrevious();
} }
private void next() private void next()
{ {
if (!canChangeBeatmap) return;
queuedDirection = TransformDirection.Next; queuedDirection = TransformDirection.Next;
playlist.PlayNext(); playlist.PlayNext();
} }

View File

@ -29,6 +29,8 @@ namespace osu.Game.Screens
internal virtual bool AllowRulesetChange => true; internal virtual bool AllowRulesetChange => true;
internal virtual bool CanChangeBeatmap => true;
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>(); private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>(); private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();

View File

@ -32,6 +32,8 @@ namespace osu.Game.Screens.Play
internal override bool ShowOverlays => false; internal override bool ShowOverlays => false;
internal override bool CanChangeBeatmap => false;
internal override bool HasLocalCursorDisplayed => !pauseContainer.IsPaused && !HasFailed && HitRenderer.ProvidingUserCursor; internal override bool HasLocalCursorDisplayed => !pauseContainer.IsPaused && !HasFailed && HitRenderer.ProvidingUserCursor;
public BeatmapInfo BeatmapInfo; public BeatmapInfo BeatmapInfo;

View File

@ -279,5 +279,7 @@ namespace osu.Game.Screens.Ranking
modeChangeButtons.Current.TriggerChange(); modeChangeButtons.Current.TriggerChange();
} }
internal override bool CanChangeBeatmap => false;
} }
} }