Add basic track reloading support while inside the editor

This commit is contained in:
Dean Herbert 2020-09-24 18:55:49 +09:00
parent 65e6dd2ac3
commit 978f6edf38
4 changed files with 38 additions and 4 deletions

View File

@ -81,6 +81,11 @@ namespace osu.Game.Overlays
mods.BindValueChanged(_ => ResetTrackAdjustments(), true);
}
/// <summary>
/// Forcefully reload the current <see cref="WorkingBeatmap"/>'s track from disk.
/// </summary>
public void ForceReloadCurrentBeatmap() => changeTrack();
/// <summary>
/// Change the position of a <see cref="BeatmapSetInfo"/> in the current playlist.
/// </summary>

View File

@ -43,6 +43,7 @@ using osuTK.Input;
namespace osu.Game.Screens.Edit
{
[Cached(typeof(IBeatSnapProvider))]
[Cached]
public class Editor : ScreenWithBeatmapBackground, IKeyBindingHandler<GlobalAction>, IKeyBindingHandler<PlatformAction>, IBeatSnapProvider
{
public override float BackgroundParallaxAmount => 0.1f;
@ -91,6 +92,9 @@ namespace osu.Game.Screens.Edit
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private MusicController music { get; set; }
[BackgroundDependencyLoader]
private void load(OsuColour colours, GameHost host)
{
@ -98,9 +102,9 @@ namespace osu.Game.Screens.Edit
beatDivisor.BindValueChanged(divisor => Beatmap.Value.BeatmapInfo.BeatDivisor = divisor.NewValue);
// Todo: should probably be done at a DrawableRuleset level to share logic with Player.
var sourceClock = (IAdjustableClock)Beatmap.Value.Track ?? new StopwatchClock();
clock = new EditorClock(Beatmap.Value, beatDivisor) { IsCoupled = false };
clock.ChangeSource(sourceClock);
UpdateClockSource();
dependencies.CacheAs(clock);
AddInternal(clock);
@ -271,6 +275,15 @@ namespace osu.Game.Screens.Edit
bottomBackground.Colour = colours.Gray2;
}
/// <summary>
/// If the beatmap's track has changed, this method must be called to keep the editor in a valid state.
/// </summary>
public void UpdateClockSource()
{
var sourceClock = (IAdjustableClock)Beatmap.Value.Track ?? new StopwatchClock();
clock.ChangeSource(sourceClock);
}
protected void Save()
{
// apply any set-level metadata changes.

View File

@ -3,6 +3,7 @@
using System;
using System.Linq;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Utils;
@ -17,7 +18,7 @@ namespace osu.Game.Screens.Edit
/// </summary>
public class EditorClock : Component, IFrameBasedClock, IAdjustableClock, ISourceChangeableClock
{
public readonly double TrackLength;
public double TrackLength;
public ControlPointInfo ControlPointInfo;
@ -190,7 +191,11 @@ namespace osu.Game.Screens.Edit
public FrameTimeInfo TimeInfo => underlyingClock.TimeInfo;
public void ChangeSource(IClock source) => underlyingClock.ChangeSource(source);
public void ChangeSource(IClock source)
{
underlyingClock.ChangeSource(source);
TrackLength = (source as Track)?.Length ?? 60000;
}
public IClock Source => underlyingClock.Source;

View File

@ -18,6 +18,7 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.IO;
using osu.Game.Overlays;
using osuTK;
using FileInfo = System.IO.FileInfo;
@ -139,6 +140,12 @@ namespace osu.Game.Screens.Edit.Setup
[Resolved]
private FileStore files { get; set; }
[Resolved]
private MusicController music { get; set; }
[Resolved]
private Editor editor { get; set; }
private void audioTrackChanged(ValueChangedEvent<string> filePath)
{
var info = new FileInfo(filePath.NewValue);
@ -173,6 +180,10 @@ namespace osu.Game.Screens.Edit.Setup
});
Beatmap.Value.Metadata.AudioFile = info.Name;
music.ForceReloadCurrentBeatmap();
editor.UpdateClockSource();
}
private void onCommit(TextBox sender, bool newText)