2020-10-01 17:49:48 +08:00
|
|
|
// 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.
|
|
|
|
|
2021-11-14 00:21:48 +08:00
|
|
|
#nullable enable
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2020-10-01 17:49:48 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2021-09-14 17:51:22 +08:00
|
|
|
using osu.Framework.Extensions;
|
2021-11-14 00:21:48 +08:00
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2021-09-14 17:51:22 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Framework.Input.Events;
|
2020-10-01 17:49:48 +08:00
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2021-09-14 17:51:22 +08:00
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2021-09-14 18:21:23 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2021-09-14 17:51:22 +08:00
|
|
|
using osu.Game.Screens.Edit.Timing;
|
2021-11-14 01:09:40 +08:00
|
|
|
using osuTK;
|
2020-10-01 17:49:48 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|
|
|
{
|
2021-09-14 17:51:22 +08:00
|
|
|
public class SamplePointPiece : HitObjectPointPiece, IHasPopover
|
2020-10-01 17:49:48 +08:00
|
|
|
{
|
2021-11-13 23:58:24 +08:00
|
|
|
public readonly HitObject HitObject;
|
2020-10-01 18:29:34 +08:00
|
|
|
|
2020-10-01 17:49:48 +08:00
|
|
|
private readonly Bindable<string> bank;
|
|
|
|
private readonly BindableNumber<int> volume;
|
|
|
|
|
2021-09-14 18:21:23 +08:00
|
|
|
public SamplePointPiece(HitObject hitObject)
|
|
|
|
: base(hitObject.SampleControlPoint)
|
2020-10-01 17:49:48 +08:00
|
|
|
{
|
2021-11-13 23:58:24 +08:00
|
|
|
HitObject = hitObject;
|
2021-09-14 18:21:23 +08:00
|
|
|
volume = hitObject.SampleControlPoint.SampleVolumeBindable.GetBoundCopy();
|
|
|
|
bank = hitObject.SampleControlPoint.SampleBankBindable.GetBoundCopy();
|
2020-10-01 17:49:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-01-15 08:06:39 +08:00
|
|
|
private void load()
|
2020-10-01 17:49:48 +08:00
|
|
|
{
|
2021-09-10 12:44:39 +08:00
|
|
|
volume.BindValueChanged(volume => updateText());
|
|
|
|
bank.BindValueChanged(bank => updateText(), true);
|
|
|
|
}
|
2020-10-01 17:49:48 +08:00
|
|
|
|
2021-09-14 17:51:22 +08:00
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
{
|
|
|
|
this.ShowPopover();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:44:39 +08:00
|
|
|
private void updateText()
|
|
|
|
{
|
|
|
|
Label.Text = $"{bank.Value} {volume.Value}";
|
2020-10-01 17:49:48 +08:00
|
|
|
}
|
2021-09-14 17:51:22 +08:00
|
|
|
|
2021-11-13 23:58:24 +08:00
|
|
|
public Popover GetPopover() => new SampleEditPopover(HitObject);
|
2021-09-14 17:51:22 +08:00
|
|
|
|
|
|
|
public class SampleEditPopover : OsuPopover
|
|
|
|
{
|
2021-09-14 18:21:23 +08:00
|
|
|
private readonly HitObject hitObject;
|
2021-09-14 17:51:22 +08:00
|
|
|
|
2021-11-14 00:21:48 +08:00
|
|
|
private LabelledTextBox bank = null!;
|
|
|
|
private IndeterminateSliderWithTextBoxInput<int> volume = null!;
|
2021-09-14 17:51:22 +08:00
|
|
|
|
|
|
|
[Resolved(canBeNull: true)]
|
2021-11-14 00:21:48 +08:00
|
|
|
private EditorBeatmap beatmap { get; set; } = null!;
|
2021-09-14 17:51:22 +08:00
|
|
|
|
2021-09-14 18:21:23 +08:00
|
|
|
public SampleEditPopover(HitObject hitObject)
|
2021-09-14 17:51:22 +08:00
|
|
|
{
|
2021-09-14 18:21:23 +08:00
|
|
|
this.hitObject = hitObject;
|
2021-09-14 17:51:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Width = 200,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2021-11-14 01:09:40 +08:00
|
|
|
Spacing = new Vector2(0, 10),
|
2021-09-14 17:51:22 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
bank = new LabelledTextBox
|
|
|
|
{
|
|
|
|
Label = "Bank Name",
|
|
|
|
},
|
2021-11-14 00:21:48 +08:00
|
|
|
volume = new IndeterminateSliderWithTextBoxInput<int>("Volume", new SampleControlPoint().SampleVolumeBindable)
|
2021-09-14 17:51:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-11-14 00:21:48 +08:00
|
|
|
// if the piece belongs to a currently selected object, assume that the user wants to change all selected objects.
|
|
|
|
// if the piece belongs to an unselected object, operate on that object alone, independently of the selection.
|
|
|
|
var relevantObjects = (beatmap.SelectedHitObjects.Contains(hitObject) ? beatmap.SelectedHitObjects : hitObject.Yield()).ToArray();
|
|
|
|
var relevantControlPoints = relevantObjects.Select(h => h.SampleControlPoint).ToArray();
|
|
|
|
|
|
|
|
// even if there are multiple objects selected, we can still display sample volume or bank if they all have the same value.
|
2021-11-14 01:06:32 +08:00
|
|
|
string? commonBank = getCommonBank(relevantControlPoints);
|
2021-11-14 00:21:48 +08:00
|
|
|
if (!string.IsNullOrEmpty(commonBank))
|
|
|
|
bank.Current.Value = commonBank;
|
|
|
|
|
2021-11-14 01:06:32 +08:00
|
|
|
int? commonVolume = getCommonVolume(relevantControlPoints);
|
2021-11-14 00:21:48 +08:00
|
|
|
if (commonVolume != null)
|
|
|
|
volume.Current.Value = commonVolume.Value;
|
|
|
|
|
2021-11-14 01:06:32 +08:00
|
|
|
updateBankPlaceholderText(relevantObjects);
|
|
|
|
bank.Current.BindValueChanged(val =>
|
|
|
|
{
|
|
|
|
updateBankFor(relevantObjects, val.NewValue);
|
|
|
|
updateBankPlaceholderText(relevantObjects);
|
|
|
|
});
|
|
|
|
// on commit, ensure that the value is correct by sourcing it from the objects' control points again.
|
|
|
|
// this ensures that committing empty text causes a revert to the previous value.
|
|
|
|
bank.OnCommit += (_, __) => bank.Current.Value = getCommonBank(relevantControlPoints);
|
|
|
|
|
2021-11-14 00:21:48 +08:00
|
|
|
volume.Current.BindValueChanged(val => updateVolumeFor(relevantObjects, val.NewValue));
|
|
|
|
}
|
|
|
|
|
2021-11-14 01:06:32 +08:00
|
|
|
private static string? getCommonBank(SampleControlPoint[] relevantControlPoints) => relevantControlPoints.Select(point => point.SampleBank).Distinct().Count() == 1 ? relevantControlPoints.First().SampleBank : null;
|
|
|
|
private static int? getCommonVolume(SampleControlPoint[] relevantControlPoints) => relevantControlPoints.Select(point => point.SampleVolume).Distinct().Count() == 1 ? (int?)relevantControlPoints.First().SampleVolume : null;
|
|
|
|
|
2021-11-14 00:21:48 +08:00
|
|
|
private void updateBankFor(IEnumerable<HitObject> objects, string? newBank)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(newBank))
|
|
|
|
return;
|
|
|
|
|
|
|
|
beatmap.BeginChange();
|
|
|
|
|
|
|
|
foreach (var h in objects)
|
|
|
|
{
|
|
|
|
h.SampleControlPoint.SampleBank = newBank;
|
|
|
|
beatmap.Update(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
beatmap.EndChange();
|
|
|
|
}
|
|
|
|
|
2021-11-14 01:06:32 +08:00
|
|
|
private void updateBankPlaceholderText(IEnumerable<HitObject> objects)
|
|
|
|
{
|
|
|
|
string? commonBank = getCommonBank(objects.Select(h => h.SampleControlPoint).ToArray());
|
|
|
|
bank.PlaceholderText = string.IsNullOrEmpty(commonBank) ? "(multiple)" : null;
|
|
|
|
}
|
|
|
|
|
2021-11-14 00:21:48 +08:00
|
|
|
private void updateVolumeFor(IEnumerable<HitObject> objects, int? newVolume)
|
|
|
|
{
|
|
|
|
if (newVolume == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
beatmap.BeginChange();
|
|
|
|
|
|
|
|
foreach (var h in objects)
|
|
|
|
{
|
|
|
|
h.SampleControlPoint.SampleVolume = newVolume.Value;
|
|
|
|
beatmap.Update(h);
|
|
|
|
}
|
2021-09-14 17:51:22 +08:00
|
|
|
|
2021-11-14 00:21:48 +08:00
|
|
|
beatmap.EndChange();
|
2021-09-14 17:51:22 +08:00
|
|
|
}
|
|
|
|
}
|
2020-10-01 17:49:48 +08:00
|
|
|
}
|
|
|
|
}
|