osu/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs

60 lines
2.4 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 09:19:50 +00:00
using osu.Game.Rulesets.Objects.Drawables;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Graphics.Containers;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public class DrawableOsuHitObject : DrawableHitObject<OsuHitObject>
{
private readonly ShakeContainer shakeContainer;
2019-06-30 15:28:20 +00:00
// Must be set to update IsHovered as it's used in relax mdo to detect osu hit objects.
2019-06-30 15:27:47 +00:00
public override bool HandlePositionalInput => true;
2018-04-13 09:19:50 +00:00
protected DrawableOsuHitObject(OsuHitObject hitObject)
: base(hitObject)
{
base.AddInternal(shakeContainer = new ShakeContainer
{
ShakeDuration = 30,
RelativeSizeAxes = Axes.Both
});
2019-07-16 04:45:59 +00:00
2018-04-13 09:19:50 +00:00
Alpha = 0;
}
// Forward all internal management to shakeContainer.
// This is a bit ugly but we don't have the concept of InternalContent so it'll have to do for now. (https://github.com/ppy/osu-framework/issues/1690)
protected override void AddInternal(Drawable drawable) => shakeContainer.Add(drawable);
protected override void ClearInternal(bool disposeChildren = true) => shakeContainer.Clear(disposeChildren);
protected override bool RemoveInternal(Drawable drawable) => shakeContainer.Remove(drawable);
protected sealed override double InitialLifetimeOffset => HitObject.TimePreempt;
2018-04-13 09:19:50 +00:00
private OsuInputManager osuActionInputManager;
2019-11-12 10:35:08 +00:00
internal OsuInputManager OsuActionInputManager => osuActionInputManager ??= GetContainingInputManager() as OsuInputManager;
protected virtual void Shake(double maximumLength) => shakeContainer.Shake(maximumLength);
2018-04-13 09:19:50 +00:00
2019-09-13 09:49:21 +00:00
protected override void UpdateStateTransforms(ArmedState state)
2019-09-12 10:29:08 +00:00
{
2019-09-13 09:49:21 +00:00
base.UpdateStateTransforms(state);
2019-09-12 10:29:08 +00:00
2019-09-13 09:49:21 +00:00
switch (state)
{
case ArmedState.Idle:
// Manually set to reduce the number of future alive objects to a bare minimum.
LifetimeStart = HitObject.StartTime - HitObject.TimePreempt;
break;
}
2019-09-12 10:29:08 +00:00
}
protected override JudgementResult CreateResult(Judgement judgement) => new OsuJudgementResult(HitObject, judgement);
2018-04-13 09:19:50 +00:00
}
}