1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-07 01:07:24 +08:00
osu-lazer/osu.Game/Rulesets/Edit/DrawableEditRuleset.cs

111 lines
4.0 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 15:36:06 +08:00
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Edit
{
2019-03-20 13:49:33 +08:00
public abstract class DrawableEditRuleset : CompositeDrawable
{
/// <summary>
2019-03-20 13:49:33 +08:00
/// The <see cref="Playfield"/> contained by this <see cref="DrawableEditRuleset"/>.
/// </summary>
public abstract Playfield Playfield { get; }
public abstract PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer();
2019-03-20 13:49:33 +08:00
internal DrawableEditRuleset()
{
RelativeSizeAxes = Axes.Both;
}
/// <summary>
/// Adds a <see cref="HitObject"/> to the <see cref="Beatmap"/> and displays a visual representation of it.
/// </summary>
/// <param name="hitObject">The <see cref="HitObject"/> to add.</param>
/// <returns>The visual representation of <paramref name="hitObject"/>.</returns>
internal abstract DrawableHitObject Add(HitObject hitObject);
2018-10-18 15:36:06 +08:00
/// <summary>
/// Removes a <see cref="HitObject"/> from the <see cref="Beatmap"/> and the display.
/// </summary>
/// <param name="hitObject">The <see cref="HitObject"/> to remove.</param>
/// <returns>The visual representation of the removed <paramref name="hitObject"/>.</returns>
internal abstract DrawableHitObject Remove(HitObject hitObject);
}
2019-03-20 13:49:33 +08:00
public class DrawableEditRuleset<TObject> : DrawableEditRuleset
where TObject : HitObject
{
2019-03-20 10:22:34 +08:00
public override Playfield Playfield => drawableRuleset.Playfield;
public override PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer() => drawableRuleset.CreatePlayfieldAdjustmentContainer();
2019-03-20 10:22:34 +08:00
private Ruleset ruleset => drawableRuleset.Ruleset;
private Beatmap<TObject> beatmap => drawableRuleset.Beatmap;
2019-03-20 10:22:34 +08:00
private readonly DrawableRuleset<TObject> drawableRuleset;
2019-03-20 13:49:33 +08:00
public DrawableEditRuleset(DrawableRuleset<TObject> drawableRuleset)
{
2019-03-20 10:22:34 +08:00
this.drawableRuleset = drawableRuleset;
2019-03-20 10:22:34 +08:00
InternalChild = drawableRuleset;
Playfield.DisplayJudgements.Value = false;
}
internal override DrawableHitObject Add(HitObject hitObject)
{
var tObject = (TObject)hitObject;
// Add to beatmap, preserving sorting order
var insertionIndex = beatmap.HitObjects.FindLastIndex(h => h.StartTime <= hitObject.StartTime);
beatmap.HitObjects.Insert(insertionIndex + 1, tObject);
// Process object
var processor = ruleset.CreateBeatmapProcessor(beatmap);
2018-11-12 17:24:18 +08:00
processor?.PreProcess();
tObject.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty);
2018-11-12 17:24:18 +08:00
processor?.PostProcess();
// Add visual representation
var drawableObject = drawableRuleset.CreateDrawableRepresentation(tObject);
2019-03-20 10:22:34 +08:00
drawableRuleset.Playfield.Add(drawableObject);
drawableRuleset.Playfield.PostProcess();
return drawableObject;
}
2018-10-18 15:36:06 +08:00
internal override DrawableHitObject Remove(HitObject hitObject)
{
var tObject = (TObject)hitObject;
// Remove from beatmap
beatmap.HitObjects.Remove(tObject);
// Process the beatmap
var processor = ruleset.CreateBeatmapProcessor(beatmap);
2018-11-20 16:26:00 +08:00
processor?.PreProcess();
processor?.PostProcess();
2018-10-18 15:36:06 +08:00
// Remove visual representation
var drawableObject = Playfield.AllHitObjects.Single(d => d.HitObject == hitObject);
2019-03-20 10:22:34 +08:00
drawableRuleset.Playfield.Remove(drawableObject);
drawableRuleset.Playfield.PostProcess();
2018-10-18 15:36:06 +08:00
return drawableObject;
}
}
}