2022-09-05 10:49:48 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-12-21 18:41:50 +08:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2020-01-24 10:52:32 +08:00
|
|
|
using System.Collections.Generic;
|
2019-12-21 21:08:28 +08:00
|
|
|
using System.Linq;
|
2022-09-03 05:07:30 +08:00
|
|
|
using osu.Framework.Bindables;
|
2019-12-21 18:41:50 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2022-09-03 05:07:30 +08:00
|
|
|
using osu.Game.Configuration;
|
2019-12-21 18:41:50 +08:00
|
|
|
using osu.Game.Rulesets.Judgements;
|
2021-06-08 22:09:18 +08:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
2019-12-21 18:41:50 +08:00
|
|
|
using osuTK;
|
2019-12-21 19:52:53 +08:00
|
|
|
using osuTK.Graphics;
|
2019-12-21 18:41:50 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
|
|
|
{
|
|
|
|
public class ColourHitErrorMeter : HitErrorMeter
|
|
|
|
{
|
2019-12-22 08:17:56 +08:00
|
|
|
private const int animation_duration = 200;
|
2022-06-13 15:35:46 +08:00
|
|
|
private const int drawable_judgement_size = 8;
|
2019-12-21 19:30:41 +08:00
|
|
|
|
2022-09-11 02:30:43 +08:00
|
|
|
[SettingSource("Judgement count", "Number of displayed judgements")]
|
2022-09-04 23:24:12 +08:00
|
|
|
public BindableNumber<int> HitShapeCount { get; } = new BindableNumber<int>(20)
|
2022-09-03 05:07:30 +08:00
|
|
|
{
|
|
|
|
MinValue = 1,
|
|
|
|
MaxValue = 30,
|
|
|
|
Precision = 1
|
|
|
|
};
|
|
|
|
|
2022-09-11 02:30:43 +08:00
|
|
|
[SettingSource("Opacity", "Visibility of the displayed judgements")]
|
2022-09-04 23:24:12 +08:00
|
|
|
public BindableNumber<float> HitShapeOpacity { get; } = new BindableNumber<float>(1)
|
2022-09-03 05:07:30 +08:00
|
|
|
{
|
2022-09-03 07:27:22 +08:00
|
|
|
MinValue = 0.01f,
|
2022-09-03 05:07:30 +08:00
|
|
|
MaxValue = 1,
|
2022-09-08 17:58:14 +08:00
|
|
|
Precision = 0.01f,
|
2022-09-03 05:07:30 +08:00
|
|
|
};
|
|
|
|
|
2022-09-11 02:30:43 +08:00
|
|
|
[SettingSource("Spacing", "Space between each displayed judgement")]
|
2022-09-04 23:24:12 +08:00
|
|
|
public BindableNumber<float> HitShapeSpacing { get; } = new BindableNumber<float>(2)
|
2022-09-03 05:07:30 +08:00
|
|
|
{
|
|
|
|
MinValue = 0,
|
2022-09-03 07:27:22 +08:00
|
|
|
MaxValue = 10,
|
2022-09-08 17:58:14 +08:00
|
|
|
Precision = 0.1f
|
2022-09-03 05:07:30 +08:00
|
|
|
};
|
|
|
|
|
2022-09-11 02:30:43 +08:00
|
|
|
[SettingSource("Shape", "The shape of each displayed judgement")]
|
2022-09-04 23:24:12 +08:00
|
|
|
public Bindable<ShapeStyle> HitShape { get; } = new Bindable<ShapeStyle>();
|
|
|
|
|
|
|
|
private readonly JudgementFlow judgementsFlow;
|
|
|
|
|
2021-05-17 18:46:50 +08:00
|
|
|
public ColourHitErrorMeter()
|
2019-12-21 18:41:50 +08:00
|
|
|
{
|
2019-12-21 19:30:41 +08:00
|
|
|
AutoSizeAxes = Axes.Both;
|
2022-09-03 07:27:22 +08:00
|
|
|
InternalChild = judgementsFlow = new JudgementFlow();
|
2019-12-21 21:08:28 +08:00
|
|
|
}
|
|
|
|
|
2021-06-08 22:09:18 +08:00
|
|
|
protected override void OnNewJudgement(JudgementResult judgement)
|
|
|
|
{
|
|
|
|
if (!judgement.Type.IsScorable() || judgement.Type.IsBonus())
|
|
|
|
return;
|
|
|
|
|
2022-09-04 23:24:12 +08:00
|
|
|
judgementsFlow.Push(GetColourForHitResult(judgement.Type), HitShapeCount.Value);
|
2022-09-03 05:07:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2022-09-04 23:24:12 +08:00
|
|
|
HitShapeOpacity.BindValueChanged(_ => judgementsFlow.Alpha = HitShapeOpacity.Value, true);
|
|
|
|
HitShapeSpacing.BindValueChanged(_ =>
|
|
|
|
{
|
|
|
|
judgementsFlow.Height = HitShapeCount.Value * (drawable_judgement_size + HitShapeSpacing.Value) - HitShapeSpacing.Value;
|
|
|
|
judgementsFlow.Spacing = new Vector2(0, HitShapeSpacing.Value);
|
|
|
|
}, true);
|
|
|
|
HitShapeCount.BindValueChanged(_ =>
|
|
|
|
{
|
2022-09-11 02:30:43 +08:00
|
|
|
//Used to clear out the overflowing judgement children when the value is lowered
|
|
|
|
judgementsFlow.RemoveAll(_ => true);
|
2022-09-04 23:24:12 +08:00
|
|
|
judgementsFlow.Height = HitShapeCount.Value * (drawable_judgement_size + HitShapeSpacing.Value) - HitShapeSpacing.Value;
|
|
|
|
}, true);
|
2022-09-11 02:30:43 +08:00
|
|
|
HitShape.BindValueChanged(_ => judgementsFlow.Shape.Value = HitShape.Value, true);
|
2021-06-08 22:09:18 +08:00
|
|
|
}
|
2019-12-21 21:08:28 +08:00
|
|
|
|
2021-09-20 22:22:36 +08:00
|
|
|
public override void Clear() => judgementsFlow.Clear();
|
2021-09-18 04:19:41 +08:00
|
|
|
|
2022-09-04 23:24:12 +08:00
|
|
|
private class JudgementFlow : FillFlowContainer<HitErrorShape>
|
2019-12-21 21:08:28 +08:00
|
|
|
{
|
2020-01-24 10:52:32 +08:00
|
|
|
public override IEnumerable<Drawable> FlowingChildren => base.FlowingChildren.Reverse();
|
2022-09-09 15:30:08 +08:00
|
|
|
|
|
|
|
public readonly Bindable<ShapeStyle> Shape = new Bindable<ShapeStyle>();
|
2019-12-22 08:06:57 +08:00
|
|
|
|
2022-09-03 07:27:22 +08:00
|
|
|
public JudgementFlow()
|
2019-12-21 21:08:28 +08:00
|
|
|
{
|
2022-09-03 07:27:22 +08:00
|
|
|
Width = drawable_judgement_size;
|
2019-12-22 08:06:57 +08:00
|
|
|
Direction = FillDirection.Vertical;
|
|
|
|
LayoutDuration = animation_duration;
|
|
|
|
LayoutEasing = Easing.OutQuint;
|
2019-12-21 21:08:28 +08:00
|
|
|
}
|
|
|
|
|
2022-09-04 23:24:12 +08:00
|
|
|
public void Push(Color4 colour, int maxErrorShapeCount)
|
2019-12-21 21:08:28 +08:00
|
|
|
{
|
2022-09-09 15:30:08 +08:00
|
|
|
Add(new HitErrorShape(colour, drawable_judgement_size)
|
|
|
|
{
|
|
|
|
Shape = { BindTarget = Shape },
|
|
|
|
});
|
2019-12-21 21:08:28 +08:00
|
|
|
|
2022-09-04 23:24:12 +08:00
|
|
|
if (Children.Count > maxErrorShapeCount)
|
2019-12-22 08:41:19 +08:00
|
|
|
Children.FirstOrDefault(c => !c.IsRemoved)?.Remove();
|
2019-12-21 21:08:28 +08:00
|
|
|
}
|
2019-12-21 19:30:41 +08:00
|
|
|
}
|
|
|
|
|
2022-09-05 10:49:48 +08:00
|
|
|
public class HitErrorShape : Container
|
2019-12-21 19:30:41 +08:00
|
|
|
{
|
2019-12-22 08:30:17 +08:00
|
|
|
public bool IsRemoved { get; private set; }
|
2022-06-13 22:54:43 +08:00
|
|
|
|
2022-09-09 15:30:08 +08:00
|
|
|
public readonly Bindable<ShapeStyle> Shape = new Bindable<ShapeStyle>();
|
|
|
|
|
|
|
|
private readonly Color4 colour;
|
|
|
|
|
|
|
|
public HitErrorShape(Color4 colour, int size)
|
2022-06-13 22:54:43 +08:00
|
|
|
{
|
2022-09-09 15:30:08 +08:00
|
|
|
this.colour = colour;
|
2022-06-13 22:54:43 +08:00
|
|
|
Size = new Vector2(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
2019-12-22 08:17:56 +08:00
|
|
|
{
|
2022-06-13 22:54:43 +08:00
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-09-09 15:30:08 +08:00
|
|
|
Shape.BindValueChanged(shape =>
|
|
|
|
{
|
|
|
|
switch (shape.NewValue)
|
|
|
|
{
|
|
|
|
case ShapeStyle.Circle:
|
|
|
|
Child = new Circle
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0,
|
|
|
|
Colour = colour
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ShapeStyle.Square:
|
|
|
|
Child = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0,
|
|
|
|
Colour = colour
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
2022-09-04 23:24:12 +08:00
|
|
|
Child.FadeInFromZero(animation_duration, Easing.OutQuint);
|
|
|
|
Child.MoveToY(-DrawSize.Y);
|
|
|
|
Child.MoveToY(0, animation_duration, Easing.OutQuint);
|
2019-12-22 08:17:56 +08:00
|
|
|
}
|
2019-12-22 08:30:17 +08:00
|
|
|
|
|
|
|
public void Remove()
|
|
|
|
{
|
|
|
|
IsRemoved = true;
|
2022-06-13 22:54:43 +08:00
|
|
|
|
2019-12-22 08:30:17 +08:00
|
|
|
this.FadeOut(animation_duration, Easing.OutQuint).Expire();
|
|
|
|
}
|
2019-12-21 18:41:50 +08:00
|
|
|
}
|
2022-09-04 23:24:12 +08:00
|
|
|
|
|
|
|
public enum ShapeStyle
|
|
|
|
{
|
|
|
|
Circle,
|
|
|
|
Square
|
|
|
|
}
|
2019-12-21 18:41:50 +08:00
|
|
|
}
|
|
|
|
}
|