1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 02:02:53 +08:00

Improve sample bank text box UX in case of multiple selection

This commit is contained in:
Bartłomiej Dach 2021-11-13 18:06:32 +01:00
parent 76baf08140
commit 73ca1d39a2
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
2 changed files with 25 additions and 5 deletions

View File

@ -237,6 +237,10 @@ namespace osu.Game.Tests.Visual.Editing
var popover = this.ChildrenOfType<SamplePointPiece.SampleEditPopover>().Single();
var textBox = popover.ChildrenOfType<LabelledTextBox>().First();
textBox.Current.Value = bank;
// force a commit via keyboard.
// this is needed when testing attempting to set empty bank - which should revert to the previous value, but only on commit.
InputManager.ChangeFocus(textBox);
InputManager.Key(Key.Enter);
});
private void hitObjectHasSampleBank(int objectIndex, string bank) => AddAssert($"{objectIndex.ToOrdinalWords()} has bank {bank}", () =>

View File

@ -99,20 +99,30 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
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.
string? commonBank = relevantControlPoints.Select(point => point.SampleBank).Distinct().Count() == 1 ? relevantControlPoints.First().SampleBank : null;
string? commonBank = getCommonBank(relevantControlPoints);
if (!string.IsNullOrEmpty(commonBank))
bank.Current.Value = commonBank;
int? commonVolume = relevantControlPoints.Select(point => point.SampleVolume).Distinct().Count() == 1 ? (int?)relevantControlPoints.First().SampleVolume : null;
int? commonVolume = getCommonVolume(relevantControlPoints);
if (commonVolume != null)
volume.Current.Value = commonVolume.Value;
bank.Current.BindValueChanged(val => updateBankFor(relevantObjects, val.NewValue));
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);
volume.Current.BindValueChanged(val => updateVolumeFor(relevantObjects, val.NewValue));
}
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;
private void updateBankFor(IEnumerable<HitObject> objects, string? newBank)
{
if (string.IsNullOrEmpty(newBank))
@ -129,6 +139,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
beatmap.EndChange();
}
private void updateBankPlaceholderText(IEnumerable<HitObject> objects)
{
string? commonBank = getCommonBank(objects.Select(h => h.SampleControlPoint).ToArray());
bank.PlaceholderText = string.IsNullOrEmpty(commonBank) ? "(multiple)" : null;
}
private void updateVolumeFor(IEnumerable<HitObject> objects, int? newVolume)
{
if (newVolume == null)