mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 06:42:56 +08:00
Rework and rename to OnNewDrawableHitObject.
The semantics is changed and hopefully more clear.
This commit is contained in:
parent
27f5a99726
commit
82aefa3868
@ -58,7 +58,7 @@ namespace osu.Game.Rulesets.Catch.UI
|
||||
|
||||
NewResult += onNewResult;
|
||||
RevertResult += onRevertResult;
|
||||
DrawableHitObjectAdded += d => ((DrawableCatchHitObject)d).CheckPosition = CheckIfWeCanCatch;
|
||||
OnNewDrawableHitObject += d => ((DrawableCatchHitObject)d).CheckPosition = CheckIfWeCanCatch;
|
||||
}
|
||||
|
||||
public bool CheckIfWeCanCatch(CatchHitObject obj) => CatcherArea.AttemptCatch(obj);
|
||||
|
@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
|
||||
public OsuEditPlayfield()
|
||||
{
|
||||
DrawableHitObjectAdded += d => d.ApplyCustomUpdateState += updateState;
|
||||
OnNewDrawableHitObject += d => d.ApplyCustomUpdateState += updateState;
|
||||
}
|
||||
|
||||
private const double editor_hit_object_fade_out_extension = 700;
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -91,23 +92,28 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
AddRangeInternal(poolDictionary.Values);
|
||||
|
||||
NewResult += onNewResult;
|
||||
DrawableHitObjectAdded += onDrawableHitObjectAdded;
|
||||
OnNewDrawableHitObject += onDrawableHitObjectAdded;
|
||||
}
|
||||
|
||||
private void onDrawableHitObjectAdded(DrawableHitObject drawable)
|
||||
{
|
||||
((DrawableOsuHitObject)drawable).CheckHittable = CheckHittable;
|
||||
|
||||
Debug.Assert(!drawable.IsLoaded, $"Already loaded {nameof(DrawableHitObject)} is added to {nameof(OsuPlayfield)}");
|
||||
drawable.OnLoadComplete += onDrawableHitObjectLoaded;
|
||||
}
|
||||
|
||||
private void onDrawableHitObjectLoaded(Drawable drawable)
|
||||
{
|
||||
// note: `Slider`'s `ProxiedLayer` is added when its nested `DrawableHitCircle` is loaded.
|
||||
switch (drawable)
|
||||
{
|
||||
case DrawableSpinner _:
|
||||
if (!drawable.HasProxy)
|
||||
spinnerProxies.Add(drawable.CreateProxy());
|
||||
spinnerProxies.Add(drawable.CreateProxy());
|
||||
break;
|
||||
|
||||
case IDrawableHitObjectWithProxiedApproach approach:
|
||||
if (!approach.ProxiedLayer.HasProxy)
|
||||
approachCircles.Add(approach.ProxiedLayer.CreateProxy());
|
||||
case DrawableHitCircle hitCircle:
|
||||
approachCircles.Add(hitCircle.ProxiedLayer.CreateProxy());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,11 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
/// </summary>
|
||||
public event Action<DrawableHitObject, JudgementResult> OnRevertResult;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a new nested hit object is created by <see cref="CreateNestedHitObject" />.
|
||||
/// </summary>
|
||||
internal event Action<DrawableHitObject> OnNestedDrawableCreated;
|
||||
|
||||
/// <summary>
|
||||
/// Whether a visual indicator should be displayed when a scoring result occurs.
|
||||
/// </summary>
|
||||
@ -214,10 +219,15 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
|
||||
foreach (var h in HitObject.NestedHitObjects)
|
||||
{
|
||||
var drawableNested = pooledObjectProvider?.GetPooledDrawableRepresentation(h)
|
||||
var pooledDrawableNested = pooledObjectProvider?.GetPooledDrawableRepresentation(h);
|
||||
var drawableNested = pooledDrawableNested
|
||||
?? CreateNestedHitObject(h)
|
||||
?? throw new InvalidOperationException($"{nameof(CreateNestedHitObject)} returned null for {h.GetType().ReadableName()}.");
|
||||
|
||||
// Invoke the event only if this nested object is just created by `CreateNestedHitObject`.
|
||||
if (pooledDrawableNested == null)
|
||||
OnNestedDrawableCreated?.Invoke(drawableNested);
|
||||
|
||||
drawableNested.OnNewResult += onNewResult;
|
||||
drawableNested.OnRevertResult += onRevertResult;
|
||||
drawableNested.ApplyCustomUpdateState += onApplyCustomUpdateState;
|
||||
|
@ -42,14 +42,6 @@ namespace osu.Game.Rulesets.UI
|
||||
/// </summary>
|
||||
public event Action<DrawableHitObject, JudgementResult> RevertResult;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a <see cref="DrawableHitObject"/> is added.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This event is also called for nested <see cref="DrawableHitObject"/>s.
|
||||
/// </remarks>
|
||||
public event Action<DrawableHitObject> DrawableHitObjectAdded;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a <see cref="HitObject"/> becomes used by a <see cref="DrawableHitObject"/>.
|
||||
/// </summary>
|
||||
@ -123,8 +115,6 @@ namespace osu.Game.Rulesets.UI
|
||||
bindStartTime(drawable);
|
||||
AddInternal(drawableMap[entry] = drawable, false);
|
||||
|
||||
DrawableHitObjectAdded?.Invoke(drawable);
|
||||
|
||||
HitObjectUsageBegan?.Invoke(entry.HitObject);
|
||||
}
|
||||
|
||||
@ -157,16 +147,6 @@ namespace osu.Game.Rulesets.UI
|
||||
hitObject.OnRevertResult += onRevertResult;
|
||||
|
||||
AddInternal(hitObject);
|
||||
|
||||
onDrawableHitObjectAddedRecursive(hitObject);
|
||||
}
|
||||
|
||||
private void onDrawableHitObjectAddedRecursive(DrawableHitObject hitObject)
|
||||
{
|
||||
DrawableHitObjectAdded?.Invoke(hitObject);
|
||||
|
||||
foreach (var nested in hitObject.NestedHitObjects)
|
||||
onDrawableHitObjectAddedRecursive(nested);
|
||||
}
|
||||
|
||||
public virtual bool Remove(DrawableHitObject hitObject)
|
||||
|
@ -33,12 +33,14 @@ namespace osu.Game.Rulesets.UI
|
||||
public event Action<DrawableHitObject, JudgementResult> RevertResult;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a <see cref="DrawableHitObject"/> is added.
|
||||
/// Invoked before a new <see cref="DrawableHitObject"/> is added.
|
||||
/// This event is invoked only once for each <see cref="DrawableHitObject"/>
|
||||
/// even the drawable is pooled and used multiple times for different <see cref="HitObject"/>s.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This event is also called for nested <see cref="DrawableHitObject"/>s.
|
||||
/// </remarks>
|
||||
public event Action<DrawableHitObject> DrawableHitObjectAdded;
|
||||
public event Action<DrawableHitObject> OnNewDrawableHitObject;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="DrawableHitObject"/> contained in this Playfield.
|
||||
@ -93,13 +95,15 @@ namespace osu.Game.Rulesets.UI
|
||||
/// </summary>
|
||||
protected Playfield()
|
||||
{
|
||||
OnNewDrawableHitObject += d =>
|
||||
d.OnNestedDrawableCreated += nested => OnNewDrawableHitObject?.Invoke(nested);
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
hitObjectContainerLazy = new Lazy<HitObjectContainer>(() => CreateHitObjectContainer().With(h =>
|
||||
{
|
||||
h.NewResult += (d, r) => NewResult?.Invoke(d, r);
|
||||
h.RevertResult += (d, r) => RevertResult?.Invoke(d, r);
|
||||
h.DrawableHitObjectAdded += d => DrawableHitObjectAdded?.Invoke(d);
|
||||
h.HitObjectUsageBegan += o => HitObjectUsageBegan?.Invoke(o);
|
||||
h.HitObjectUsageFinished += o => HitObjectUsageFinished?.Invoke(o);
|
||||
}));
|
||||
@ -133,6 +137,8 @@ namespace osu.Game.Rulesets.UI
|
||||
/// <param name="h">The DrawableHitObject to add.</param>
|
||||
public virtual void Add(DrawableHitObject h)
|
||||
{
|
||||
OnNewDrawableHitObject?.Invoke(h);
|
||||
|
||||
HitObjectContainer.Add(h);
|
||||
OnHitObjectAdded(h.HitObject);
|
||||
}
|
||||
@ -334,6 +340,8 @@ namespace osu.Game.Rulesets.UI
|
||||
// This is done before Apply() so that the state is updated once when the hitobject is applied.
|
||||
if (!dho.IsLoaded)
|
||||
{
|
||||
OnNewDrawableHitObject?.Invoke(dho);
|
||||
|
||||
foreach (var m in mods.OfType<IApplicableToDrawableHitObjects>())
|
||||
m.ApplyToDrawableHitObjects(dho.Yield());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user