1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 09:02:55 +08:00

Add popovers to adjust SV and samples from the timeline

This commit is contained in:
Dean Herbert 2021-09-14 18:51:22 +09:00
parent 9d17f84681
commit e4dd59aee2
3 changed files with 141 additions and 6 deletions

View File

@ -1,20 +1,33 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Objects;
using osu.Game.Screens.Edit.Timing;
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
public class DifficultyPointPiece : HitObjectPointPiece
public class DifficultyPointPiece : HitObjectPointPiece, IHasPopover
{
private readonly HitObject hitObject;
private readonly BindableNumber<double> speedMultiplier;
public DifficultyPointPiece(DifficultyControlPoint point)
: base(point)
public DifficultyPointPiece(HitObject hitObject)
: base(hitObject.DifficultyControlPoint)
{
speedMultiplier = point.SliderVelocityBindable.GetBoundCopy();
this.hitObject = hitObject;
speedMultiplier = hitObject.DifficultyControlPoint.SliderVelocityBindable.GetBoundCopy();
}
protected override void LoadComplete()
@ -23,5 +36,64 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
speedMultiplier.BindValueChanged(multiplier => Label.Text = $"{multiplier.NewValue:n2}x", true);
}
protected override bool OnClick(ClickEvent e)
{
this.ShowPopover();
return true;
}
public Popover GetPopover() => new DifficultyEditPopover(hitObject);
public class DifficultyEditPopover : OsuPopover
{
private readonly HitObject hitObject;
private readonly DifficultyControlPoint point;
private SliderWithTextBoxInput<double> sliderVelocitySlider;
[Resolved(canBeNull: true)]
private EditorBeatmap beatmap { get; set; }
public DifficultyEditPopover(HitObject hitObject)
{
this.hitObject = hitObject;
point = hitObject.DifficultyControlPoint;
}
[BackgroundDependencyLoader]
private void load()
{
Children = new Drawable[]
{
new FillFlowContainer
{
Width = 200,
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
sliderVelocitySlider = new SliderWithTextBoxInput<double>("Slider Velocity")
{
Current = new DifficultyControlPoint().SliderVelocityBindable,
KeyboardStep = 0.1f
}
}
}
};
var selectedPointBindable = point.SliderVelocityBindable;
// there may be legacy control points, which contain infinite precision for compatibility reasons (see LegacyDifficultyControlPoint).
// generally that level of precision could only be set by externally editing the .osu file, so at the point
// a user is looking to update this within the editor it should be safe to obliterate this additional precision.
double expectedPrecision = new DifficultyControlPoint().SliderVelocityBindable.Precision;
if (selectedPointBindable.Precision < expectedPrecision)
selectedPointBindable.Precision = expectedPrecision;
sliderVelocitySlider.Current = selectedPointBindable;
sliderVelocitySlider.Current.BindValueChanged(_ => beatmap?.Update(hitObject));
}
}
}
}

View File

@ -3,12 +3,20 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Screens.Edit.Timing;
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
public class SamplePointPiece : HitObjectPointPiece
public class SamplePointPiece : HitObjectPointPiece, IHasPopover
{
private readonly SampleControlPoint samplePoint;
@ -30,9 +38,64 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
bank.BindValueChanged(bank => updateText(), true);
}
protected override bool OnClick(ClickEvent e)
{
this.ShowPopover();
return true;
}
private void updateText()
{
Label.Text = $"{bank.Value} {volume.Value}";
}
public Popover GetPopover() => new SampleEditPopover(samplePoint);
public class SampleEditPopover : OsuPopover
{
private readonly SampleControlPoint point;
private LabelledTextBox bank;
private SliderWithTextBoxInput<int> volume;
[Resolved(canBeNull: true)]
protected IEditorChangeHandler ChangeHandler { get; private set; }
public SampleEditPopover(SampleControlPoint point)
{
this.point = point;
}
[BackgroundDependencyLoader]
private void load()
{
Children = new Drawable[]
{
new FillFlowContainer
{
Width = 200,
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
bank = new LabelledTextBox
{
Label = "Bank Name",
},
volume = new SliderWithTextBoxInput<int>("Volume")
{
Current = new SampleControlPoint().SampleVolumeBindable,
}
}
}
};
bank.Current = point.SampleBankBindable;
bank.Current.BindValueChanged(_ => ChangeHandler?.SaveState());
volume.Current = point.SampleVolumeBindable;
volume.Current.BindValueChanged(_ => ChangeHandler?.SaveState());
}
}
}
}

View File

@ -212,7 +212,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
if (Item.DifficultyControlPoint != null && Item is IHasDistance)
{
AddInternal(difficultyOverrideDisplay = new DifficultyPointPiece(Item.DifficultyControlPoint)
AddInternal(difficultyOverrideDisplay = new DifficultyPointPiece(Item)
{
Anchor = Anchor.TopLeft,
Origin = Anchor.BottomCentre