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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-12-15 05:27:45 +08:00
|
|
|
using JetBrains.Annotations;
|
2020-12-13 19:51:10 +08: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-15 04:47:31 +08:00
|
|
|
public abstract partial class DrawableTaikoStrongableHitObject<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
|
|
|
{
|
2020-12-15 05:27:45 +08:00
|
|
|
private readonly Bindable<bool> isStrong = new BindableBool();
|
2020-12-13 19:51:10 +08:00
|
|
|
|
|
|
|
private readonly Container<DrawableStrongNestedHit> strongHitContainer;
|
|
|
|
|
2020-12-15 05:27:45 +08:00
|
|
|
protected DrawableTaikoStrongableHitObject([CanBeNull] TObject hitObject)
|
2020-12-13 19:51:10 +08:00
|
|
|
: base(hitObject)
|
|
|
|
{
|
|
|
|
AddInternal(strongHitContainer = new Container<DrawableStrongNestedHit>());
|
|
|
|
}
|
|
|
|
|
2020-12-15 05:27:45 +08:00
|
|
|
protected override void OnApply()
|
2020-12-13 19:51:10 +08:00
|
|
|
{
|
2020-12-15 05:27:45 +08:00
|
|
|
isStrong.BindTo(HitObject.IsStrongBindable);
|
2021-05-21 15:15:27 +08:00
|
|
|
// this doesn't need to be run inline as RecreatePieces is called by the base call below.
|
2021-05-21 15:45:28 +08:00
|
|
|
isStrong.BindValueChanged(_ => Scheduler.AddOnce(RecreatePieces));
|
2020-12-15 05:27:45 +08: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 19:51:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2020-12-21 00:57:19 +08:00
|
|
|
strongHitContainer.Clear(false);
|
2020-12-13 19:51:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|