1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

Add a glow fade based on density of hits.

This commit is contained in:
smoogipooo 2017-04-20 17:11:58 +09:00
parent e92e08f86d
commit 6e3018f36d
4 changed files with 72 additions and 4 deletions

View File

@ -19,6 +19,11 @@ namespace osu.Game.Rulesets.Scoring
/// </summary>
public event Action Failed;
/// <summary>
/// Invoked when a new judgement has occurred. This occurs after the judgement has been processed by the <see cref="ScoreProcessor"/>.
/// </summary>
public event Action<Judgement> NewJudgement;
/// <summary>
/// The current total score.
/// </summary>
@ -105,6 +110,15 @@ namespace osu.Game.Rulesets.Scoring
Failed?.Invoke();
}
/// <summary>
/// Notifies subscribers of <see cref="NewJudgement"/> that a new judgement has occurred.
/// </summary>
/// <param name="judgement">The judgement to notify subscribers of.</param>
protected void NotifyNewJudgement(Judgement judgement)
{
NewJudgement?.Invoke(judgement);
}
/// <summary>
/// Retrieve a score populated with data for the current play this processor is responsible for.
/// </summary>
@ -177,6 +191,8 @@ namespace osu.Game.Rulesets.Scoring
Judgements.Add(judgement);
OnNewJudgement(judgement);
NotifyNewJudgement(judgement);
}
else
OnJudgementChanged(judgement);

View File

@ -94,7 +94,7 @@ namespace osu.Game.Rulesets.UI
}
}
public void BindProcessor(ScoreProcessor processor)
public virtual void BindProcessor(ScoreProcessor processor)
{
ScoreCounter?.Current.BindTo(processor.TotalScore);
AccuracyCounter?.Current.BindTo(processor.Accuracy);
@ -102,7 +102,7 @@ namespace osu.Game.Rulesets.UI
HealthDisplay?.Current.BindTo(processor.Health);
}
public void BindHitRenderer(HitRenderer hitRenderer)
public virtual void BindHitRenderer(HitRenderer hitRenderer)
{
hitRenderer.InputManager.Add(KeyCounter.GetReceptor());
}

View File

@ -3,15 +3,43 @@
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Scoring;
using System;
namespace osu.Game.Rulesets.UI
{
public class StandardHealthDisplay : HealthDisplay, IHasAccentColour
{
/// <summary>
/// The base opacity of the glow.
/// </summary>
private const float base_glow_opacity = 0.6f;
/// <summary>
/// The number of sequential hits required within <see cref="glow_fade_delay"/> to reach the maximum glow opacity.
/// </summary>
private const int glow_max_hits = 8;
/// <summary>
/// The amount of time to delay before fading the glow opacity back to <see cref="base_glow_opacity"/>.
/// <para>
/// This is calculated to require a stream snapped to 1/4 at 150bpm to reach the maximum glow opacity with <see cref="glow_max_hits"/> hits.
/// </para>
/// </summary>
private const float glow_fade_delay = 100;
/// <summary>
/// The amount of time to fade the glow to <see cref="base_glow_opacity"/> after <see cref="glow_fade_delay"/>.
/// </summary>
private const double glow_fade_time = 500;
private readonly Container fill;
public Color4 AccentColour
@ -32,7 +60,7 @@ namespace osu.Game.Rulesets.UI
fill.EdgeEffect = new EdgeEffect
{
Colour = glowColour,
Colour = glowColour.Opacity(base_glow_opacity),
Radius = 8,
Roundness = 4,
Type = EdgeEffectType.Glow,
@ -65,6 +93,21 @@ namespace osu.Game.Rulesets.UI
};
}
public void BindProcessor(ScoreProcessor processor)
{
processor.NewJudgement += onNewJudgement;
}
private void onNewJudgement(Judgement judgement)
{
if (judgement.Result == HitResult.Miss)
return;
fill.FadeEdgeEffectTo(Math.Min(1, fill.EdgeEffect.Colour.Linear.A + (1f - base_glow_opacity) / glow_max_hits), 50, EasingTypes.OutQuint);
fill.Delay(glow_fade_delay);
fill.FadeEdgeEffectTo(base_glow_opacity, glow_fade_time, EasingTypes.OutQuint);
}
protected override void SetHealth(float value) => fill.ResizeTo(new Vector2(value, 1), 200, EasingTypes.OutQuint);
}
}

View File

@ -8,6 +8,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play;
namespace osu.Game.Rulesets.UI
@ -75,8 +76,16 @@ namespace osu.Game.Rulesets.UI
if (shd != null)
{
shd.AccentColour = colours.BlueLighter;
shd.GlowColour = colours.BlueDarker.Opacity(0.6f);
shd.GlowColour = colours.BlueDarker;
}
}
public override void BindProcessor(ScoreProcessor processor)
{
base.BindProcessor(processor);
var shd = HealthDisplay as StandardHealthDisplay;
shd?.BindProcessor(processor);
}
}
}