2019-01-24 16:43:03 +08:00
|
|
|
// 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-03 14:36:14 +08:00
|
|
|
|
2018-10-18 15:36:06 +08:00
|
|
|
using System.Linq;
|
2018-10-03 14:36:14 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2018-10-03 15:49:59 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-10-03 14:36:14 +08:00
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit
|
|
|
|
{
|
2019-03-20 13:49:33 +08:00
|
|
|
public abstract class DrawableEditRuleset : CompositeDrawable
|
2018-10-03 14:36:14 +08:00
|
|
|
{
|
2018-10-17 17:01:38 +08:00
|
|
|
/// <summary>
|
2019-03-20 13:49:33 +08:00
|
|
|
/// The <see cref="Playfield"/> contained by this <see cref="DrawableEditRuleset"/>.
|
2018-10-17 17:01:38 +08:00
|
|
|
/// </summary>
|
|
|
|
public abstract Playfield Playfield { get; }
|
2018-10-03 14:36:14 +08:00
|
|
|
|
2019-03-31 00:29:37 +08:00
|
|
|
public abstract PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer();
|
|
|
|
|
2019-03-20 13:49:33 +08:00
|
|
|
internal DrawableEditRuleset()
|
2018-10-03 14:36:14 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:41:17 +08:00
|
|
|
/// <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);
|
2018-10-03 14:36:14 +08:00
|
|
|
}
|
|
|
|
|
2019-03-20 13:49:33 +08:00
|
|
|
public class DrawableEditRuleset<TObject> : DrawableEditRuleset
|
2018-10-03 14:36:14 +08:00
|
|
|
where TObject : HitObject
|
|
|
|
{
|
2019-03-20 10:22:34 +08:00
|
|
|
public override Playfield Playfield => drawableRuleset.Playfield;
|
2018-10-03 14:36:14 +08:00
|
|
|
|
2019-03-31 00:29:37 +08:00
|
|
|
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;
|
2018-10-03 14:36:14 +08:00
|
|
|
|
2019-03-20 10:22:34 +08:00
|
|
|
private readonly DrawableRuleset<TObject> drawableRuleset;
|
2018-10-17 17:01:38 +08:00
|
|
|
|
2019-03-20 13:49:33 +08:00
|
|
|
public DrawableEditRuleset(DrawableRuleset<TObject> drawableRuleset)
|
2018-10-03 14:36:14 +08:00
|
|
|
{
|
2019-03-20 10:22:34 +08:00
|
|
|
this.drawableRuleset = drawableRuleset;
|
2018-10-17 17:01:38 +08:00
|
|
|
|
2019-03-20 10:22:34 +08:00
|
|
|
InternalChild = drawableRuleset;
|
2018-10-03 14:36:14 +08:00
|
|
|
|
2018-10-17 17:01:38 +08:00
|
|
|
Playfield.DisplayJudgements.Value = false;
|
2018-10-03 14:36:14 +08:00
|
|
|
}
|
|
|
|
|
2018-10-17 16:41:17 +08:00
|
|
|
internal override DrawableHitObject Add(HitObject hitObject)
|
2018-10-03 14:36:14 +08:00
|
|
|
{
|
|
|
|
var tObject = (TObject)hitObject;
|
|
|
|
|
2018-10-17 16:41:17 +08:00
|
|
|
// Add to beatmap, preserving sorting order
|
2018-10-03 14:36:14 +08:00
|
|
|
var insertionIndex = beatmap.HitObjects.FindLastIndex(h => h.StartTime <= hitObject.StartTime);
|
|
|
|
beatmap.HitObjects.Insert(insertionIndex + 1, tObject);
|
|
|
|
|
2018-10-17 16:41:17 +08:00
|
|
|
// Process object
|
2018-10-03 14:36:14 +08:00
|
|
|
var processor = ruleset.CreateBeatmapProcessor(beatmap);
|
|
|
|
|
2018-11-12 17:24:18 +08:00
|
|
|
processor?.PreProcess();
|
2018-10-03 14:36:14 +08:00
|
|
|
tObject.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty);
|
2018-11-12 17:24:18 +08:00
|
|
|
processor?.PostProcess();
|
2018-10-03 14:36:14 +08:00
|
|
|
|
2018-10-17 16:41:17 +08:00
|
|
|
// Add visual representation
|
2019-03-24 22:40:43 +08:00
|
|
|
var drawableObject = drawableRuleset.CreateDrawableRepresentation(tObject);
|
2018-10-03 15:49:59 +08:00
|
|
|
|
2019-03-20 10:22:34 +08:00
|
|
|
drawableRuleset.Playfield.Add(drawableObject);
|
|
|
|
drawableRuleset.Playfield.PostProcess();
|
2018-10-03 15:49:59 +08:00
|
|
|
|
|
|
|
return drawableObject;
|
2018-10-03 14:36:14 +08:00
|
|
|
}
|
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;
|
|
|
|
}
|
2018-10-03 14:36:14 +08:00
|
|
|
}
|
|
|
|
}
|