1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 20:38:33 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableTaikoHitObject.cs

231 lines
7.2 KiB
C#
Raw Normal View History

// 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
using System.Collections.Generic;
using System.Linq;
2020-05-26 13:43:38 +08:00
using osu.Framework.Allocation;
2020-05-26 13:54:12 +08:00
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Input.Bindings;
using osu.Game.Audio;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Skinning;
using osuTK;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{
public abstract class DrawableTaikoHitObject : DrawableHitObject<TaikoHitObject>, IKeyBindingHandler<TaikoAction>
{
protected readonly Container Content;
2018-06-17 16:56:46 +08:00
private readonly Container proxiedContent;
private readonly Container nonProxiedContent;
protected DrawableTaikoHitObject(TaikoHitObject hitObject)
: base(hitObject)
{
AddRangeInternal(new[]
{
nonProxiedContent = new Container
{
RelativeSizeAxes = Axes.Both,
Child = Content = new Container { RelativeSizeAxes = Axes.Both }
},
proxiedContent = new ProxiedContentContainer { RelativeSizeAxes = Axes.Both }
});
}
/// <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.
/// </summary>
protected override bool ComputeIsMaskedAway(RectangleF maskingBounds) => false;
2018-06-17 23:27:18 +08:00
private bool isProxied;
/// <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.
/// </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;
nonProxiedContent.Remove(Content);
2018-06-17 16:56:46 +08:00
proxiedContent.Add(Content);
}
/// <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.
/// </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;
2018-06-17 16:56:46 +08:00
proxiedContent.Remove(Content);
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();
public abstract bool OnPressed(TaikoAction action);
public virtual void OnReleased(TaikoAction action)
{
}
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;
}
}
private class ProxiedContentContainer : Container
{
public override bool RemoveWhenNotAlive => false;
}
}
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);
public new TObject 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-09-24 12:28:29 +08:00
private readonly Bindable<bool> isStrong;
2020-05-26 13:54:12 +08:00
private readonly Container<DrawableStrongNestedHit> strongHitContainer;
2018-04-13 17:19:50 +08:00
protected DrawableTaikoHitObject(TObject hitObject)
2018-04-13 17:19:50 +08:00
: base(hitObject)
{
HitObject = hitObject;
2020-09-24 12:28:29 +08:00
isStrong = HitObject.IsStrongBindable.GetBoundCopy();
2018-04-13 17:19:50 +08:00
Anchor = Anchor.CentreLeft;
Origin = Anchor.Custom;
RelativeSizeAxes = Axes.Both;
2020-05-26 13:54:12 +08:00
2020-05-26 13:43:38 +08:00
AddInternal(strongHitContainer = new Container<DrawableStrongNestedHit>());
}
[BackgroundDependencyLoader]
private void load()
{
isStrong.BindValueChanged(_ =>
{
// will overwrite samples, should only be called on change.
updateSamplesFromStrong();
RecreatePieces();
});
RecreatePieces();
}
private HitSampleInfo[] getStrongSamples() => HitObject.Samples.Where(s => s.Name == HitSampleInfo.HIT_FINISH).ToArray();
2020-09-24 12:28:29 +08:00
protected override void LoadSamples()
{
2020-09-24 12:28:29 +08:00
base.LoadSamples();
2020-09-24 12:28:29 +08:00
isStrong.Value = getStrongSamples().Any();
}
private void updateSamplesFromStrong()
{
var strongSamples = getStrongSamples();
if (isStrong.Value != strongSamples.Any())
{
if (isStrong.Value)
HitObject.Samples.Add(new HitSampleInfo { Name = HitSampleInfo.HIT_FINISH });
else
{
foreach (var sample in strongSamples)
HitObject.Samples.Remove(sample);
}
}
2020-05-26 13:43:38 +08:00
}
protected virtual void RecreatePieces()
{
2018-04-13 17:19:50 +08:00
Size = BaseSize = new Vector2(HitObject.IsStrong ? TaikoHitObject.DEFAULT_STRONG_SIZE : TaikoHitObject.DEFAULT_SIZE);
2020-05-26 13:54:12 +08:00
MainPiece?.Expire();
Content.Add(MainPiece = CreateMainPiece());
}
protected override void AddNestedHitObject(DrawableHitObject hitObject)
{
base.AddNestedHitObject(hitObject);
2019-04-01 11:16:05 +08:00
2019-10-17 11:53:54 +08:00
switch (hitObject)
{
case DrawableStrongNestedHit strong:
strongHitContainer.Add(strong);
break;
}
}
protected override void ClearNestedHitObjects()
{
base.ClearNestedHitObjects();
strongHitContainer.Clear();
}
2018-08-14 13:29:49 +08:00
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
{
switch (hitObject)
{
case StrongHitObject strong:
return CreateStrongHit(strong);
}
return base.CreateNestedHitObject(hitObject);
2018-04-13 17:19:50 +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
protected abstract SkinnableDrawable CreateMainPiece();
2018-08-03 15:56:46 +08:00
/// <summary>
/// Creates the handler for this <see cref="DrawableHitObject"/>'s <see cref="StrongHitObject"/>.
/// This is only invoked if <see cref="TaikoHitObject.IsStrong"/> is true for <see cref="HitObject"/>.
/// </summary>
/// <param name="hitObject">The strong hitobject.</param>
/// <returns>The strong hitobject handler.</returns>
protected virtual DrawableStrongNestedHit CreateStrongHit(StrongHitObject hitObject) => null;
2018-04-13 17:19:50 +08:00
}
}