mirror of
https://github.com/ppy/osu
synced 2025-02-18 11:26:57 +00:00
Update SamplePointPiece.cs
This commit is contained in:
parent
39d9f0c3f5
commit
87ca0f5335
@ -12,7 +12,7 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Beatmaps.ControlPoints;
|
using osu.Game.Audio;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.UserInterfaceV2;
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
@ -26,14 +26,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
{
|
{
|
||||||
public readonly HitObject HitObject;
|
public readonly HitObject HitObject;
|
||||||
|
|
||||||
private readonly Bindable<string> bank;
|
private readonly BindableList<HitSampleInfo> samplesBindable;
|
||||||
private readonly BindableNumber<int> volume;
|
|
||||||
|
|
||||||
public SamplePointPiece(HitObject hitObject)
|
public SamplePointPiece(HitObject hitObject)
|
||||||
{
|
{
|
||||||
HitObject = hitObject;
|
HitObject = hitObject;
|
||||||
volume = hitObject.SampleControlPoint.SampleVolumeBindable.GetBoundCopy();
|
samplesBindable = hitObject.SamplesBindable.GetBoundCopy();
|
||||||
bank = hitObject.SampleControlPoint.SampleBankBindable.GetBoundCopy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Color4 GetRepresentingColour(OsuColour colours) => colours.Pink;
|
protected override Color4 GetRepresentingColour(OsuColour colours) => colours.Pink;
|
||||||
@ -41,8 +39,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
volume.BindValueChanged(_ => updateText());
|
samplesBindable.BindCollectionChanged((_, _) => updateText(), true);
|
||||||
bank.BindValueChanged(_ => updateText(), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
@ -53,7 +50,17 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
|
|
||||||
private void updateText()
|
private void updateText()
|
||||||
{
|
{
|
||||||
Label.Text = $"{bank.Value} {volume.Value}";
|
Label.Text = $"{GetBankValue(samplesBindable)} {GetVolumeValue(samplesBindable)}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string? GetBankValue(IEnumerable<HitSampleInfo> samples)
|
||||||
|
{
|
||||||
|
return samples.FirstOrDefault()?.Bank;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int GetVolumeValue(ICollection<HitSampleInfo> samples)
|
||||||
|
{
|
||||||
|
return samples.Count == 0 ? 0 : samples.Max(o => o.Volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Popover GetPopover() => new SampleEditPopover(HitObject);
|
public Popover GetPopover() => new SampleEditPopover(HitObject);
|
||||||
@ -92,7 +99,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
{
|
{
|
||||||
Label = "Bank Name",
|
Label = "Bank Name",
|
||||||
},
|
},
|
||||||
volume = new IndeterminateSliderWithTextBoxInput<int>("Volume", new SampleControlPoint().SampleVolumeBindable)
|
volume = new IndeterminateSliderWithTextBoxInput<int>("Volume", new BindableInt(100)
|
||||||
|
{
|
||||||
|
MinValue = 0,
|
||||||
|
MaxValue = 100,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -103,14 +114,14 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
// if the piece belongs to a currently selected object, assume that the user wants to change all selected objects.
|
// 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.
|
// 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 relevantObjects = (beatmap.SelectedHitObjects.Contains(hitObject) ? beatmap.SelectedHitObjects : hitObject.Yield()).ToArray();
|
||||||
var relevantControlPoints = relevantObjects.Select(h => h.SampleControlPoint).ToArray();
|
var relevantSamples = relevantObjects.Select(h => h.Samples).ToArray();
|
||||||
|
|
||||||
// even if there are multiple objects selected, we can still display sample volume or bank if they all have the same value.
|
// even if there are multiple objects selected, we can still display sample volume or bank if they all have the same value.
|
||||||
string? commonBank = getCommonBank(relevantControlPoints);
|
string? commonBank = getCommonBank(relevantSamples);
|
||||||
if (!string.IsNullOrEmpty(commonBank))
|
if (!string.IsNullOrEmpty(commonBank))
|
||||||
bank.Current.Value = commonBank;
|
bank.Current.Value = commonBank;
|
||||||
|
|
||||||
int? commonVolume = getCommonVolume(relevantControlPoints);
|
int? commonVolume = getCommonVolume(relevantSamples);
|
||||||
if (commonVolume != null)
|
if (commonVolume != null)
|
||||||
volume.Current.Value = commonVolume.Value;
|
volume.Current.Value = commonVolume.Value;
|
||||||
|
|
||||||
@ -120,9 +131,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
updateBankFor(relevantObjects, val.NewValue);
|
updateBankFor(relevantObjects, val.NewValue);
|
||||||
updateBankPlaceholderText(relevantObjects);
|
updateBankPlaceholderText(relevantObjects);
|
||||||
});
|
});
|
||||||
// on commit, ensure that the value is correct by sourcing it from the objects' control points again.
|
// on commit, ensure that the value is correct by sourcing it from the objects' samples again.
|
||||||
// this ensures that committing empty text causes a revert to the previous value.
|
// this ensures that committing empty text causes a revert to the previous value.
|
||||||
bank.OnCommit += (_, _) => bank.Current.Value = getCommonBank(relevantControlPoints);
|
bank.OnCommit += (_, _) => bank.Current.Value = getCommonBank(relevantSamples);
|
||||||
|
|
||||||
volume.Current.BindValueChanged(val => updateVolumeFor(relevantObjects, val.NewValue));
|
volume.Current.BindValueChanged(val => updateVolumeFor(relevantObjects, val.NewValue));
|
||||||
}
|
}
|
||||||
@ -133,8 +144,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
ScheduleAfterChildren(() => GetContainingInputManager().ChangeFocus(volume));
|
ScheduleAfterChildren(() => GetContainingInputManager().ChangeFocus(volume));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string? getCommonBank(SampleControlPoint[] relevantControlPoints) => relevantControlPoints.Select(point => point.SampleBank).Distinct().Count() == 1 ? relevantControlPoints.First().SampleBank : null;
|
private static string? getCommonBank(IList<HitSampleInfo>[] relevantSamples) => relevantSamples.Select(GetBankValue).Distinct().Count() == 1 ? GetBankValue(relevantSamples.First()) : null;
|
||||||
private static int? getCommonVolume(SampleControlPoint[] relevantControlPoints) => relevantControlPoints.Select(point => point.SampleVolume).Distinct().Count() == 1 ? relevantControlPoints.First().SampleVolume : null;
|
private static int? getCommonVolume(IList<HitSampleInfo>[] relevantSamples) => relevantSamples.Select(GetVolumeValue).Distinct().Count() == 1 ? GetVolumeValue(relevantSamples.First()) : null;
|
||||||
|
|
||||||
private void updateBankFor(IEnumerable<HitObject> objects, string? newBank)
|
private void updateBankFor(IEnumerable<HitObject> objects, string? newBank)
|
||||||
{
|
{
|
||||||
@ -145,7 +156,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
|
|
||||||
foreach (var h in objects)
|
foreach (var h in objects)
|
||||||
{
|
{
|
||||||
h.SampleControlPoint.SampleBank = newBank;
|
for (int i = 0; i < h.Samples.Count; i++)
|
||||||
|
{
|
||||||
|
h.Samples[i] = h.Samples[i].With(newBank: newBank);
|
||||||
|
}
|
||||||
|
|
||||||
beatmap.Update(h);
|
beatmap.Update(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +169,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
|
|
||||||
private void updateBankPlaceholderText(IEnumerable<HitObject> objects)
|
private void updateBankPlaceholderText(IEnumerable<HitObject> objects)
|
||||||
{
|
{
|
||||||
string? commonBank = getCommonBank(objects.Select(h => h.SampleControlPoint).ToArray());
|
string? commonBank = getCommonBank(objects.Select(h => h.Samples).ToArray());
|
||||||
bank.PlaceholderText = string.IsNullOrEmpty(commonBank) ? "(multiple)" : string.Empty;
|
bank.PlaceholderText = string.IsNullOrEmpty(commonBank) ? "(multiple)" : string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +182,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
|
|
||||||
foreach (var h in objects)
|
foreach (var h in objects)
|
||||||
{
|
{
|
||||||
h.SampleControlPoint.SampleVolume = newVolume.Value;
|
for (int i = 0; i < h.Samples.Count; i++)
|
||||||
|
{
|
||||||
|
h.Samples[i] = h.Samples[i].With(newVolume: newVolume.Value);
|
||||||
|
}
|
||||||
|
|
||||||
beatmap.Update(h);
|
beatmap.Update(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user