mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 20:12:57 +08:00
Reduce pollution in DrawableHitObject in favor of a loosely-coupled IScrollingHitObject.
This commit is contained in:
parent
8c0850d679
commit
34ac932fe2
@ -152,11 +152,13 @@ namespace osu.Desktop.VisualTests.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestDrawableHitObject : DrawableHitObject
|
private class TestDrawableHitObject : DrawableHitObject, IScrollingHitObject
|
||||||
{
|
{
|
||||||
private readonly Box background;
|
private readonly Box background;
|
||||||
private const float height = 14;
|
private const float height = 14;
|
||||||
|
|
||||||
|
public BindableDouble LifetimeOffset { get; } = new BindableDouble();
|
||||||
|
|
||||||
public TestDrawableHitObject(HitObject hitObject)
|
public TestDrawableHitObject(HitObject hitObject)
|
||||||
: base(hitObject)
|
: base(hitObject)
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@ using osu.Game.Rulesets.Objects.Drawables;
|
|||||||
|
|
||||||
namespace osu.Game.Rulesets.Mania.Objects.Drawables
|
namespace osu.Game.Rulesets.Mania.Objects.Drawables
|
||||||
{
|
{
|
||||||
public abstract class DrawableManiaHitObject<TObject> : DrawableHitObject<ManiaHitObject, ManiaJudgement>
|
public abstract class DrawableManiaHitObject<TObject> : DrawableScrollingHitObject<ManiaHitObject, ManiaJudgement>
|
||||||
where TObject : ManiaHitObject
|
where TObject : ManiaHitObject
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -18,22 +18,6 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
{
|
{
|
||||||
public abstract class DrawableHitObject : Container
|
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;
|
public readonly HitObject HitObject;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -45,22 +29,6 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
{
|
{
|
||||||
HitObject = hitObject;
|
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
|
public abstract class DrawableHitObject<TObject> : DrawableHitObject
|
||||||
@ -217,13 +185,12 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
private List<DrawableHitObject<TObject, TJudgement>> nestedHitObjects;
|
private List<DrawableHitObject<TObject, TJudgement>> nestedHitObjects;
|
||||||
protected IEnumerable<DrawableHitObject<TObject, TJudgement>> NestedHitObjects => 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)
|
if (nestedHitObjects == null)
|
||||||
nestedHitObjects = new List<DrawableHitObject<TObject, TJudgement>>();
|
nestedHitObjects = new List<DrawableHitObject<TObject, TJudgement>>();
|
||||||
|
|
||||||
h.OnJudgement += d => OnJudgement?.Invoke(d);
|
h.OnJudgement += d => OnJudgement?.Invoke(d);
|
||||||
h.LifetimeOffset = LifetimeOffset;
|
|
||||||
nestedHitObjects.Add(h);
|
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; }
|
||||||
|
}
|
||||||
|
}
|
@ -51,6 +51,13 @@ namespace osu.Game.Rulesets.Timing
|
|||||||
this.scrollingAxes = scrollingAxes;
|
this.scrollingAxes = scrollingAxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Add(SpeedAdjustmentContainer speedAdjustment)
|
||||||
|
{
|
||||||
|
speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange);
|
||||||
|
speedAdjustment.ScrollingAxes = scrollingAxes;
|
||||||
|
base.Add(speedAdjustment);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a hit object to this <see cref="SpeedAdjustmentCollection"/>. The hit objects will be kept in a queue
|
/// Adds a hit object to this <see cref="SpeedAdjustmentCollection"/>. The hit objects will be kept in a queue
|
||||||
/// and will be processed when new <see cref="SpeedAdjustmentContainer"/>s are added to this <see cref="SpeedAdjustmentCollection"/>.
|
/// and will be processed when new <see cref="SpeedAdjustmentContainer"/>s are added to this <see cref="SpeedAdjustmentCollection"/>.
|
||||||
@ -58,14 +65,10 @@ namespace osu.Game.Rulesets.Timing
|
|||||||
/// <param name="hitObject">The hit object to add.</param>
|
/// <param name="hitObject">The hit object to add.</param>
|
||||||
public void Add(DrawableHitObject hitObject)
|
public void Add(DrawableHitObject hitObject)
|
||||||
{
|
{
|
||||||
queuedHitObjects.Enqueue(hitObject);
|
if (!(hitObject is IScrollingHitObject))
|
||||||
}
|
throw new InvalidOperationException($"Hit objects added to a {nameof(SpeedAdjustmentCollection)} must implement {nameof(IScrollingHitObject)}.");
|
||||||
|
|
||||||
public override void Add(SpeedAdjustmentContainer speedAdjustment)
|
queuedHitObjects.Enqueue(hitObject);
|
||||||
{
|
|
||||||
speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange);
|
|
||||||
speedAdjustment.ScrollingAxes = scrollingAxes;
|
|
||||||
base.Add(speedAdjustment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
|
@ -82,7 +82,9 @@ namespace osu.Game.Rulesets.Timing
|
|||||||
|
|
||||||
public override void Add(DrawableHitObject drawable)
|
public override void Add(DrawableHitObject drawable)
|
||||||
{
|
{
|
||||||
drawable.LifetimeOffset.BindTo(VisibleTimeRange);
|
var scrollingHitObject = drawable as IScrollingHitObject;
|
||||||
|
scrollingHitObject?.LifetimeOffset.BindTo(VisibleTimeRange);
|
||||||
|
|
||||||
base.Add(drawable);
|
base.Add(drawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,6 +185,7 @@
|
|||||||
<Compile Include="Rulesets\Objects\SliderCurve.cs" />
|
<Compile Include="Rulesets\Objects\SliderCurve.cs" />
|
||||||
<Compile Include="Rulesets\Objects\Types\CurveType.cs" />
|
<Compile Include="Rulesets\Objects\Types\CurveType.cs" />
|
||||||
<Compile Include="Rulesets\Objects\Drawables\IDrawableHitObjectWithProxiedApproach.cs" />
|
<Compile Include="Rulesets\Objects\Drawables\IDrawableHitObjectWithProxiedApproach.cs" />
|
||||||
|
<Compile Include="Rulesets\Objects\Drawables\IScrollingHitObject.cs" />
|
||||||
<Compile Include="Rulesets\Judgements\Judgement.cs" />
|
<Compile Include="Rulesets\Judgements\Judgement.cs" />
|
||||||
<Compile Include="Rulesets\Objects\HitObjectParser.cs" />
|
<Compile Include="Rulesets\Objects\HitObjectParser.cs" />
|
||||||
<Compile Include="Rulesets\Objects\HitObjectStartTimeComparer.cs" />
|
<Compile Include="Rulesets\Objects\HitObjectStartTimeComparer.cs" />
|
||||||
@ -223,6 +224,7 @@
|
|||||||
<Compile Include="Beatmaps\Drawables\DifficultyColouredContainer.cs" />
|
<Compile Include="Beatmaps\Drawables\DifficultyColouredContainer.cs" />
|
||||||
<Compile Include="Beatmaps\Drawables\Panel.cs" />
|
<Compile Include="Beatmaps\Drawables\Panel.cs" />
|
||||||
<Compile Include="Rulesets\Objects\Drawables\DrawableHitObject.cs" />
|
<Compile Include="Rulesets\Objects\Drawables\DrawableHitObject.cs" />
|
||||||
|
<Compile Include="Rulesets\Objects\Drawables\DrawableScrollingHitObject.cs" />
|
||||||
<Compile Include="Rulesets\Objects\HitObject.cs" />
|
<Compile Include="Rulesets\Objects\HitObject.cs" />
|
||||||
<Compile Include="Configuration\OsuConfigManager.cs" />
|
<Compile Include="Configuration\OsuConfigManager.cs" />
|
||||||
<Compile Include="Overlays\Notifications\IHasCompletionTarget.cs" />
|
<Compile Include="Overlays\Notifications\IHasCompletionTarget.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user