mirror of
https://github.com/ppy/osu.git
synced 2026-05-18 20:30:27 +08:00
@@ -0,0 +1,162 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Tests.Visual;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Rulesets.Osu.Judgements;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Extensions.ObjectExtensions;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Rulesets.Osu.HUD;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Tests
|
||||
{
|
||||
public partial class TestSceneAimErrorMeter : OsuManualInputManagerTestScene
|
||||
{
|
||||
private DependencyProvidingContainer dependencyContainer = null!;
|
||||
private ScoreProcessor scoreProcessor = null!;
|
||||
|
||||
private TestAimErrorMeter aimErrorMeter = null!;
|
||||
|
||||
private CircularContainer gameObject = null!;
|
||||
|
||||
private ScheduledDelegate? automaticAdditionDelegate;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
AddSliderStep("Hit marker size", 0f, 12f, 7f, t =>
|
||||
{
|
||||
if (aimErrorMeter.IsNotNull())
|
||||
aimErrorMeter.HitMarkerSize.Value = t;
|
||||
});
|
||||
AddSliderStep("Average position marker size", 1f, 25f, 7f, t =>
|
||||
{
|
||||
if (aimErrorMeter.IsNotNull())
|
||||
aimErrorMeter.AverageMarkerSize.Value = t;
|
||||
});
|
||||
}
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetupSteps() => AddStep("Create components", () =>
|
||||
{
|
||||
automaticAdditionDelegate?.Cancel();
|
||||
automaticAdditionDelegate = null;
|
||||
|
||||
var ruleset = new OsuRuleset();
|
||||
|
||||
scoreProcessor = new ScoreProcessor(ruleset);
|
||||
Child = dependencyContainer = new DependencyProvidingContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
CachedDependencies = new (Type, object)[]
|
||||
{
|
||||
(typeof(ScoreProcessor), scoreProcessor)
|
||||
}
|
||||
};
|
||||
dependencyContainer.Children = new Drawable[]
|
||||
{
|
||||
aimErrorMeter = new TestAimErrorMeter
|
||||
{
|
||||
Margin = new MarginPadding
|
||||
{
|
||||
Top = 100
|
||||
},
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
Scale = new Vector2(2),
|
||||
},
|
||||
|
||||
gameObject = new CircularContainer
|
||||
{
|
||||
Size = new Vector2(2 * OsuHitObject.OBJECT_RADIUS),
|
||||
Position = new Vector2(256, 192),
|
||||
Colour = Color4.Yellow,
|
||||
Masking = true,
|
||||
BorderThickness = 2,
|
||||
BorderColour = Color4.White,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Alpha = 0,
|
||||
AlwaysPresent = true
|
||||
},
|
||||
new Circle
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(4),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
protected override bool OnMouseDown(MouseDownEvent e)
|
||||
{
|
||||
// the division by 2 is because CS=5 applies a 0.5x (plus fudge) multiplier to `OBJECT_RADIUS`
|
||||
aimErrorMeter.AddPoint((gameObject.ToLocalSpace(e.ScreenSpaceMouseDownPosition) - new Vector2(OsuHitObject.OBJECT_RADIUS)) / 2);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestManyHitPointsAutomatic()
|
||||
{
|
||||
AddStep("add scheduled delegate", () =>
|
||||
{
|
||||
automaticAdditionDelegate = Scheduler.AddDelayed(() =>
|
||||
{
|
||||
var randomPos = new Vector2(
|
||||
RNG.NextSingle(0, 2 * OsuHitObject.OBJECT_RADIUS),
|
||||
RNG.NextSingle(0, 2 * OsuHitObject.OBJECT_RADIUS));
|
||||
|
||||
aimErrorMeter.AddPoint(randomPos - new Vector2(OsuHitObject.OBJECT_RADIUS));
|
||||
InputManager.MoveMouseTo(gameObject.ToScreenSpace(randomPos));
|
||||
}, 1, true);
|
||||
});
|
||||
AddWaitStep("wait for some hit points", 10);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDisplayStyles()
|
||||
{
|
||||
AddStep("Switch hit position marker style to +", () => aimErrorMeter.HitMarkerStyle.Value = AimErrorMeter.MarkerStyle.Plus);
|
||||
AddStep("Switch hit position marker style to x", () => aimErrorMeter.HitMarkerStyle.Value = AimErrorMeter.MarkerStyle.X);
|
||||
AddStep("Switch average position marker style to +", () => aimErrorMeter.AverageMarkerStyle.Value = AimErrorMeter.MarkerStyle.Plus);
|
||||
AddStep("Switch average position marker style to x", () => aimErrorMeter.AverageMarkerStyle.Value = AimErrorMeter.MarkerStyle.X);
|
||||
|
||||
AddStep("Switch position display to absolute", () => aimErrorMeter.PositionDisplayStyle.Value = AimErrorMeter.PositionDisplay.Absolute);
|
||||
AddStep("Switch position display to relative", () => aimErrorMeter.PositionDisplayStyle.Value = AimErrorMeter.PositionDisplay.Normalised);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestManualPlacement()
|
||||
{
|
||||
AddStep("return user input", () => InputManager.UseParentInput = true);
|
||||
}
|
||||
|
||||
private partial class TestAimErrorMeter : AimErrorMeter
|
||||
{
|
||||
public void AddPoint(Vector2 position)
|
||||
{
|
||||
OnNewJudgement(new OsuHitCircleJudgementResult(new HitCircle(), new OsuJudgement())
|
||||
{
|
||||
CursorPositionAtHit = position
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,475 @@
|
||||
// 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.
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Pooling;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Localisation.HUD;
|
||||
using osu.Game.Rulesets.Judgements;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Objects.Legacy;
|
||||
using osu.Game.Rulesets.Osu.Judgements;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Rulesets.Osu.Statistics;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Screens.Play.HUD.HitErrorMeters;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
using Container = osu.Framework.Graphics.Containers.Container;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.HUD
|
||||
{
|
||||
[Cached]
|
||||
public partial class AimErrorMeter : HitErrorMeter
|
||||
{
|
||||
[SettingSource(typeof(AimErrorMeterStrings), nameof(AimErrorMeterStrings.HitMarkerSize), nameof(AimErrorMeterStrings.HitMarkerSizeDescription))]
|
||||
public BindableNumber<float> HitMarkerSize { get; } = new BindableNumber<float>(7f)
|
||||
{
|
||||
MinValue = 0f,
|
||||
MaxValue = 12f,
|
||||
Precision = 1f
|
||||
};
|
||||
|
||||
[SettingSource(typeof(AimErrorMeterStrings), nameof(AimErrorMeterStrings.HitMarkerStyle), nameof(AimErrorMeterStrings.HitMarkerStyleDescription))]
|
||||
public Bindable<MarkerStyle> HitMarkerStyle { get; } = new Bindable<MarkerStyle>();
|
||||
|
||||
[SettingSource(typeof(AimErrorMeterStrings), nameof(AimErrorMeterStrings.AverageMarkerSize), nameof(AimErrorMeterStrings.AverageMarkerSizeDescription))]
|
||||
public BindableNumber<float> AverageMarkerSize { get; } = new BindableNumber<float>(12f)
|
||||
{
|
||||
MinValue = 7f,
|
||||
MaxValue = 25f,
|
||||
Precision = 1f
|
||||
};
|
||||
|
||||
[SettingSource(typeof(AimErrorMeterStrings), nameof(AimErrorMeterStrings.AverageMarkerStyle), nameof(AimErrorMeterStrings.AverageMarkerStyleDescription))]
|
||||
public Bindable<MarkerStyle> AverageMarkerStyle { get; } = new Bindable<MarkerStyle>(MarkerStyle.Plus);
|
||||
|
||||
[SettingSource(typeof(AimErrorMeterStrings), nameof(AimErrorMeterStrings.PositionDisplayStyle), nameof(AimErrorMeterStrings.PositionDisplayStyleDescription))]
|
||||
public Bindable<PositionDisplay> PositionDisplayStyle { get; } = new Bindable<PositionDisplay>();
|
||||
|
||||
// used for calculate relative position.
|
||||
private Vector2? lastObjectPosition;
|
||||
|
||||
private Container averagePositionMarker = null!;
|
||||
private Container averagePositionMarkerRotationContainer = null!;
|
||||
private Vector2? averagePosition;
|
||||
|
||||
private readonly DrawablePool<HitPositionMarker> hitPositionPool = new DrawablePool<HitPositionMarker>(30);
|
||||
private Container hitPositionMarkerContainer = null!;
|
||||
|
||||
private Container arrowBackgroundContainer = null!;
|
||||
private UprightAspectMaintainingContainer rotateFixedContainer = null!;
|
||||
private Container mainContainer = null!;
|
||||
|
||||
private float objectRadius;
|
||||
|
||||
private const int max_concurrent_judgements = 30;
|
||||
|
||||
private const float line_thickness = 2;
|
||||
private const float inner_portion = 0.85f;
|
||||
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; } = null!;
|
||||
|
||||
public AimErrorMeter()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
AlwaysPresent = true;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(IBindable<WorkingBeatmap> beatmap, ScoreProcessor processor)
|
||||
{
|
||||
InternalChild = new Container
|
||||
{
|
||||
Height = 100,
|
||||
Width = 100,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
hitPositionPool,
|
||||
rotateFixedContainer = new UprightAspectMaintainingContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
mainContainer = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new CircularContainer
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
BorderColour = Colour4.White,
|
||||
Masking = true,
|
||||
BorderThickness = 2,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = new Vector2(inner_portion),
|
||||
Child = new Box
|
||||
{
|
||||
Colour = Colour4.Gray,
|
||||
Alpha = 0.3f,
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
},
|
||||
arrowBackgroundContainer = new Container
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Name = "Arrow Background",
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Rotation = 45,
|
||||
Alpha = 0f,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Circle
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Height = inner_portion + 0.2f,
|
||||
Width = line_thickness / 2,
|
||||
},
|
||||
new Circle
|
||||
{
|
||||
Height = 5f,
|
||||
Width = line_thickness / 2,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.TopCentre,
|
||||
Margin = new MarginPadding(-line_thickness / 4),
|
||||
RelativePositionAxes = Axes.Both,
|
||||
Y = -(inner_portion + 0.2f) / 2,
|
||||
Rotation = -45
|
||||
},
|
||||
new Circle
|
||||
{
|
||||
Height = 5f,
|
||||
Width = line_thickness / 2,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.TopCentre,
|
||||
Margin = new MarginPadding(-line_thickness / 4),
|
||||
RelativePositionAxes = Axes.Both,
|
||||
Y = -(inner_portion + 0.2f) / 2,
|
||||
Rotation = 45
|
||||
}
|
||||
}
|
||||
},
|
||||
new Container
|
||||
{
|
||||
Name = "Cross Background",
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Circle
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Alpha = 0.5f,
|
||||
Width = line_thickness,
|
||||
Height = inner_portion * 0.9f
|
||||
},
|
||||
new Circle
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Alpha = 0.5f,
|
||||
Width = line_thickness,
|
||||
Height = inner_portion * 0.9f,
|
||||
Rotation = 90
|
||||
},
|
||||
new Circle
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Alpha = 0.2f,
|
||||
Width = line_thickness / 2,
|
||||
Height = inner_portion * 0.9f,
|
||||
Rotation = 45
|
||||
},
|
||||
new Circle
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Alpha = 0.2f,
|
||||
Width = line_thickness / 2,
|
||||
Height = inner_portion * 0.9f,
|
||||
Rotation = 135
|
||||
},
|
||||
}
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
hitPositionMarkerContainer = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre
|
||||
},
|
||||
averagePositionMarker = new UprightAspectMaintainingContainer
|
||||
{
|
||||
RelativePositionAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Child = averagePositionMarkerRotationContainer = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Circle
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Width = 0.25f,
|
||||
},
|
||||
new Circle
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Width = 0.25f,
|
||||
Rotation = 90
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// handle IApplicableToDifficulty for CS change.
|
||||
BeatmapDifficulty newDifficulty = new BeatmapDifficulty();
|
||||
beatmap.Value.Beatmap.Difficulty.CopyTo(newDifficulty);
|
||||
|
||||
var mods = processor.Mods.Value;
|
||||
|
||||
foreach (var mod in mods.OfType<IApplicableToDifficulty>())
|
||||
mod.ApplyToDifficulty(newDifficulty);
|
||||
|
||||
objectRadius = OsuHitObject.OBJECT_RADIUS * LegacyRulesetExtensions.CalculateScaleFromCircleSize(newDifficulty.CircleSize, true);
|
||||
|
||||
AverageMarkerSize.BindValueChanged(size => averagePositionMarker.Size = new Vector2(size.NewValue), true);
|
||||
AverageMarkerStyle.BindValueChanged(style => averagePositionMarkerRotationContainer.Rotation = style.NewValue == MarkerStyle.Plus ? 0 : 45, true);
|
||||
|
||||
PositionDisplayStyle.BindValueChanged(s =>
|
||||
{
|
||||
Clear();
|
||||
|
||||
if (s.NewValue == PositionDisplay.Normalised)
|
||||
{
|
||||
arrowBackgroundContainer.FadeIn(100);
|
||||
rotateFixedContainer.Remove(mainContainer, false);
|
||||
AddInternal(mainContainer);
|
||||
}
|
||||
else
|
||||
{
|
||||
arrowBackgroundContainer.FadeOut(100);
|
||||
// when in absolute mode, rotation of the aim error meter as a whole should not affect how the component is displayed
|
||||
RemoveInternal(mainContainer, false);
|
||||
rotateFixedContainer.Add(mainContainer);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
protected override void OnNewJudgement(JudgementResult judgement)
|
||||
{
|
||||
if (judgement is not OsuHitCircleJudgementResult circleJudgement) return;
|
||||
|
||||
if (circleJudgement.CursorPositionAtHit == null) return;
|
||||
|
||||
if (hitPositionMarkerContainer.Count > max_concurrent_judgements)
|
||||
{
|
||||
const double quick_fade_time = 300;
|
||||
|
||||
// check with a bit of lenience to avoid precision error in comparison.
|
||||
var old = hitPositionMarkerContainer.FirstOrDefault(j => j.LifetimeEnd > Clock.CurrentTime + quick_fade_time * 1.1);
|
||||
|
||||
if (old != null)
|
||||
{
|
||||
old.ClearTransforms();
|
||||
old.FadeOut(quick_fade_time).Expire();
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 hitPosition;
|
||||
|
||||
if (PositionDisplayStyle.Value == PositionDisplay.Normalised && lastObjectPosition != null)
|
||||
{
|
||||
hitPosition = AccuracyHeatmap.FindRelativeHitPosition(lastObjectPosition.Value, ((OsuHitObject)circleJudgement.HitObject).StackedEndPosition,
|
||||
circleJudgement.CursorPositionAtHit.Value, objectRadius, 45) * 0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
// get relative position between mouse position and current object.
|
||||
hitPosition = (circleJudgement.CursorPositionAtHit.Value - ((OsuHitObject)circleJudgement.HitObject).StackedPosition) / objectRadius / 2 * inner_portion;
|
||||
}
|
||||
|
||||
hitPosition = Vector2.Clamp(hitPosition, new Vector2(-0.5f), new Vector2(0.5f));
|
||||
|
||||
hitPositionPool.Get(drawableHit =>
|
||||
{
|
||||
drawableHit.X = hitPosition.X;
|
||||
drawableHit.Y = hitPosition.Y;
|
||||
drawableHit.Colour = getColourForPosition(hitPosition);
|
||||
|
||||
hitPositionMarkerContainer.Add(drawableHit);
|
||||
});
|
||||
|
||||
var newAveragePosition = 0.1f * hitPosition + 0.9f * (averagePosition ?? hitPosition);
|
||||
averagePositionMarker.MoveTo(newAveragePosition, 800, Easing.OutQuint);
|
||||
averagePosition = newAveragePosition;
|
||||
lastObjectPosition = ((OsuHitObject)circleJudgement.HitObject).StackedPosition;
|
||||
}
|
||||
|
||||
private Color4 getColourForPosition(Vector2 position)
|
||||
{
|
||||
float distance = Vector2.Distance(position, Vector2.Zero);
|
||||
|
||||
if (distance >= 0.5f * inner_portion)
|
||||
return colours.Red;
|
||||
|
||||
if (distance >= 0.35f * inner_portion)
|
||||
return colours.Yellow;
|
||||
|
||||
if (distance >= 0.2f * inner_portion)
|
||||
return colours.Green;
|
||||
|
||||
return colours.Blue;
|
||||
}
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
averagePosition = null;
|
||||
averagePositionMarker.MoveTo(Vector2.Zero, 800, Easing.OutQuint);
|
||||
lastObjectPosition = null;
|
||||
|
||||
foreach (var h in hitPositionMarkerContainer)
|
||||
{
|
||||
h.ClearTransforms();
|
||||
h.Expire();
|
||||
}
|
||||
}
|
||||
|
||||
private partial class HitPositionMarker : PoolableDrawable
|
||||
{
|
||||
[Resolved]
|
||||
private AimErrorMeter aimErrorMeter { get; set; } = null!;
|
||||
|
||||
public readonly BindableNumber<float> MarkerSize = new BindableFloat();
|
||||
public readonly Bindable<MarkerStyle> Style = new Bindable<MarkerStyle>();
|
||||
|
||||
private readonly Container content;
|
||||
|
||||
public HitPositionMarker()
|
||||
{
|
||||
RelativePositionAxes = Axes.Both;
|
||||
|
||||
Anchor = Anchor.Centre;
|
||||
Origin = Anchor.Centre;
|
||||
|
||||
InternalChild = new UprightAspectMaintainingContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Child = content = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Circle
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Width = 0.25f,
|
||||
Rotation = -45
|
||||
},
|
||||
new Circle
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Width = 0.25f,
|
||||
Rotation = 45
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
MarkerSize.BindTo(aimErrorMeter.HitMarkerSize);
|
||||
MarkerSize.BindValueChanged(size => Size = new Vector2(size.NewValue), true);
|
||||
Style.BindTo(aimErrorMeter.HitMarkerStyle);
|
||||
Style.BindValueChanged(style => content.Rotation = style.NewValue == MarkerStyle.X ? 0 : 45, true);
|
||||
}
|
||||
|
||||
protected override void PrepareForUse()
|
||||
{
|
||||
base.PrepareForUse();
|
||||
|
||||
const int judgement_fade_in_duration = 100;
|
||||
const int judgement_fade_out_duration = 5000;
|
||||
|
||||
this
|
||||
.ResizeTo(new Vector2(0))
|
||||
.FadeInFromZero(judgement_fade_in_duration, Easing.OutQuint)
|
||||
.ResizeTo(new Vector2(MarkerSize.Value), judgement_fade_in_duration, Easing.OutQuint)
|
||||
.Then()
|
||||
.FadeOut(judgement_fade_out_duration)
|
||||
.Expire();
|
||||
}
|
||||
}
|
||||
|
||||
public enum MarkerStyle
|
||||
{
|
||||
[Description("x")]
|
||||
X,
|
||||
|
||||
[Description("+")]
|
||||
Plus,
|
||||
}
|
||||
|
||||
public enum PositionDisplay
|
||||
{
|
||||
[LocalisableDescription(typeof(AimErrorMeterStrings), nameof(AimErrorMeterStrings.Absolute))]
|
||||
Absolute,
|
||||
|
||||
[LocalisableDescription(typeof(AimErrorMeterStrings), nameof(AimErrorMeterStrings.Normalised))]
|
||||
Normalised,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -232,10 +232,47 @@ namespace osu.Game.Rulesets.Osu.Statistics
|
||||
if (pointGrid.Content.Count == 0)
|
||||
return;
|
||||
|
||||
double angle1 = Math.Atan2(end.Y - hitPoint.Y, hitPoint.X - end.X); // Angle between the end point and the hit point.
|
||||
double angle2 = Math.Atan2(end.Y - start.Y, start.X - end.X); // Angle between the end point and the start point.
|
||||
Vector2 relativePosition = FindRelativeHitPosition(start, end, hitPoint, radius, rotation);
|
||||
|
||||
var localCentre = new Vector2(points_per_dimension - 1) / 2;
|
||||
float localRadius = localCentre.X * inner_portion;
|
||||
var localPoint = localCentre + localRadius * relativePosition;
|
||||
|
||||
// Find the most relevant hit point.
|
||||
int r = (int)Math.Round(localPoint.Y);
|
||||
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, ((GridPoint)pointGrid.Content[r][c]).Increment());
|
||||
|
||||
bufferedGrid.ForceRedraw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalises the position of a hit on a circle such that it is relative to the movement that was performed to arrive at said circle.
|
||||
/// </summary>
|
||||
/// <param name="previousObjectPosition">The position of the object prior to the one getting hit.</param>
|
||||
/// <param name="nextObjectPosition">The position of the object which is getting hit.</param>
|
||||
/// <param name="hitPoint">The point at which the user hit.</param>
|
||||
/// <param name="objectRadius">The radius of <paramref name="previousObjectPosition"/> and <paramref name="nextObjectPosition"/>.</param>
|
||||
/// <param name="rotation">
|
||||
/// The rotation of the axis which is to be considered in the same direction as the vector
|
||||
/// leading from <paramref name="previousObjectPosition"/> to <paramref name="nextObjectPosition"/>.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// A 2D vector representing the <paramref name="hitPoint"/> as relative to the movement between <paramref name="previousObjectPosition"/> and <paramref name="nextObjectPosition"/>
|
||||
/// and relative to the <paramref name="objectRadius"/>.
|
||||
/// If the object was hit perfectly in the middle, the return value will be <see cref="Vector2.Zero"/>.
|
||||
/// If the object was hit perfectly at its edge, the returned vector will have a magnitude of 1.
|
||||
/// </returns>
|
||||
public static Vector2 FindRelativeHitPosition(Vector2 previousObjectPosition, Vector2 nextObjectPosition, Vector2 hitPoint, float objectRadius, float rotation)
|
||||
{
|
||||
double angle1 = Math.Atan2(nextObjectPosition.Y - hitPoint.Y, hitPoint.X - nextObjectPosition.X); // Angle between the end point and the hit point.
|
||||
double angle2 = Math.Atan2(nextObjectPosition.Y - previousObjectPosition.Y, previousObjectPosition.X - nextObjectPosition.X); // Angle between the end point and the start point.
|
||||
double finalAngle = angle2 - angle1; // Angle between start, end, and hit points.
|
||||
float normalisedDistance = Vector2.Distance(hitPoint, end) / radius;
|
||||
float normalisedDistance = Vector2.Distance(hitPoint, nextObjectPosition) / objectRadius; // Distance between the hit point and the end point.
|
||||
|
||||
// Consider two objects placed horizontally, with the start on the left and the end on the right.
|
||||
// The above calculated the angle between {end, start}, and the angle between {end, hitPoint}, in the form:
|
||||
@@ -254,22 +291,7 @@ namespace osu.Game.Rulesets.Osu.Statistics
|
||||
//
|
||||
// We also need to apply the anti-clockwise rotation.
|
||||
double rotatedAngle = finalAngle - float.DegreesToRadians(rotation);
|
||||
var rotatedCoordinate = -1 * new Vector2((float)Math.Cos(rotatedAngle), (float)Math.Sin(rotatedAngle));
|
||||
|
||||
Vector2 localCentre = new Vector2(points_per_dimension - 1) / 2;
|
||||
float localRadius = localCentre.X * inner_portion * normalisedDistance;
|
||||
Vector2 localPoint = localCentre + localRadius * rotatedCoordinate;
|
||||
|
||||
// Find the most relevant hit point.
|
||||
int r = (int)Math.Round(localPoint.Y);
|
||||
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, ((GridPoint)pointGrid.Content[r][c]).Increment());
|
||||
|
||||
bufferedGrid.ForceRedraw();
|
||||
return -normalisedDistance * new Vector2((float)Math.Cos(rotatedAngle), (float)Math.Sin(rotatedAngle));
|
||||
}
|
||||
|
||||
private abstract partial class GridPoint : CompositeDrawable
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Localisation;
|
||||
|
||||
namespace osu.Game.Localisation.HUD
|
||||
{
|
||||
public static class AimErrorMeterStrings
|
||||
{
|
||||
private const string prefix = @"osu.Game.Resources.Localisation.HUD.AimErrorMeterStrings";
|
||||
|
||||
/// <summary>
|
||||
/// "Hit marker size"
|
||||
/// </summary>
|
||||
public static LocalisableString HitMarkerSize => new TranslatableString(getKey(@"hit_marker_size"), @"Hit marker size");
|
||||
|
||||
/// <summary>
|
||||
/// "Controls the size of the markers displayed after every hit."
|
||||
/// </summary>
|
||||
public static LocalisableString HitMarkerSizeDescription => new TranslatableString(getKey(@"hit_marker_size_description"), @"Controls the size of the markers displayed after every hit.");
|
||||
|
||||
/// <summary>
|
||||
/// "Hit marker style"
|
||||
/// </summary>
|
||||
public static LocalisableString HitMarkerStyle => new TranslatableString(getKey(@"hit_marker_style"), @"Hit marker style");
|
||||
|
||||
/// <summary>
|
||||
/// "The visual style of the hit markers."
|
||||
/// </summary>
|
||||
public static LocalisableString HitMarkerStyleDescription => new TranslatableString(getKey(@"hit_marker_style_description"), @"The visual style of the hit markers.");
|
||||
|
||||
/// <summary>
|
||||
/// "Average position marker size"
|
||||
/// </summary>
|
||||
public static LocalisableString AverageMarkerSize => new TranslatableString(getKey(@"average_marker_size"), @"Average position marker size");
|
||||
|
||||
/// <summary>
|
||||
/// "Controls the size of the marker showing average hit position."
|
||||
/// </summary>
|
||||
public static LocalisableString AverageMarkerSizeDescription => new TranslatableString(getKey(@"average_marker_size_description"), @"Controls the size of the marker showing average hit position.");
|
||||
|
||||
/// <summary>
|
||||
/// "Average position marker style"
|
||||
/// </summary>
|
||||
public static LocalisableString AverageMarkerStyle => new TranslatableString(getKey(@"average_marker_style"), @"Average position marker style");
|
||||
|
||||
/// <summary>
|
||||
/// "The visual style of the average position marker."
|
||||
/// </summary>
|
||||
public static LocalisableString AverageMarkerStyleDescription => new TranslatableString(getKey(@"average_marker_style_description"), @"The visual style of the average position marker.");
|
||||
|
||||
/// <summary>
|
||||
/// "Position display style"
|
||||
/// </summary>
|
||||
public static LocalisableString PositionDisplayStyle => new TranslatableString(getKey(@"position_style"), @"Position display style");
|
||||
|
||||
/// <summary>
|
||||
/// "Controls whether positions displayed on the meter are absolute (as seen on screen) or normalised (relative to the direction of movement from previous object)."
|
||||
/// </summary>
|
||||
public static LocalisableString PositionDisplayStyleDescription => new TranslatableString(getKey(@"position_style_description"), @"Controls whether positions displayed on the meter are absolute (as seen on screen) or normalised (relative to the direction of movement from previous object).");
|
||||
|
||||
/// <summary>
|
||||
/// "Absolute"
|
||||
/// </summary>
|
||||
public static LocalisableString Absolute => new TranslatableString(getKey(@"absolute"), @"Absolute");
|
||||
|
||||
/// <summary>
|
||||
/// "Normalised"
|
||||
/// </summary>
|
||||
public static LocalisableString Normalised => new TranslatableString(getKey(@"normalised"), @"Normalised");
|
||||
|
||||
private static string getKey(string key) => $@"{prefix}:{key}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user