1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 17:42:54 +08:00
osu-lazer/osu.Game/Screens/Play/HitErrorDisplay/HitErrorDisplayOverlay.cs

127 lines
3.8 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Scoring;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
2019-08-20 03:04:27 +08:00
using osu.Game.Rulesets.Objects;
namespace osu.Game.Screens.Play.HitErrorDisplay
{
public class HitErrorDisplayOverlay : Container<HitErrorDisplay>
{
private const int fade_duration = 200;
private const int margin = 10;
private readonly Bindable<ScoreMeterType> type = new Bindable<ScoreMeterType>();
2019-08-20 03:04:27 +08:00
private readonly HitWindows hitWindows;
private readonly ScoreProcessor processor;
2019-08-21 14:16:09 +08:00
private BarHitErrorDisplay leftDisplay;
private BarHitErrorDisplay rightDisplay;
public HitErrorDisplayOverlay(ScoreProcessor processor)
{
2019-08-20 03:04:27 +08:00
this.processor = processor;
hitWindows = processor.CreateHitWindows();
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, Bindable<WorkingBeatmap> workingBeatmap)
{
config.BindWith(OsuSetting.ScoreMeter, type);
hitWindows.SetDifficulty(workingBeatmap.Value.BeatmapInfo.BaseDifficulty.OverallDifficulty);
}
protected override void LoadComplete()
{
base.LoadComplete();
type.BindValueChanged(onTypeChanged, true);
}
private void onTypeChanged(ValueChangedEvent<ScoreMeterType> type)
{
switch (type.NewValue)
{
case ScoreMeterType.None:
2019-08-21 14:16:09 +08:00
removeLeftDisplay();
removeRightDisplay();
break;
2019-08-20 03:04:27 +08:00
case ScoreMeterType.HitErrorBoth:
2019-08-21 14:16:09 +08:00
addLeftDisplay();
addRightDisplay();
2019-08-20 03:04:27 +08:00
break;
case ScoreMeterType.HitErrorLeft:
2019-08-21 14:16:09 +08:00
addLeftDisplay();
removeRightDisplay();
2019-08-20 03:04:27 +08:00
break;
case ScoreMeterType.HitErrorRight:
2019-08-21 14:16:09 +08:00
addRightDisplay();
removeLeftDisplay();
break;
}
}
2019-08-20 03:04:27 +08:00
2019-08-21 14:16:09 +08:00
private void addLeftDisplay()
2019-08-20 03:04:27 +08:00
{
2019-08-21 14:16:09 +08:00
if (leftDisplay != null)
return;
leftDisplay = createNew();
}
private void addRightDisplay()
{
if (rightDisplay != null)
return;
rightDisplay = createNew(true);
}
private void removeRightDisplay()
{
if (rightDisplay == null)
return;
processor.NewJudgement -= rightDisplay.OnNewJudgement;
rightDisplay.FadeOut(fade_duration, Easing.OutQuint).Expire();
rightDisplay = null;
}
private void removeLeftDisplay()
{
if (leftDisplay == null)
return;
processor.NewJudgement -= leftDisplay.OnNewJudgement;
leftDisplay.FadeOut(fade_duration, Easing.OutQuint).Expire();
leftDisplay = null;
2019-08-20 03:04:27 +08:00
}
2019-08-21 14:16:09 +08:00
private BarHitErrorDisplay createNew(bool reversed = false)
2019-08-20 03:04:27 +08:00
{
var display = new BarHitErrorDisplay(hitWindows, reversed)
2019-08-20 03:04:27 +08:00
{
Margin = new MarginPadding(margin),
Anchor = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
Origin = reversed ? Anchor.CentreRight : Anchor.CentreLeft,
Alpha = 0,
};
processor.NewJudgement += display.OnNewJudgement;
Add(display);
display.FadeInFromZero(fade_duration, Easing.OutQuint);
2019-08-21 14:16:09 +08:00
return display;
2019-08-20 03:04:27 +08:00
}
}
}