2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-09-23 17:09:40 +08:00
|
|
|
|
using System.Linq;
|
2020-12-15 05:20:35 +08:00
|
|
|
|
using JetBrains.Annotations;
|
2020-09-23 17:09:40 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2018-06-11 20:45:19 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2020-09-23 17:09:40 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2021-09-16 17:26:12 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2020-09-23 17:09:40 +08:00
|
|
|
|
using osu.Game.Audio;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2020-04-15 15:54:50 +08:00
|
|
|
|
using osu.Game.Skinning;
|
2020-09-23 17:09:40 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
|
|
|
|
{
|
2018-06-11 20:45:19 +08:00
|
|
|
|
public abstract class DrawableTaikoHitObject : DrawableHitObject<TaikoHitObject>, IKeyBindingHandler<TaikoAction>
|
|
|
|
|
{
|
|
|
|
|
protected readonly Container Content;
|
2018-06-17 16:56:46 +08:00
|
|
|
|
private readonly Container proxiedContent;
|
2018-06-11 20:45:19 +08:00
|
|
|
|
|
|
|
|
|
private readonly Container nonProxiedContent;
|
|
|
|
|
|
2020-12-15 05:20:35 +08:00
|
|
|
|
protected DrawableTaikoHitObject([CanBeNull] TaikoHitObject hitObject)
|
2018-06-11 20:45:19 +08:00
|
|
|
|
: base(hitObject)
|
|
|
|
|
{
|
2019-03-25 12:47:28 +08:00
|
|
|
|
AddRangeInternal(new[]
|
2018-06-11 20:45:19 +08:00
|
|
|
|
{
|
|
|
|
|
nonProxiedContent = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Child = Content = new Container { RelativeSizeAxes = Axes.Both }
|
|
|
|
|
},
|
2018-11-15 19:26:12 +08:00
|
|
|
|
proxiedContent = new ProxiedContentContainer { RelativeSizeAxes = Axes.Both }
|
2019-03-25 12:47:28 +08:00
|
|
|
|
});
|
2018-06-11 20:45:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-06-17 16:56:46 +08:00
|
|
|
|
/// <see cref="proxiedContent"/> is proxied into an upper layer. We don't want to get masked away otherwise <see cref="proxiedContent"/> would too.
|
2018-06-11 20:45:19 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
protected override bool ComputeIsMaskedAway(RectangleF maskingBounds) => false;
|
|
|
|
|
|
2018-06-17 23:27:18 +08:00
|
|
|
|
private bool isProxied;
|
|
|
|
|
|
2018-06-11 20:45:19 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Moves <see cref="Content"/> to a layer proxied above the playfield.
|
2020-04-15 12:00:38 +08:00
|
|
|
|
/// Does nothing if content is already proxied.
|
2018-06-11 20:45:19 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
protected void ProxyContent()
|
|
|
|
|
{
|
2018-06-17 23:27:18 +08:00
|
|
|
|
if (isProxied) return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-06-17 23:27:18 +08:00
|
|
|
|
isProxied = true;
|
|
|
|
|
|
2022-08-26 14:19:05 +08:00
|
|
|
|
nonProxiedContent.Remove(Content, false);
|
2018-06-17 16:56:46 +08:00
|
|
|
|
proxiedContent.Add(Content);
|
2018-06-11 20:45:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Moves <see cref="Content"/> to the normal hitobject layer.
|
2018-06-17 23:27:18 +08:00
|
|
|
|
/// Does nothing is content is not currently proxied.
|
2018-06-11 20:45:19 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
protected void UnproxyContent()
|
|
|
|
|
{
|
2018-06-17 23:27:18 +08:00
|
|
|
|
if (!isProxied) return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-06-17 23:27:18 +08:00
|
|
|
|
isProxied = false;
|
|
|
|
|
|
2022-08-26 14:19:05 +08:00
|
|
|
|
proxiedContent.Remove(Content, false);
|
2018-06-11 20:45:19 +08:00
|
|
|
|
nonProxiedContent.Add(Content);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-17 16:56:46 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a proxy for the content of this <see cref="DrawableTaikoHitObject"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Drawable CreateProxiedContent() => proxiedContent.CreateProxy();
|
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
public abstract bool OnPressed(KeyBindingPressEvent<TaikoAction> e);
|
2020-01-22 12:22:34 +08:00
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
public virtual void OnReleased(KeyBindingReleaseEvent<TaikoAction> e)
|
2020-01-22 12:22:34 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
2018-11-15 19:26:12 +08:00
|
|
|
|
|
2019-08-27 13:19:55 +08:00
|
|
|
|
public override double LifetimeStart
|
|
|
|
|
{
|
|
|
|
|
get => base.LifetimeStart;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.LifetimeStart = value;
|
|
|
|
|
proxiedContent.LifetimeStart = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override double LifetimeEnd
|
|
|
|
|
{
|
|
|
|
|
get => base.LifetimeEnd;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.LifetimeEnd = value;
|
|
|
|
|
proxiedContent.LifetimeEnd = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 19:26:12 +08:00
|
|
|
|
private class ProxiedContentContainer : Container
|
|
|
|
|
{
|
2019-08-27 13:19:55 +08:00
|
|
|
|
public override bool RemoveWhenNotAlive => false;
|
2018-11-15 19:26:12 +08:00
|
|
|
|
}
|
2018-06-11 20:45:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-11 12:14:34 +08:00
|
|
|
|
public abstract class DrawableTaikoHitObject<TObject> : DrawableTaikoHitObject
|
|
|
|
|
where TObject : TaikoHitObject
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
public override Vector2 OriginPosition => new Vector2(DrawHeight / 2);
|
|
|
|
|
|
2020-12-15 05:20:35 +08:00
|
|
|
|
public new TObject HitObject => (TObject)base.HitObject;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-05-26 13:43:38 +08:00
|
|
|
|
protected Vector2 BaseSize;
|
|
|
|
|
protected SkinnableDrawable MainPiece;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-12-15 05:20:35 +08:00
|
|
|
|
protected DrawableTaikoHitObject([CanBeNull] TObject hitObject)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
: base(hitObject)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft;
|
|
|
|
|
Origin = Anchor.Custom;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2020-05-26 13:43:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-15 05:20:35 +08:00
|
|
|
|
protected override void OnApply()
|
2020-05-26 13:43:38 +08:00
|
|
|
|
{
|
2020-12-15 05:20:35 +08:00
|
|
|
|
base.OnApply();
|
2022-11-07 14:17:20 +08:00
|
|
|
|
|
|
|
|
|
// TODO: THIS CANNOT BE HERE, it makes pooling pointless (see https://github.com/ppy/osu/issues/21072).
|
2020-09-23 16:57:57 +08:00
|
|
|
|
RecreatePieces();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-26 13:43:38 +08:00
|
|
|
|
protected virtual void RecreatePieces()
|
|
|
|
|
{
|
2020-12-13 19:51:10 +08:00
|
|
|
|
Size = BaseSize = new Vector2(TaikoHitObject.DEFAULT_SIZE);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-05-21 15:41:39 +08:00
|
|
|
|
if (MainPiece != null)
|
2022-08-26 14:19:05 +08:00
|
|
|
|
Content.Remove(MainPiece, true);
|
2021-05-21 15:41:39 +08:00
|
|
|
|
|
2018-06-11 20:45:19 +08:00
|
|
|
|
Content.Add(MainPiece = CreateMainPiece());
|
2019-10-17 10:57:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 11:53:54 +08:00
|
|
|
|
// Most osu!taiko hitsounds are managed by the drum (see DrumSampleMapping).
|
2020-05-19 22:28:13 +08:00
|
|
|
|
public override IEnumerable<HitSampleInfo> GetSamples() => Enumerable.Empty<HitSampleInfo>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-04-15 15:54:50 +08:00
|
|
|
|
protected abstract SkinnableDrawable CreateMainPiece();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|