mirror of
https://github.com/ppy/osu.git
synced 2025-01-16 01:33:22 +08:00
Merge pull request #7732 from peppy/editor-beatmap-component
Make EditorBeatmap a drawable component
This commit is contained in:
commit
190f870097
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Beatmaps.ControlPoints;
|
using osu.Game.Beatmaps.ControlPoints;
|
||||||
using osu.Game.Rulesets.Edit;
|
using osu.Game.Rulesets.Edit;
|
||||||
@ -23,15 +25,31 @@ namespace osu.Game.Tests.Editor
|
|||||||
[Cached(typeof(IBeatSnapProvider))]
|
[Cached(typeof(IBeatSnapProvider))]
|
||||||
private readonly EditorBeatmap editorBeatmap;
|
private readonly EditorBeatmap editorBeatmap;
|
||||||
|
|
||||||
|
protected override Container<Drawable> Content { get; }
|
||||||
|
|
||||||
public TestSceneHitObjectComposerDistanceSnapping()
|
public TestSceneHitObjectComposerDistanceSnapping()
|
||||||
{
|
{
|
||||||
editorBeatmap = new EditorBeatmap(new OsuBeatmap(), BeatDivisor);
|
base.Content.Add(new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
editorBeatmap = new EditorBeatmap(new OsuBeatmap()),
|
||||||
|
Content = new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup() => Schedule(() =>
|
public void Setup() => Schedule(() =>
|
||||||
{
|
{
|
||||||
Child = composer = new TestHitObjectComposer();
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
composer = new TestHitObjectComposer()
|
||||||
|
};
|
||||||
|
|
||||||
BeatDivisor.Value = 1;
|
BeatDivisor.Value = 1;
|
||||||
|
|
||||||
|
@ -38,13 +38,14 @@ namespace osu.Game.Tests.Visual.Editor
|
|||||||
{
|
{
|
||||||
Beatmap.Value = new WaveformTestBeatmap(audio);
|
Beatmap.Value = new WaveformTestBeatmap(audio);
|
||||||
|
|
||||||
var editorBeatmap = new EditorBeatmap((Beatmap<HitObject>)Beatmap.Value.Beatmap, BeatDivisor);
|
var editorBeatmap = new EditorBeatmap((Beatmap<HitObject>)Beatmap.Value.Beatmap);
|
||||||
|
|
||||||
Dependencies.Cache(editorBeatmap);
|
Dependencies.Cache(editorBeatmap);
|
||||||
Dependencies.CacheAs<IBeatSnapProvider>(editorBeatmap);
|
Dependencies.CacheAs<IBeatSnapProvider>(editorBeatmap);
|
||||||
|
|
||||||
AddRange(new Drawable[]
|
AddRange(new Drawable[]
|
||||||
{
|
{
|
||||||
|
editorBeatmap,
|
||||||
new FillFlowContainer
|
new FillFlowContainer
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
|
@ -11,7 +11,6 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Threading;
|
|
||||||
using osu.Framework.Timing;
|
using osu.Framework.Timing;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.ControlPoints;
|
using osu.Game.Beatmaps.ControlPoints;
|
||||||
@ -50,8 +49,6 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private IBeatSnapProvider beatSnapProvider { get; set; }
|
private IBeatSnapProvider beatSnapProvider { get; set; }
|
||||||
|
|
||||||
private IBeatmapProcessor beatmapProcessor;
|
|
||||||
|
|
||||||
private DrawableEditRulesetWrapper<TObject> drawableRulesetWrapper;
|
private DrawableEditRulesetWrapper<TObject> drawableRulesetWrapper;
|
||||||
private ComposeBlueprintContainer blueprintContainer;
|
private ComposeBlueprintContainer blueprintContainer;
|
||||||
private Container distanceSnapGridContainer;
|
private Container distanceSnapGridContainer;
|
||||||
@ -71,8 +68,6 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(IFrameBasedClock framedClock)
|
private void load(IFrameBasedClock framedClock)
|
||||||
{
|
{
|
||||||
beatmapProcessor = Ruleset.CreateBeatmapProcessor(EditorBeatmap.PlayableBeatmap);
|
|
||||||
|
|
||||||
EditorBeatmap.HitObjectAdded += addHitObject;
|
EditorBeatmap.HitObjectAdded += addHitObject;
|
||||||
EditorBeatmap.HitObjectRemoved += removeHitObject;
|
EditorBeatmap.HitObjectRemoved += removeHitObject;
|
||||||
EditorBeatmap.StartTimeChanged += UpdateHitObject;
|
EditorBeatmap.StartTimeChanged += UpdateHitObject;
|
||||||
@ -240,19 +235,6 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
lastGridUpdateTime = EditorClock.CurrentTime;
|
lastGridUpdateTime = EditorClock.CurrentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScheduledDelegate scheduledUpdate;
|
|
||||||
|
|
||||||
public override void UpdateHitObject(HitObject hitObject)
|
|
||||||
{
|
|
||||||
scheduledUpdate?.Cancel();
|
|
||||||
scheduledUpdate = Schedule(() =>
|
|
||||||
{
|
|
||||||
beatmapProcessor?.PreProcess();
|
|
||||||
hitObject?.ApplyDefaults(EditorBeatmap.ControlPointInfo, EditorBeatmap.BeatmapInfo.BaseDifficulty);
|
|
||||||
beatmapProcessor?.PostProcess();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addHitObject(HitObject hitObject) => UpdateHitObject(hitObject);
|
private void addHitObject(HitObject hitObject) => UpdateHitObject(hitObject);
|
||||||
|
|
||||||
private void removeHitObject(HitObject hitObject) => UpdateHitObject(null);
|
private void removeHitObject(HitObject hitObject) => UpdateHitObject(null);
|
||||||
@ -309,6 +291,8 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
public override float GetSnappedDistanceFromDistance(double referenceTime, float distance)
|
public override float GetSnappedDistanceFromDistance(double referenceTime, float distance)
|
||||||
=> DurationToDistance(referenceTime, beatSnapProvider.SnapTime(DistanceToDuration(referenceTime, distance), referenceTime));
|
=> DurationToDistance(referenceTime, beatSnapProvider.SnapTime(DistanceToDuration(referenceTime, distance), referenceTime));
|
||||||
|
|
||||||
|
public override void UpdateHitObject(HitObject hitObject) => EditorBeatmap.UpdateHitObject(hitObject);
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
@ -80,15 +80,15 @@ namespace osu.Game.Screens.Edit
|
|||||||
clock = new EditorClock(Beatmap.Value, beatDivisor) { IsCoupled = false };
|
clock = new EditorClock(Beatmap.Value, beatDivisor) { IsCoupled = false };
|
||||||
clock.ChangeSource(sourceClock);
|
clock.ChangeSource(sourceClock);
|
||||||
|
|
||||||
playableBeatmap = Beatmap.Value.GetPlayableBeatmap(Beatmap.Value.BeatmapInfo.Ruleset);
|
|
||||||
editorBeatmap = new EditorBeatmap(playableBeatmap, beatDivisor);
|
|
||||||
|
|
||||||
dependencies.CacheAs<IFrameBasedClock>(clock);
|
dependencies.CacheAs<IFrameBasedClock>(clock);
|
||||||
dependencies.CacheAs<IAdjustableClock>(clock);
|
dependencies.CacheAs<IAdjustableClock>(clock);
|
||||||
|
|
||||||
// todo: remove caching of this and consume via editorBeatmap?
|
// todo: remove caching of this and consume via editorBeatmap?
|
||||||
dependencies.Cache(beatDivisor);
|
dependencies.Cache(beatDivisor);
|
||||||
|
|
||||||
|
playableBeatmap = Beatmap.Value.GetPlayableBeatmap(Beatmap.Value.BeatmapInfo.Ruleset);
|
||||||
|
AddInternal(editorBeatmap = new EditorBeatmap(playableBeatmap));
|
||||||
|
|
||||||
dependencies.CacheAs(editorBeatmap);
|
dependencies.CacheAs(editorBeatmap);
|
||||||
|
|
||||||
EditorMenuBar menuBar;
|
EditorMenuBar menuBar;
|
||||||
@ -104,7 +104,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
fileMenuItems.Add(new EditorMenuItem("Exit", MenuItemType.Standard, this.Exit));
|
fileMenuItems.Add(new EditorMenuItem("Exit", MenuItemType.Standard, this.Exit));
|
||||||
|
|
||||||
InternalChild = new OsuContextMenuContainer
|
AddInternal(new OsuContextMenuContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Children = new[]
|
Children = new[]
|
||||||
@ -189,7 +189,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
menuBar.Mode.ValueChanged += onModeChanged;
|
menuBar.Mode.ValueChanged += onModeChanged;
|
||||||
|
|
||||||
|
@ -4,7 +4,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.ControlPoints;
|
using osu.Game.Beatmaps.ControlPoints;
|
||||||
using osu.Game.Beatmaps.Timing;
|
using osu.Game.Beatmaps.Timing;
|
||||||
@ -13,7 +16,7 @@ using osu.Game.Rulesets.Objects;
|
|||||||
|
|
||||||
namespace osu.Game.Screens.Edit
|
namespace osu.Game.Screens.Edit
|
||||||
{
|
{
|
||||||
public class EditorBeatmap : IBeatmap, IBeatSnapProvider
|
public class EditorBeatmap : Component, IBeatmap, IBeatSnapProvider
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked when a <see cref="HitObject"/> is added to this <see cref="EditorBeatmap"/>.
|
/// Invoked when a <see cref="HitObject"/> is added to this <see cref="EditorBeatmap"/>.
|
||||||
@ -34,19 +37,40 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
public readonly IBeatmap PlayableBeatmap;
|
public readonly IBeatmap PlayableBeatmap;
|
||||||
|
|
||||||
private readonly BindableBeatDivisor beatDivisor;
|
[Resolved]
|
||||||
|
private BindableBeatDivisor beatDivisor { get; set; }
|
||||||
|
|
||||||
|
private readonly IBeatmapProcessor beatmapProcessor;
|
||||||
|
|
||||||
private readonly Dictionary<HitObject, Bindable<double>> startTimeBindables = new Dictionary<HitObject, Bindable<double>>();
|
private readonly Dictionary<HitObject, Bindable<double>> startTimeBindables = new Dictionary<HitObject, Bindable<double>>();
|
||||||
|
|
||||||
public EditorBeatmap(IBeatmap playableBeatmap, BindableBeatDivisor beatDivisor = null)
|
public EditorBeatmap(IBeatmap playableBeatmap)
|
||||||
{
|
{
|
||||||
PlayableBeatmap = playableBeatmap;
|
PlayableBeatmap = playableBeatmap;
|
||||||
this.beatDivisor = beatDivisor;
|
|
||||||
|
beatmapProcessor = playableBeatmap.BeatmapInfo.Ruleset?.CreateInstance().CreateBeatmapProcessor(PlayableBeatmap);
|
||||||
|
|
||||||
foreach (var obj in HitObjects)
|
foreach (var obj in HitObjects)
|
||||||
trackStartTime(obj);
|
trackStartTime(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ScheduledDelegate scheduledUpdate;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a <see cref="HitObject"/>, invoking <see cref="HitObject.ApplyDefaults"/> and re-processing the beatmap.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hitObject">The <see cref="HitObject"/> to update.</param>
|
||||||
|
public void UpdateHitObject(HitObject hitObject)
|
||||||
|
{
|
||||||
|
scheduledUpdate?.Cancel();
|
||||||
|
scheduledUpdate = Scheduler.AddDelayed(() =>
|
||||||
|
{
|
||||||
|
beatmapProcessor?.PreProcess();
|
||||||
|
hitObject?.ApplyDefaults(ControlPointInfo, BeatmapInfo.BaseDifficulty);
|
||||||
|
beatmapProcessor?.PostProcess();
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
|
||||||
public BeatmapInfo BeatmapInfo
|
public BeatmapInfo BeatmapInfo
|
||||||
{
|
{
|
||||||
get => PlayableBeatmap.BeatmapInfo;
|
get => PlayableBeatmap.BeatmapInfo;
|
||||||
|
Loading…
Reference in New Issue
Block a user