2020-12-13 11:51:10 +00: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.
|
|
|
|
|
2020-12-14 21:27:45 +00:00
|
|
|
using JetBrains.Annotations;
|
2020-12-13 11:51:10 +00:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
|
|
|
{
|
2020-12-14 20:47:31 +00:00
|
|
|
public abstract class DrawableTaikoStrongableHitObject<TObject, TStrongNestedObject> : DrawableTaikoHitObject<TObject>
|
2020-12-14 20:46:02 +00:00
|
|
|
where TObject : TaikoStrongableHitObject
|
2020-12-13 13:38:16 +00:00
|
|
|
where TStrongNestedObject : StrongNestedHitObject
|
2020-12-13 11:51:10 +00:00
|
|
|
{
|
2020-12-14 21:27:45 +00:00
|
|
|
private readonly Bindable<bool> isStrong = new BindableBool();
|
2020-12-13 11:51:10 +00:00
|
|
|
|
|
|
|
private readonly Container<DrawableStrongNestedHit> strongHitContainer;
|
|
|
|
|
2020-12-14 21:27:45 +00:00
|
|
|
protected DrawableTaikoStrongableHitObject([CanBeNull] TObject hitObject)
|
2020-12-13 11:51:10 +00:00
|
|
|
: base(hitObject)
|
|
|
|
{
|
|
|
|
AddInternal(strongHitContainer = new Container<DrawableStrongNestedHit>());
|
|
|
|
}
|
|
|
|
|
2020-12-14 21:27:45 +00:00
|
|
|
protected override void OnApply()
|
2020-12-13 11:51:10 +00:00
|
|
|
{
|
2020-12-14 21:27:45 +00:00
|
|
|
isStrong.BindTo(HitObject.IsStrongBindable);
|
2021-05-21 07:15:27 +00:00
|
|
|
// this doesn't need to be run inline as RecreatePieces is called by the base call below.
|
2021-05-21 07:45:28 +00:00
|
|
|
isStrong.BindValueChanged(_ => Scheduler.AddOnce(RecreatePieces));
|
2020-12-14 21:27:45 +00:00
|
|
|
|
|
|
|
base.OnApply();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnFree()
|
|
|
|
{
|
|
|
|
base.OnFree();
|
|
|
|
|
|
|
|
isStrong.UnbindFrom(HitObject.IsStrongBindable);
|
|
|
|
// ensure the next application does not accidentally overwrite samples.
|
|
|
|
isStrong.UnbindEvents();
|
2020-12-13 11:51:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void RecreatePieces()
|
|
|
|
{
|
|
|
|
base.RecreatePieces();
|
|
|
|
if (HitObject.IsStrong)
|
2020-12-14 20:46:02 +00:00
|
|
|
Size = BaseSize = new Vector2(TaikoStrongableHitObject.DEFAULT_STRONG_SIZE);
|
2020-12-13 11:51:10 +00: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();
|
2020-12-20 16:57:19 +00:00
|
|
|
strongHitContainer.Clear(false);
|
2020-12-13 11:51:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
|
|
|
|
{
|
|
|
|
switch (hitObject)
|
|
|
|
{
|
2020-12-13 13:38:16 +00:00
|
|
|
case TStrongNestedObject strong:
|
2020-12-13 11:53:42 +00:00
|
|
|
return CreateStrongNestedHit(strong);
|
2020-12-13 11:51:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return base.CreateNestedHitObject(hitObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates the handler for this <see cref="DrawableHitObject"/>'s <see cref="StrongNestedHitObject"/>.
|
2020-12-14 20:46:02 +00:00
|
|
|
/// This is only invoked if <see cref="TaikoStrongableHitObject.IsStrong"/> is true for <see cref="HitObject"/>.
|
2020-12-13 11:51:10 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="hitObject">The strong hitobject.</param>
|
|
|
|
/// <returns>The strong hitobject handler.</returns>
|
2020-12-13 13:38:16 +00:00
|
|
|
protected abstract DrawableStrongNestedHit CreateStrongNestedHit(TStrongNestedObject hitObject);
|
2020-12-13 11:51:10 +00:00
|
|
|
}
|
|
|
|
}
|