Move first tick tracking logic inside `TickPiece`

This commit is contained in:
Dean Herbert 2022-11-07 15:21:58 +09:00
parent cb6b9898c1
commit 1975385cc7
2 changed files with 31 additions and 17 deletions

View File

@ -5,6 +5,7 @@
using System; using System;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
@ -16,6 +17,8 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
public class DrawableDrumRollTick : DrawableTaikoStrongableHitObject<DrumRollTick, DrumRollTick.StrongNestedHit> public class DrawableDrumRollTick : DrawableTaikoStrongableHitObject<DrumRollTick, DrumRollTick.StrongNestedHit>
{ {
public BindableBool IsFirstTick = new BindableBool();
/// <summary> /// <summary>
/// The hit type corresponding to the <see cref="TaikoAction"/> that the user pressed to hit this <see cref="DrawableDrumRollTick"/>. /// The hit type corresponding to the <see cref="TaikoAction"/> that the user pressed to hit this <see cref="DrawableDrumRollTick"/>.
/// </summary> /// </summary>
@ -32,14 +35,17 @@ public DrawableDrumRollTick([CanBeNull] DrumRollTick tick)
FillMode = FillMode.Fit; FillMode = FillMode.Fit;
} }
protected override SkinnableDrawable CreateMainPiece() => new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.DrumRollTick), protected override SkinnableDrawable CreateMainPiece() => new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.DrumRollTick), _ => new TickPiece());
_ => new TickPiece
{
Filled = HitObject.FirstTick
});
public override double MaximumJudgementOffset => HitObject.HitWindow; public override double MaximumJudgementOffset => HitObject.HitWindow;
protected override void OnApply()
{
base.OnApply();
IsFirstTick.Value = HitObject.FirstTick;
}
protected override void CheckForResult(bool userTriggered, double timeOffset) protected override void CheckForResult(bool userTriggered, double timeOffset)
{ {
if (!userTriggered) if (!userTriggered)

View File

@ -1,9 +1,13 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Objects.Drawables;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -22,20 +26,10 @@ public class TickPiece : CompositeDrawable
/// </summary> /// </summary>
private const float tick_size = 0.35f; private const float tick_size = 0.35f;
private bool filled;
public bool Filled
{
get => filled;
set
{
filled = value;
fillBox.Alpha = filled ? 1 : 0;
}
}
private readonly Box fillBox; private readonly Box fillBox;
private Bindable<bool> isFirstTick = null!;
public TickPiece() public TickPiece()
{ {
Anchor = Anchor.Centre; Anchor = Anchor.Centre;
@ -62,5 +56,19 @@ public TickPiece()
} }
}; };
} }
[Resolved]
private DrawableHitObject drawableHitObject { get; set; } = null!;
protected override void LoadComplete()
{
base.LoadComplete();
if (drawableHitObject is DrawableDrumRollTick drumRollTick)
{
isFirstTick = drumRollTick.IsFirstTick.GetBoundCopy();
isFirstTick.BindValueChanged(first => fillBox.Alpha = first.NewValue ? 1 : 0, true);
}
}
} }
} }