1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 15:53:00 +08:00
osu-lazer/osu.Game/Rulesets/Edit/DrawableEditorRulesetWrapper.cs

105 lines
3.4 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.
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.UI;
2019-08-29 15:06:40 +08: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>
2021-04-26 14:37:42 +08:00
internal class DrawableEditorRulesetWrapper<TObject> : CompositeDrawable
where TObject : HitObject
{
2019-08-29 17:12:29 +08:00
public Playfield Playfield => drawableRuleset.Playfield;
2019-03-20 10:22:34 +08:00
private readonly DrawableRuleset<TObject> drawableRuleset;
2019-08-29 15:06:40 +08:00
[Resolved]
private EditorBeatmap beatmap { get; set; }
2019-08-29 15:06:40 +08:00
2021-04-26 14:37:42 +08:00
public DrawableEditorRulesetWrapper(DrawableRuleset<TObject> drawableRuleset)
{
2019-03-20 10:22:34 +08:00
this.drawableRuleset = drawableRuleset;
2019-08-29 17:12:29 +08:00
RelativeSizeAxes = Axes.Both;
2019-03-20 10:22:34 +08:00
InternalChild = drawableRuleset;
}
[BackgroundDependencyLoader]
private void load()
{
drawableRuleset.FrameStablePlayback = false;
Playfield.DisplayJudgements.Value = false;
}
[Resolved(canBeNull: true)]
private IEditorChangeHandler changeHandler { get; set; }
2019-08-29 15:06:40 +08:00
protected override void LoadComplete()
{
2019-08-29 15:06:40 +08:00
base.LoadComplete();
2019-08-29 15:06:40 +08:00
beatmap.HitObjectAdded += addHitObject;
beatmap.HitObjectRemoved += removeHitObject;
if (changeHandler != null)
{
// for now only regenerate replay on a finalised state change, not HitObjectUpdated.
changeHandler.OnStateChange += () => Scheduler.AddOnce(regenerateAutoplay);
}
else
{
beatmap.HitObjectUpdated += _ => Scheduler.AddOnce(regenerateAutoplay);
}
Scheduler.AddOnce(regenerateAutoplay);
2019-08-29 15:06:40 +08:00
}
private void regenerateAutoplay()
{
var autoplayMod = drawableRuleset.Mods.OfType<ModAutoplay>().Single();
drawableRuleset.SetReplayScore(autoplayMod.CreateScoreFromReplayData(drawableRuleset.Beatmap, drawableRuleset.Mods));
}
2019-08-29 15:06:40 +08:00
private void addHitObject(HitObject hitObject)
{
2020-11-13 16:08:20 +08:00
drawableRuleset.AddHitObject((TObject)hitObject);
2019-03-20 10:22:34 +08:00
drawableRuleset.Playfield.PostProcess();
}
2018-10-18 15:36:06 +08:00
2019-08-29 15:06:40 +08:00
private void removeHitObject(HitObject hitObject)
2018-10-18 15:36:06 +08:00
{
2020-11-13 16:08:20 +08:00
drawableRuleset.RemoveHitObject((TObject)hitObject);
2019-03-20 10:22:34 +08:00
drawableRuleset.Playfield.PostProcess();
2018-10-18 15:36:06 +08:00
}
2019-08-29 15:31:40 +08:00
2019-11-11 12:04:38 +08:00
public override bool PropagatePositionalInputSubTree => false;
public override bool PropagateNonPositionalInputSubTree => false;
2019-08-29 17:12:29 +08:00
public PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer() => drawableRuleset.CreatePlayfieldAdjustmentContainer();
2019-08-29 15:31:40 +08:00
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (beatmap != null)
{
beatmap.HitObjectAdded -= addHitObject;
beatmap.HitObjectRemoved -= removeHitObject;
}
}
}
}