Add support for reading/saving timeline zoom in editor

This commit is contained in:
Salman Ahmed 2022-01-25 10:43:43 +03:00
parent 5a9524a74e
commit d1cbdf63f0
2 changed files with 34 additions and 4 deletions

View File

@ -24,7 +24,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
[Cached] [Cached]
public class Timeline : ZoomableScrollContainer, IPositionSnapProvider public class Timeline : ZoomableScrollContainer, IPositionSnapProvider
{ {
private const float timeline_height = 72;
private const float timeline_expanded_height = 94;
private readonly Drawable userContent; private readonly Drawable userContent;
public readonly Bindable<bool> WaveformVisible = new Bindable<bool>(); public readonly Bindable<bool> WaveformVisible = new Bindable<bool>();
public readonly Bindable<bool> ControlPointsVisible = new Bindable<bool>(); public readonly Bindable<bool> ControlPointsVisible = new Bindable<bool>();
@ -58,8 +62,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private Track track; private Track track;
private const float timeline_height = 72; /// <summary>
private const float timeline_expanded_height = 94; /// The timeline zoom level at a 1x zoom scale.
/// </summary>
private float defaultTimelineZoom;
private readonly Bindable<double> timelineZoomScale = new BindableDouble(1.0);
public Timeline(Drawable userContent) public Timeline(Drawable userContent)
{ {
@ -84,7 +92,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private Bindable<float> waveformOpacity; private Bindable<float> waveformOpacity;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap, OsuColour colours, OsuConfigManager config) private void load(IBindable<WorkingBeatmap> beatmap, EditorBeatmap editorBeatmap, OsuColour colours, OsuConfigManager config)
{ {
CentreMarker centreMarker; CentreMarker centreMarker;
@ -141,9 +149,16 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{ {
MaxZoom = getZoomLevelForVisibleMilliseconds(500); MaxZoom = getZoomLevelForVisibleMilliseconds(500);
MinZoom = getZoomLevelForVisibleMilliseconds(10000); MinZoom = getZoomLevelForVisibleMilliseconds(10000);
Zoom = getZoomLevelForVisibleMilliseconds(6000); defaultTimelineZoom = getZoomLevelForVisibleMilliseconds(6000);
} }
}, true); }, true);
timelineZoomScale.Value = editorBeatmap.BeatmapInfo.TimelineZoom;
timelineZoomScale.BindValueChanged(scale =>
{
Zoom = (float)(defaultTimelineZoom * scale.NewValue);
editorBeatmap.BeatmapInfo.TimelineZoom = scale.NewValue;
}, true);
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -201,6 +216,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
return base.OnScroll(e); return base.OnScroll(e);
} }
protected override void OnZoomChange()
{
base.OnZoomChange();
timelineZoomScale.Value = Zoom / defaultTimelineZoom;
}
protected override void UpdateAfterChildren() protected override void UpdateAfterChildren()
{ {
base.UpdateAfterChildren(); base.UpdateAfterChildren();

View File

@ -136,11 +136,20 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{ {
zoomTarget = Math.Clamp(newZoom, MinZoom, MaxZoom); zoomTarget = Math.Clamp(newZoom, MinZoom, MaxZoom);
transformZoomTo(zoomTarget, focusPoint, ZoomDuration, ZoomEasing); transformZoomTo(zoomTarget, focusPoint, ZoomDuration, ZoomEasing);
OnZoomChange();
} }
private void transformZoomTo(float newZoom, float focusPoint, double duration = 0, Easing easing = Easing.None) private void transformZoomTo(float newZoom, float focusPoint, double duration = 0, Easing easing = Easing.None)
=> this.TransformTo(this.PopulateTransform(new TransformZoom(focusPoint, zoomedContent.DrawWidth, Current), newZoom, duration, easing)); => this.TransformTo(this.PopulateTransform(new TransformZoom(focusPoint, zoomedContent.DrawWidth, Current), newZoom, duration, easing));
/// <summary>
/// Invoked when the zoom target has changed.
/// </summary>
protected virtual void OnZoomChange()
{
}
private class TransformZoom : Transform<float, ZoomableScrollContainer> private class TransformZoom : Transform<float, ZoomableScrollContainer>
{ {
/// <summary> /// <summary>