1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +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;
dropletContainer.Add(h);

View File

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

View File

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

View File

@ -37,12 +37,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
RelativeSizeAxes = Axes.Y;
Container<DrawableDrumRollTick> tickContainer;
MainPiece.Add(tickContainer = new Container<DrawableDrumRollTick>
{
RelativeSizeAxes = Axes.Both,
RelativeChildOffset = new Vector2((float)HitObject.StartTime, 0),
RelativeChildSize = new Vector2((float)HitObject.Duration, 1)
});
MainPiece.Add(tickContainer = new Container<DrawableDrumRollTick> { RelativeSizeAxes = Axes.Both });
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)
: 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;
}
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
{
Filled = HitObject.FirstTick

View File

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

View File

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