1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

Move all storyboard loading to Player itself

This commit is contained in:
TocoToucan 2018-02-15 23:57:53 +03:00
parent 4535e09607
commit c57e8785e2
5 changed files with 118 additions and 106 deletions

View File

@ -5,6 +5,8 @@ using System;
using System.Linq;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
@ -14,7 +16,7 @@ using osu.Framework.Screens;
using osu.Framework.Threading;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Cursor;
using osu.Game.Online.API;
using osu.Game.Rulesets;
@ -23,10 +25,11 @@ using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play.BreaksOverlay;
using osu.Game.Screens.Ranking;
using osu.Game.Storyboards.Drawables;
namespace osu.Game.Screens.Play
{
public class Player : PlayerBase, IProvideCursor
public class Player : ScreenWithBeatmapBackground, IProvideCursor
{
public override bool ShowOverlaysOnEnter => false;
@ -53,18 +56,24 @@ namespace osu.Game.Screens.Play
private APIAccess api;
private SampleChannel sampleRestart;
private ScoreProcessor scoreProcessor;
protected RulesetContainer RulesetContainer;
private HUDOverlay hudOverlay;
private FailOverlay failOverlay;
private DrawableStoryboard storyboard;
private Container storyboardContainer;
private bool loadedSuccessfully => RulesetContainer?.Objects.Any() == true;
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, APIAccess api)
private void load(AudioManager audio, APIAccess api)
{
this.api = api;
sampleRestart = audio.Sample.Get(@"Gameplay/restart");
WorkingBeatmap working = Beatmap.Value;
Beatmap beatmap;
@ -123,7 +132,7 @@ namespace osu.Game.Screens.Play
Children = new Drawable[]
{
StoryboardContainer = new Container
storyboardContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Clock = offsetClock,
@ -185,7 +194,7 @@ namespace osu.Game.Screens.Play
};
if (ShowStoryboard)
InitializeStoryboard(false);
initializeStoryboard(false);
// Bind ScoreProcessor to ourselves
scoreProcessor.AllJudged += onCompletion;
@ -206,7 +215,7 @@ namespace osu.Game.Screens.Play
public void Restart()
{
SampleRestart?.Play();
sampleRestart?.Play();
ValidForResume = false;
RestartRequested?.Invoke();
Exit();
@ -330,5 +339,40 @@ namespace osu.Game.Screens.Play
}
protected override bool OnWheel(InputState state) => MouseWheelDisabled.Value && !pauseContainer.IsPaused;
private void initializeStoryboard(bool asyncLoad)
{
if (storyboardContainer == null)
return;
var beatmap = Beatmap.Value;
storyboard = beatmap.Storyboard.CreateDrawable(Beatmap.Value);
storyboard.Masking = true;
if (asyncLoad)
LoadComponentAsync(storyboard, storyboardContainer.Add);
else
storyboardContainer.Add(storyboard);
}
protected override void UpdateBackgroundElements()
{
if (!IsCurrentScreen) return;
base.UpdateBackgroundElements();
if (ShowStoryboard && storyboard == null)
initializeStoryboard(true);
var beatmap = Beatmap.Value;
var storyboardVisible = ShowStoryboard && beatmap.Storyboard.HasDrawable;
storyboardContainer?
.FadeColour(OsuColour.Gray(Opacity), Duration, Easing.OutQuint)
.FadeTo(storyboardVisible && Opacity > 0 ? 1 : 0, Duration, Easing.OutQuint);
Background?.FadeTo(!storyboardVisible || beatmap.Background == null ? Opacity : 0, Duration, Easing.OutQuint);
}
}
}

View File

@ -1,98 +0,0 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Screens.Backgrounds;
using osu.Game.Storyboards.Drawables;
using OpenTK;
namespace osu.Game.Screens.Play
{
public abstract class PlayerBase : OsuScreen
{
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap);
public override bool AllowBeatmapRulesetChange => false;
#region User Settings
protected Bindable<double> DimLevel;
protected Bindable<double> BlurLevel;
protected Bindable<bool> ShowStoryboard;
protected Bindable<bool> MouseWheelDisabled;
protected Bindable<double> UserAudioOffset;
protected SampleChannel SampleRestart;
#endregion
protected DrawableStoryboard Storyboard;
protected Container StoryboardContainer;
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuConfigManager config)
{
DimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
BlurLevel = config.GetBindable<double>(OsuSetting.BlurLevel);
ShowStoryboard = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
MouseWheelDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableWheel);
SampleRestart = audio.Sample.Get(@"Gameplay/restart");
UserAudioOffset = config.GetBindable<double>(OsuSetting.AudioOffset);
}
protected void ConfigureBackgroundUpdate()
{
DimLevel.ValueChanged += _ => UpdateBackgroundElements();
BlurLevel.ValueChanged += _ => UpdateBackgroundElements();
ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements();
UpdateBackgroundElements();
}
protected void UpdateBackgroundElements()
{
if (!IsCurrentScreen) return;
const float duration = 800;
var opacity = 1 - (float)DimLevel;
if (ShowStoryboard && Storyboard == null)
InitializeStoryboard(true);
var beatmap = Beatmap.Value;
var storyboardVisible = ShowStoryboard && beatmap.Storyboard.HasDrawable;
StoryboardContainer?
.FadeColour(OsuColour.Gray(opacity), duration, Easing.OutQuint)
.FadeTo(storyboardVisible && opacity > 0 ? 1 : 0, duration, Easing.OutQuint);
(Background as BackgroundScreenBeatmap)?.BlurTo(new Vector2((float)BlurLevel.Value * 25), duration, Easing.OutQuint);
Background?.FadeTo(!storyboardVisible || beatmap.Background == null ? opacity : 0, duration, Easing.OutQuint);
}
protected void InitializeStoryboard(bool asyncLoad)
{
if (StoryboardContainer == null)
return;
var beatmap = Beatmap.Value;
Storyboard = beatmap.Storyboard.CreateDrawable(Beatmap.Value);
Storyboard.Masking = true;
if (asyncLoad)
LoadComponentAsync(Storyboard, StoryboardContainer.Add);
else
StoryboardContainer.Add(Storyboard);
}
}
}

View File

@ -16,7 +16,7 @@ using osu.Game.Screens.Play.PlayerSettings;
namespace osu.Game.Screens.Play
{
public class PlayerLoader : PlayerBase
public class PlayerLoader : ScreenWithBeatmapBackground
{
private Player player;
@ -263,5 +263,13 @@ namespace osu.Game.Screens.Play
};
}
}
protected override void UpdateBackgroundElements()
{
if (!IsCurrentScreen) return;
base.UpdateBackgroundElements();
Background?.FadeTo(Opacity, Duration, Easing.OutQuint);
}
}
}

View File

@ -0,0 +1,58 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Game.Configuration;
using osu.Game.Screens.Backgrounds;
using OpenTK;
namespace osu.Game.Screens.Play
{
public abstract class ScreenWithBeatmapBackground : OsuScreen
{
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap);
public override bool AllowBeatmapRulesetChange => false;
protected float Duration => 800;
protected float Opacity => 1 - (float)DimLevel;
#region User Settings
protected Bindable<double> DimLevel;
protected Bindable<double> BlurLevel;
protected Bindable<bool> ShowStoryboard;
protected Bindable<bool> MouseWheelDisabled;
protected Bindable<double> UserAudioOffset;
#endregion
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
DimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
BlurLevel = config.GetBindable<double>(OsuSetting.BlurLevel);
ShowStoryboard = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
MouseWheelDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableWheel);
UserAudioOffset = config.GetBindable<double>(OsuSetting.AudioOffset);
}
protected void ConfigureBackgroundUpdate()
{
DimLevel.ValueChanged += _ => UpdateBackgroundElements();
BlurLevel.ValueChanged += _ => UpdateBackgroundElements();
ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements();
UpdateBackgroundElements();
}
protected virtual void UpdateBackgroundElements()
{
if (!IsCurrentScreen) return;
(Background as BackgroundScreenBeatmap)?.BlurTo(new Vector2((float)BlurLevel.Value * 25), Duration, Easing.OutQuint);
}
}
}

View File

@ -340,7 +340,7 @@
<Compile Include="Overlays\Social\SocialPanel.cs" />
<Compile Include="Rulesets\Mods\IApplicableToDrawableHitObject.cs" />
<Compile Include="Rulesets\Objects\HitWindows.cs" />
<Compile Include="Screens\Play\PlayerBase.cs" />
<Compile Include="Screens\Play\ScreenWithBeatmapBackground.cs" />
<Compile Include="Screens\Play\PlayerSettings\VisualSettings.cs" />
<Compile Include="Rulesets\Objects\CatmullApproximator.cs" />
<Compile Include="Rulesets\UI\HitObjectContainer.cs" />