1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 23:05:37 +08:00

Support HitType bindable changes

This commit is contained in:
Dean Herbert 2020-05-26 14:43:38 +09:00
parent 3487c1fd1b
commit 4e9631b546
2 changed files with 39 additions and 6 deletions

View File

@ -5,6 +5,8 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Audio;
using osu.Game.Rulesets.Objects.Drawables;
@ -19,7 +21,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
/// <summary>
/// A list of keys which can result in hits for this HitObject.
/// </summary>
public TaikoAction[] HitActions { get; }
public TaikoAction[] HitActions { get; private set; }
/// <summary>
/// The action that caused this <see cref="DrawableHit"/> to be hit.
@ -34,15 +36,35 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
private bool pressHandledThisFrame;
private Bindable<HitType> type;
public DrawableHit(Hit hit)
: base(hit)
{
FillMode = FillMode.Fit;
}
[BackgroundDependencyLoader]
private void load()
{
type = HitObject.TypeBindable.GetBoundCopy();
type.BindValueChanged(_ =>
{
updateType();
RecreatePieces();
});
updateType();
}
private void updateType()
{
HitActions =
HitObject.Type == HitType.Centre
? new[] { TaikoAction.LeftCentre, TaikoAction.RightCentre }
: new[] { TaikoAction.LeftRim, TaikoAction.RightRim };
RecreatePieces();
}
protected override SkinnableDrawable CreateMainPiece() => HitObject.Type == HitType.Centre

View File

@ -8,6 +8,7 @@ using osuTK;
using System.Linq;
using osu.Game.Audio;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Game.Rulesets.Objects;
@ -115,10 +116,10 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
public new TObject HitObject;
protected readonly Vector2 BaseSize;
protected readonly SkinnableDrawable MainPiece;
protected Vector2 BaseSize;
protected SkinnableDrawable MainPiece;
private readonly Container<DrawableStrongNestedHit> strongHitContainer;
private Container<DrawableStrongNestedHit> strongHitContainer;
protected DrawableTaikoHitObject(TObject hitObject)
: base(hitObject)
@ -129,11 +130,21 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
Origin = Anchor.Custom;
RelativeSizeAxes = Axes.Both;
AddInternal(strongHitContainer = new Container<DrawableStrongNestedHit>());
}
[BackgroundDependencyLoader]
private void load()
{
RecreatePieces();
}
protected virtual void RecreatePieces()
{
Size = BaseSize = new Vector2(HitObject.IsStrong ? TaikoHitObject.DEFAULT_STRONG_SIZE : TaikoHitObject.DEFAULT_SIZE);
Content.Clear();
Content.Add(MainPiece = CreateMainPiece());
AddInternal(strongHitContainer = new Container<DrawableStrongNestedHit>());
}
protected override void AddNestedHitObject(DrawableHitObject hitObject)