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

Show near-misses on the results-screen heatmap

This commit is contained in:
Dan Balasescu 2024-02-06 20:06:51 +09:00
parent 891346f795
commit 5850d6a578
No known key found for this signature in database
3 changed files with 81 additions and 60 deletions

View File

@ -95,12 +95,7 @@ namespace osu.Game.Rulesets.Osu.Mods
/// </summary> /// </summary>
private static void blockInputToObjectsUnderSliderHead(DrawableSliderHead slider) private static void blockInputToObjectsUnderSliderHead(DrawableSliderHead slider)
{ {
var oldHitAction = slider.HitArea.Hit; slider.HitArea.CanBeHit = () => !slider.DrawableSlider.AllJudged;
slider.HitArea.Hit = () =>
{
oldHitAction?.Invoke();
return !slider.DrawableSlider.AllJudged;
};
} }
private void applyEarlyFading(DrawableHitCircle circle) private void applyEarlyFading(DrawableHitCircle circle)

View File

@ -10,7 +10,6 @@ using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
@ -43,7 +42,6 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
Drawable IHasApproachCircle.ApproachCircle => ApproachCircle; Drawable IHasApproachCircle.ApproachCircle => ApproachCircle;
private Container scaleContainer; private Container scaleContainer;
private InputManager inputManager;
public DrawableHitCircle() public DrawableHitCircle()
: this(null) : this(null)
@ -73,14 +71,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
HitArea = new HitReceptor HitArea = new HitReceptor
{ {
Hit = () => CanBeHit = () => !AllJudged,
{ Hit = () => UpdateResult(true)
if (AllJudged)
return false;
UpdateResult(true);
return true;
},
}, },
shakeContainer = new ShakeContainer shakeContainer = new ShakeContainer
{ {
@ -114,13 +106,6 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
ScaleBindable.BindValueChanged(scale => scaleContainer.Scale = new Vector2(scale.NewValue)); ScaleBindable.BindValueChanged(scale => scaleContainer.Scale = new Vector2(scale.NewValue));
} }
protected override void LoadComplete()
{
base.LoadComplete();
inputManager = GetContainingInputManager();
}
public override double LifetimeStart public override double LifetimeStart
{ {
get => base.LifetimeStart; get => base.LifetimeStart;
@ -155,7 +140,15 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
if (!userTriggered) if (!userTriggered)
{ {
if (!HitObject.HitWindows.CanBeHit(timeOffset)) if (!HitObject.HitWindows.CanBeHit(timeOffset))
ApplyMinResult(); {
ApplyResult((r, position) =>
{
var circleResult = (OsuHitCircleJudgementResult)r;
circleResult.Type = r.Judgement.MinResult;
circleResult.CursorPositionAtHit = position;
}, computeHitPosition());
}
return; return;
} }
@ -169,22 +162,21 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
if (result == HitResult.None || clickAction != ClickAction.Hit) if (result == HitResult.None || clickAction != ClickAction.Hit)
return; return;
Vector2? hitPosition = null;
// Todo: This should also consider misses, but they're a little more interesting to handle, since we don't necessarily know the position at the time of a miss.
if (result.IsHit())
{
var localMousePosition = ToLocalSpace(inputManager.CurrentState.Mouse.Position);
hitPosition = HitObject.StackedPosition + (localMousePosition - DrawSize / 2);
}
ApplyResult<(HitResult result, Vector2? position)>((r, state) => ApplyResult<(HitResult result, Vector2? position)>((r, state) =>
{ {
var circleResult = (OsuHitCircleJudgementResult)r; var circleResult = (OsuHitCircleJudgementResult)r;
circleResult.Type = state.result; circleResult.Type = state.result;
circleResult.CursorPositionAtHit = state.position; circleResult.CursorPositionAtHit = state.position;
}, (result, hitPosition)); }, (result, computeHitPosition()));
}
private Vector2? computeHitPosition()
{
if (HitArea.ClosestPressPosition is Vector2 screenSpaceHitPosition)
return HitObject.StackedPosition + (ToLocalSpace(screenSpaceHitPosition) - DrawSize / 2);
return null;
} }
/// <summary> /// <summary>
@ -227,6 +219,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
break; break;
case ArmedState.Idle: case ArmedState.Idle:
HitArea.ClosestPressPosition = null;
HitArea.HitAction = null; HitArea.HitAction = null;
break; break;
@ -247,9 +240,11 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
// IsHovered is used // IsHovered is used
public override bool HandlePositionalInput => true; public override bool HandlePositionalInput => true;
public Func<bool> Hit; public Func<bool> CanBeHit;
public Action Hit;
public OsuAction? HitAction; public OsuAction? HitAction;
public Vector2? ClosestPressPosition;
public HitReceptor() public HitReceptor()
{ {
@ -264,12 +259,31 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
public bool OnPressed(KeyBindingPressEvent<OsuAction> e) public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
{ {
if (!(CanBeHit?.Invoke() ?? false))
return false;
switch (e.Action) switch (e.Action)
{ {
case OsuAction.LeftButton: case OsuAction.LeftButton:
case OsuAction.RightButton: case OsuAction.RightButton:
if (IsHovered && (Hit?.Invoke() ?? false)) // Only update closest press position while the object hasn't been hit yet.
if (HitAction == null)
{ {
if (ClosestPressPosition is Vector2 curClosest)
{
float oldDist = Vector2.DistanceSquared(curClosest, ScreenSpaceDrawQuad.Centre);
float newDist = Vector2.DistanceSquared(e.ScreenSpaceMousePosition, ScreenSpaceDrawQuad.Centre);
if (newDist < oldDist)
ClosestPressPosition = e.ScreenSpaceMousePosition;
}
else
ClosestPressPosition = e.ScreenSpaceMousePosition;
}
if (IsHovered)
{
Hit?.Invoke();
HitAction ??= e.Action; HitAction ??= e.Action;
return true; return true;
} }

View File

@ -197,7 +197,9 @@ namespace osu.Game.Rulesets.Osu.Statistics
var point = new HitPoint(pointType, this) var point = new HitPoint(pointType, this)
{ {
BaseColour = pointType == HitPointType.Hit ? new Color4(102, 255, 204, 255) : new Color4(255, 102, 102, 255) BaseColour = pointType == HitPointType.Hit
? new Color4(102, 255, 204, 255)
: new Color4(255, 102, 102, 255)
}; };
points[r][c] = point; points[r][c] = point;
@ -250,12 +252,15 @@ namespace osu.Game.Rulesets.Osu.Statistics
var rotatedCoordinate = -1 * new Vector2((float)Math.Cos(rotatedAngle), (float)Math.Sin(rotatedAngle)); var rotatedCoordinate = -1 * new Vector2((float)Math.Cos(rotatedAngle), (float)Math.Sin(rotatedAngle));
Vector2 localCentre = new Vector2(points_per_dimension - 1) / 2; Vector2 localCentre = new Vector2(points_per_dimension - 1) / 2;
float localRadius = localCentre.X * inner_portion * normalisedDistance; // The radius inside the inner portion which of the heatmap which the closest point lies. float localRadius = localCentre.X * inner_portion * normalisedDistance;
Vector2 localPoint = localCentre + localRadius * rotatedCoordinate; Vector2 localPoint = localCentre + localRadius * rotatedCoordinate;
// Find the most relevant hit point. // Find the most relevant hit point.
int r = Math.Clamp((int)Math.Round(localPoint.Y), 0, points_per_dimension - 1); int r = (int)Math.Round(localPoint.Y);
int c = Math.Clamp((int)Math.Round(localPoint.X), 0, points_per_dimension - 1); int c = (int)Math.Round(localPoint.X);
if (r < 0 || r >= points_per_dimension || c < 0 || c >= points_per_dimension)
return;
PeakValue = Math.Max(PeakValue, ((HitPoint)pointGrid.Content[r][c]).Increment()); PeakValue = Math.Max(PeakValue, ((HitPoint)pointGrid.Content[r][c]).Increment());
@ -298,6 +303,8 @@ namespace osu.Game.Rulesets.Osu.Statistics
{ {
base.Update(); base.Update();
if (pointType == HitPointType.Hit)
{
// the point at which alpha is saturated and we begin to adjust colour lightness. // the point at which alpha is saturated and we begin to adjust colour lightness.
const float lighten_cutoff = 0.95f; const float lighten_cutoff = 0.95f;
@ -318,9 +325,14 @@ namespace osu.Game.Rulesets.Osu.Statistics
Debug.Assert(amount <= 1); Debug.Assert(amount <= 1);
Alpha = Math.Min(amount / lighten_cutoff, 1); Alpha = Math.Min(amount / lighten_cutoff, 1);
if (pointType == HitPointType.Hit)
Colour = BaseColour.Lighten(Math.Max(0, amount - lighten_cutoff)); Colour = BaseColour.Lighten(Math.Max(0, amount - lighten_cutoff));
} }
else
{
Alpha = 0.8f;
Colour = BaseColour;
}
}
} }
private enum HitPointType private enum HitPointType