2020-08-04 03:13:02 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-09-11 17:30:14 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2020-08-04 03:13:02 +08:00
|
|
|
using osu.Game.Rulesets.Catch.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2022-10-12 14:11:52 +08:00
|
|
|
using osu.Game.Screens.Play;
|
2020-08-04 03:13:02 +08:00
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.UI
|
|
|
|
{
|
2020-08-19 13:39:40 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Represents a component that displays a skinned <see cref="ICatchComboCounter"/> and handles combo judgement results for updating it accordingly.
|
|
|
|
/// </summary>
|
2020-08-04 03:13:02 +08:00
|
|
|
public class CatchComboDisplay : SkinnableDrawable
|
|
|
|
{
|
|
|
|
private int currentCombo;
|
|
|
|
|
2022-10-12 14:14:54 +08:00
|
|
|
public ICatchComboCounter? ComboCounter => Drawable as ICatchComboCounter;
|
2020-08-04 03:13:02 +08:00
|
|
|
|
2022-10-12 14:14:33 +08:00
|
|
|
private readonly IBindable<bool> showCombo = new BindableBool(true);
|
2022-09-11 17:30:14 +08:00
|
|
|
|
2020-08-04 03:13:02 +08:00
|
|
|
public CatchComboDisplay()
|
|
|
|
: base(new CatchSkinComponent(CatchSkinComponents.CatchComboCounter), _ => Empty())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-09-11 17:30:14 +08:00
|
|
|
[BackgroundDependencyLoader(true)]
|
2022-10-12 14:14:54 +08:00
|
|
|
private void load(Player? player)
|
2022-09-11 17:30:14 +08:00
|
|
|
{
|
2022-10-12 14:14:33 +08:00
|
|
|
if (player != null)
|
2022-09-11 17:30:14 +08:00
|
|
|
{
|
2022-10-12 14:14:33 +08:00
|
|
|
showCombo.BindTo(player.ShowingOverlayComponents);
|
|
|
|
showCombo.BindValueChanged(s =>
|
2022-09-11 17:30:14 +08:00
|
|
|
{
|
2022-10-12 14:14:33 +08:00
|
|
|
if (!s.NewValue)
|
|
|
|
ComboCounter?.Hide();
|
|
|
|
else
|
|
|
|
ComboCounter?.Show();
|
|
|
|
}, true);
|
2022-09-11 17:30:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-27 13:50:42 +08:00
|
|
|
protected override void SkinChanged(ISkinSource skin)
|
2020-08-04 03:13:02 +08:00
|
|
|
{
|
2021-05-27 13:50:42 +08:00
|
|
|
base.SkinChanged(skin);
|
2020-09-22 11:35:18 +08:00
|
|
|
ComboCounter?.UpdateCombo(currentCombo);
|
2020-08-04 03:13:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void OnNewResult(DrawableCatchHitObject judgedObject, JudgementResult result)
|
|
|
|
{
|
2020-09-29 13:26:36 +08:00
|
|
|
if (!result.Type.AffectsCombo() || !result.HasResult)
|
2020-08-04 03:13:02 +08:00
|
|
|
return;
|
|
|
|
|
2020-10-03 04:57:49 +08:00
|
|
|
if (!result.IsHit)
|
2020-08-04 03:13:02 +08:00
|
|
|
{
|
|
|
|
updateCombo(0, null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCombo(result.ComboAtJudgement + 1, judgedObject.AccentColour.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnRevertResult(DrawableCatchHitObject judgedObject, JudgementResult result)
|
|
|
|
{
|
2020-09-29 13:26:36 +08:00
|
|
|
if (!result.Type.AffectsCombo() || !result.HasResult)
|
2020-08-04 03:13:02 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
updateCombo(result.ComboAtJudgement, judgedObject.AccentColour.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateCombo(int newCombo, Color4? hitObjectColour)
|
|
|
|
{
|
|
|
|
currentCombo = newCombo;
|
|
|
|
ComboCounter?.UpdateCombo(newCombo, hitObjectColour);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|