mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 07:33:55 +09:00
Merge pull request #23308 from OliBomby/sample-control-points
Remove SampleControlPoint and DifficultyControlPoint from HitObject
This commit is contained in:
@ -13,12 +13,14 @@ 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.Containers;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Screens.Edit.Timing;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
{
|
||||
@ -29,13 +31,14 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
private readonly BindableNumber<double> speedMultiplier;
|
||||
|
||||
public DifficultyPointPiece(HitObject hitObject)
|
||||
: base(hitObject.DifficultyControlPoint)
|
||||
{
|
||||
HitObject = hitObject;
|
||||
|
||||
speedMultiplier = hitObject.DifficultyControlPoint.SliderVelocityBindable.GetBoundCopy();
|
||||
speedMultiplier = (hitObject as IHasSliderVelocity)?.SliderVelocityBindable.GetBoundCopy();
|
||||
}
|
||||
|
||||
protected override Color4 GetRepresentingColour(OsuColour colours) => colours.Lime1;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
@ -78,7 +81,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
Spacing = new Vector2(0, 15),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
sliderVelocitySlider = new IndeterminateSliderWithTextBoxInput<double>("Velocity", new DifficultyControlPoint().SliderVelocityBindable)
|
||||
sliderVelocitySlider = new IndeterminateSliderWithTextBoxInput<double>("Velocity", new BindableDouble(1)
|
||||
{
|
||||
Precision = 0.01,
|
||||
MinValue = 0.1,
|
||||
MaxValue = 10
|
||||
})
|
||||
{
|
||||
KeyboardStep = 0.1f
|
||||
},
|
||||
@ -94,11 +102,10 @@ 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 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.DifficultyControlPoint).ToArray();
|
||||
var relevantObjects = (beatmap.SelectedHitObjects.Contains(hitObject) ? beatmap.SelectedHitObjects : hitObject.Yield()).Where(o => o is IHasSliderVelocity).ToArray();
|
||||
|
||||
// even if there are multiple objects selected, we can still display a value if they all have the same value.
|
||||
var selectedPointBindable = relevantControlPoints.Select(point => point.SliderVelocity).Distinct().Count() == 1 ? relevantControlPoints.First().SliderVelocityBindable : null;
|
||||
var selectedPointBindable = relevantObjects.Select(point => ((IHasSliderVelocity)point).SliderVelocity).Distinct().Count() == 1 ? ((IHasSliderVelocity)relevantObjects.First()).SliderVelocityBindable : null;
|
||||
|
||||
if (selectedPointBindable != null)
|
||||
{
|
||||
@ -117,7 +124,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
|
||||
foreach (var h in relevantObjects)
|
||||
{
|
||||
h.DifficultyControlPoint.SliderVelocity = val.NewValue.Value;
|
||||
((IHasSliderVelocity)h).SliderVelocity = val.NewValue.Value;
|
||||
beatmap.Update(h);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Beatmaps.ControlPoints;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osuTK.Graphics;
|
||||
@ -16,21 +15,14 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
{
|
||||
public partial class HitObjectPointPiece : CircularContainer
|
||||
{
|
||||
private readonly ControlPoint point;
|
||||
|
||||
protected OsuSpriteText Label { get; private set; }
|
||||
|
||||
protected HitObjectPointPiece(ControlPoint point)
|
||||
{
|
||||
this.point = point;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
|
||||
Color4 colour = point.GetRepresentingColour(colours);
|
||||
Color4 colour = GetRepresentingColour(colours);
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
@ -61,5 +53,10 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
protected virtual Color4 GetRepresentingColour(OsuColour colours)
|
||||
{
|
||||
return colours.Yellow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,11 +12,13 @@ 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.Audio;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Screens.Edit.Timing;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
{
|
||||
@ -24,22 +26,20 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
{
|
||||
public readonly HitObject HitObject;
|
||||
|
||||
private readonly Bindable<string> bank;
|
||||
private readonly BindableNumber<int> volume;
|
||||
private readonly BindableList<HitSampleInfo> samplesBindable;
|
||||
|
||||
public SamplePointPiece(HitObject hitObject)
|
||||
: base(hitObject.SampleControlPoint)
|
||||
{
|
||||
HitObject = hitObject;
|
||||
volume = hitObject.SampleControlPoint.SampleVolumeBindable.GetBoundCopy();
|
||||
bank = hitObject.SampleControlPoint.SampleBankBindable.GetBoundCopy();
|
||||
samplesBindable = hitObject.SamplesBindable.GetBoundCopy();
|
||||
}
|
||||
|
||||
protected override Color4 GetRepresentingColour(OsuColour colours) => colours.Pink;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
volume.BindValueChanged(_ => updateText());
|
||||
bank.BindValueChanged(_ => updateText(), true);
|
||||
samplesBindable.BindCollectionChanged((_, _) => updateText(), true);
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
@ -50,7 +50,17 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
|
||||
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);
|
||||
@ -89,7 +99,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
{
|
||||
Label = "Bank Name",
|
||||
},
|
||||
volume = new IndeterminateSliderWithTextBoxInput<int>("Volume", new SampleControlPoint().SampleVolumeBindable)
|
||||
volume = new IndeterminateSliderWithTextBoxInput<int>("Volume", new BindableInt(100)
|
||||
{
|
||||
MinValue = 0,
|
||||
MaxValue = 100,
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -100,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 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();
|
||||
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.
|
||||
string? commonBank = getCommonBank(relevantControlPoints);
|
||||
string? commonBank = getCommonBank(relevantSamples);
|
||||
if (!string.IsNullOrEmpty(commonBank))
|
||||
bank.Current.Value = commonBank;
|
||||
|
||||
int? commonVolume = getCommonVolume(relevantControlPoints);
|
||||
int? commonVolume = getCommonVolume(relevantSamples);
|
||||
if (commonVolume != null)
|
||||
volume.Current.Value = commonVolume.Value;
|
||||
|
||||
@ -117,9 +131,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
updateBankFor(relevantObjects, val.NewValue);
|
||||
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.
|
||||
bank.OnCommit += (_, _) => bank.Current.Value = getCommonBank(relevantControlPoints);
|
||||
bank.OnCommit += (_, _) => bank.Current.Value = getCommonBank(relevantSamples);
|
||||
|
||||
volume.Current.BindValueChanged(val => updateVolumeFor(relevantObjects, val.NewValue));
|
||||
}
|
||||
@ -130,8 +144,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
ScheduleAfterChildren(() => GetContainingInputManager().ChangeFocus(volume));
|
||||
}
|
||||
|
||||
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 ? relevantControlPoints.First().SampleVolume : null;
|
||||
private static string? getCommonBank(IList<HitSampleInfo>[] relevantSamples) => relevantSamples.Select(GetBankValue).Distinct().Count() == 1 ? GetBankValue(relevantSamples.First()) : 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)
|
||||
{
|
||||
@ -142,7 +156,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -151,7 +169,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -164,7 +182,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@ using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps.ControlPoints;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Overlays;
|
||||
@ -102,6 +101,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
},
|
||||
}
|
||||
},
|
||||
new SamplePointPiece(Item)
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.TopCentre
|
||||
},
|
||||
});
|
||||
|
||||
if (item is IHasDuration)
|
||||
@ -111,6 +115,15 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
OnDragHandled = e => OnDragHandled?.Invoke(e)
|
||||
});
|
||||
}
|
||||
|
||||
if (item is IHasSliderVelocity)
|
||||
{
|
||||
AddInternal(new DifficultyPointPiece(Item)
|
||||
{
|
||||
Anchor = Anchor.TopLeft,
|
||||
Origin = Anchor.BottomCentre
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -187,12 +200,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
colouredComponents.Colour = OsuColour.ForegroundTextColourFor(averageColour);
|
||||
}
|
||||
|
||||
private SamplePointPiece? sampleOverrideDisplay;
|
||||
private DifficultyPointPiece? difficultyOverrideDisplay;
|
||||
|
||||
private DifficultyControlPoint difficultyControlPoint = null!;
|
||||
private SampleControlPoint sampleControlPoint = null!;
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
@ -208,36 +215,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
if (Item is IHasRepeats repeats)
|
||||
updateRepeats(repeats);
|
||||
}
|
||||
|
||||
if (!ReferenceEquals(difficultyControlPoint, Item.DifficultyControlPoint))
|
||||
{
|
||||
difficultyControlPoint = Item.DifficultyControlPoint;
|
||||
difficultyOverrideDisplay?.Expire();
|
||||
|
||||
if (Item.DifficultyControlPoint != null && Item is IHasDistance)
|
||||
{
|
||||
AddInternal(difficultyOverrideDisplay = new DifficultyPointPiece(Item)
|
||||
{
|
||||
Anchor = Anchor.TopLeft,
|
||||
Origin = Anchor.BottomCentre
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!ReferenceEquals(sampleControlPoint, Item.SampleControlPoint))
|
||||
{
|
||||
sampleControlPoint = Item.SampleControlPoint;
|
||||
sampleOverrideDisplay?.Expire();
|
||||
|
||||
if (Item.SampleControlPoint != null)
|
||||
{
|
||||
AddInternal(sampleOverrideDisplay = new SamplePointPiece(Item)
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.TopCentre
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRepeats(IHasRepeats repeats)
|
||||
@ -395,17 +372,14 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
case IHasRepeats repeatHitObject:
|
||||
double proposedDuration = time - hitObject.StartTime;
|
||||
|
||||
if (e.CurrentState.Keyboard.ShiftPressed)
|
||||
if (e.CurrentState.Keyboard.ShiftPressed && hitObject is IHasSliderVelocity hasSliderVelocity)
|
||||
{
|
||||
if (ReferenceEquals(hitObject.DifficultyControlPoint, DifficultyControlPoint.DEFAULT))
|
||||
hitObject.DifficultyControlPoint = new DifficultyControlPoint();
|
||||
double newVelocity = hasSliderVelocity.SliderVelocity * (repeatHitObject.Duration / proposedDuration);
|
||||
|
||||
double newVelocity = hitObject.DifficultyControlPoint.SliderVelocity * (repeatHitObject.Duration / proposedDuration);
|
||||
|
||||
if (Precision.AlmostEquals(newVelocity, hitObject.DifficultyControlPoint.SliderVelocity))
|
||||
if (Precision.AlmostEquals(newVelocity, hasSliderVelocity.SliderVelocity))
|
||||
return;
|
||||
|
||||
hitObject.DifficultyControlPoint.SliderVelocity = newVelocity;
|
||||
hasSliderVelocity.SliderVelocity = newVelocity;
|
||||
beatmap.Update(hitObject);
|
||||
}
|
||||
else
|
||||
|
Reference in New Issue
Block a user