1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 02:53:01 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/HitErrorDisplay.cs

103 lines
3.0 KiB
C#
Raw Normal View History

2019-08-11 19:57:21 +08:00
// 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.
2019-08-30 14:32:47 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2019-08-30 14:51:36 +08:00
using osu.Framework.Extensions.IEnumerableExtensions;
2019-08-30 17:46:42 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-08-30 14:32:47 +08:00
using osu.Game.Configuration;
2019-08-30 14:51:36 +08:00
using osu.Game.Rulesets.Judgements;
2019-08-30 17:46:42 +08:00
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play.HUD.HitErrorMeters;
2019-08-11 19:57:21 +08:00
2019-08-30 17:46:42 +08:00
namespace osu.Game.Screens.Play.HUD
2019-08-11 19:57:21 +08:00
{
2019-08-30 14:32:47 +08:00
public class HitErrorDisplay : Container<HitErrorMeter>
2019-08-11 19:57:21 +08:00
{
2019-08-30 14:32:47 +08:00
private const int fade_duration = 200;
private const int margin = 10;
2019-08-11 20:53:15 +08:00
2019-08-30 14:32:47 +08:00
private readonly Bindable<ScoreMeterType> type = new Bindable<ScoreMeterType>();
2019-08-30 17:46:42 +08:00
private readonly HitWindows hitWindows;
2019-08-30 14:32:47 +08:00
private readonly ScoreProcessor processor;
2019-08-30 17:46:42 +08:00
public HitErrorDisplay(ScoreProcessor processor, HitWindows hitWindows)
2019-08-30 14:32:47 +08:00
{
this.processor = processor;
2019-08-30 17:46:42 +08:00
this.hitWindows = hitWindows;
RelativeSizeAxes = Axes.Both;
2019-08-30 14:51:36 +08:00
processor.NewJudgement += onNewJudgement;
}
2019-08-30 14:32:47 +08:00
[BackgroundDependencyLoader]
2019-08-30 17:46:42 +08:00
private void load(OsuConfigManager config)
2019-08-30 14:32:47 +08:00
{
config.BindWith(OsuSetting.ScoreMeter, type);
}
protected override void LoadComplete()
{
base.LoadComplete();
type.BindValueChanged(typeChanged, true);
}
2019-08-30 18:47:21 +08:00
private void onNewJudgement(JudgementResult result)
{
2019-10-09 18:08:31 +08:00
if (result.HitObject.HitWindows.WindowFor(HitResult.Miss) == 0)
return;
2019-08-30 18:47:21 +08:00
foreach (var c in Children)
c.OnNewJudgement(result);
}
2019-08-30 14:32:47 +08:00
private void typeChanged(ValueChangedEvent<ScoreMeterType> type)
{
2019-08-30 14:51:36 +08:00
Children.ForEach(c => c.FadeOut(fade_duration, Easing.OutQuint));
if (hitWindows == null)
return;
2019-08-30 14:32:47 +08:00
switch (type.NewValue)
{
case ScoreMeterType.HitErrorBoth:
2019-08-30 14:51:36 +08:00
createBar(false);
createBar(true);
2019-08-30 14:32:47 +08:00
break;
case ScoreMeterType.HitErrorLeft:
2019-08-30 14:51:36 +08:00
createBar(false);
2019-08-30 14:32:47 +08:00
break;
case ScoreMeterType.HitErrorRight:
2019-08-30 14:51:36 +08:00
createBar(true);
2019-08-30 14:32:47 +08:00
break;
}
}
2019-08-30 14:51:36 +08:00
private void createBar(bool rightAligned)
2019-08-30 14:32:47 +08:00
{
2019-08-30 14:51:36 +08:00
var display = new BarHitErrorMeter(hitWindows, rightAligned)
2019-08-30 14:32:47 +08:00
{
Margin = new MarginPadding(margin),
2019-08-30 14:51:36 +08:00
Anchor = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
Origin = rightAligned ? Anchor.CentreRight : Anchor.CentreLeft,
2019-08-30 14:32:47 +08:00
Alpha = 0,
};
Add(display);
display.FadeInFromZero(fade_duration, Easing.OutQuint);
}
2019-08-30 18:47:21 +08:00
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
processor.NewJudgement -= onNewJudgement;
}
2019-08-11 19:57:21 +08:00
}
}