osu/osu.Game/Rulesets/Edit/DrawableEditRulesetWrapper.cs

85 lines
2.7 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-10-18 07:36:06 +00:00
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.UI;
2019-08-29 07:06:40 +00:00
using osu.Game.Screens.Edit;
namespace osu.Game.Rulesets.Edit
{
/// <summary>
/// A wrapper for a <see cref="DrawableRuleset{TObject}"/>. Handles adding visual representations of <see cref="HitObject"/>s to the underlying <see cref="DrawableRuleset{TObject}"/>.
/// </summary>
internal class DrawableEditRulesetWrapper<TObject> : CompositeDrawable
where TObject : HitObject
{
2019-08-29 09:12:29 +00:00
public Playfield Playfield => drawableRuleset.Playfield;
2019-03-20 02:22:34 +00:00
private readonly DrawableRuleset<TObject> drawableRuleset;
2019-08-29 07:06:40 +00:00
[Resolved]
private IEditorBeatmap<TObject> beatmap { get; set; }
2019-08-29 07:06:40 +00:00
public DrawableEditRulesetWrapper(DrawableRuleset<TObject> drawableRuleset)
{
2019-03-20 02:22:34 +00:00
this.drawableRuleset = drawableRuleset;
2019-08-29 09:12:29 +00:00
RelativeSizeAxes = Axes.Both;
2019-03-20 02:22:34 +00:00
InternalChild = drawableRuleset;
}
[BackgroundDependencyLoader]
private void load()
{
drawableRuleset.FrameStablePlayback = false;
Playfield.DisplayJudgements.Value = false;
}
2019-08-29 07:06:40 +00:00
protected override void LoadComplete()
{
2019-08-29 07:06:40 +00:00
base.LoadComplete();
2019-08-29 07:06:40 +00:00
beatmap.HitObjectAdded += addHitObject;
beatmap.HitObjectRemoved += removeHitObject;
}
2019-08-29 07:06:40 +00:00
private void addHitObject(HitObject hitObject)
{
var drawableObject = drawableRuleset.CreateDrawableRepresentation((TObject)hitObject);
2019-03-20 02:22:34 +00:00
drawableRuleset.Playfield.Add(drawableObject);
drawableRuleset.Playfield.PostProcess();
}
2018-10-18 07:36:06 +00:00
2019-08-29 07:06:40 +00:00
private void removeHitObject(HitObject hitObject)
2018-10-18 07:36:06 +00:00
{
var drawableObject = Playfield.AllHitObjects.Single(d => d.HitObject == hitObject);
2019-03-20 02:22:34 +00:00
drawableRuleset.Playfield.Remove(drawableObject);
drawableRuleset.Playfield.PostProcess();
2018-10-18 07:36:06 +00:00
}
2019-08-29 07:31:40 +00:00
2019-11-11 04:04:38 +00:00
public override bool PropagatePositionalInputSubTree => false;
public override bool PropagateNonPositionalInputSubTree => false;
2019-08-29 09:12:29 +00:00
public PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer() => drawableRuleset.CreatePlayfieldAdjustmentContainer();
2019-08-29 07:31:40 +00:00
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (beatmap != null)
{
beatmap.HitObjectAdded -= addHitObject;
beatmap.HitObjectRemoved -= removeHitObject;
}
}
}
}