1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-07 00:57:45 +08:00

118 lines
3.8 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 18:19:50 +09:00
using System.Diagnostics;
using JetBrains.Annotations;
using osu.Framework.Allocation;
2018-04-13 18:19:50 +09:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Skinning.Default;
using osu.Game.Skinning;
2018-11-20 16:51:59 +09:00
using osuTK;
2018-04-13 18:19:50 +09:00
namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public class DrawableSliderTail : DrawableOsuHitObject, IRequireTracking, ITrackSnaking, IHasMainCirclePiece
2018-04-13 18:19:50 +09:00
{
2020-11-12 15:59:48 +09:00
public new SliderTailCircle HitObject => (SliderTailCircle)base.HitObject;
[CanBeNull]
public Slider Slider => DrawableSlider?.HitObject;
protected DrawableSlider DrawableSlider => (DrawableSlider)ParentHitObject;
2018-04-13 18:19:50 +09:00
/// <summary>
/// The judgement text is provided by the <see cref="DrawableSlider"/>.
/// </summary>
public override bool DisplayResult => false;
2018-04-13 18:19:50 +09:00
/// <summary>
2021-04-02 18:00:28 +09:00
/// Whether the hit samples only play on successful hits.
/// If <c>false</c>, the hit samples will also play on misses.
/// </summary>
public bool SamplePlaysOnlyOnHit { get; set; } = true;
2018-04-13 18:19:50 +09:00
public bool Tracking { get; set; }
public SkinnableDrawable CirclePiece { get; private set; }
2020-11-05 13:51:46 +09:00
private Container scaleContainer;
2020-11-12 15:59:48 +09:00
public DrawableSliderTail()
: base(null)
{
}
2020-11-05 13:51:46 +09:00
public DrawableSliderTail(SliderTailCircle tailCircle)
2020-10-02 14:20:55 +09:00
: base(tailCircle)
2018-04-13 18:19:50 +09:00
{
2020-11-05 13:51:46 +09:00
}
2018-04-13 18:19:50 +09:00
2020-11-05 13:51:46 +09:00
[BackgroundDependencyLoader]
private void load()
{
Origin = Anchor.Centre;
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
2018-04-13 18:19:50 +09:00
InternalChildren = new Drawable[]
{
scaleContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Children = new Drawable[]
{
// no default for this; only visible in legacy skins.
CirclePiece = new SkinnableDrawable(new OsuSkinComponent(OsuSkinComponents.SliderTailHitCircle), _ => Empty())
}
},
};
2018-04-13 18:19:50 +09:00
2020-11-12 15:59:48 +09:00
ScaleBindable.BindValueChanged(scale => scaleContainer.Scale = new Vector2(scale.NewValue));
}
2018-11-14 14:29:22 +09:00
protected override void UpdateInitialTransforms()
{
base.UpdateInitialTransforms();
CirclePiece.FadeInFromZero(HitObject.TimeFadeIn);
}
2020-11-04 16:19:07 +09:00
protected override void UpdateHitStateTransforms(ArmedState state)
{
2020-11-04 16:19:07 +09:00
base.UpdateHitStateTransforms(state);
Debug.Assert(HitObject.HitWindows != null);
(CirclePiece.Drawable as IMainCirclePiece)?.Animate(state);
switch (state)
{
case ArmedState.Idle:
this.Delay(HitObject.TimePreempt).FadeOut(500);
break;
case ArmedState.Miss:
this.FadeOut(100);
break;
case ArmedState.Hit:
// todo: temporary / arbitrary
this.Delay(800).FadeOut();
break;
}
2018-04-13 18:19:50 +09:00
}
protected override void CheckForResult(bool userTriggered, double timeOffset)
2018-04-13 18:19:50 +09:00
{
if (!userTriggered && timeOffset >= 0)
2020-09-29 14:35:43 +09:00
ApplyResult(r => r.Type = Tracking ? r.Judgement.MaxResult : r.Judgement.MinResult);
2018-04-13 18:19:50 +09:00
}
2020-10-02 14:20:55 +09:00
public void UpdateSnakingPosition(Vector2 start, Vector2 end) =>
2020-11-12 15:59:48 +09:00
Position = HitObject.RepeatIndex % 2 == 0 ? end : start;
2018-04-13 18:19:50 +09:00
}
}