2020-12-13 19:51:10 +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.
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Audio;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
|
|
|
{
|
2020-12-13 21:38:16 +08:00
|
|
|
public abstract class DrawableTaikoStrongHitObject<TObject, TStrongNestedObject> : DrawableTaikoHitObject<TObject>
|
2020-12-15 04:46:02 +08:00
|
|
|
where TObject : TaikoStrongableHitObject
|
2020-12-13 21:38:16 +08:00
|
|
|
where TStrongNestedObject : StrongNestedHitObject
|
2020-12-13 19:51:10 +08:00
|
|
|
{
|
|
|
|
private readonly Bindable<bool> isStrong;
|
|
|
|
|
|
|
|
private readonly Container<DrawableStrongNestedHit> strongHitContainer;
|
|
|
|
|
|
|
|
protected DrawableTaikoStrongHitObject(TObject hitObject)
|
|
|
|
: base(hitObject)
|
|
|
|
{
|
|
|
|
isStrong = HitObject.IsStrongBindable.GetBoundCopy();
|
|
|
|
|
|
|
|
AddInternal(strongHitContainer = new Container<DrawableStrongNestedHit>());
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
isStrong.BindValueChanged(_ =>
|
|
|
|
{
|
|
|
|
// will overwrite samples, should only be called on change.
|
|
|
|
updateSamplesFromStrong();
|
|
|
|
|
|
|
|
RecreatePieces();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private HitSampleInfo[] getStrongSamples() => HitObject.Samples.Where(s => s.Name == HitSampleInfo.HIT_FINISH).ToArray();
|
|
|
|
|
|
|
|
protected override void LoadSamples()
|
|
|
|
{
|
|
|
|
base.LoadSamples();
|
|
|
|
isStrong.Value = getStrongSamples().Any();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateSamplesFromStrong()
|
|
|
|
{
|
|
|
|
var strongSamples = getStrongSamples();
|
|
|
|
|
|
|
|
if (isStrong.Value != strongSamples.Any())
|
|
|
|
{
|
|
|
|
if (isStrong.Value)
|
|
|
|
HitObject.Samples.Add(new HitSampleInfo(HitSampleInfo.HIT_FINISH));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
foreach (var sample in strongSamples)
|
|
|
|
HitObject.Samples.Remove(sample);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void RecreatePieces()
|
|
|
|
{
|
|
|
|
base.RecreatePieces();
|
|
|
|
if (HitObject.IsStrong)
|
2020-12-15 04:46:02 +08:00
|
|
|
Size = BaseSize = new Vector2(TaikoStrongableHitObject.DEFAULT_STRONG_SIZE);
|
2020-12-13 19:51:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void AddNestedHitObject(DrawableHitObject hitObject)
|
|
|
|
{
|
|
|
|
base.AddNestedHitObject(hitObject);
|
|
|
|
|
|
|
|
switch (hitObject)
|
|
|
|
{
|
|
|
|
case DrawableStrongNestedHit strong:
|
|
|
|
strongHitContainer.Add(strong);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void ClearNestedHitObjects()
|
|
|
|
{
|
|
|
|
base.ClearNestedHitObjects();
|
|
|
|
strongHitContainer.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
|
|
|
|
{
|
|
|
|
switch (hitObject)
|
|
|
|
{
|
2020-12-13 21:38:16 +08:00
|
|
|
case TStrongNestedObject strong:
|
2020-12-13 19:53:42 +08:00
|
|
|
return CreateStrongNestedHit(strong);
|
2020-12-13 19:51:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return base.CreateNestedHitObject(hitObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates the handler for this <see cref="DrawableHitObject"/>'s <see cref="StrongNestedHitObject"/>.
|
2020-12-15 04:46:02 +08:00
|
|
|
/// This is only invoked if <see cref="TaikoStrongableHitObject.IsStrong"/> is true for <see cref="HitObject"/>.
|
2020-12-13 19:51:10 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="hitObject">The strong hitobject.</param>
|
|
|
|
/// <returns>The strong hitobject handler.</returns>
|
2020-12-13 21:38:16 +08:00
|
|
|
protected abstract DrawableStrongNestedHit CreateStrongNestedHit(TStrongNestedObject hitObject);
|
2020-12-13 19:51:10 +08:00
|
|
|
}
|
|
|
|
}
|