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

152 lines
4.6 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-12-12 15:09:42 +08:00
if (processor != null)
processor.NewJudgement += onNewJudgement;
2019-08-30 14:51:36 +08:00
}
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:
createBar(Anchor.CentreLeft);
createBar(Anchor.CentreRight);
2019-08-30 14:32:47 +08:00
break;
case ScoreMeterType.HitErrorLeft:
createBar(Anchor.CentreLeft);
2019-08-30 14:32:47 +08:00
break;
case ScoreMeterType.HitErrorRight:
createBar(Anchor.CentreRight);
break;
case ScoreMeterType.HitErrorBottom:
createBar(Anchor.BottomCentre);
2019-08-30 14:32:47 +08:00
break;
2019-12-21 18:41:50 +08:00
case ScoreMeterType.ColourBoth:
createColour(Anchor.CentreLeft);
createColour(Anchor.CentreRight);
2019-12-21 18:41:50 +08:00
break;
case ScoreMeterType.ColourLeft:
createColour(Anchor.CentreLeft);
2019-12-21 18:41:50 +08:00
break;
case ScoreMeterType.ColourRight:
createColour(Anchor.CentreRight);
break;
case ScoreMeterType.ColourBottom:
createColour(Anchor.BottomCentre);
2019-12-21 18:41:50 +08:00
break;
2019-08-30 14:32:47 +08:00
}
}
private void createBar(Anchor anchor)
2019-08-30 14:32:47 +08:00
{
bool rightAligned = (anchor & Anchor.x2) > 0;
bool bottomAligned = (anchor & Anchor.y2) > 0;
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),
Anchor = anchor,
Origin = bottomAligned ? Anchor.CentreLeft : anchor,
2019-08-30 14:32:47 +08:00
Alpha = 0,
Rotation = bottomAligned ? 270 : 0
2019-08-30 14:32:47 +08:00
};
2019-12-21 18:41:50 +08:00
completeDisplayLoading(display);
}
private void createColour(Anchor anchor)
2019-12-21 18:41:50 +08:00
{
bool bottomAligned = (anchor & Anchor.y2) > 0;
2019-12-21 18:41:50 +08:00
var display = new ColourHitErrorMeter(hitWindows)
{
Margin = new MarginPadding(margin),
Anchor = anchor,
Origin = bottomAligned ? Anchor.CentreLeft : anchor,
2019-12-21 18:41:50 +08:00
Alpha = 0,
Rotation = bottomAligned ? 270 : 0
2019-12-21 18:41:50 +08:00
};
completeDisplayLoading(display);
}
private void completeDisplayLoading(HitErrorMeter display)
{
2019-08-30 14:32:47 +08:00
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);
2019-12-12 15:09:42 +08:00
if (processor != null)
processor.NewJudgement -= onNewJudgement;
2019-08-30 18:47:21 +08:00
}
2019-08-11 19:57:21 +08:00
}
}