mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 22:56:36 +09:00
Reduce pollution in DrawableHitObject in favor of a loosely-coupled IScrollingHitObject.
This commit is contained in:
@ -18,22 +18,6 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
{
|
||||
public abstract class DrawableHitObject : Container
|
||||
{
|
||||
private readonly BindableDouble lifetimeOffset = new BindableDouble();
|
||||
/// <summary>
|
||||
/// Time offset before the hit object start time at which this <see cref="DrawableHitObject"/> becomes visible and the time offset
|
||||
/// after the hit object's end time after which it expires.
|
||||
///
|
||||
/// <para>
|
||||
/// This provides only a default life time range, however classes inheriting from <see cref="DrawableHitObject"/> should expire their state through
|
||||
/// <see cref="DrawableHitObject{TObject, TJudgement}.UpdateState(ArmedState)"/> if more tight control over the life time is desired.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public BindableDouble LifetimeOffset
|
||||
{
|
||||
get { return lifetimeOffset; }
|
||||
set { lifetimeOffset.BindTo(value); }
|
||||
}
|
||||
|
||||
public readonly HitObject HitObject;
|
||||
|
||||
/// <summary>
|
||||
@ -45,22 +29,6 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
{
|
||||
HitObject = hitObject;
|
||||
}
|
||||
|
||||
public override double LifetimeStart
|
||||
{
|
||||
get { return Math.Min(HitObject.StartTime - lifetimeOffset, base.LifetimeStart); }
|
||||
set { base.LifetimeStart = value; }
|
||||
}
|
||||
|
||||
public override double LifetimeEnd
|
||||
{
|
||||
get
|
||||
{
|
||||
var endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime;
|
||||
return Math.Max(endTime + LifetimeOffset, base.LifetimeEnd);
|
||||
}
|
||||
set { base.LifetimeEnd = value; }
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class DrawableHitObject<TObject> : DrawableHitObject
|
||||
@ -217,13 +185,12 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
private List<DrawableHitObject<TObject, TJudgement>> nestedHitObjects;
|
||||
protected IEnumerable<DrawableHitObject<TObject, TJudgement>> NestedHitObjects => nestedHitObjects;
|
||||
|
||||
protected void AddNested(DrawableHitObject<TObject, TJudgement> h)
|
||||
protected virtual void AddNested(DrawableHitObject<TObject, TJudgement> h)
|
||||
{
|
||||
if (nestedHitObjects == null)
|
||||
nestedHitObjects = new List<DrawableHitObject<TObject, TJudgement>>();
|
||||
|
||||
h.OnJudgement += d => OnJudgement?.Invoke(d);
|
||||
h.LifetimeOffset = LifetimeOffset;
|
||||
nestedHitObjects.Add(h);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Game.Rulesets.Judgements;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
|
||||
namespace osu.Game.Rulesets.Objects.Drawables
|
||||
{
|
||||
/// <summary>
|
||||
/// A basic class that overrides <see cref="DrawableHitObject{TObject, TJudgement}"/> and implements <see cref="IScrollingHitObject"/>.
|
||||
/// </summary>
|
||||
public abstract class DrawableScrollingHitObject<TObject, TJudgement> : DrawableHitObject<TObject, TJudgement>, IScrollingHitObject
|
||||
where TObject : HitObject
|
||||
where TJudgement : Judgement
|
||||
{
|
||||
public BindableDouble LifetimeOffset { get; } = new BindableDouble();
|
||||
|
||||
public DrawableScrollingHitObject(TObject hitObject)
|
||||
: base(hitObject)
|
||||
{
|
||||
}
|
||||
|
||||
public override double LifetimeStart
|
||||
{
|
||||
get { return Math.Min(HitObject.StartTime - LifetimeOffset, base.LifetimeStart); }
|
||||
set { base.LifetimeStart = value; }
|
||||
}
|
||||
|
||||
public override double LifetimeEnd
|
||||
{
|
||||
get
|
||||
{
|
||||
var endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime;
|
||||
return Math.Max(endTime + LifetimeOffset, base.LifetimeEnd);
|
||||
}
|
||||
set { base.LifetimeEnd = value; }
|
||||
}
|
||||
|
||||
protected override void AddNested(DrawableHitObject<TObject, TJudgement> h)
|
||||
{
|
||||
var scrollingHitObject = h as IScrollingHitObject;
|
||||
scrollingHitObject?.LifetimeOffset.BindTo(LifetimeOffset);
|
||||
|
||||
base.AddNested(h);
|
||||
}
|
||||
}
|
||||
}
|
25
osu.Game/Rulesets/Objects/Drawables/IScrollingHitObject.cs
Normal file
25
osu.Game/Rulesets/Objects/Drawables/IScrollingHitObject.cs
Normal file
@ -0,0 +1,25 @@
|
||||
// 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;
|
||||
|
||||
namespace osu.Game.Rulesets.Objects.Drawables
|
||||
{
|
||||
/// <summary>
|
||||
/// An interface that exposes properties required for scrolling hit objects to be properly displayed.
|
||||
/// </summary>
|
||||
public interface IScrollingHitObject : IDrawable
|
||||
{
|
||||
/// <summary>
|
||||
/// Time offset before the hit object start time at which this <see cref="IScrollingHitObject"/> becomes visible and the time offset
|
||||
/// after the hit object's end time after which it expires.
|
||||
///
|
||||
/// <para>
|
||||
/// This provides only a default life time range, however classes inheriting from <see cref="IScrollingHitObject"/> should override
|
||||
/// their life times if more tight control is desired.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
BindableDouble LifetimeOffset { get; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user