1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 11:47:24 +08:00

Use bindable flow for zoom handling

This commit is contained in:
Dean Herbert 2024-09-27 17:13:26 +09:00
parent 34087a0f1a
commit ce41dc4629
No known key found for this signature in database
3 changed files with 26 additions and 30 deletions

View File

@ -92,7 +92,7 @@ namespace osu.Game.Rulesets.Mania.Edit
base.Update();
if (screenWithTimeline?.TimelineArea.Timeline != null)
drawableRuleset.TimelineTimeRange = EditorClock.TrackLength / screenWithTimeline.TimelineArea.Timeline.CurrentZoom / 2;
drawableRuleset.TimelineTimeRange = EditorClock.TrackLength / screenWithTimeline.TimelineArea.Timeline.CurrentZoom.Value / 2;
}
}
}

View File

@ -72,36 +72,31 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
samplesVisible = config.GetBindable<bool>(OsuSetting.EditorTimelineShowSamples);
}
private BindableNumber<float>? timelineZoom;
protected override void LoadComplete()
{
base.LoadComplete();
samplesVisible.BindValueChanged(visible => this.FadeTo(visible.NewValue ? 1 : 0, 200, Easing.OutQuint));
this.FadeTo(samplesVisible.Value ? 1 : 0);
}
private float lastZoom;
private const float zoom_threshold = 40f;
protected override void Update()
{
base.Update();
// Retract visual state if the timeline is zoomed out too far.
if (timeline is null || timeline.Zoom == lastZoom) return;
lastZoom = timeline.Zoom;
if (timeline.Zoom < zoom_threshold)
timelineZoom = timeline?.CurrentZoom.GetBoundCopy();
timelineZoom?.BindValueChanged(zoom =>
{
Label.FadeOut(200, Easing.OutQuint);
LabelContainer.ResizeWidthTo(16, 200, Easing.OutQuint);
}
else
{
Label.FadeIn(200, Easing.OutQuint);
LabelContainer.ResizeWidthTo(Label.Width, 200, Easing.OutQuint);
}
const float zoom_threshold = 40f;
if (zoom.NewValue < zoom_threshold)
{
Label.FadeOut(200, Easing.OutQuint);
LabelContainer.ResizeWidthTo(16, 200, Easing.OutQuint);
}
else
{
Label.FadeIn(200, Easing.OutQuint);
LabelContainer.ResizeWidthTo(Label.Width, 200, Easing.OutQuint);
}
}, true);
}
protected override void Dispose(bool isDisposing)

View File

@ -3,6 +3,7 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transforms;
@ -32,10 +33,10 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
protected override Container<Drawable> Content => zoomedContent;
/// <summary>
/// The current zoom level of <see cref="ZoomableScrollContainer"/>.
/// The current (final) zoom level of <see cref="ZoomableScrollContainer"/>.
/// It may differ from <see cref="Zoom"/> during transitions.
/// </summary>
public float CurrentZoom { get; private set; } = 1;
public BindableFloat CurrentZoom { get; private set; } = new BindableFloat(1);
private bool isZoomSetUp;
@ -98,7 +99,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
minZoom = minimum;
maxZoom = maximum;
CurrentZoom = zoomTarget = initial;
CurrentZoom.Value = zoomTarget = initial;
zoomedContentWidthCache.Invalidate();
isZoomSetUp = true;
@ -124,7 +125,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
if (IsLoaded)
setZoomTarget(newZoom, ToSpaceOfOtherDrawable(new Vector2(DrawWidth / 2, 0), zoomedContent).X);
else
CurrentZoom = zoomTarget = newZoom;
CurrentZoom.Value = zoomTarget = newZoom;
}
protected override void UpdateAfterChildren()
@ -154,7 +155,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private void updateZoomedContentWidth()
{
zoomedContent.Width = DrawWidth * CurrentZoom;
zoomedContent.Width = DrawWidth * CurrentZoom.Value;
zoomedContentWidthCache.Validate();
}
@ -238,7 +239,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
float expectedWidth = d.DrawWidth * newZoom;
float targetOffset = expectedWidth * (focusPoint / contentSize) - focusOffset;
d.CurrentZoom = newZoom;
d.CurrentZoom.Value = newZoom;
d.updateZoomedContentWidth();
// Temporarily here to make sure ScrollTo gets the correct DrawSize for scrollable area.
@ -247,7 +248,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
d.ScrollTo(targetOffset, false);
}
protected override void ReadIntoStartValue(ZoomableScrollContainer d) => StartValue = d.CurrentZoom;
protected override void ReadIntoStartValue(ZoomableScrollContainer d) => StartValue = d.CurrentZoom.Value;
}
}
}