1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 15:32:56 +08:00
osu-lazer/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs

67 lines
2.3 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Rulesets.Objects.Drawables
{
/// <summary>
2017-09-06 17:05:51 +08:00
/// A basic class that overrides <see cref="DrawableHitObject{TObject}"/> and implements <see cref="IScrollingHitObject"/>.
/// This object does not need to have its <see cref="Drawable.RelativePositionAxes"/> set to be able to scroll, as this will
/// will be set by the scrolling container that contains it.
/// </summary>
2017-09-06 17:05:51 +08:00
public abstract class DrawableScrollingHitObject<TObject> : DrawableHitObject<TObject>, IScrollingHitObject
where TObject : HitObject
{
public BindableDouble LifetimeOffset { get; } = new BindableDouble();
Axes IScrollingHitObject.ScrollingAxes
{
set
{
RelativePositionAxes |= value;
if ((value & Axes.X) > 0)
X = (float)HitObject.StartTime;
if ((value & Axes.Y) > 0)
Y = (float)HitObject.StartTime;
}
}
public override bool RemoveWhenNotAlive => false;
protected override bool RequiresChildrenUpdate => true;
2017-06-21 19:17:15 +08:00
protected DrawableScrollingHitObject(TObject hitObject)
: base(hitObject)
{
}
2017-08-07 13:07:49 +08:00
private double? lifetimeStart;
public override double LifetimeStart
{
2017-08-07 13:07:49 +08:00
get { return lifetimeStart ?? HitObject.StartTime - LifetimeOffset; }
set { lifetimeStart = value; }
}
2017-08-07 13:07:49 +08:00
private double? lifetimeEnd;
public override double LifetimeEnd
{
get
{
var endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime;
2017-08-07 13:07:49 +08:00
return lifetimeEnd ?? endTime + LifetimeOffset;
}
2017-08-07 13:07:49 +08:00
set { lifetimeEnd = value; }
}
2017-09-06 17:05:51 +08:00
protected override void AddNested(DrawableHitObject<TObject> h)
{
var scrollingHitObject = h as IScrollingHitObject;
scrollingHitObject?.LifetimeOffset.BindTo(LifetimeOffset);
base.AddNested(h);
}
}
}