mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 11:42:56 +08:00
Hook up + use editor beatmap
This commit is contained in:
parent
840f224619
commit
7927b684d3
@ -16,15 +16,13 @@ using osu.Game.Rulesets.Osu.Edit;
|
||||
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles;
|
||||
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles.Components;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Screens.Edit.Compose;
|
||||
using osu.Game.Screens.Edit.Compose.Components;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Editor
|
||||
{
|
||||
[TestFixture]
|
||||
[Cached(Type = typeof(IPlacementHandler))]
|
||||
public class TestSceneHitObjectComposer : OsuTestScene, IPlacementHandler
|
||||
public class TestSceneHitObjectComposer : OsuTestScene
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||
{
|
||||
@ -39,8 +37,6 @@ namespace osu.Game.Tests.Visual.Editor
|
||||
typeof(HitCirclePlacementBlueprint),
|
||||
};
|
||||
|
||||
private HitObjectComposer composer;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
@ -67,15 +63,7 @@ namespace osu.Game.Tests.Visual.Editor
|
||||
Dependencies.CacheAs<IAdjustableClock>(clock);
|
||||
Dependencies.CacheAs<IFrameBasedClock>(clock);
|
||||
|
||||
Child = composer = new OsuHitObjectComposer(new OsuRuleset());
|
||||
Child = new OsuHitObjectComposer(new OsuRuleset());
|
||||
}
|
||||
|
||||
public void BeginPlacement(HitObject hitObject)
|
||||
{
|
||||
}
|
||||
|
||||
public void EndPlacement(HitObject hitObject) => composer.Add(hitObject);
|
||||
|
||||
public void Delete(HitObject hitObject) => composer.Remove(hitObject);
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,9 @@ using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
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;
|
||||
using osu.Game.Screens.Edit;
|
||||
|
||||
namespace osu.Game.Rulesets.Edit
|
||||
{
|
||||
@ -25,20 +24,6 @@ namespace osu.Game.Rulesets.Edit
|
||||
{
|
||||
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);
|
||||
|
||||
/// <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);
|
||||
}
|
||||
|
||||
public class DrawableEditRuleset<TObject> : DrawableEditRuleset
|
||||
@ -48,11 +33,11 @@ namespace osu.Game.Rulesets.Edit
|
||||
|
||||
public override PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer() => drawableRuleset.CreatePlayfieldAdjustmentContainer();
|
||||
|
||||
private Ruleset ruleset => drawableRuleset.Ruleset;
|
||||
private Beatmap<TObject> beatmap => drawableRuleset.Beatmap;
|
||||
|
||||
private readonly DrawableRuleset<TObject> drawableRuleset;
|
||||
|
||||
[Resolved]
|
||||
private EditorBeatmap<TObject> beatmap { get; set; }
|
||||
|
||||
public DrawableEditRuleset(DrawableRuleset<TObject> drawableRuleset)
|
||||
{
|
||||
this.drawableRuleset = drawableRuleset;
|
||||
@ -67,50 +52,28 @@ namespace osu.Game.Rulesets.Edit
|
||||
Playfield.DisplayJudgements.Value = false;
|
||||
}
|
||||
|
||||
internal override DrawableHitObject Add(HitObject hitObject)
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
var tObject = (TObject)hitObject;
|
||||
base.LoadComplete();
|
||||
|
||||
// Add to beatmap, preserving sorting order
|
||||
var insertionIndex = beatmap.HitObjects.FindLastIndex(h => h.StartTime <= hitObject.StartTime);
|
||||
beatmap.HitObjects.Insert(insertionIndex + 1, tObject);
|
||||
beatmap.HitObjectAdded += addHitObject;
|
||||
beatmap.HitObjectRemoved += removeHitObject;
|
||||
}
|
||||
|
||||
// Process object
|
||||
var processor = ruleset.CreateBeatmapProcessor(beatmap);
|
||||
|
||||
processor?.PreProcess();
|
||||
tObject.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty);
|
||||
processor?.PostProcess();
|
||||
|
||||
// Add visual representation
|
||||
var drawableObject = drawableRuleset.CreateDrawableRepresentation(tObject);
|
||||
private void addHitObject(HitObject hitObject)
|
||||
{
|
||||
var drawableObject = drawableRuleset.CreateDrawableRepresentation((TObject)hitObject);
|
||||
|
||||
drawableRuleset.Playfield.Add(drawableObject);
|
||||
drawableRuleset.Playfield.PostProcess();
|
||||
|
||||
return drawableObject;
|
||||
}
|
||||
|
||||
internal override DrawableHitObject Remove(HitObject hitObject)
|
||||
private void removeHitObject(HitObject hitObject)
|
||||
{
|
||||
var tObject = (TObject)hitObject;
|
||||
|
||||
// Remove from beatmap
|
||||
beatmap.HitObjects.Remove(tObject);
|
||||
|
||||
// Process the beatmap
|
||||
var processor = ruleset.CreateBeatmapProcessor(beatmap);
|
||||
|
||||
processor?.PreProcess();
|
||||
processor?.PostProcess();
|
||||
|
||||
// Remove visual representation
|
||||
var drawableObject = Playfield.AllHitObjects.Single(d => d.HitObject == hitObject);
|
||||
|
||||
drawableRuleset.Playfield.Remove(drawableObject);
|
||||
drawableRuleset.Playfield.PostProcess();
|
||||
|
||||
return drawableObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Screens.Edit;
|
||||
using osu.Game.Screens.Edit.Components.RadioButtons;
|
||||
using osu.Game.Screens.Edit.Compose;
|
||||
using osu.Game.Screens.Edit.Compose.Components;
|
||||
|
||||
namespace osu.Game.Rulesets.Edit
|
||||
@ -154,14 +155,6 @@ namespace osu.Game.Rulesets.Edit
|
||||
/// </summary>
|
||||
public virtual bool CursorInPlacementArea => DrawableRuleset.Playfield.ReceivePositionalInputAt(inputManager.CurrentState.Mouse.Position);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="HitObject"/> to the <see cref="Beatmaps.Beatmap"/> and visualises it.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The <see cref="HitObject"/> to add.</param>
|
||||
public void Add(HitObject hitObject) => blueprintContainer.AddBlueprintFor(DrawableRuleset.Add(hitObject));
|
||||
|
||||
public void Remove(HitObject hitObject) => blueprintContainer.RemoveBlueprintFor(DrawableRuleset.Remove(hitObject));
|
||||
|
||||
internal abstract DrawableEditRuleset CreateDrawableRuleset();
|
||||
|
||||
protected abstract IReadOnlyList<HitObjectCompositionTool> CompositionTools { get; }
|
||||
@ -178,9 +171,16 @@ namespace osu.Game.Rulesets.Edit
|
||||
public virtual SelectionHandler CreateSelectionHandler() => new SelectionHandler();
|
||||
}
|
||||
|
||||
public abstract class HitObjectComposer<TObject> : HitObjectComposer
|
||||
[Cached(Type = typeof(IPlacementHandler))]
|
||||
public abstract class HitObjectComposer<TObject> : HitObjectComposer, IPlacementHandler
|
||||
where TObject : HitObject
|
||||
{
|
||||
private Beatmap<TObject> playableBeatmap;
|
||||
|
||||
[Cached]
|
||||
[Cached(typeof(IEditorBeatmap))]
|
||||
private EditorBeatmap<TObject> editorBeatmap;
|
||||
|
||||
protected HitObjectComposer(Ruleset ruleset)
|
||||
: base(ruleset)
|
||||
{
|
||||
@ -189,19 +189,55 @@ namespace osu.Game.Rulesets.Edit
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
{
|
||||
var workingBeatmap = parent.Get<IBindable<WorkingBeatmap>>();
|
||||
var playableBeatmap = (Beatmap<TObject>)workingBeatmap.Value.GetPlayableBeatmap(Ruleset.RulesetInfo, Array.Empty<Mod>());
|
||||
var editorBeatmap = new EditorBeatmap<TObject>(playableBeatmap);
|
||||
playableBeatmap = (Beatmap<TObject>)workingBeatmap.Value.GetPlayableBeatmap(Ruleset.RulesetInfo, Array.Empty<Mod>());
|
||||
|
||||
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||
dependencies.CacheAs(editorBeatmap);
|
||||
dependencies.CacheAs<IEditorBeatmap>(editorBeatmap);
|
||||
editorBeatmap = new EditorBeatmap<TObject>(playableBeatmap);
|
||||
editorBeatmap.HitObjectAdded += addHitObject;
|
||||
editorBeatmap.HitObjectRemoved += removeHitObject;
|
||||
|
||||
return dependencies;
|
||||
return base.CreateChildDependencies(parent);
|
||||
}
|
||||
|
||||
private void addHitObject(HitObject hitObject)
|
||||
{
|
||||
// Process object
|
||||
var processor = Ruleset.CreateBeatmapProcessor(playableBeatmap);
|
||||
|
||||
processor?.PreProcess();
|
||||
hitObject.ApplyDefaults(playableBeatmap.ControlPointInfo, playableBeatmap.BeatmapInfo.BaseDifficulty);
|
||||
processor?.PostProcess();
|
||||
}
|
||||
|
||||
private void removeHitObject(HitObject hitObject)
|
||||
{
|
||||
var processor = Ruleset.CreateBeatmapProcessor(playableBeatmap);
|
||||
|
||||
processor?.PreProcess();
|
||||
processor?.PostProcess();
|
||||
}
|
||||
|
||||
internal override DrawableEditRuleset CreateDrawableRuleset()
|
||||
=> new DrawableEditRuleset<TObject>(CreateDrawableRuleset(Ruleset, Beatmap.Value, Array.Empty<Mod>()));
|
||||
|
||||
protected abstract DrawableRuleset<TObject> CreateDrawableRuleset(Ruleset ruleset, WorkingBeatmap beatmap, IReadOnlyList<Mod> mods);
|
||||
|
||||
public void BeginPlacement(HitObject hitObject)
|
||||
{
|
||||
}
|
||||
|
||||
public void EndPlacement(HitObject hitObject) => editorBeatmap.Add(hitObject);
|
||||
|
||||
public void Delete(HitObject hitObject) => editorBeatmap.Remove(hitObject);
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (editorBeatmap != null)
|
||||
{
|
||||
editorBeatmap.HitObjectAdded -= addHitObject;
|
||||
editorBeatmap.HitObjectRemoved -= removeHitObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ using osu.Framework.Input.Events;
|
||||
using osu.Framework.Input.States;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Edit.Tools;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Compose.Components
|
||||
@ -29,6 +30,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
[Resolved]
|
||||
private HitObjectComposer composer { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private IEditorBeatmap beatmap { get; set; }
|
||||
|
||||
public BlueprintContainer()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
@ -53,7 +57,15 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
};
|
||||
|
||||
foreach (var obj in composer.HitObjects)
|
||||
AddBlueprintFor(obj);
|
||||
addBlueprintFor(obj);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
beatmap.HitObjectAdded += addBlueprintFor;
|
||||
beatmap.HitObjectRemoved += removeBlueprintFor;
|
||||
}
|
||||
|
||||
private HitObjectCompositionTool currentTool;
|
||||
@ -75,11 +87,32 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a blueprint for a <see cref="DrawableHitObject"/> which adds movement support.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to create a blueprint for.</param>
|
||||
public void AddBlueprintFor(DrawableHitObject hitObject)
|
||||
private void addBlueprintFor(HitObject hitObject)
|
||||
{
|
||||
var drawable = composer.HitObjects.FirstOrDefault(d => d.HitObject == hitObject);
|
||||
if (drawable == null)
|
||||
return;
|
||||
|
||||
addBlueprintFor(drawable);
|
||||
}
|
||||
|
||||
private void removeBlueprintFor(HitObject hitObject)
|
||||
{
|
||||
var blueprint = selectionBlueprints.Single(m => m.HitObject.HitObject == hitObject);
|
||||
if (blueprint == null)
|
||||
return;
|
||||
|
||||
blueprint.Deselect();
|
||||
|
||||
blueprint.Selected -= onBlueprintSelected;
|
||||
blueprint.Deselected -= onBlueprintDeselected;
|
||||
blueprint.SelectionRequested -= onSelectionRequested;
|
||||
blueprint.DragRequested -= onDragRequested;
|
||||
|
||||
selectionBlueprints.Remove(blueprint);
|
||||
}
|
||||
|
||||
private void addBlueprintFor(DrawableHitObject hitObject)
|
||||
{
|
||||
refreshTool();
|
||||
|
||||
@ -95,25 +128,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
selectionBlueprints.Add(blueprint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a blueprint for a <see cref="DrawableHitObject"/>.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The <see cref="DrawableHitObject"/> for which to remove the blueprint.</param>
|
||||
public void RemoveBlueprintFor(DrawableHitObject hitObject)
|
||||
{
|
||||
var blueprint = selectionBlueprints.Single(m => m.HitObject == hitObject);
|
||||
if (blueprint == null)
|
||||
return;
|
||||
|
||||
blueprint.Deselect();
|
||||
|
||||
blueprint.Selected -= onBlueprintSelected;
|
||||
blueprint.Deselected -= onBlueprintDeselected;
|
||||
blueprint.SelectionRequested -= onSelectionRequested;
|
||||
blueprint.DragRequested -= onDragRequested;
|
||||
|
||||
selectionBlueprints.Remove(blueprint);
|
||||
}
|
||||
private void removeBlueprintFor(DrawableHitObject hitObject) => removeBlueprintFor(hitObject.HitObject);
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
@ -183,6 +198,17 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
|
||||
private void onDragRequested(SelectionBlueprint blueprint, DragEvent dragEvent) => selectionHandler.HandleDrag(blueprint, dragEvent);
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (beatmap != null)
|
||||
{
|
||||
beatmap.HitObjectAdded -= addBlueprintFor;
|
||||
beatmap.HitObjectRemoved -= removeBlueprintFor;
|
||||
}
|
||||
}
|
||||
|
||||
private class SelectionBlueprintContainer : Container<SelectionBlueprint>
|
||||
{
|
||||
protected override int Compare(Drawable x, Drawable y)
|
||||
|
@ -9,15 +9,13 @@ using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Screens.Edit.Compose.Components;
|
||||
using osu.Game.Screens.Edit.Compose.Components.Timeline;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Compose
|
||||
{
|
||||
[Cached(Type = typeof(IPlacementHandler))]
|
||||
public class ComposeScreen : EditorScreen, IPlacementHandler
|
||||
public class ComposeScreen : EditorScreen
|
||||
{
|
||||
private const float vertical_margins = 10;
|
||||
private const float horizontal_margins = 20;
|
||||
@ -119,13 +117,5 @@ namespace osu.Game.Screens.Edit.Compose
|
||||
|
||||
composerContainer.Child = composer;
|
||||
}
|
||||
|
||||
public void BeginPlacement(HitObject hitObject)
|
||||
{
|
||||
}
|
||||
|
||||
public void EndPlacement(HitObject hitObject) => composer.Add(hitObject);
|
||||
|
||||
public void Delete(HitObject hitObject) => composer.Remove(hitObject);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user