osu/osu.Game/Screens/Play/HUD/HitErrorMeters/HitErrorMeter.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.7 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2019-08-30 06:32:47 +00:00
// See the LICENCE file in the repository root for full licence text.
2022-06-17 07:37:17 +00:00
#nullable disable
2019-12-21 11:52:53 +00:00
using osu.Framework.Allocation;
2019-08-30 06:32:47 +00:00
using osu.Framework.Graphics.Containers;
2019-12-21 11:52:53 +00:00
using osu.Game.Graphics;
2019-08-30 06:32:47 +00:00
using osu.Game.Rulesets.Judgements;
2019-09-06 06:24:00 +00:00
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using osu.Game.Skinning;
2019-12-21 11:52:53 +00:00
using osuTK.Graphics;
2019-08-30 06:32:47 +00:00
2019-08-30 09:46:42 +00:00
namespace osu.Game.Screens.Play.HUD.HitErrorMeters
2019-08-30 06:32:47 +00:00
{
public abstract partial class HitErrorMeter : CompositeDrawable, ISkinnableDrawable
2019-08-30 06:32:47 +00:00
{
protected HitWindows HitWindows { get; private set; }
2019-08-30 06:32:47 +00:00
[Resolved]
private ScoreProcessor processor { get; set; }
2019-12-21 11:52:53 +00:00
[Resolved]
private OsuColour colours { get; set; }
[Resolved(canBeNull: true)]
private GameplayClockContainer gameplayClockContainer { get; set; }
public bool UsesFixedAnchor { get; set; }
[BackgroundDependencyLoader(true)]
private void load(DrawableRuleset drawableRuleset)
2019-08-30 06:32:47 +00:00
{
HitWindows = drawableRuleset?.FirstAvailableHitWindows ?? HitWindows.Empty;
// This is to allow the visual state to be correct after HUD comes visible after being hidden.
AlwaysPresent = true;
2019-08-30 06:32:47 +00:00
}
protected override void LoadComplete()
{
base.LoadComplete();
if (gameplayClockContainer != null)
gameplayClockContainer.OnSeek += Clear;
2021-12-21 04:05:26 +00:00
processor.NewJudgement += processorNewJudgement;
}
2021-12-21 04:05:26 +00:00
// Scheduled as meter implementations are likely going to change/add drawables when reacting to this.
private void processorNewJudgement(JudgementResult j) => Schedule(() => OnNewJudgement(j));
/// <summary>
/// Fired when a new judgement arrives.
/// </summary>
/// <param name="judgement">The new judgement.</param>
protected abstract void OnNewJudgement(JudgementResult judgement);
2019-12-21 11:52:53 +00:00
protected Color4 GetColourForHitResult(HitResult result)
{
return colours.ForHitResult(result);
2019-12-21 11:52:53 +00:00
}
/// <summary>
/// Invoked by <see cref="GameplayClockContainer.OnSeek"/>.
/// Any inheritors of <see cref="HitErrorMeter"/> should have this method clear their container that displays the hit error results.
/// </summary>
2021-09-20 14:22:36 +00:00
public abstract void Clear();
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (processor != null)
2021-12-21 04:05:26 +00:00
processor.NewJudgement -= processorNewJudgement;
2021-09-20 14:07:42 +00:00
if (gameplayClockContainer != null)
gameplayClockContainer.OnSeek -= Clear;
}
2019-08-30 06:32:47 +00:00
}
}