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

Introduce PlayerBase class

This commit is contained in:
TocoToucan 2018-02-08 23:28:42 +03:00
parent 0ba76bbaa1
commit d437c1d7ec
4 changed files with 99 additions and 89 deletions

View File

@ -5,9 +5,6 @@ using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Allocation; 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;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
@ -18,31 +15,23 @@ using osu.Framework.Threading;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Cursor;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Play.BreaksOverlay; using osu.Game.Screens.Play.BreaksOverlay;
using osu.Game.Screens.Ranking; using osu.Game.Screens.Ranking;
using osu.Game.Storyboards.Drawables;
using OpenTK;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
public class Player : OsuScreen, IProvideCursor public class Player : PlayerBase, IProvideCursor
{ {
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap);
public override bool ShowOverlaysOnEnter => false; public override bool ShowOverlaysOnEnter => false;
public Action RestartRequested; public Action RestartRequested;
public override bool AllowBeatmapRulesetChange => false;
public bool HasFailed { get; private set; } public bool HasFailed { get; private set; }
public bool AllowPause { get; set; } = true; public bool AllowPause { get; set; } = true;
@ -67,39 +56,16 @@ namespace osu.Game.Screens.Play
private ScoreProcessor scoreProcessor; private ScoreProcessor scoreProcessor;
protected RulesetContainer RulesetContainer; protected RulesetContainer RulesetContainer;
#region User Settings
private Bindable<double> dimLevel;
private Bindable<double> blurLevel;
private Bindable<bool> showStoryboard;
private Bindable<bool> mouseWheelDisabled;
private Bindable<double> userAudioOffset;
private SampleChannel sampleRestart;
#endregion
private Container storyboardContainer;
private DrawableStoryboard storyboard;
private HUDOverlay hudOverlay; private HUDOverlay hudOverlay;
private FailOverlay failOverlay; private FailOverlay failOverlay;
private bool loadedSuccessfully => RulesetContainer?.Objects.Any() == true; private bool loadedSuccessfully => RulesetContainer?.Objects.Any() == true;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio, OsuConfigManager config, APIAccess api) private void load(OsuConfigManager config, APIAccess api)
{ {
this.api = api; this.api = api;
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");
WorkingBeatmap working = Beatmap.Value; WorkingBeatmap working = Beatmap.Value;
Beatmap beatmap; Beatmap beatmap;
@ -150,15 +116,14 @@ namespace osu.Game.Screens.Play
offsetClock = new FramedOffsetClock(decoupledClock); offsetClock = new FramedOffsetClock(decoupledClock);
userAudioOffset = config.GetBindable<double>(OsuSetting.AudioOffset); UserAudioOffset.ValueChanged += v => offsetClock.Offset = v;
userAudioOffset.ValueChanged += v => offsetClock.Offset = v; UserAudioOffset.TriggerChange();
userAudioOffset.TriggerChange();
scoreProcessor = RulesetContainer.CreateScoreProcessor(); scoreProcessor = RulesetContainer.CreateScoreProcessor();
Children = new Drawable[] Children = new Drawable[]
{ {
storyboardContainer = new Container StoryboardContainer = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Clock = offsetClock, Clock = offsetClock,
@ -219,8 +184,8 @@ namespace osu.Game.Screens.Play
} }
}; };
if (showStoryboard) if (ShowStoryboard)
initializeStoryboard(false); InitializeStoryboard(false);
// Bind ScoreProcessor to ourselves // Bind ScoreProcessor to ourselves
scoreProcessor.AllJudged += onCompletion; scoreProcessor.AllJudged += onCompletion;
@ -239,22 +204,9 @@ namespace osu.Game.Screens.Play
mod.ApplyToClock(adjustableSourceClock); mod.ApplyToClock(adjustableSourceClock);
} }
private void initializeStoryboard(bool asyncLoad)
{
var beatmap = Beatmap.Value;
storyboard = beatmap.Storyboard.CreateDrawable(Beatmap.Value);
storyboard.Masking = true;
if (asyncLoad)
LoadComponentAsync(storyboard, storyboardContainer.Add);
else
storyboardContainer.Add(storyboard);
}
public void Restart() public void Restart()
{ {
sampleRestart?.Play(); SampleRestart?.Play();
ValidForResume = false; ValidForResume = false;
RestartRequested?.Invoke(); RestartRequested?.Invoke();
Exit(); Exit();
@ -310,10 +262,10 @@ namespace osu.Game.Screens.Play
if (!loadedSuccessfully) if (!loadedSuccessfully)
return; return;
dimLevel.ValueChanged += _ => updateBackgroundElements(); DimLevel.ValueChanged += _ => UpdateBackgroundElements();
blurLevel.ValueChanged += _ => updateBackgroundElements(); BlurLevel.ValueChanged += _ => UpdateBackgroundElements();
showStoryboard.ValueChanged += _ => updateBackgroundElements(); ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements();
updateBackgroundElements(); UpdateBackgroundElements();
Content.Alpha = 0; Content.Alpha = 0;
Content Content
@ -368,28 +320,6 @@ namespace osu.Game.Screens.Play
return true; return true;
} }
private 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);
}
private void fadeOut() private void fadeOut()
{ {
const float fade_out_duration = 250; const float fade_out_duration = 250;
@ -402,6 +332,6 @@ namespace osu.Game.Screens.Play
Background?.FadeTo(1f, fade_out_duration); Background?.FadeTo(1f, fade_out_duration);
} }
protected override bool OnWheel(InputState state) => mouseWheelDisabled.Value && !pauseContainer.IsPaused; protected override bool OnWheel(InputState state) => MouseWheelDisabled.Value && !pauseContainer.IsPaused;
} }
} }

View File

@ -0,0 +1,84 @@
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 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)
{
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

@ -9,7 +9,6 @@ using osu.Framework.Screens;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Backgrounds;
using OpenTK; using OpenTK;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
@ -17,7 +16,7 @@ using osu.Game.Screens.Play.PlayerSettings;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
public class PlayerLoader : OsuScreen public class PlayerLoader : PlayerBase
{ {
private Player player; private Player player;
@ -27,10 +26,6 @@ namespace osu.Game.Screens.Play
private bool showOverlays = true; private bool showOverlays = true;
public override bool ShowOverlaysOnEnter => showOverlays; public override bool ShowOverlaysOnEnter => showOverlays;
public override bool AllowBeatmapRulesetChange => false;
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap);
public PlayerLoader(Player player) public PlayerLoader(Player player)
{ {
this.player = player; this.player = player;

View File

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