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