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-11-14 00:34:22 +08:00
|
|
|
using osu.Framework.Allocation;
|
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;
|
2022-11-14 00:34:22 +08:00
|
|
|
using osu.Framework.Graphics.Pooling;
|
2019-12-21 18:41:50 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2023-02-02 07:44:00 +08:00
|
|
|
using osu.Framework.Localisation;
|
2022-09-03 05:07:30 +08:00
|
|
|
using osu.Game.Configuration;
|
2023-02-03 14:34:57 +08:00
|
|
|
using osu.Game.Localisation.HUD;
|
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;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD.HitErrorMeters
|
|
|
|
{
|
2022-11-14 00:34:22 +08:00
|
|
|
[Cached]
|
2019-12-21 18:41:50 +08:00
|
|
|
public partial 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
|
|
|
|
2023-02-02 07:44:00 +08:00
|
|
|
[SettingSource(typeof(ColourHitErrorMeterStrings), nameof(ColourHitErrorMeterStrings.JudgementCount), nameof(ColourHitErrorMeterStrings.JudgementCountDescription))]
|
2022-09-22 14:18:20 +08:00
|
|
|
public BindableNumber<int> JudgementCount { get; } = new BindableNumber<int>(20)
|
2022-09-03 05:07:30 +08:00
|
|
|
{
|
|
|
|
MinValue = 1,
|
2022-09-22 14:45:23 +08:00
|
|
|
MaxValue = 50,
|
2022-09-03 05:07:30 +08:00
|
|
|
};
|
|
|
|
|
2023-02-02 07:44:00 +08:00
|
|
|
[SettingSource(typeof(ColourHitErrorMeterStrings), nameof(ColourHitErrorMeterStrings.JudgementSpacing), nameof(ColourHitErrorMeterStrings.JudgementSpacingDescription))]
|
2022-09-22 14:21:27 +08:00
|
|
|
public BindableNumber<float> JudgementSpacing { 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-03 05:07:30 +08:00
|
|
|
};
|
|
|
|
|
2023-02-02 07:44:00 +08:00
|
|
|
[SettingSource(typeof(ColourHitErrorMeterStrings), nameof(ColourHitErrorMeterStrings.JudgementShape), nameof(ColourHitErrorMeterStrings.JudgementShapeDescription))]
|
2022-09-22 14:21:27 +08:00
|
|
|
public Bindable<ShapeStyle> JudgementShape { get; } = new Bindable<ShapeStyle>();
|
2022-09-04 23:24:12 +08:00
|
|
|
|
2024-01-16 04:39:33 +08:00
|
|
|
private readonly DrawablePool<HitErrorShape> judgementShapePool;
|
2022-09-04 23:24:12 +08:00
|
|
|
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;
|
2024-01-16 04:39:33 +08:00
|
|
|
InternalChildren = new Drawable[]
|
2022-09-22 14:21:27 +08:00
|
|
|
{
|
2024-01-16 04:39:33 +08:00
|
|
|
judgementShapePool = new DrawablePool<HitErrorShape>(50),
|
|
|
|
judgementsFlow = new JudgementFlow
|
|
|
|
{
|
|
|
|
JudgementShape = { BindTarget = JudgementShape },
|
|
|
|
JudgementSpacing = { BindTarget = JudgementSpacing },
|
|
|
|
JudgementCount = { BindTarget = JudgementCount }
|
|
|
|
}
|
2022-09-22 14:21:27 +08:00
|
|
|
};
|
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;
|
|
|
|
|
2024-01-16 04:39:33 +08:00
|
|
|
judgementsFlow.Push(judgementShapePool.Get(shape => shape.Colour = GetColourForHitResult(judgement.Type)));
|
2021-06-08 22:09:18 +08:00
|
|
|
}
|
2019-12-21 21:08:28 +08:00
|
|
|
|
2023-12-13 15:13:23 +08:00
|
|
|
public override void Clear()
|
|
|
|
{
|
|
|
|
foreach (var j in judgementsFlow)
|
2023-12-13 16:00:21 +08:00
|
|
|
{
|
|
|
|
j.ClearTransforms();
|
|
|
|
j.Expire();
|
|
|
|
}
|
2023-12-13 15:13:23 +08:00
|
|
|
}
|
2021-09-18 04:19:41 +08:00
|
|
|
|
2022-09-04 23:24:12 +08:00
|
|
|
private partial 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
|
|
|
|
2022-09-22 14:45:23 +08:00
|
|
|
public readonly Bindable<ShapeStyle> JudgementShape = new Bindable<ShapeStyle>();
|
|
|
|
|
|
|
|
public readonly Bindable<float> JudgementSpacing = new Bindable<float>();
|
|
|
|
|
|
|
|
public readonly Bindable<int> JudgementCount = new Bindable<int>();
|
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-22 14:45:23 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-11-14 00:34:22 +08:00
|
|
|
JudgementCount.BindValueChanged(_ =>
|
2022-09-22 14:45:23 +08:00
|
|
|
{
|
|
|
|
removeExtraJudgements();
|
|
|
|
updateMetrics();
|
|
|
|
});
|
|
|
|
|
|
|
|
JudgementSpacing.BindValueChanged(_ => updateMetrics(), true);
|
|
|
|
}
|
|
|
|
|
2024-01-16 04:39:33 +08:00
|
|
|
public void Push(HitErrorShape shape)
|
2019-12-21 21:08:28 +08:00
|
|
|
{
|
2024-01-16 04:39:33 +08:00
|
|
|
Add(shape);
|
|
|
|
removeExtraJudgements();
|
2022-09-22 14:45:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void removeExtraJudgements()
|
|
|
|
{
|
|
|
|
var remainingChildren = Children.Where(c => !c.IsRemoved);
|
|
|
|
|
|
|
|
while (remainingChildren.Count() > JudgementCount.Value)
|
|
|
|
remainingChildren.First().Remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateMetrics()
|
|
|
|
{
|
|
|
|
Height = JudgementCount.Value * (drawable_judgement_size + JudgementSpacing.Value) - JudgementSpacing.Value;
|
|
|
|
Spacing = new Vector2(0, JudgementSpacing.Value);
|
2019-12-21 21:08:28 +08:00
|
|
|
}
|
2019-12-21 19:30:41 +08:00
|
|
|
}
|
|
|
|
|
2022-11-14 00:34:22 +08:00
|
|
|
public partial class HitErrorShape : PoolableDrawable
|
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>();
|
|
|
|
|
2022-11-14 00:34:22 +08:00
|
|
|
[Resolved]
|
|
|
|
private ColourHitErrorMeter hitErrorMeter { get; set; } = null!;
|
2022-09-09 15:30:08 +08:00
|
|
|
|
2022-09-22 14:24:57 +08:00
|
|
|
private Container content = null!;
|
|
|
|
|
2022-11-14 00:34:22 +08:00
|
|
|
public HitErrorShape()
|
2022-06-13 22:54:43 +08:00
|
|
|
{
|
2022-11-14 00:34:22 +08:00
|
|
|
Size = new Vector2(drawable_judgement_size);
|
2022-06-13 22:54:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
2019-12-22 08:17:56 +08:00
|
|
|
{
|
2022-06-13 22:54:43 +08:00
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-11-14 00:34:22 +08:00
|
|
|
InternalChild = content = new Container
|
2022-09-22 14:24:57 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
};
|
|
|
|
|
2022-11-14 00:34:22 +08:00
|
|
|
Shape.BindTo(hitErrorMeter.JudgementShape);
|
2022-09-09 15:30:08 +08:00
|
|
|
Shape.BindValueChanged(shape =>
|
|
|
|
{
|
|
|
|
switch (shape.NewValue)
|
|
|
|
{
|
|
|
|
case ShapeStyle.Circle:
|
2022-09-22 14:24:57 +08:00
|
|
|
content.Child = new Circle { RelativeSizeAxes = Axes.Both };
|
2022-09-09 15:30:08 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ShapeStyle.Square:
|
2022-09-22 14:24:57 +08:00
|
|
|
content.Child = new Box { RelativeSizeAxes = Axes.Both };
|
2022-09-09 15:30:08 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}, true);
|
2022-11-14 00:34:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PrepareForUse()
|
|
|
|
{
|
|
|
|
base.PrepareForUse();
|
|
|
|
|
2022-11-15 10:55:33 +08:00
|
|
|
this.FadeInFromZero(animation_duration, Easing.OutQuint)
|
2022-11-15 10:33:19 +08:00
|
|
|
// On pool re-use, start flow animation from (0,0).
|
|
|
|
.MoveTo(Vector2.Zero);
|
2022-09-09 15:30:08 +08:00
|
|
|
|
2022-11-15 10:55:33 +08:00
|
|
|
content.MoveToY(-DrawSize.Y)
|
2022-11-14 00:34:22 +08:00
|
|
|
.MoveToY(0, animation_duration, Easing.OutQuint);
|
2019-12-22 08:17:56 +08:00
|
|
|
}
|
2019-12-22 08:30:17 +08:00
|
|
|
|
2022-11-15 10:55:33 +08:00
|
|
|
protected override void FreeAfterUse()
|
|
|
|
{
|
|
|
|
base.FreeAfterUse();
|
|
|
|
IsRemoved = false;
|
|
|
|
}
|
|
|
|
|
2019-12-22 08:30:17 +08:00
|
|
|
public void Remove()
|
|
|
|
{
|
|
|
|
IsRemoved = true;
|
2022-06-13 22:54:43 +08:00
|
|
|
|
2022-11-14 00:34:22 +08:00
|
|
|
this.FadeOut(animation_duration, Easing.OutQuint)
|
|
|
|
.Expire();
|
2019-12-22 08:30:17 +08:00
|
|
|
}
|
2019-12-21 18:41:50 +08:00
|
|
|
}
|
2022-09-04 23:24:12 +08:00
|
|
|
|
|
|
|
public enum ShapeStyle
|
|
|
|
{
|
2023-02-02 07:44:00 +08:00
|
|
|
[LocalisableDescription(typeof(ColourHitErrorMeterStrings), nameof(ColourHitErrorMeterStrings.ShapeStyleCircle))]
|
2022-09-04 23:24:12 +08:00
|
|
|
Circle,
|
2023-02-02 07:44:00 +08:00
|
|
|
|
|
|
|
[LocalisableDescription(typeof(ColourHitErrorMeterStrings), nameof(ColourHitErrorMeterStrings.ShapeStyleSquare))]
|
2022-09-04 23:24:12 +08:00
|
|
|
Square
|
|
|
|
}
|
2019-12-21 18:41:50 +08:00
|
|
|
}
|
|
|
|
}
|