1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 09:47:52 +08:00

Make ScrollingHitObjectContainer handle nested hitobjects

This commit is contained in:
smoogipoo 2018-01-11 15:08:30 +09:00
parent a6d8b28221
commit 9d00e5bb7d
8 changed files with 59 additions and 70 deletions

View File

@ -45,7 +45,7 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawable
} }
} }
protected override void AddNested(DrawableHitObject<CatchHitObject> h) protected override void AddNested(DrawableHitObject h)
{ {
((DrawableCatchHitObject)h).CheckPosition = o => CheckPosition?.Invoke(o) ?? false; ((DrawableCatchHitObject)h).CheckPosition = o => CheckPosition?.Invoke(o) ?? false;
dropletContainer.Add(h); dropletContainer.Add(h);

View File

@ -7,7 +7,6 @@ using osu.Game.Rulesets.Objects.Drawables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces; using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
using OpenTK.Graphics; using OpenTK.Graphics;
using OpenTK;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Mania.Judgements; using osu.Game.Rulesets.Mania.Judgements;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
@ -59,12 +58,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
}, },
tickContainer = new Container<DrawableHoldNoteTick> tickContainer = new Container<DrawableHoldNoteTick> { RelativeSizeAxes = Axes.Both },
{
RelativeSizeAxes = Axes.Both,
RelativeChildOffset = new Vector2(0, (float)HitObject.StartTime),
RelativeChildSize = new Vector2(1, (float)HitObject.Duration)
},
head = new DrawableHeadNote(this, action) head = new DrawableHeadNote(this, action)
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
@ -72,7 +66,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
}, },
tail = new DrawableTailNote(this, action) tail = new DrawableTailNote(this, action)
{ {
Anchor = Anchor.BottomCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre Origin = Anchor.TopCentre
} }
}); });
@ -174,13 +168,6 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
{ {
this.holdNote = holdNote; this.holdNote = holdNote;
RelativePositionAxes = Axes.None;
Y = 0;
// Life time managed by the parent DrawableHoldNote
LifetimeStart = double.MinValue;
LifetimeEnd = double.MaxValue;
GlowPiece.Alpha = 0; GlowPiece.Alpha = 0;
} }
@ -213,13 +200,6 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
{ {
this.holdNote = holdNote; this.holdNote = holdNote;
RelativePositionAxes = Axes.None;
Y = 0;
// Life time managed by the parent DrawableHoldNote
LifetimeStart = double.MinValue;
LifetimeEnd = double.MaxValue;
GlowPiece.Alpha = 0; GlowPiece.Alpha = 0;
} }

View File

@ -32,9 +32,6 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
Anchor = Anchor.TopCentre; Anchor = Anchor.TopCentre;
Origin = Anchor.TopCentre; Origin = Anchor.TopCentre;
RelativePositionAxes = Axes.Y;
Y = (float)HitObject.StartTime;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
Size = new Vector2(1); Size = new Vector2(1);

View File

@ -37,12 +37,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
Container<DrawableDrumRollTick> tickContainer; Container<DrawableDrumRollTick> tickContainer;
MainPiece.Add(tickContainer = new Container<DrawableDrumRollTick> MainPiece.Add(tickContainer = new Container<DrawableDrumRollTick> { RelativeSizeAxes = Axes.Both });
{
RelativeSizeAxes = Axes.Both,
RelativeChildOffset = new Vector2((float)HitObject.StartTime, 0),
RelativeChildSize = new Vector2((float)HitObject.Duration, 1)
});
foreach (var tick in drumRoll.NestedHitObjects.OfType<DrumRollTick>()) foreach (var tick in drumRoll.NestedHitObjects.OfType<DrumRollTick>())
{ {

View File

@ -15,23 +15,11 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
public DrawableDrumRollTick(DrumRollTick tick) public DrawableDrumRollTick(DrumRollTick tick)
: base(tick) : base(tick)
{ {
// Because ticks aren't added by the ScrollingPlayfield, we need to set the following properties ourselves
RelativePositionAxes = Axes.X;
X = (float)tick.StartTime;
FillMode = FillMode.Fit; FillMode = FillMode.Fit;
} }
public override bool DisplayJudgement => false; public override bool DisplayJudgement => false;
protected override void LoadComplete()
{
base.LoadComplete();
// We need to set this here because RelativeSizeAxes won't/can't set our size by default with a different RelativeChildSize
Width *= Parent.RelativeChildSize.X;
}
protected override TaikoPiece CreateMainPiece() => new TickPiece protected override TaikoPiece CreateMainPiece() => new TickPiece
{ {
Filled = HitObject.FirstTick Filled = HitObject.FirstTick

View File

@ -38,11 +38,30 @@ namespace osu.Game.Rulesets.Objects.Drawables
public override bool RemoveWhenNotAlive => false; public override bool RemoveWhenNotAlive => false;
protected override bool RequiresChildrenUpdate => true; protected override bool RequiresChildrenUpdate => true;
public virtual bool AllJudged => false;
protected DrawableHitObject(HitObject hitObject) protected DrawableHitObject(HitObject hitObject)
{ {
HitObject = hitObject; HitObject = hitObject;
} }
/// <summary>
/// Processes this <see cref="DrawableHitObject"/>, checking if any judgements have occurred.
/// </summary>
/// <param name="userTriggered">Whether the user triggered this process.</param>
/// <returns>Whether a judgement has occurred from this <see cref="DrawableHitObject"/> or any nested <see cref="DrawableHitObject"/>s.</returns>
protected internal virtual bool UpdateJudgement(bool userTriggered) => false;
private List<DrawableHitObject> nestedHitObjects;
public IReadOnlyList<DrawableHitObject> NestedHitObjects => nestedHitObjects;
protected virtual void AddNested(DrawableHitObject h)
{
if (nestedHitObjects == null)
nestedHitObjects = new List<DrawableHitObject>();
nestedHitObjects.Add(h);
}
/// <summary> /// <summary>
/// The screen-space point that causes this <see cref="DrawableHitObject"/> to be selected in the Editor. /// The screen-space point that causes this <see cref="DrawableHitObject"/> to be selected in the Editor.
/// </summary> /// </summary>
@ -145,7 +164,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// <summary> /// <summary>
/// Whether this <see cref="DrawableHitObject"/> and all of its nested <see cref="DrawableHitObject"/>s have been judged. /// Whether this <see cref="DrawableHitObject"/> and all of its nested <see cref="DrawableHitObject"/>s have been judged.
/// </summary> /// </summary>
public bool AllJudged => (!ProvidesJudgement || judgementFinalized) && (NestedHitObjects?.All(h => h.AllJudged) ?? true); public sealed override bool AllJudged => (!ProvidesJudgement || judgementFinalized) && (NestedHitObjects?.All(h => h.AllJudged) ?? true);
/// <summary> /// <summary>
/// Notifies that a new judgement has occurred for this <see cref="DrawableHitObject"/>. /// Notifies that a new judgement has occurred for this <see cref="DrawableHitObject"/>.
@ -181,7 +200,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// </summary> /// </summary>
/// <param name="userTriggered">Whether the user triggered this process.</param> /// <param name="userTriggered">Whether the user triggered this process.</param>
/// <returns>Whether a judgement has occurred from this <see cref="DrawableHitObject"/> or any nested <see cref="DrawableHitObject"/>s.</returns> /// <returns>Whether a judgement has occurred from this <see cref="DrawableHitObject"/> or any nested <see cref="DrawableHitObject"/>s.</returns>
protected bool UpdateJudgement(bool userTriggered) protected internal sealed override bool UpdateJudgement(bool userTriggered)
{ {
judgementOccurred = false; judgementOccurred = false;
@ -238,18 +257,16 @@ namespace osu.Game.Rulesets.Objects.Drawables
UpdateJudgement(false); UpdateJudgement(false);
} }
private List<DrawableHitObject<TObject>> nestedHitObjects; protected override void AddNested(DrawableHitObject h)
protected IEnumerable<DrawableHitObject<TObject>> NestedHitObjects => nestedHitObjects;
protected virtual void AddNested(DrawableHitObject<TObject> h)
{ {
if (nestedHitObjects == null) base.AddNested(h);
nestedHitObjects = new List<DrawableHitObject<TObject>>();
h.OnJudgement += (d, j) => OnJudgement?.Invoke(d, j); if (!(h is DrawableHitObject<TObject> hWithJudgement))
h.OnJudgementRemoved += (d, j) => OnJudgementRemoved?.Invoke(d, j); return;
h.ApplyCustomUpdateState += (d, s) => ApplyCustomUpdateState?.Invoke(d, s);
nestedHitObjects.Add(h); hWithJudgement.OnJudgement += (d, j) => OnJudgement?.Invoke(d, j);
hWithJudgement.OnJudgementRemoved += (d, j) => OnJudgementRemoved?.Invoke(d, j);
hWithJudgement.ApplyCustomUpdateState += (d, s) => ApplyCustomUpdateState?.Invoke(d, s);
} }
/// <summary> /// <summary>

View File

@ -29,22 +29,25 @@ namespace osu.Game.Rulesets.UI.Scrolling.Algorithms
obj.LifetimeStart = obj.HitObject.StartTime - timeRange - 1000; obj.LifetimeStart = obj.HitObject.StartTime - timeRange - 1000;
if (!(obj.HitObject is IHasEndTime endTime)) if (obj.HitObject is IHasEndTime endTime)
continue;
var diff = positionAt(endTime.EndTime, timeRange) - startPosition;
switch (direction)
{ {
case ScrollingDirection.Up: var diff = positionAt(endTime.EndTime, timeRange) - startPosition;
case ScrollingDirection.Down:
obj.Height = (float)(diff * length.Y); switch (direction)
break; {
case ScrollingDirection.Left: case ScrollingDirection.Up:
case ScrollingDirection.Right: case ScrollingDirection.Down:
obj.Width = (float)(diff * length.X); obj.Height = (float)(diff * length.Y);
break; break;
case ScrollingDirection.Left:
case ScrollingDirection.Right:
obj.Width = (float)(diff * length.X);
break;
}
} }
if (obj.NestedHitObjects != null)
ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length);
} }
} }
@ -71,6 +74,9 @@ namespace osu.Game.Rulesets.UI.Scrolling.Algorithms
obj.X = (float)(-finalPosition * length.X); obj.X = (float)(-finalPosition * length.X);
break; break;
} }
if (obj.NestedHitObjects != null)
ComputePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length);
} }
} }

View File

@ -26,6 +26,9 @@ namespace osu.Game.Rulesets.UI.Scrolling.Algorithms
{ {
var controlPoint = controlPointAt(obj.HitObject.StartTime); var controlPoint = controlPointAt(obj.HitObject.StartTime);
obj.LifetimeStart = obj.HitObject.StartTime - timeRange / controlPoint.Multiplier; obj.LifetimeStart = obj.HitObject.StartTime - timeRange / controlPoint.Multiplier;
if (obj.NestedHitObjects != null)
ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length);
} }
} }
@ -52,6 +55,9 @@ namespace osu.Game.Rulesets.UI.Scrolling.Algorithms
obj.X = (float)(-position * length.X); obj.X = (float)(-position * length.X);
break; break;
} }
if (obj.NestedHitObjects != null)
ComputePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length);
} }
} }