From 244ca4e8c75293d7f00c62aeae010316f95cdfc4 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Mon, 8 May 2023 11:54:33 +0200 Subject: [PATCH 01/45] Remove dependency on SamplesBindable --- .../Edit/Compose/Components/Timeline/SamplePointPiece.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index b02cfb505e..1f673a7b10 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -26,12 +26,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline { public readonly HitObject HitObject; - private readonly BindableList samplesBindable; + [Resolved(canBeNull: true)] + private EditorBeatmap editorBeatmap { get; set; } = null!; public SamplePointPiece(HitObject hitObject) { HitObject = hitObject; - samplesBindable = hitObject.SamplesBindable.GetBoundCopy(); } protected override Color4 GetRepresentingColour(OsuColour colours) => colours.Pink; @@ -39,7 +39,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline [BackgroundDependencyLoader] private void load() { - samplesBindable.BindCollectionChanged((_, _) => updateText(), true); + HitObject.DefaultsApplied += _ => updateText(); + updateText(); } protected override bool OnClick(ClickEvent e) @@ -50,7 +51,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private void updateText() { - Label.Text = $"{GetBankValue(samplesBindable)} {GetVolumeValue(samplesBindable)}"; + Label.Text = $"{GetBankValue(HitObject.Samples)} {GetVolumeValue(HitObject.Samples)}"; } public static string? GetBankValue(IEnumerable samples) From b447018e5b54009a297495d7ef96a48bbc5a1d18 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Mon, 8 May 2023 11:55:58 +0200 Subject: [PATCH 02/45] remove editor beatmap --- .../Edit/Compose/Components/Timeline/SamplePointPiece.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 1f673a7b10..4f3526b531 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -26,9 +26,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline { public readonly HitObject HitObject; - [Resolved(canBeNull: true)] - private EditorBeatmap editorBeatmap { get; set; } = null!; - public SamplePointPiece(HitObject hitObject) { HitObject = hitObject; From cb7b747d52dec03881c056cbc6545777a5c5dc47 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Mon, 8 May 2023 12:38:53 +0200 Subject: [PATCH 03/45] create NodeSamplePointPiece --- .../Timeline/NodeSamplePointPiece.cs | 54 +++++++++++++++++++ .../Components/Timeline/SamplePointPiece.cs | 10 ++-- 2 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs new file mode 100644 index 0000000000..dc91401c13 --- /dev/null +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs @@ -0,0 +1,54 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using osu.Framework.Graphics.UserInterface; +using osu.Game.Audio; +using osu.Game.Graphics; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Types; +using osuTK.Graphics; + +namespace osu.Game.Screens.Edit.Compose.Components.Timeline +{ + public partial class NodeSamplePointPiece : SamplePointPiece + { + public readonly int NodeIndex; + + public NodeSamplePointPiece(HitObject hitObject, int nodeIndex) + : base(hitObject) + { + if (hitObject is not IHasRepeats) + throw new System.ArgumentException($"HitObject must implement {nameof(IHasRepeats)}", nameof(hitObject)); + + NodeIndex = nodeIndex; + } + + protected override Color4 GetRepresentingColour(OsuColour colours) => colours.Purple; + + protected override IList GetSamples() + { + var hasRepeats = (IHasRepeats)HitObject; + return NodeIndex < hasRepeats.NodeSamples.Count ? hasRepeats.NodeSamples[NodeIndex] : HitObject.Samples; + } + + public override Popover GetPopover() => new NodeSampleEditPopover(HitObject); + + public partial class NodeSampleEditPopover : SampleEditPopover + { + private readonly int nodeIndex; + + protected override IList GetSamples(HitObject ho) + { + var hasRepeats = (IHasRepeats)ho; + return nodeIndex < hasRepeats.NodeSamples.Count ? hasRepeats.NodeSamples[nodeIndex] : ho.Samples; + } + + public NodeSampleEditPopover(HitObject hitObject, int nodeIndex = 0) + : base(hitObject) + { + this.nodeIndex = nodeIndex; + } + } + } +} diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 4f3526b531..064e96c255 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -48,7 +48,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private void updateText() { - Label.Text = $"{GetBankValue(HitObject.Samples)} {GetVolumeValue(HitObject.Samples)}"; + Label.Text = $"{GetBankValue(GetSamples())} {GetVolumeValue(GetSamples())}"; } public static string? GetBankValue(IEnumerable samples) @@ -61,7 +61,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline return samples.Count == 0 ? 0 : samples.Max(o => o.Volume); } - public Popover GetPopover() => new SampleEditPopover(HitObject); + protected virtual IList GetSamples() => HitObject.Samples; + + public virtual Popover GetPopover() => new SampleEditPopover(HitObject); public partial class SampleEditPopover : OsuPopover { @@ -70,6 +72,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private LabelledTextBox bank = null!; private IndeterminateSliderWithTextBoxInput volume = null!; + protected virtual IList GetSamples(HitObject ho) => ho.Samples; + [Resolved(canBeNull: true)] private EditorBeatmap beatmap { get; set; } = null!; @@ -112,7 +116,7 @@ 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 relevantSamples = relevantObjects.Select(h => h.Samples).ToArray(); + var relevantSamples = relevantObjects.Select(GetSamples).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(relevantSamples); From 32f945d304509a4e3f359f667caa4ccb3d473e19 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Mon, 8 May 2023 13:05:53 +0200 Subject: [PATCH 04/45] fix updating wrong samples --- .../Components/Timeline/NodeSamplePointPiece.cs | 4 ++-- .../Components/Timeline/SamplePointPiece.cs | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs index dc91401c13..437d3c3d3a 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs @@ -32,7 +32,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline return NodeIndex < hasRepeats.NodeSamples.Count ? hasRepeats.NodeSamples[NodeIndex] : HitObject.Samples; } - public override Popover GetPopover() => new NodeSampleEditPopover(HitObject); + public override Popover GetPopover() => new NodeSampleEditPopover(HitObject, NodeIndex); public partial class NodeSampleEditPopover : SampleEditPopover { @@ -44,7 +44,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline return nodeIndex < hasRepeats.NodeSamples.Count ? hasRepeats.NodeSamples[nodeIndex] : ho.Samples; } - public NodeSampleEditPopover(HitObject hitObject, int nodeIndex = 0) + public NodeSampleEditPopover(HitObject hitObject, int nodeIndex) : base(hitObject) { this.nodeIndex = nodeIndex; diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 064e96c255..50b1ec80ff 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -158,9 +158,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline foreach (var h in objects) { - for (int i = 0; i < h.Samples.Count; i++) + var samples = GetSamples(h); + + for (int i = 0; i < samples.Count; i++) { - h.Samples[i] = h.Samples[i].With(newBank: newBank); + samples[i] = samples[i].With(newBank: newBank); } beatmap.Update(h); @@ -171,7 +173,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private void updateBankPlaceholderText(IEnumerable objects) { - string? commonBank = getCommonBank(objects.Select(h => h.Samples).ToArray()); + string? commonBank = getCommonBank(objects.Select(GetSamples).ToArray()); bank.PlaceholderText = string.IsNullOrEmpty(commonBank) ? "(multiple)" : string.Empty; } @@ -184,9 +186,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline foreach (var h in objects) { - for (int i = 0; i < h.Samples.Count; i++) + var samples = GetSamples(h); + + for (int i = 0; i < samples.Count; i++) { - h.Samples[i] = h.Samples[i].With(newVolume: newVolume.Value); + samples[i] = samples[i].With(newVolume: newVolume.Value); } beatmap.Update(h); From e945846759e16fb51d589d665accae195ab9957a Mon Sep 17 00:00:00 2001 From: OliBomby Date: Mon, 8 May 2023 13:10:24 +0200 Subject: [PATCH 05/45] Add node sample pieces to timeline blueprint --- .../Timeline/TimelineHitObjectBlueprint.cs | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs index ea063e9216..e7c14fc53d 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs @@ -32,6 +32,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private const float circle_size = 38; private Container? repeatsContainer; + private Container? nodeSamplesContainer; public Action? OnDragHandled = null!; @@ -49,6 +50,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private readonly Border border; private readonly Container colouredComponents; + private readonly Container sampleComponents; private readonly OsuSpriteText comboIndexText; [Resolved] @@ -101,10 +103,15 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline }, } }, + sampleComponents = new Container + { + RelativeSizeAxes = Axes.Both, + }, new SamplePointPiece(Item) { Anchor = Anchor.BottomLeft, - Origin = Anchor.TopCentre + Origin = Anchor.TopCentre, + X = Item is IHasRepeats ? -10 : 0 }, }); @@ -233,6 +240,25 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline X = (float)(i + 1) / (repeats.RepeatCount + 1) }); } + + // Add node sample pieces + nodeSamplesContainer?.Expire(); + + sampleComponents.Add(nodeSamplesContainer = new Container + { + RelativeSizeAxes = Axes.Both, + }); + + for (int i = 0; i < repeats.RepeatCount + 2; i++) + { + nodeSamplesContainer.Add(new NodeSamplePointPiece(Item, i) + { + X = (float)i / (repeats.RepeatCount + 1), + RelativePositionAxes = Axes.X, + Anchor = Anchor.BottomLeft, + Origin = Anchor.TopCentre, + }); + } } protected override bool ShouldBeConsideredForInput(Drawable child) => true; From 3b5bae774259451c62c16a4202c6f4e963cb9fde Mon Sep 17 00:00:00 2001 From: OliBomby Date: Mon, 8 May 2023 13:16:30 +0200 Subject: [PATCH 06/45] Abbreviate common bank names on timeline --- .../Compose/Components/Timeline/SamplePointPiece.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 50b1ec80ff..1f3f5305b8 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -48,7 +48,18 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private void updateText() { - Label.Text = $"{GetBankValue(GetSamples())} {GetVolumeValue(GetSamples())}"; + Label.Text = $"{abbreviateBank(GetBankValue(GetSamples()))} {GetVolumeValue(GetSamples())}"; + } + + private static string? abbreviateBank(string? bank) + { + return bank switch + { + "normal" => "N", + "soft" => "S", + "drum" => "D", + _ => bank + }; } public static string? GetBankValue(IEnumerable samples) From 88d840a60d143cd404c6f033380653abc7550055 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Mon, 8 May 2023 14:42:15 +0200 Subject: [PATCH 07/45] fix assigned hitsounds dont have bank or volume --- osu.Game/Rulesets/Objects/HitObject.cs | 4 ++-- .../Screens/Edit/Compose/Components/EditorSelectionHandler.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Rulesets/Objects/HitObject.cs b/osu.Game/Rulesets/Objects/HitObject.cs index a4cb976d50..352ee72962 100644 --- a/osu.Game/Rulesets/Objects/HitObject.cs +++ b/osu.Game/Rulesets/Objects/HitObject.cs @@ -210,10 +210,10 @@ namespace osu.Game.Rulesets.Objects /// /// The name of the sample. /// A populated . - protected HitSampleInfo GetSampleInfo(string sampleName = HitSampleInfo.HIT_NORMAL) + public HitSampleInfo GetSampleInfo(string sampleName = HitSampleInfo.HIT_NORMAL) { var hitnormalSample = Samples.FirstOrDefault(s => s.Name == HitSampleInfo.HIT_NORMAL); - return hitnormalSample == null ? new HitSampleInfo(sampleName) : hitnormalSample.With(newName: sampleName); + return hitnormalSample == null ? new HitSampleInfo(sampleName, SampleControlPoint.DEFAULT_BANK, volume: 100) : hitnormalSample.With(newName: sampleName); } } diff --git a/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs b/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs index 357cc940f2..694b24c567 100644 --- a/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs +++ b/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs @@ -122,7 +122,7 @@ namespace osu.Game.Screens.Edit.Compose.Components if (h.Samples.Any(s => s.Name == sampleName)) return; - h.Samples.Add(new HitSampleInfo(sampleName)); + h.Samples.Add(h.GetSampleInfo(sampleName)); EditorBeatmap.Update(h); }); } From 4c365304351fdc3d9f62c6cab40d11e421be4ae3 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Mon, 8 May 2023 15:08:40 +0200 Subject: [PATCH 08/45] allow editing additions in sample point piece --- .../Components/ComposeBlueprintContainer.cs | 4 +- .../Compose/Components/SelectionHandler.cs | 2 +- .../Components/Timeline/SamplePointPiece.cs | 146 ++++++++++++++++++ 3 files changed, 149 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/ComposeBlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/ComposeBlueprintContainer.cs index 453e4b9130..0a87314a2a 100644 --- a/osu.Game/Screens/Edit/Compose/Components/ComposeBlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/ComposeBlueprintContainer.cs @@ -206,10 +206,10 @@ namespace osu.Game.Screens.Edit.Compose.Components yield return new TernaryButton(NewCombo, "New combo", () => new SpriteIcon { Icon = FontAwesome.Regular.DotCircle }); foreach (var kvp in SelectionHandler.SelectionSampleStates) - yield return new TernaryButton(kvp.Value, kvp.Key.Replace("hit", string.Empty).Titleize(), () => getIconForSample(kvp.Key)); + yield return new TernaryButton(kvp.Value, kvp.Key.Replace("hit", string.Empty).Titleize(), () => GetIconForSample(kvp.Key)); } - private Drawable getIconForSample(string sampleName) + public static Drawable GetIconForSample(string sampleName) { switch (sampleName) { diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs index 9e4fb26688..93d51c849e 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs @@ -279,7 +279,7 @@ namespace osu.Game.Screens.Edit.Compose.Components /// /// Given a selection target and a function of truth, retrieve the correct ternary state for display. /// - protected static TernaryState GetStateFromSelection(IEnumerable selection, Func func) + public static TernaryState GetStateFromSelection(IEnumerable selection, Func func) { if (selection.Any(func)) return selection.All(func) ? TernaryState.True : TernaryState.Indeterminate; diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 1f3f5305b8..0cac914e2c 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; +using Humanizer; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions; @@ -14,11 +15,14 @@ using osu.Framework.Graphics.UserInterface; using osu.Framework.Input.Events; using osu.Game.Audio; using osu.Game.Graphics; +using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Rulesets.Objects; +using osu.Game.Screens.Edit.Components.TernaryButtons; using osu.Game.Screens.Edit.Timing; using osuTK; using osuTK.Graphics; +using osuTK.Input; namespace osu.Game.Screens.Edit.Compose.Components.Timeline { @@ -83,6 +87,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private LabelledTextBox bank = null!; private IndeterminateSliderWithTextBoxInput volume = null!; + private FillFlowContainer togglesCollection = null!; + protected virtual IList GetSamples(HitObject ho) => ho.Samples; [Resolved(canBeNull: true)] @@ -108,6 +114,13 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline Spacing = new Vector2(0, 10), Children = new Drawable[] { + togglesCollection = new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(5, 5), + }, bank = new LabelledTextBox { Label = "Bank Name", @@ -149,6 +162,10 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline bank.OnCommit += (_, _) => bank.Current.Value = getCommonBank(relevantSamples); volume.Current.BindValueChanged(val => updateVolumeFor(relevantObjects, val.NewValue)); + + createStateBindables(relevantObjects); + updateTernaryStates(relevantObjects); + togglesCollection.AddRange(createTernaryButtons().Select(b => new DrawableTernaryButton(b) { RelativeSizeAxes = Axes.None, Size = new Vector2(40, 40) })); } protected override void LoadComplete() @@ -209,6 +226,135 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline beatmap.EndChange(); } + + #region hitsound toggles + + private readonly Dictionary> selectionSampleStates = new Dictionary>(); + + private void createStateBindables(IEnumerable objects) + { + foreach (string sampleName in HitSampleInfo.AllAdditions) + { + var bindable = new Bindable + { + Description = sampleName.Replace("hit", string.Empty).Titleize() + }; + + bindable.ValueChanged += state => + { + switch (state.NewValue) + { + case TernaryState.False: + removeHitSampleFor(objects, sampleName); + break; + + case TernaryState.True: + addHitSampleFor(objects, sampleName); + break; + } + }; + + selectionSampleStates[sampleName] = bindable; + } + } + + private void updateTernaryStates(IEnumerable objects) + { + foreach ((string sampleName, var bindable) in selectionSampleStates) + { + bindable.Value = SelectionHandler.GetStateFromSelection(objects, h => GetSamples(h).Any(s => s.Name == sampleName)); + } + } + + private IEnumerable createTernaryButtons() + { + foreach ((string sampleName, var bindable) in selectionSampleStates) + yield return new TernaryButton(bindable, string.Empty, () => ComposeBlueprintContainer.GetIconForSample(sampleName)); + } + + private void addHitSampleFor(IEnumerable objects, string sampleName) + { + if (string.IsNullOrEmpty(sampleName)) + return; + + beatmap.BeginChange(); + + foreach (var h in objects) + { + var samples = GetSamples(h); + + // Make sure there isn't already an existing sample + if (samples.Any(s => s.Name == sampleName)) + return; + + samples.Add(h.GetSampleInfo(sampleName)); + beatmap.Update(h); + } + + beatmap.EndChange(); + } + + private void removeHitSampleFor(IEnumerable objects, string sampleName) + { + if (string.IsNullOrEmpty(sampleName)) + return; + + beatmap.BeginChange(); + + foreach (var h in objects) + { + var samples = GetSamples(h); + + for (int i = 0; i < samples.Count; i++) + { + if (samples[i].Name == sampleName) + samples.RemoveAt(i--); + } + + beatmap.Update(h); + } + + beatmap.EndChange(); + } + + protected override bool OnKeyDown(KeyDownEvent e) + { + if (e.ControlPressed || e.AltPressed || e.SuperPressed || e.ShiftPressed || !checkRightToggleFromKey(e.Key, out int rightIndex)) + return base.OnKeyDown(e); + + var item = togglesCollection.ElementAtOrDefault(rightIndex); + + if (item is not DrawableTernaryButton button) return base.OnKeyDown(e); + + button.Button.Toggle(); + return true; + } + + private bool checkRightToggleFromKey(Key key, out int index) + { + switch (key) + { + case Key.W: + index = 0; + break; + + case Key.E: + index = 1; + break; + + case Key.R: + index = 2; + break; + + default: + index = -1; + break; + } + + return index >= 0; + } + + #endregion } } } From bb8285e2ef99cba43b0a95e2082841fc1a6af7a5 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Mon, 8 May 2023 15:14:25 +0200 Subject: [PATCH 09/45] cleanup code duplication --- .../Components/Timeline/SamplePointPiece.cs | 62 +++++++------------ 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 0cac914e2c..69fff8a8a7 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Collections.Generic; using System.Linq; using Humanizer; @@ -177,28 +178,34 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private static string? getCommonBank(IList[] relevantSamples) => relevantSamples.Select(GetBankValue).Distinct().Count() == 1 ? GetBankValue(relevantSamples.First()) : null; private static int? getCommonVolume(IList[] relevantSamples) => relevantSamples.Select(GetVolumeValue).Distinct().Count() == 1 ? GetVolumeValue(relevantSamples.First()) : null; - private void updateBankFor(IEnumerable objects, string? newBank) + private void updateFor(IEnumerable objects, Action> updateAction) { - if (string.IsNullOrEmpty(newBank)) - return; - beatmap.BeginChange(); foreach (var h in objects) { var samples = GetSamples(h); - - for (int i = 0; i < samples.Count; i++) - { - samples[i] = samples[i].With(newBank: newBank); - } - + updateAction(h, samples); beatmap.Update(h); } beatmap.EndChange(); } + private void updateBankFor(IEnumerable objects, string? newBank) + { + if (string.IsNullOrEmpty(newBank)) + return; + + updateFor(objects, (_, samples) => + { + for (int i = 0; i < samples.Count; i++) + { + samples[i] = samples[i].With(newBank: newBank); + } + }); + } + private void updateBankPlaceholderText(IEnumerable objects) { string? commonBank = getCommonBank(objects.Select(GetSamples).ToArray()); @@ -210,21 +217,13 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (newVolume == null) return; - beatmap.BeginChange(); - - foreach (var h in objects) + updateFor(objects, (_, samples) => { - var samples = GetSamples(h); - for (int i = 0; i < samples.Count; i++) { samples[i] = samples[i].With(newVolume: newVolume.Value); } - - beatmap.Update(h); - } - - beatmap.EndChange(); + }); } #region hitsound toggles @@ -277,21 +276,14 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (string.IsNullOrEmpty(sampleName)) return; - beatmap.BeginChange(); - - foreach (var h in objects) + updateFor(objects, (h, samples) => { - var samples = GetSamples(h); - // Make sure there isn't already an existing sample if (samples.Any(s => s.Name == sampleName)) return; samples.Add(h.GetSampleInfo(sampleName)); - beatmap.Update(h); - } - - beatmap.EndChange(); + }); } private void removeHitSampleFor(IEnumerable objects, string sampleName) @@ -299,22 +291,14 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (string.IsNullOrEmpty(sampleName)) return; - beatmap.BeginChange(); - - foreach (var h in objects) + updateFor(objects, (_, samples) => { - var samples = GetSamples(h); - for (int i = 0; i < samples.Count; i++) { if (samples[i].Name == sampleName) samples.RemoveAt(i--); } - - beatmap.Update(h); - } - - beatmap.EndChange(); + }); } protected override bool OnKeyDown(KeyDownEvent e) From 7260dcac60f00b48489d3a100c907355d45f38f3 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Mon, 8 May 2023 15:57:30 +0200 Subject: [PATCH 10/45] fix crash on multiselect and node sample piece popup --- .../Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs index 437d3c3d3a..de43e16e55 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs @@ -40,7 +40,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline protected override IList GetSamples(HitObject ho) { - var hasRepeats = (IHasRepeats)ho; + if (ho is not IHasRepeats hasRepeats) + return ho.Samples; + return nodeIndex < hasRepeats.NodeSamples.Count ? hasRepeats.NodeSamples[nodeIndex] : ho.Samples; } From dd0fceaec69eb322b75851ccfd17a0ddc97e1346 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Mon, 8 May 2023 16:12:03 +0200 Subject: [PATCH 11/45] add addition bank --- .../Components/EditorSelectionHandler.cs | 3 +- .../Components/Timeline/SamplePointPiece.cs | 53 ++++++++++++++++++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs b/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs index 694b24c567..71a01d9988 100644 --- a/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs +++ b/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs @@ -122,7 +122,8 @@ namespace osu.Game.Screens.Edit.Compose.Components if (h.Samples.Any(s => s.Name == sampleName)) return; - h.Samples.Add(h.GetSampleInfo(sampleName)); + var relevantSample = h.Samples.FirstOrDefault(s => s.Name != HitSampleInfo.HIT_NORMAL); + h.Samples.Add(relevantSample?.With(sampleName) ?? h.GetSampleInfo(sampleName)); EditorBeatmap.Update(h); }); } diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 69fff8a8a7..a6a7a59793 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -69,7 +69,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline public static string? GetBankValue(IEnumerable samples) { - return samples.FirstOrDefault()?.Bank; + return samples.FirstOrDefault(o => o.Name == HitSampleInfo.HIT_NORMAL)?.Bank; + } + + public static string? GetAdditionBankValue(IEnumerable samples) + { + return samples.FirstOrDefault(o => o.Name != HitSampleInfo.HIT_NORMAL)?.Bank ?? GetBankValue(samples); } public static int GetVolumeValue(ICollection samples) @@ -86,6 +91,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private readonly HitObject hitObject; private LabelledTextBox bank = null!; + private LabelledTextBox additionBank = null!; private IndeterminateSliderWithTextBoxInput volume = null!; private FillFlowContainer togglesCollection = null!; @@ -126,6 +132,10 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline { Label = "Bank Name", }, + additionBank = new LabelledTextBox + { + Label = "Addition Bank", + }, volume = new IndeterminateSliderWithTextBoxInput("Volume", new BindableInt(100) { MinValue = 0, @@ -136,6 +146,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline }; bank.TabbableContentContainer = flow; + additionBank.TabbableContentContainer = flow; volume.TabbableContentContainer = flow; // if the piece belongs to a currently selected object, assume that the user wants to change all selected objects. @@ -148,6 +159,10 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (!string.IsNullOrEmpty(commonBank)) bank.Current.Value = commonBank; + string? commonAdditionBank = getCommonAdditionBank(relevantSamples); + if (!string.IsNullOrEmpty(commonAdditionBank)) + additionBank.Current.Value = commonAdditionBank; + int? commonVolume = getCommonVolume(relevantSamples); if (commonVolume != null) volume.Current.Value = commonVolume.Value; @@ -162,6 +177,14 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline // this ensures that committing empty text causes a revert to the previous value. bank.OnCommit += (_, _) => bank.Current.Value = getCommonBank(relevantSamples); + updateAdditionBankPlaceholderText(relevantObjects); + additionBank.Current.BindValueChanged(val => + { + updateAdditionBankFor(relevantObjects, val.NewValue); + updateAdditionBankPlaceholderText(relevantObjects); + }); + additionBank.OnCommit += (_, _) => additionBank.Current.Value = getCommonAdditionBank(relevantSamples); + volume.Current.BindValueChanged(val => updateVolumeFor(relevantObjects, val.NewValue)); createStateBindables(relevantObjects); @@ -176,6 +199,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline } private static string? getCommonBank(IList[] relevantSamples) => relevantSamples.Select(GetBankValue).Distinct().Count() == 1 ? GetBankValue(relevantSamples.First()) : null; + private static string? getCommonAdditionBank(IList[] relevantSamples) => relevantSamples.Select(GetAdditionBankValue).Distinct().Count() == 1 ? GetAdditionBankValue(relevantSamples.First()) : null; private static int? getCommonVolume(IList[] relevantSamples) => relevantSamples.Select(GetVolumeValue).Distinct().Count() == 1 ? GetVolumeValue(relevantSamples.First()) : null; private void updateFor(IEnumerable objects, Action> updateAction) @@ -201,6 +225,24 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline { for (int i = 0; i < samples.Count; i++) { + if (samples[i].Name != HitSampleInfo.HIT_NORMAL) continue; + + samples[i] = samples[i].With(newBank: newBank); + } + }); + } + + private void updateAdditionBankFor(IEnumerable objects, string? newBank) + { + if (string.IsNullOrEmpty(newBank)) + return; + + updateFor(objects, (_, samples) => + { + for (int i = 0; i < samples.Count; i++) + { + if (samples[i].Name == HitSampleInfo.HIT_NORMAL) continue; + samples[i] = samples[i].With(newBank: newBank); } }); @@ -212,6 +254,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline bank.PlaceholderText = string.IsNullOrEmpty(commonBank) ? "(multiple)" : string.Empty; } + private void updateAdditionBankPlaceholderText(IEnumerable objects) + { + string? commonAdditionBank = getCommonAdditionBank(objects.Select(GetSamples).ToArray()); + additionBank.PlaceholderText = string.IsNullOrEmpty(commonAdditionBank) ? "(multiple)" : string.Empty; + } + private void updateVolumeFor(IEnumerable objects, int? newVolume) { if (newVolume == null) @@ -282,7 +330,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (samples.Any(s => s.Name == sampleName)) return; - samples.Add(h.GetSampleInfo(sampleName)); + var relevantSample = samples.FirstOrDefault(s => s.Name != HitSampleInfo.HIT_NORMAL) ?? samples.FirstOrDefault(); + samples.Add(relevantSample?.With(sampleName) ?? h.GetSampleInfo(sampleName)); }); } From 114f12a79056cc20951d06aec1ade073899d684a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 30 May 2023 14:04:02 +0900 Subject: [PATCH 12/45] Adjust `CreateHitSampleInfo` to handle additions correctly, rather than implementing locally --- osu.Game/Rulesets/Objects/HitObject.cs | 12 ++++++++++-- .../Compose/Components/EditorSelectionHandler.cs | 6 ++---- .../Compose/Components/Timeline/SamplePointPiece.cs | 3 +-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/osu.Game/Rulesets/Objects/HitObject.cs b/osu.Game/Rulesets/Objects/HitObject.cs index ed3d3a6eb2..e87fb56b73 100644 --- a/osu.Game/Rulesets/Objects/HitObject.cs +++ b/osu.Game/Rulesets/Objects/HitObject.cs @@ -216,8 +216,16 @@ namespace osu.Game.Rulesets.Objects /// A populated . public HitSampleInfo CreateHitSampleInfo(string sampleName = HitSampleInfo.HIT_NORMAL) { - if (Samples.FirstOrDefault(s => s.Name == HitSampleInfo.HIT_NORMAL) is HitSampleInfo existingSample) - return existingSample.With(newName: sampleName); + // As per stable, all non-normal "addition" samples should use the same bank. + if (sampleName != HitSampleInfo.HIT_NORMAL) + { + if (Samples.FirstOrDefault(s => s.Name != HitSampleInfo.HIT_NORMAL) is HitSampleInfo existingAddition) + return existingAddition.With(newName: sampleName); + } + + // Fall back to using the normal sample bank otherwise. + if (Samples.FirstOrDefault(s => s.Name == HitSampleInfo.HIT_NORMAL) is HitSampleInfo existingNormal) + return existingNormal.With(newName: sampleName); return new HitSampleInfo(sampleName); } diff --git a/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs b/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs index 07622e4385..9bf6cfffe6 100644 --- a/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs +++ b/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs @@ -222,12 +222,10 @@ namespace osu.Game.Screens.Edit.Compose.Components if (h.Samples.Any(s => s.Name == sampleName)) return; - var existingNonNormalSample = h.Samples.FirstOrDefault(s => s.Name != HitSampleInfo.HIT_NORMAL); - var sampleToAdd = h.CreateHitSampleInfo(sampleName); - h.Samples.Add(existingNonNormalSample?.With(sampleName) ?? h.GetSampleInfo(sampleName)); - h.Samples.Add(h.CreateHitSampleInfo(sampleName)); + h.Samples.Add(sampleToAdd); + EditorBeatmap.Update(h); }); } diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index a6a7a59793..64330e354a 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -330,8 +330,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (samples.Any(s => s.Name == sampleName)) return; - var relevantSample = samples.FirstOrDefault(s => s.Name != HitSampleInfo.HIT_NORMAL) ?? samples.FirstOrDefault(); - samples.Add(relevantSample?.With(sampleName) ?? h.GetSampleInfo(sampleName)); + samples.Add(h.CreateHitSampleInfo(sampleName)); }); } From 7a46b7b96177a234622031c77f51b632c816750d Mon Sep 17 00:00:00 2001 From: OliBomby Date: Wed, 31 May 2023 14:33:06 +0200 Subject: [PATCH 13/45] Invert colors --- .../Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs | 4 ---- .../Edit/Compose/Components/Timeline/SamplePointPiece.cs | 4 +++- .../Components/Timeline/TimelineHitObjectBlueprint.cs | 5 +++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs index de43e16e55..f168fb791f 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs @@ -4,10 +4,8 @@ using System.Collections.Generic; using osu.Framework.Graphics.UserInterface; using osu.Game.Audio; -using osu.Game.Graphics; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Types; -using osuTK.Graphics; namespace osu.Game.Screens.Edit.Compose.Components.Timeline { @@ -24,8 +22,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline NodeIndex = nodeIndex; } - protected override Color4 GetRepresentingColour(OsuColour colours) => colours.Purple; - protected override IList GetSamples() { var hasRepeats = (IHasRepeats)HitObject; diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 64330e354a..61004aae88 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -36,7 +36,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline HitObject = hitObject; } - protected override Color4 GetRepresentingColour(OsuColour colours) => colours.Pink; + public bool AlternativeColor { get; init; } + + protected override Color4 GetRepresentingColour(OsuColour colours) => AlternativeColor ? colours.Purple : colours.Pink; [BackgroundDependencyLoader] private void load() diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs index e7c14fc53d..ddac3bb667 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs @@ -111,7 +111,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline { Anchor = Anchor.BottomLeft, Origin = Anchor.TopCentre, - X = Item is IHasRepeats ? -10 : 0 + X = Item is IHasRepeats ? -10 : 0, + AlternativeColor = Item is IHasRepeats }, }); @@ -256,7 +257,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline X = (float)i / (repeats.RepeatCount + 1), RelativePositionAxes = Axes.X, Anchor = Anchor.BottomLeft, - Origin = Anchor.TopCentre, + Origin = Anchor.TopCentre }); } } From b7bc49b1f4ea438daa1e313b7cface55f62c84a7 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Wed, 31 May 2023 16:28:43 +0200 Subject: [PATCH 14/45] Fix regressed bank inheriting behaviour on node samples --- .../Edit/Compose/Components/Timeline/SamplePointPiece.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 61004aae88..b52463d8f3 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -332,7 +332,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (samples.Any(s => s.Name == sampleName)) return; - samples.Add(h.CreateHitSampleInfo(sampleName)); + // First try inheriting the sample info from the node samples instead of the samples of the hitobject + var relevantSample = samples.FirstOrDefault(s => s.Name != HitSampleInfo.HIT_NORMAL) ?? samples.FirstOrDefault(); + samples.Add(relevantSample?.With(sampleName) ?? h.CreateHitSampleInfo(sampleName)); }); } From fede432969fbf202f0a0d702ebedc02ab1e66a34 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Wed, 31 May 2023 20:00:19 +0200 Subject: [PATCH 15/45] Make relevantObject and relevantSamples instance variables --- .../Components/Timeline/SamplePointPiece.cs | 100 ++++++++++-------- 1 file changed, 57 insertions(+), 43 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index b52463d8f3..bbc5380e70 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -98,6 +98,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private FillFlowContainer togglesCollection = null!; + private HitObject[] relevantObjects = null!; + private IList[] relevantSamples = null!; + protected virtual IList GetSamples(HitObject ho) => ho.Samples; [Resolved(canBeNull: true)] @@ -153,44 +156,41 @@ 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 relevantSamples = relevantObjects.Select(GetSamples).ToArray(); + relevantObjects = (beatmap.SelectedHitObjects.Contains(hitObject) ? beatmap.SelectedHitObjects : hitObject.Yield()).ToArray(); + relevantSamples = relevantObjects.Select(GetSamples).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(relevantSamples); + string? commonBank = getCommonBank(); if (!string.IsNullOrEmpty(commonBank)) bank.Current.Value = commonBank; - string? commonAdditionBank = getCommonAdditionBank(relevantSamples); - if (!string.IsNullOrEmpty(commonAdditionBank)) - additionBank.Current.Value = commonAdditionBank; - - int? commonVolume = getCommonVolume(relevantSamples); + int? commonVolume = getCommonVolume(); if (commonVolume != null) volume.Current.Value = commonVolume.Value; - updateBankPlaceholderText(relevantObjects); + updateBankPlaceholderText(); bank.Current.BindValueChanged(val => { - updateBankFor(relevantObjects, val.NewValue); - updateBankPlaceholderText(relevantObjects); + updateBank(val.NewValue); + updateBankPlaceholderText(); }); // 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(relevantSamples); + bank.OnCommit += (_, _) => bank.Current.Value = getCommonBank(); - updateAdditionBankPlaceholderText(relevantObjects); + updateAdditionBankPlaceholderText(); + updateAdditionBankText(); additionBank.Current.BindValueChanged(val => { - updateAdditionBankFor(relevantObjects, val.NewValue); - updateAdditionBankPlaceholderText(relevantObjects); + updateAdditionBank(val.NewValue); + updateAdditionBankPlaceholderText(); }); - additionBank.OnCommit += (_, _) => additionBank.Current.Value = getCommonAdditionBank(relevantSamples); + additionBank.OnCommit += (_, _) => updateAdditionBankText(); - volume.Current.BindValueChanged(val => updateVolumeFor(relevantObjects, val.NewValue)); + volume.Current.BindValueChanged(val => updateVolume(val.NewValue)); - createStateBindables(relevantObjects); - updateTernaryStates(relevantObjects); + createStateBindables(); + updateTernaryStates(); togglesCollection.AddRange(createTernaryButtons().Select(b => new DrawableTernaryButton(b) { RelativeSizeAxes = Axes.None, Size = new Vector2(40, 40) })); } @@ -200,15 +200,15 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline ScheduleAfterChildren(() => GetContainingInputManager().ChangeFocus(volume)); } - private static string? getCommonBank(IList[] relevantSamples) => relevantSamples.Select(GetBankValue).Distinct().Count() == 1 ? GetBankValue(relevantSamples.First()) : null; - private static string? getCommonAdditionBank(IList[] relevantSamples) => relevantSamples.Select(GetAdditionBankValue).Distinct().Count() == 1 ? GetAdditionBankValue(relevantSamples.First()) : null; - private static int? getCommonVolume(IList[] relevantSamples) => relevantSamples.Select(GetVolumeValue).Distinct().Count() == 1 ? GetVolumeValue(relevantSamples.First()) : null; + private string? getCommonBank() => relevantSamples.Select(GetBankValue).Distinct().Count() == 1 ? GetBankValue(relevantSamples.First()) : null; + private string? getCommonAdditionBank() => relevantSamples.Select(GetAdditionBankValue).Distinct().Count() == 1 ? GetAdditionBankValue(relevantSamples.First()) : null; + private int? getCommonVolume() => relevantSamples.Select(GetVolumeValue).Distinct().Count() == 1 ? GetVolumeValue(relevantSamples.First()) : null; - private void updateFor(IEnumerable objects, Action> updateAction) + private void update(Action> updateAction) { beatmap.BeginChange(); - foreach (var h in objects) + foreach (var h in relevantObjects) { var samples = GetSamples(h); updateAction(h, samples); @@ -218,12 +218,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline beatmap.EndChange(); } - private void updateBankFor(IEnumerable objects, string? newBank) + private void updateBank(string? newBank) { if (string.IsNullOrEmpty(newBank)) return; - updateFor(objects, (_, samples) => + update((_, samples) => { for (int i = 0; i < samples.Count; i++) { @@ -234,12 +234,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline }); } - private void updateAdditionBankFor(IEnumerable objects, string? newBank) + private void updateAdditionBank(string? newBank) { if (string.IsNullOrEmpty(newBank)) return; - updateFor(objects, (_, samples) => + update((_, samples) => { for (int i = 0; i < samples.Count; i++) { @@ -250,24 +250,34 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline }); } - private void updateBankPlaceholderText(IEnumerable objects) + private void updateBankPlaceholderText() { - string? commonBank = getCommonBank(objects.Select(GetSamples).ToArray()); + string? commonBank = getCommonBank(); bank.PlaceholderText = string.IsNullOrEmpty(commonBank) ? "(multiple)" : string.Empty; } - private void updateAdditionBankPlaceholderText(IEnumerable objects) + private void updateAdditionBankPlaceholderText() { - string? commonAdditionBank = getCommonAdditionBank(objects.Select(GetSamples).ToArray()); + string? commonAdditionBank = getCommonAdditionBank(); additionBank.PlaceholderText = string.IsNullOrEmpty(commonAdditionBank) ? "(multiple)" : string.Empty; } - private void updateVolumeFor(IEnumerable objects, int? newVolume) + private void updateAdditionBankText() + { + if (additionBank.Current.Disabled) return; + + string? commonAdditionBank = getCommonAdditionBank(); + if (string.IsNullOrEmpty(commonAdditionBank)) return; + + additionBank.Current.Value = commonAdditionBank; + } + + private void updateVolume(int? newVolume) { if (newVolume == null) return; - updateFor(objects, (_, samples) => + update((_, samples) => { for (int i = 0; i < samples.Count; i++) { @@ -280,7 +290,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private readonly Dictionary> selectionSampleStates = new Dictionary>(); - private void createStateBindables(IEnumerable objects) + private void createStateBindables() { foreach (string sampleName in HitSampleInfo.AllAdditions) { @@ -294,11 +304,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline switch (state.NewValue) { case TernaryState.False: - removeHitSampleFor(objects, sampleName); + removeHitSample(sampleName); break; case TernaryState.True: - addHitSampleFor(objects, sampleName); + addHitSample(sampleName); break; } }; @@ -307,11 +317,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline } } - private void updateTernaryStates(IEnumerable objects) + private void updateTernaryStates() { foreach ((string sampleName, var bindable) in selectionSampleStates) { - bindable.Value = SelectionHandler.GetStateFromSelection(objects, h => GetSamples(h).Any(s => s.Name == sampleName)); + bindable.Value = SelectionHandler.GetStateFromSelection(relevantObjects, h => GetSamples(h).Any(s => s.Name == sampleName)); } } @@ -321,12 +331,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline yield return new TernaryButton(bindable, string.Empty, () => ComposeBlueprintContainer.GetIconForSample(sampleName)); } - private void addHitSampleFor(IEnumerable objects, string sampleName) + private void addHitSample(string sampleName) { if (string.IsNullOrEmpty(sampleName)) return; - updateFor(objects, (h, samples) => + update((h, samples) => { // Make sure there isn't already an existing sample if (samples.Any(s => s.Name == sampleName)) @@ -336,14 +346,16 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline var relevantSample = samples.FirstOrDefault(s => s.Name != HitSampleInfo.HIT_NORMAL) ?? samples.FirstOrDefault(); samples.Add(relevantSample?.With(sampleName) ?? h.CreateHitSampleInfo(sampleName)); }); + + updateAdditionBankText(); } - private void removeHitSampleFor(IEnumerable objects, string sampleName) + private void removeHitSample(string sampleName) { if (string.IsNullOrEmpty(sampleName)) return; - updateFor(objects, (_, samples) => + update((_, samples) => { for (int i = 0; i < samples.Count; i++) { @@ -351,6 +363,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline samples.RemoveAt(i--); } }); + + updateAdditionBankText(); } protected override bool OnKeyDown(KeyDownEvent e) From 9e78a6b34e0deb25a4933b14d14f16cd91165bfd Mon Sep 17 00:00:00 2001 From: OliBomby Date: Wed, 31 May 2023 20:00:45 +0200 Subject: [PATCH 16/45] hide addition bank field when no additions active --- .../Compose/Components/Timeline/SamplePointPiece.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index bbc5380e70..37a6fa8a22 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -180,6 +180,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline updateAdditionBankPlaceholderText(); updateAdditionBankText(); + updateAdditionBankActivated(); additionBank.Current.BindValueChanged(val => { updateAdditionBank(val.NewValue); @@ -262,6 +263,15 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline additionBank.PlaceholderText = string.IsNullOrEmpty(commonAdditionBank) ? "(multiple)" : string.Empty; } + private void updateAdditionBankActivated() + { + bool anyAdditions = relevantSamples.Any(o => o.Any(s => s.Name != HitSampleInfo.HIT_NORMAL)); + if (anyAdditions) + additionBank.Show(); + else + additionBank.Hide(); + } + private void updateAdditionBankText() { if (additionBank.Current.Disabled) return; @@ -347,6 +357,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline samples.Add(relevantSample?.With(sampleName) ?? h.CreateHitSampleInfo(sampleName)); }); + updateAdditionBankActivated(); updateAdditionBankText(); } @@ -365,6 +376,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline }); updateAdditionBankText(); + updateAdditionBankActivated(); } protected override bool OnKeyDown(KeyDownEvent e) From 8acfe6b58b1de2de3466315fc74b000a428860c1 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Thu, 1 Jun 2023 07:41:30 +0200 Subject: [PATCH 17/45] Add PopoverContainer to TimelineTestScene --- .../Visual/Editing/TimelineTestScene.cs | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TimelineTestScene.cs b/osu.Game.Tests/Visual/Editing/TimelineTestScene.cs index cb45ad5a07..afec75e948 100644 --- a/osu.Game.Tests/Visual/Editing/TimelineTestScene.cs +++ b/osu.Game.Tests/Visual/Editing/TimelineTestScene.cs @@ -9,6 +9,7 @@ using osu.Framework.Audio; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Shapes; using osu.Framework.Testing; using osu.Game.Beatmaps; @@ -51,28 +52,35 @@ namespace osu.Game.Tests.Visual.Editing Composer.Alpha = 0; - Add(new OsuContextMenuContainer + Add(new PopoverContainer { RelativeSizeAxes = Axes.Both, Children = new Drawable[] { - EditorBeatmap, - Composer, - new FillFlowContainer + new OsuContextMenuContainer { - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Vertical, - Spacing = new Vector2(0, 5), + RelativeSizeAxes = Axes.Both, Children = new Drawable[] { - new StartStopButton(), - new AudioVisualiser(), + EditorBeatmap, + Composer, + new FillFlowContainer + { + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 5), + Children = new Drawable[] + { + new StartStopButton(), + new AudioVisualiser(), + } + }, + TimelineArea = new TimelineArea(CreateTestComponent()) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } } - }, - TimelineArea = new TimelineArea(CreateTestComponent()) - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, } } }); From 2812b2345779e6d9af397b0af0f4f30dff4e864b Mon Sep 17 00:00:00 2001 From: OliBomby Date: Thu, 1 Jun 2023 08:03:41 +0200 Subject: [PATCH 18/45] Add sample point piece test --- .../TestSceneTimelineHitObjectBlueprint.cs | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs b/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs index 08e036248b..61bfaad64c 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs @@ -8,10 +8,14 @@ using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.UserInterface; using osu.Framework.Testing; +using osu.Game.Audio; using osu.Game.Graphics.UserInterface; +using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Screens.Edit.Components.TernaryButtons; using osu.Game.Screens.Edit.Compose.Components.Timeline; +using osu.Game.Screens.Edit.Timing; using osuTK; using osuTK.Input; using static osu.Game.Screens.Edit.Compose.Components.Timeline.TimelineHitObjectBlueprint; @@ -111,5 +115,73 @@ namespace osu.Game.Tests.Visual.Editing AddAssert("object has zero repeats", () => EditorBeatmap.HitObjects.OfType().Single().RepeatCount == 0); } + + [Test] + public void TestSamplePointPiece() + { + SamplePointPiece samplePointPiece; + SamplePointPiece.SampleEditPopover popover = null!; + + AddStep("add circle", () => + { + EditorBeatmap.Clear(); + EditorBeatmap.Add(new HitCircle + { + Position = new Vector2(256, 256), + StartTime = 2700, + Samples = + { + new HitSampleInfo(HitSampleInfo.HIT_NORMAL) + } + }); + }); + + AddStep("open hitsound popover", () => + { + samplePointPiece = this.ChildrenOfType().Single(); + InputManager.MoveMouseTo(samplePointPiece); + InputManager.PressButton(MouseButton.Left); + InputManager.ReleaseButton(MouseButton.Left); + }); + + AddStep("add whistle addition", () => + { + popover = this.ChildrenOfType().First(); + var whistleTernaryButton = popover.ChildrenOfType().First(); + InputManager.MoveMouseTo(whistleTernaryButton); + InputManager.PressButton(MouseButton.Left); + InputManager.ReleaseButton(MouseButton.Left); + }); + + AddAssert("has whistle sample", () => EditorBeatmap.HitObjects.First().Samples.Any(o => o.Name == HitSampleInfo.HIT_WHISTLE)); + + AddStep("change bank name", () => + { + var bankTextBox = popover.ChildrenOfType().First(); + bankTextBox.Current.Value = "soft"; + }); + + AddAssert("bank name changed", () => + EditorBeatmap.HitObjects.First().Samples.Where(o => o.Name == HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "soft") + && EditorBeatmap.HitObjects.First().Samples.Where(o => o.Name != HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "normal")); + + AddStep("change addition bank name", () => + { + var bankTextBox = popover.ChildrenOfType().ToArray()[1]; + bankTextBox.Current.Value = "drum"; + }); + + AddAssert("addition bank name changed", () => + EditorBeatmap.HitObjects.First().Samples.Where(o => o.Name == HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "soft") + && EditorBeatmap.HitObjects.First().Samples.Where(o => o.Name != HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "drum")); + + AddStep("change volume", () => + { + var bankTextBox = popover.ChildrenOfType>().Single(); + bankTextBox.Current.Value = 30; + }); + + AddAssert("volume changed", () => EditorBeatmap.HitObjects.First().Samples.All(o => o.Volume == 30)); + } } } From aa52d86ea3304c0cf6922ef1e584fc4a6244cb39 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Thu, 1 Jun 2023 08:12:39 +0200 Subject: [PATCH 19/45] add nodesample piece test --- .../TestSceneTimelineHitObjectBlueprint.cs | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs b/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs index 61bfaad64c..6524722687 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs @@ -3,6 +3,7 @@ #nullable disable +using System.Collections.Generic; using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; @@ -11,6 +12,7 @@ using osu.Framework.Testing; using osu.Game.Audio; using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterfaceV2; +using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Screens.Edit.Components.TernaryButtons; @@ -183,5 +185,80 @@ namespace osu.Game.Tests.Visual.Editing AddAssert("volume changed", () => EditorBeatmap.HitObjects.First().Samples.All(o => o.Volume == 30)); } + + [Test] + public void TestNodeSamplePointPiece() + { + Slider slider = null!; + SamplePointPiece samplePointPiece; + SamplePointPiece.SampleEditPopover popover = null!; + + AddStep("add slider", () => + { + EditorBeatmap.Clear(); + EditorBeatmap.Add(slider = new Slider + { + Position = new Vector2(256, 256), + StartTime = 2700, + Path = new SliderPath(new[] { new PathControlPoint(Vector2.Zero), new PathControlPoint(new Vector2(250, 0)) }), + Samples = + { + new HitSampleInfo(HitSampleInfo.HIT_NORMAL) + }, + NodeSamples = + { + new List { new HitSampleInfo(HitSampleInfo.HIT_NORMAL) }, + new List { new HitSampleInfo(HitSampleInfo.HIT_NORMAL) }, + } + }); + }); + + AddStep("open slider end hitsound popover", () => + { + samplePointPiece = this.ChildrenOfType().Last(); + InputManager.MoveMouseTo(samplePointPiece); + InputManager.PressButton(MouseButton.Left); + InputManager.ReleaseButton(MouseButton.Left); + }); + + AddStep("add whistle addition", () => + { + popover = this.ChildrenOfType().First(); + var whistleTernaryButton = popover.ChildrenOfType().First(); + InputManager.MoveMouseTo(whistleTernaryButton); + InputManager.PressButton(MouseButton.Left); + InputManager.ReleaseButton(MouseButton.Left); + }); + + AddAssert("has whistle sample", () => slider.NodeSamples[1].Any(o => o.Name == HitSampleInfo.HIT_WHISTLE)); + + AddStep("change bank name", () => + { + var bankTextBox = popover.ChildrenOfType().First(); + bankTextBox.Current.Value = "soft"; + }); + + AddAssert("bank name changed", () => + slider.NodeSamples[1].Where(o => o.Name == HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "soft") + && slider.NodeSamples[1].Where(o => o.Name != HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "normal")); + + AddStep("change addition bank name", () => + { + var bankTextBox = popover.ChildrenOfType().ToArray()[1]; + bankTextBox.Current.Value = "drum"; + }); + + AddAssert("addition bank name changed", () => + slider.NodeSamples[1].Where(o => o.Name == HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "soft") + && slider.NodeSamples[1].Where(o => o.Name != HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "drum")); + + AddStep("change volume", () => + { + var bankTextBox = popover.ChildrenOfType>().Single(); + bankTextBox.Current.Value = 30; + }); + + AddAssert("volume changed", () => slider.NodeSamples[1].All(o => o.Volume == 30)); + } } } From e70939005257e6b853117edbf3f7aa504f3d273e Mon Sep 17 00:00:00 2001 From: OliBomby Date: Thu, 1 Jun 2023 09:00:59 +0200 Subject: [PATCH 20/45] reset popover at the end of sample tests --- .../TestSceneTimelineHitObjectBlueprint.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs b/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs index 6524722687..4410ae4112 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs @@ -121,7 +121,6 @@ namespace osu.Game.Tests.Visual.Editing [Test] public void TestSamplePointPiece() { - SamplePointPiece samplePointPiece; SamplePointPiece.SampleEditPopover popover = null!; AddStep("add circle", () => @@ -140,7 +139,7 @@ namespace osu.Game.Tests.Visual.Editing AddStep("open hitsound popover", () => { - samplePointPiece = this.ChildrenOfType().Single(); + var samplePointPiece = this.ChildrenOfType().Single(); InputManager.MoveMouseTo(samplePointPiece); InputManager.PressButton(MouseButton.Left); InputManager.ReleaseButton(MouseButton.Left); @@ -184,13 +183,20 @@ namespace osu.Game.Tests.Visual.Editing }); AddAssert("volume changed", () => EditorBeatmap.HitObjects.First().Samples.All(o => o.Volume == 30)); + + AddStep("close popover", () => + { + InputManager.MoveMouseTo(popover, new Vector2(200, 0)); + InputManager.PressButton(MouseButton.Left); + InputManager.ReleaseButton(MouseButton.Left); + popover = null; + }); } [Test] public void TestNodeSamplePointPiece() { Slider slider = null!; - SamplePointPiece samplePointPiece; SamplePointPiece.SampleEditPopover popover = null!; AddStep("add slider", () => @@ -215,7 +221,7 @@ namespace osu.Game.Tests.Visual.Editing AddStep("open slider end hitsound popover", () => { - samplePointPiece = this.ChildrenOfType().Last(); + var samplePointPiece = this.ChildrenOfType().Last(); InputManager.MoveMouseTo(samplePointPiece); InputManager.PressButton(MouseButton.Left); InputManager.ReleaseButton(MouseButton.Left); @@ -259,6 +265,14 @@ namespace osu.Game.Tests.Visual.Editing }); AddAssert("volume changed", () => slider.NodeSamples[1].All(o => o.Volume == 30)); + + AddStep("close popover", () => + { + InputManager.MoveMouseTo(popover, new Vector2(200, 0)); + InputManager.PressButton(MouseButton.Left); + InputManager.ReleaseButton(MouseButton.Left); + popover = null; + }); } } } From 63d9be9523a547c0c87d4e08cda6e79483ba359a Mon Sep 17 00:00:00 2001 From: OliBomby Date: Thu, 1 Jun 2023 09:27:04 +0200 Subject: [PATCH 21/45] merge updateAdditionBankPlaceholderText and updateAdditionBankActivated --- .../Components/Timeline/SamplePointPiece.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 37a6fa8a22..997e342dad 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -178,13 +178,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline // this ensures that committing empty text causes a revert to the previous value. bank.OnCommit += (_, _) => bank.Current.Value = getCommonBank(); - updateAdditionBankPlaceholderText(); updateAdditionBankText(); - updateAdditionBankActivated(); + updateAdditionBankVisual(); additionBank.Current.BindValueChanged(val => { updateAdditionBank(val.NewValue); - updateAdditionBankPlaceholderText(); + updateAdditionBankVisual(); }); additionBank.OnCommit += (_, _) => updateAdditionBankText(); @@ -257,14 +256,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline bank.PlaceholderText = string.IsNullOrEmpty(commonBank) ? "(multiple)" : string.Empty; } - private void updateAdditionBankPlaceholderText() + private void updateAdditionBankVisual() { string? commonAdditionBank = getCommonAdditionBank(); additionBank.PlaceholderText = string.IsNullOrEmpty(commonAdditionBank) ? "(multiple)" : string.Empty; - } - private void updateAdditionBankActivated() - { bool anyAdditions = relevantSamples.Any(o => o.Any(s => s.Name != HitSampleInfo.HIT_NORMAL)); if (anyAdditions) additionBank.Show(); @@ -274,8 +270,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private void updateAdditionBankText() { - if (additionBank.Current.Disabled) return; - string? commonAdditionBank = getCommonAdditionBank(); if (string.IsNullOrEmpty(commonAdditionBank)) return; @@ -357,7 +351,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline samples.Add(relevantSample?.With(sampleName) ?? h.CreateHitSampleInfo(sampleName)); }); - updateAdditionBankActivated(); + updateAdditionBankVisual(); updateAdditionBankText(); } @@ -376,7 +370,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline }); updateAdditionBankText(); - updateAdditionBankActivated(); + updateAdditionBankVisual(); } protected override bool OnKeyDown(KeyDownEvent e) From 1eb9b8e135ff2ae31f65bde9b7d5c01dae2a9afc Mon Sep 17 00:00:00 2001 From: OliBomby Date: Thu, 1 Jun 2023 09:34:21 +0200 Subject: [PATCH 22/45] added xmldoc and renamed GetSamples --- .../Components/Timeline/NodeSamplePointPiece.cs | 2 +- .../Components/Timeline/SamplePointPiece.cs | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs index f168fb791f..ae3838bc41 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/NodeSamplePointPiece.cs @@ -34,7 +34,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline { private readonly int nodeIndex; - protected override IList GetSamples(HitObject ho) + protected override IList GetRelevantSamples(HitObject ho) { if (ho is not IHasRepeats hasRepeats) return ho.Samples; diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 997e342dad..26cdf87d02 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -101,7 +101,13 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private HitObject[] relevantObjects = null!; private IList[] relevantSamples = null!; - protected virtual IList GetSamples(HitObject ho) => ho.Samples; + /// + /// Gets the sub-set of samples relevant to this sample point piece. + /// For example, to edit node samples this should return the samples at the index of the node. + /// + /// The hit object to get the relevant samples from. + /// The relevant list of samples. + protected virtual IList GetRelevantSamples(HitObject ho) => ho.Samples; [Resolved(canBeNull: true)] private EditorBeatmap beatmap { get; set; } = null!; @@ -157,7 +163,7 @@ 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. relevantObjects = (beatmap.SelectedHitObjects.Contains(hitObject) ? beatmap.SelectedHitObjects : hitObject.Yield()).ToArray(); - relevantSamples = relevantObjects.Select(GetSamples).ToArray(); + relevantSamples = relevantObjects.Select(GetRelevantSamples).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(); @@ -210,7 +216,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline foreach (var h in relevantObjects) { - var samples = GetSamples(h); + var samples = GetRelevantSamples(h); updateAction(h, samples); beatmap.Update(h); } @@ -325,7 +331,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline { foreach ((string sampleName, var bindable) in selectionSampleStates) { - bindable.Value = SelectionHandler.GetStateFromSelection(relevantObjects, h => GetSamples(h).Any(s => s.Name == sampleName)); + bindable.Value = SelectionHandler.GetStateFromSelection(relevantObjects, h => GetRelevantSamples(h).Any(s => s.Name == sampleName)); } } From eb8ac8951361cf8ba77cad6f69f09fc371209a67 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Thu, 1 Jun 2023 09:50:14 +0200 Subject: [PATCH 23/45] rename sample update logic and add xmldoc for clarity --- .../Components/Timeline/SamplePointPiece.cs | 65 ++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 26cdf87d02..2060a8ddd3 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -99,7 +99,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private FillFlowContainer togglesCollection = null!; private HitObject[] relevantObjects = null!; - private IList[] relevantSamples = null!; + private IList[] allRelevantSamples = null!; /// /// Gets the sub-set of samples relevant to this sample point piece. @@ -163,7 +163,7 @@ 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. relevantObjects = (beatmap.SelectedHitObjects.Contains(hitObject) ? beatmap.SelectedHitObjects : hitObject.Yield()).ToArray(); - relevantSamples = relevantObjects.Select(GetRelevantSamples).ToArray(); + allRelevantSamples = relevantObjects.Select(GetRelevantSamples).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(); @@ -206,19 +206,24 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline ScheduleAfterChildren(() => GetContainingInputManager().ChangeFocus(volume)); } - private string? getCommonBank() => relevantSamples.Select(GetBankValue).Distinct().Count() == 1 ? GetBankValue(relevantSamples.First()) : null; - private string? getCommonAdditionBank() => relevantSamples.Select(GetAdditionBankValue).Distinct().Count() == 1 ? GetAdditionBankValue(relevantSamples.First()) : null; - private int? getCommonVolume() => relevantSamples.Select(GetVolumeValue).Distinct().Count() == 1 ? GetVolumeValue(relevantSamples.First()) : null; + private string? getCommonBank() => allRelevantSamples.Select(GetBankValue).Distinct().Count() == 1 ? GetBankValue(allRelevantSamples.First()) : null; + private string? getCommonAdditionBank() => allRelevantSamples.Select(GetAdditionBankValue).Distinct().Count() == 1 ? GetAdditionBankValue(allRelevantSamples.First()) : null; + private int? getCommonVolume() => allRelevantSamples.Select(GetVolumeValue).Distinct().Count() == 1 ? GetVolumeValue(allRelevantSamples.First()) : null; - private void update(Action> updateAction) + /// + /// Applies the given update action on all samples of + /// and invokes the necessary update notifiers for the beatmap and hit objects. + /// + /// The action to perform on each element of . + private void updateAllRelevantSamples(Action> updateAction) { beatmap.BeginChange(); - foreach (var h in relevantObjects) + foreach (var relevantHitObject in relevantObjects) { - var samples = GetRelevantSamples(h); - updateAction(h, samples); - beatmap.Update(h); + var relevantSamples = GetRelevantSamples(relevantHitObject); + updateAction(relevantHitObject, relevantSamples); + beatmap.Update(relevantHitObject); } beatmap.EndChange(); @@ -229,13 +234,13 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (string.IsNullOrEmpty(newBank)) return; - update((_, samples) => + updateAllRelevantSamples((_, relevantSamples) => { - for (int i = 0; i < samples.Count; i++) + for (int i = 0; i < relevantSamples.Count; i++) { - if (samples[i].Name != HitSampleInfo.HIT_NORMAL) continue; + if (relevantSamples[i].Name != HitSampleInfo.HIT_NORMAL) continue; - samples[i] = samples[i].With(newBank: newBank); + relevantSamples[i] = relevantSamples[i].With(newBank: newBank); } }); } @@ -245,13 +250,13 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (string.IsNullOrEmpty(newBank)) return; - update((_, samples) => + updateAllRelevantSamples((_, relevantSamples) => { - for (int i = 0; i < samples.Count; i++) + for (int i = 0; i < relevantSamples.Count; i++) { - if (samples[i].Name == HitSampleInfo.HIT_NORMAL) continue; + if (relevantSamples[i].Name == HitSampleInfo.HIT_NORMAL) continue; - samples[i] = samples[i].With(newBank: newBank); + relevantSamples[i] = relevantSamples[i].With(newBank: newBank); } }); } @@ -267,7 +272,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline string? commonAdditionBank = getCommonAdditionBank(); additionBank.PlaceholderText = string.IsNullOrEmpty(commonAdditionBank) ? "(multiple)" : string.Empty; - bool anyAdditions = relevantSamples.Any(o => o.Any(s => s.Name != HitSampleInfo.HIT_NORMAL)); + bool anyAdditions = allRelevantSamples.Any(o => o.Any(s => s.Name != HitSampleInfo.HIT_NORMAL)); if (anyAdditions) additionBank.Show(); else @@ -287,11 +292,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (newVolume == null) return; - update((_, samples) => + updateAllRelevantSamples((_, relevantSamples) => { - for (int i = 0; i < samples.Count; i++) + for (int i = 0; i < relevantSamples.Count; i++) { - samples[i] = samples[i].With(newVolume: newVolume.Value); + relevantSamples[i] = relevantSamples[i].With(newVolume: newVolume.Value); } }); } @@ -346,15 +351,15 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (string.IsNullOrEmpty(sampleName)) return; - update((h, samples) => + updateAllRelevantSamples((h, relevantSamples) => { // Make sure there isn't already an existing sample - if (samples.Any(s => s.Name == sampleName)) + if (relevantSamples.Any(s => s.Name == sampleName)) return; // First try inheriting the sample info from the node samples instead of the samples of the hitobject - var relevantSample = samples.FirstOrDefault(s => s.Name != HitSampleInfo.HIT_NORMAL) ?? samples.FirstOrDefault(); - samples.Add(relevantSample?.With(sampleName) ?? h.CreateHitSampleInfo(sampleName)); + var relevantSample = relevantSamples.FirstOrDefault(s => s.Name != HitSampleInfo.HIT_NORMAL) ?? relevantSamples.FirstOrDefault(); + relevantSamples.Add(relevantSample?.With(sampleName) ?? h.CreateHitSampleInfo(sampleName)); }); updateAdditionBankVisual(); @@ -366,12 +371,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (string.IsNullOrEmpty(sampleName)) return; - update((_, samples) => + updateAllRelevantSamples((_, relevantSamples) => { - for (int i = 0; i < samples.Count; i++) + for (int i = 0; i < relevantSamples.Count; i++) { - if (samples[i].Name == sampleName) - samples.RemoveAt(i--); + if (relevantSamples[i].Name == sampleName) + relevantSamples.RemoveAt(i--); } }); From 3110f87831014a044ed316c78a8125043965f8cd Mon Sep 17 00:00:00 2001 From: OliBomby Date: Thu, 1 Jun 2023 18:48:12 +0200 Subject: [PATCH 24/45] Revert "Add PopoverContainer to TimelineTestScene" This reverts commit 8acfe6b58b1de2de3466315fc74b000a428860c1. --- .../Visual/Editing/TimelineTestScene.cs | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TimelineTestScene.cs b/osu.Game.Tests/Visual/Editing/TimelineTestScene.cs index afec75e948..cb45ad5a07 100644 --- a/osu.Game.Tests/Visual/Editing/TimelineTestScene.cs +++ b/osu.Game.Tests/Visual/Editing/TimelineTestScene.cs @@ -9,7 +9,6 @@ using osu.Framework.Audio; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Shapes; using osu.Framework.Testing; using osu.Game.Beatmaps; @@ -52,35 +51,28 @@ namespace osu.Game.Tests.Visual.Editing Composer.Alpha = 0; - Add(new PopoverContainer + Add(new OsuContextMenuContainer { RelativeSizeAxes = Axes.Both, Children = new Drawable[] { - new OsuContextMenuContainer + EditorBeatmap, + Composer, + new FillFlowContainer { - RelativeSizeAxes = Axes.Both, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 5), Children = new Drawable[] { - EditorBeatmap, - Composer, - new FillFlowContainer - { - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Vertical, - Spacing = new Vector2(0, 5), - Children = new Drawable[] - { - new StartStopButton(), - new AudioVisualiser(), - } - }, - TimelineArea = new TimelineArea(CreateTestComponent()) - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - } + new StartStopButton(), + new AudioVisualiser(), } + }, + TimelineArea = new TimelineArea(CreateTestComponent()) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, } } }); From 035163a7921ef12225b15973ff9302652a99a204 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Fri, 2 Jun 2023 00:40:00 +0200 Subject: [PATCH 25/45] add new behaviour tests to TestSceneHitObjectSampleAdjustments --- .../TestSceneHitObjectSampleAdjustments.cs | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneHitObjectSampleAdjustments.cs b/osu.Game.Tests/Visual/Editing/TestSceneHitObjectSampleAdjustments.cs index b0b51a5dbd..4136deda3e 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneHitObjectSampleAdjustments.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneHitObjectSampleAdjustments.cs @@ -14,9 +14,12 @@ using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Rulesets; using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.UI; +using osu.Game.Screens.Edit.Components.TernaryButtons; using osu.Game.Screens.Edit.Compose.Components.Timeline; using osu.Game.Screens.Edit.Timing; using osu.Game.Tests.Beatmaps; @@ -227,6 +230,84 @@ namespace osu.Game.Tests.Visual.Editing samplePopoverHasSingleBank(HitSampleInfo.BANK_NORMAL); } + [Test] + public void TestPopoverAddSampleAddition() + { + clickSamplePiece(0); + + setBankViaPopover(HitSampleInfo.BANK_SOFT); + hitObjectHasSampleBank(0, HitSampleInfo.BANK_SOFT); + + toggleAdditionViaPopover(0); + + hitObjectHasSampleBank(0, HitSampleInfo.BANK_SOFT); + hitObjectHasSamples(0, HitSampleInfo.HIT_NORMAL, HitSampleInfo.HIT_WHISTLE); + + setAdditionBankViaPopover(HitSampleInfo.BANK_DRUM); + + hitObjectHasSampleNormalBank(0, HitSampleInfo.BANK_SOFT); + hitObjectHasSampleAdditionBank(0, HitSampleInfo.BANK_DRUM); + + toggleAdditionViaPopover(0); + + hitObjectHasSampleBank(0, HitSampleInfo.BANK_SOFT); + hitObjectHasSamples(0, HitSampleInfo.HIT_NORMAL); + } + + [Test] + public void TestNodeSamplePopover() + { + AddStep("add slider", () => + { + EditorBeatmap.Clear(); + EditorBeatmap.Add(new Slider + { + Position = new Vector2(256, 256), + StartTime = 0, + Path = new SliderPath(new[] { new PathControlPoint(Vector2.Zero), new PathControlPoint(new Vector2(250, 0)) }), + Samples = + { + new HitSampleInfo(HitSampleInfo.HIT_NORMAL) + }, + NodeSamples = + { + new List { new HitSampleInfo(HitSampleInfo.HIT_NORMAL) }, + new List { new HitSampleInfo(HitSampleInfo.HIT_NORMAL) }, + } + }); + }); + + clickNodeSamplePiece(0, 1); + + setBankViaPopover(HitSampleInfo.BANK_SOFT); + hitObjectNodeHasSampleBank(0, 0, HitSampleInfo.BANK_NORMAL); + hitObjectNodeHasSampleBank(0, 1, HitSampleInfo.BANK_SOFT); + + toggleAdditionViaPopover(0); + + hitObjectNodeHasSampleBank(0, 0, HitSampleInfo.BANK_NORMAL); + hitObjectNodeHasSampleBank(0, 1, HitSampleInfo.BANK_SOFT); + hitObjectNodeHasSamples(0, 0, HitSampleInfo.HIT_NORMAL); + hitObjectNodeHasSamples(0, 1, HitSampleInfo.HIT_NORMAL, HitSampleInfo.HIT_WHISTLE); + + setAdditionBankViaPopover(HitSampleInfo.BANK_DRUM); + + hitObjectNodeHasSampleBank(0, 0, HitSampleInfo.BANK_NORMAL); + hitObjectNodeHasSampleNormalBank(0, 1, HitSampleInfo.BANK_SOFT); + hitObjectNodeHasSampleAdditionBank(0, 1, HitSampleInfo.BANK_DRUM); + + toggleAdditionViaPopover(0); + + hitObjectNodeHasSampleBank(0, 1, HitSampleInfo.BANK_SOFT); + hitObjectNodeHasSamples(0, 0, HitSampleInfo.HIT_NORMAL); + hitObjectNodeHasSamples(0, 1, HitSampleInfo.HIT_NORMAL); + + setVolumeViaPopover(10); + + hitObjectNodeHasSampleVolume(0, 0, 100); + hitObjectNodeHasSampleVolume(0, 1, 10); + } + [Test] public void TestHotkeysMultipleSelectionWithSameSampleBank() { @@ -330,6 +411,14 @@ namespace osu.Game.Tests.Visual.Editing InputManager.Click(MouseButton.Left); }); + private void clickNodeSamplePiece(int objectIndex, int nodeIndex) => AddStep($"click {objectIndex.ToOrdinalWords()} object {nodeIndex.ToOrdinalWords()} node sample piece", () => + { + var samplePiece = this.ChildrenOfType().Where(piece => piece.HitObject == EditorBeatmap.HitObjects.ElementAt(objectIndex)).ToArray()[nodeIndex]; + + InputManager.MoveMouseTo(samplePiece); + InputManager.Click(MouseButton.Left); + }); + private void samplePopoverHasFocus() => AddUntilStep("sample popover textbox focused", () => { var popover = this.ChildrenOfType().SingleOrDefault(); @@ -391,6 +480,12 @@ namespace osu.Game.Tests.Visual.Editing return h.Samples.All(o => o.Volume == volume); }); + private void hitObjectNodeHasSampleVolume(int objectIndex, int nodeIndex, int volume) => AddAssert($"{objectIndex.ToOrdinalWords()} object {nodeIndex.ToOrdinalWords()} node has volume {volume}", () => + { + var h = EditorBeatmap.HitObjects.ElementAt(objectIndex) as IHasRepeats; + return h is not null && h.NodeSamples[nodeIndex].All(o => o.Volume == volume); + }); + private void setBankViaPopover(string bank) => AddStep($"set bank {bank} via popover", () => { var popover = this.ChildrenOfType().Single(); @@ -402,6 +497,26 @@ namespace osu.Game.Tests.Visual.Editing InputManager.Key(Key.Enter); }); + private void setAdditionBankViaPopover(string bank) => AddStep($"set addition bank {bank} via popover", () => + { + var popover = this.ChildrenOfType().Single(); + var textBox = popover.ChildrenOfType().ToArray()[1]; + 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 toggleAdditionViaPopover(int index) => AddStep($"toggle addition {index} via popover", () => + { + var popover = this.ChildrenOfType().First(); + var ternaryButton = popover.ChildrenOfType().ToArray()[index]; + InputManager.MoveMouseTo(ternaryButton); + InputManager.PressButton(MouseButton.Left); + InputManager.ReleaseButton(MouseButton.Left); + }); + private void hitObjectHasSamples(int objectIndex, params string[] samples) => AddAssert($"{objectIndex.ToOrdinalWords()} has samples {string.Join(',', samples)}", () => { var h = EditorBeatmap.HitObjects.ElementAt(objectIndex); @@ -413,5 +528,41 @@ namespace osu.Game.Tests.Visual.Editing var h = EditorBeatmap.HitObjects.ElementAt(objectIndex); return h.Samples.All(o => o.Bank == bank); }); + + private void hitObjectHasSampleNormalBank(int objectIndex, string bank) => AddAssert($"{objectIndex.ToOrdinalWords()} has normal bank {bank}", () => + { + var h = EditorBeatmap.HitObjects.ElementAt(objectIndex); + return h.Samples.Where(o => o.Name == HitSampleInfo.HIT_NORMAL).All(o => o.Bank == bank); + }); + + private void hitObjectHasSampleAdditionBank(int objectIndex, string bank) => AddAssert($"{objectIndex.ToOrdinalWords()} has addition bank {bank}", () => + { + var h = EditorBeatmap.HitObjects.ElementAt(objectIndex); + return h.Samples.Where(o => o.Name != HitSampleInfo.HIT_NORMAL).All(o => o.Bank == bank); + }); + + private void hitObjectNodeHasSamples(int objectIndex, int nodeIndex, params string[] samples) => AddAssert($"{objectIndex.ToOrdinalWords()} object {nodeIndex.ToOrdinalWords()} node has samples {string.Join(',', samples)}", () => + { + var h = EditorBeatmap.HitObjects.ElementAt(objectIndex) as IHasRepeats; + return h is not null && h.NodeSamples[nodeIndex].Select(s => s.Name).SequenceEqual(samples); + }); + + private void hitObjectNodeHasSampleBank(int objectIndex, int nodeIndex, string bank) => AddAssert($"{objectIndex.ToOrdinalWords()} object {nodeIndex.ToOrdinalWords()} node has bank {bank}", () => + { + var h = EditorBeatmap.HitObjects.ElementAt(objectIndex) as IHasRepeats; + return h is not null && h.NodeSamples[nodeIndex].All(o => o.Bank == bank); + }); + + private void hitObjectNodeHasSampleNormalBank(int objectIndex, int nodeIndex, string bank) => AddAssert($"{objectIndex.ToOrdinalWords()} object {nodeIndex.ToOrdinalWords()} node has normal bank {bank}", () => + { + var h = EditorBeatmap.HitObjects.ElementAt(objectIndex) as IHasRepeats; + return h is not null && h.NodeSamples[nodeIndex].Where(o => o.Name == HitSampleInfo.HIT_NORMAL).All(o => o.Bank == bank); + }); + + private void hitObjectNodeHasSampleAdditionBank(int objectIndex, int nodeIndex, string bank) => AddAssert($"{objectIndex.ToOrdinalWords()} object {nodeIndex.ToOrdinalWords()} node has addition bank {bank}", () => + { + var h = EditorBeatmap.HitObjects.ElementAt(objectIndex) as IHasRepeats; + return h is not null && h.NodeSamples[nodeIndex].Where(o => o.Name != HitSampleInfo.HIT_NORMAL).All(o => o.Bank == bank); + }); } } From acd8ff9a242f88a88997ef834469ea2b9a4f43ed Mon Sep 17 00:00:00 2001 From: OliBomby Date: Fri, 2 Jun 2023 00:42:36 +0200 Subject: [PATCH 26/45] revert add sample point piece tests --- .../TestSceneTimelineHitObjectBlueprint.cs | 163 ------------------ 1 file changed, 163 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs b/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs index 4410ae4112..08e036248b 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneTimelineHitObjectBlueprint.cs @@ -3,21 +3,15 @@ #nullable disable -using System.Collections.Generic; using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.UserInterface; using osu.Framework.Testing; -using osu.Game.Audio; using osu.Game.Graphics.UserInterface; -using osu.Game.Graphics.UserInterfaceV2; -using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Osu.Objects; -using osu.Game.Screens.Edit.Components.TernaryButtons; using osu.Game.Screens.Edit.Compose.Components.Timeline; -using osu.Game.Screens.Edit.Timing; using osuTK; using osuTK.Input; using static osu.Game.Screens.Edit.Compose.Components.Timeline.TimelineHitObjectBlueprint; @@ -117,162 +111,5 @@ namespace osu.Game.Tests.Visual.Editing AddAssert("object has zero repeats", () => EditorBeatmap.HitObjects.OfType().Single().RepeatCount == 0); } - - [Test] - public void TestSamplePointPiece() - { - SamplePointPiece.SampleEditPopover popover = null!; - - AddStep("add circle", () => - { - EditorBeatmap.Clear(); - EditorBeatmap.Add(new HitCircle - { - Position = new Vector2(256, 256), - StartTime = 2700, - Samples = - { - new HitSampleInfo(HitSampleInfo.HIT_NORMAL) - } - }); - }); - - AddStep("open hitsound popover", () => - { - var samplePointPiece = this.ChildrenOfType().Single(); - InputManager.MoveMouseTo(samplePointPiece); - InputManager.PressButton(MouseButton.Left); - InputManager.ReleaseButton(MouseButton.Left); - }); - - AddStep("add whistle addition", () => - { - popover = this.ChildrenOfType().First(); - var whistleTernaryButton = popover.ChildrenOfType().First(); - InputManager.MoveMouseTo(whistleTernaryButton); - InputManager.PressButton(MouseButton.Left); - InputManager.ReleaseButton(MouseButton.Left); - }); - - AddAssert("has whistle sample", () => EditorBeatmap.HitObjects.First().Samples.Any(o => o.Name == HitSampleInfo.HIT_WHISTLE)); - - AddStep("change bank name", () => - { - var bankTextBox = popover.ChildrenOfType().First(); - bankTextBox.Current.Value = "soft"; - }); - - AddAssert("bank name changed", () => - EditorBeatmap.HitObjects.First().Samples.Where(o => o.Name == HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "soft") - && EditorBeatmap.HitObjects.First().Samples.Where(o => o.Name != HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "normal")); - - AddStep("change addition bank name", () => - { - var bankTextBox = popover.ChildrenOfType().ToArray()[1]; - bankTextBox.Current.Value = "drum"; - }); - - AddAssert("addition bank name changed", () => - EditorBeatmap.HitObjects.First().Samples.Where(o => o.Name == HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "soft") - && EditorBeatmap.HitObjects.First().Samples.Where(o => o.Name != HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "drum")); - - AddStep("change volume", () => - { - var bankTextBox = popover.ChildrenOfType>().Single(); - bankTextBox.Current.Value = 30; - }); - - AddAssert("volume changed", () => EditorBeatmap.HitObjects.First().Samples.All(o => o.Volume == 30)); - - AddStep("close popover", () => - { - InputManager.MoveMouseTo(popover, new Vector2(200, 0)); - InputManager.PressButton(MouseButton.Left); - InputManager.ReleaseButton(MouseButton.Left); - popover = null; - }); - } - - [Test] - public void TestNodeSamplePointPiece() - { - Slider slider = null!; - SamplePointPiece.SampleEditPopover popover = null!; - - AddStep("add slider", () => - { - EditorBeatmap.Clear(); - EditorBeatmap.Add(slider = new Slider - { - Position = new Vector2(256, 256), - StartTime = 2700, - Path = new SliderPath(new[] { new PathControlPoint(Vector2.Zero), new PathControlPoint(new Vector2(250, 0)) }), - Samples = - { - new HitSampleInfo(HitSampleInfo.HIT_NORMAL) - }, - NodeSamples = - { - new List { new HitSampleInfo(HitSampleInfo.HIT_NORMAL) }, - new List { new HitSampleInfo(HitSampleInfo.HIT_NORMAL) }, - } - }); - }); - - AddStep("open slider end hitsound popover", () => - { - var samplePointPiece = this.ChildrenOfType().Last(); - InputManager.MoveMouseTo(samplePointPiece); - InputManager.PressButton(MouseButton.Left); - InputManager.ReleaseButton(MouseButton.Left); - }); - - AddStep("add whistle addition", () => - { - popover = this.ChildrenOfType().First(); - var whistleTernaryButton = popover.ChildrenOfType().First(); - InputManager.MoveMouseTo(whistleTernaryButton); - InputManager.PressButton(MouseButton.Left); - InputManager.ReleaseButton(MouseButton.Left); - }); - - AddAssert("has whistle sample", () => slider.NodeSamples[1].Any(o => o.Name == HitSampleInfo.HIT_WHISTLE)); - - AddStep("change bank name", () => - { - var bankTextBox = popover.ChildrenOfType().First(); - bankTextBox.Current.Value = "soft"; - }); - - AddAssert("bank name changed", () => - slider.NodeSamples[1].Where(o => o.Name == HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "soft") - && slider.NodeSamples[1].Where(o => o.Name != HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "normal")); - - AddStep("change addition bank name", () => - { - var bankTextBox = popover.ChildrenOfType().ToArray()[1]; - bankTextBox.Current.Value = "drum"; - }); - - AddAssert("addition bank name changed", () => - slider.NodeSamples[1].Where(o => o.Name == HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "soft") - && slider.NodeSamples[1].Where(o => o.Name != HitSampleInfo.HIT_NORMAL).All(o => o.Bank == "drum")); - - AddStep("change volume", () => - { - var bankTextBox = popover.ChildrenOfType>().Single(); - bankTextBox.Current.Value = 30; - }); - - AddAssert("volume changed", () => slider.NodeSamples[1].All(o => o.Volume == 30)); - - AddStep("close popover", () => - { - InputManager.MoveMouseTo(popover, new Vector2(200, 0)); - InputManager.PressButton(MouseButton.Left); - InputManager.ReleaseButton(MouseButton.Left); - popover = null; - }); - } } } From da516b90390ef06682155e051911ddd21d2e95a5 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Fri, 2 Jun 2023 00:50:21 +0200 Subject: [PATCH 27/45] Change purple to darker pink --- .../Edit/Compose/Components/Timeline/SamplePointPiece.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 2060a8ddd3..de85435d02 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -38,7 +38,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline public bool AlternativeColor { get; init; } - protected override Color4 GetRepresentingColour(OsuColour colours) => AlternativeColor ? colours.Purple : colours.Pink; + protected override Color4 GetRepresentingColour(OsuColour colours) => AlternativeColor ? colours.PinkDarker : colours.Pink; [BackgroundDependencyLoader] private void load() From 848f0e305eafd6d5258e8bf86d1f7ea547b67cef Mon Sep 17 00:00:00 2001 From: OliBomby Date: Fri, 2 Jun 2023 00:55:37 +0200 Subject: [PATCH 28/45] Change position of sliderbody hitsound piece for less overlap --- .../Compose/Components/Timeline/TimelineHitObjectBlueprint.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs index ddac3bb667..c642b9f29f 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs @@ -111,7 +111,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline { Anchor = Anchor.BottomLeft, Origin = Anchor.TopCentre, - X = Item is IHasRepeats ? -10 : 0, + X = Item is IHasRepeats ? 30 : 0, AlternativeColor = Item is IHasRepeats }, }); From 3f96795bbf9c6f69b673a89a71f82586da25ac4d Mon Sep 17 00:00:00 2001 From: OliBomby Date: Fri, 2 Jun 2023 01:02:35 +0200 Subject: [PATCH 29/45] fix merge conflict --- .../Compose/Components/Timeline/TimelineHitObjectBlueprint.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs index 00bd1a7019..f41daf30ce 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs @@ -109,7 +109,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline { RelativeSizeAxes = Axes.Both, }, - new SamplePointPiece(Item) + samplePointPiece = new SamplePointPiece(Item) { Anchor = Anchor.BottomLeft, Origin = Anchor.TopCentre, From cc4e11a5ac3f6ab2debfa10f08c402621f8acb79 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Wed, 16 Aug 2023 20:48:52 +0200 Subject: [PATCH 30/45] Ensure populated node samples so new objects have unique node sample lists --- osu.Game.Rulesets.Catch/Objects/JuiceStream.cs | 2 ++ osu.Game.Rulesets.Osu/Objects/Slider.cs | 2 ++ osu.Game/Rulesets/Objects/Types/IHasRepeats.cs | 15 +++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/osu.Game.Rulesets.Catch/Objects/JuiceStream.cs b/osu.Game.Rulesets.Catch/Objects/JuiceStream.cs index 169e99c90c..d9bbbedfcf 100644 --- a/osu.Game.Rulesets.Catch/Objects/JuiceStream.cs +++ b/osu.Game.Rulesets.Catch/Objects/JuiceStream.cs @@ -72,6 +72,8 @@ namespace osu.Game.Rulesets.Catch.Objects { base.CreateNestedHitObjects(cancellationToken); + this.PopulateNodeSamples(); + var dropletSamples = Samples.Select(s => s.With(@"slidertick")).ToList(); int nodeIndex = 0; diff --git a/osu.Game.Rulesets.Osu/Objects/Slider.cs b/osu.Game.Rulesets.Osu/Objects/Slider.cs index 4189f8ba1e..5ae76f1ac7 100644 --- a/osu.Game.Rulesets.Osu/Objects/Slider.cs +++ b/osu.Game.Rulesets.Osu/Objects/Slider.cs @@ -246,6 +246,8 @@ namespace osu.Game.Rulesets.Osu.Objects protected void UpdateNestedSamples() { + this.PopulateNodeSamples(); + var firstSample = Samples.FirstOrDefault(s => s.Name == HitSampleInfo.HIT_NORMAL) ?? Samples.FirstOrDefault(); // TODO: remove this when guaranteed sort is present for samples (https://github.com/ppy/osu/issues/1933) var sampleList = new List(); diff --git a/osu.Game/Rulesets/Objects/Types/IHasRepeats.cs b/osu.Game/Rulesets/Objects/Types/IHasRepeats.cs index 2a4215b960..9677ac4fbd 100644 --- a/osu.Game/Rulesets/Objects/Types/IHasRepeats.cs +++ b/osu.Game/Rulesets/Objects/Types/IHasRepeats.cs @@ -3,6 +3,7 @@ using osu.Game.Audio; using System.Collections.Generic; +using System.Linq; namespace osu.Game.Rulesets.Objects.Types { @@ -45,5 +46,19 @@ namespace osu.Game.Rulesets.Objects.Types public static IList GetNodeSamples(this T obj, int nodeIndex) where T : HitObject, IHasRepeats => nodeIndex < obj.NodeSamples.Count ? obj.NodeSamples[nodeIndex] : obj.Samples; + + /// + /// Ensures that the list of node samples is at least as long as the number of nodes. + /// + /// The . + public static void PopulateNodeSamples(this T obj) + where T : HitObject, IHasRepeats + { + if (obj.NodeSamples.Count >= obj.RepeatCount + 2) + return; + + while (obj.NodeSamples.Count < obj.RepeatCount + 2) + obj.NodeSamples.Add(obj.Samples.Select(o => o.With()).ToList()); + } } } From 02b7c8f27be47d968728a1fec3eb0eb77a3a7cf5 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Wed, 16 Aug 2023 21:15:47 +0200 Subject: [PATCH 31/45] Move sliderbody hs to middle of first span --- .../Timeline/TimelineHitObjectBlueprint.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs index f41daf30ce..d3a045db07 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs @@ -105,17 +105,17 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline }, } }, - sampleComponents = new Container - { - RelativeSizeAxes = Axes.Both, - }, samplePointPiece = new SamplePointPiece(Item) { Anchor = Anchor.BottomLeft, Origin = Anchor.TopCentre, - X = Item is IHasRepeats ? 30 : 0, + RelativePositionAxes = Axes.X, AlternativeColor = Item is IHasRepeats }, + sampleComponents = new Container + { + RelativeSizeAxes = Axes.Both, + }, }); if (item is IHasDuration) @@ -262,6 +262,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline Origin = Anchor.TopCentre }); } + + samplePointPiece.X = 1f / (repeats.RepeatCount + 1) / 2; } protected override bool ShouldBeConsideredForInput(Drawable child) => true; From a938b810b467d5d89acfe03ce43cf493a5e55d8d Mon Sep 17 00:00:00 2001 From: OliBomby Date: Wed, 16 Aug 2023 22:07:36 +0200 Subject: [PATCH 32/45] Add keybind for bank setting --- .../Components/Timeline/SamplePointPiece.cs | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index de85435d02..664998c267 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -182,7 +182,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline }); // 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(); + bank.OnCommit += (_, _) => updateBankText(); updateAdditionBankText(); updateAdditionBankVisual(); @@ -261,6 +261,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline }); } + private void updateBankText() + { + bank.Current.Value = getCommonBank(); + } + private void updateBankPlaceholderText() { string? commonBank = getCommonBank(); @@ -305,6 +310,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private readonly Dictionary> selectionSampleStates = new Dictionary>(); + private readonly List banks = new List(); + private void createStateBindables() { foreach (string sampleName in HitSampleInfo.AllAdditions) @@ -330,6 +337,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline selectionSampleStates[sampleName] = bindable; } + + banks.AddRange(HitSampleInfo.AllBanks); } private void updateTernaryStates() @@ -386,14 +395,26 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline protected override bool OnKeyDown(KeyDownEvent e) { - if (e.ControlPressed || e.AltPressed || e.SuperPressed || e.ShiftPressed || !checkRightToggleFromKey(e.Key, out int rightIndex)) + if (e.ControlPressed || e.AltPressed || e.SuperPressed || !checkRightToggleFromKey(e.Key, out int rightIndex)) return base.OnKeyDown(e); - var item = togglesCollection.ElementAtOrDefault(rightIndex); + if (e.ShiftPressed) + { + string? bank = banks.ElementAtOrDefault(rightIndex); + updateBank(bank); + updateBankText(); + updateAdditionBank(bank); + updateAdditionBankText(); + } + else + { + var item = togglesCollection.ElementAtOrDefault(rightIndex); - if (item is not DrawableTernaryButton button) return base.OnKeyDown(e); + if (item is not DrawableTernaryButton button) return base.OnKeyDown(e); + + button.Button.Toggle(); + } - button.Button.Toggle(); return true; } From fd54c329fa59b0b270bfe1d94791fcf9507eae5d Mon Sep 17 00:00:00 2001 From: OliBomby Date: Wed, 16 Aug 2023 22:08:49 +0200 Subject: [PATCH 33/45] dont focus volume, so keybinds immediately available --- .../Edit/Compose/Components/Timeline/SamplePointPiece.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 664998c267..97397ba2da 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -200,12 +200,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline togglesCollection.AddRange(createTernaryButtons().Select(b => new DrawableTernaryButton(b) { RelativeSizeAxes = Axes.None, Size = new Vector2(40, 40) })); } - protected override void LoadComplete() - { - base.LoadComplete(); - ScheduleAfterChildren(() => GetContainingInputManager().ChangeFocus(volume)); - } - private string? getCommonBank() => allRelevantSamples.Select(GetBankValue).Distinct().Count() == 1 ? GetBankValue(allRelevantSamples.First()) : null; private string? getCommonAdditionBank() => allRelevantSamples.Select(GetAdditionBankValue).Distinct().Count() == 1 ? GetAdditionBankValue(allRelevantSamples.First()) : null; private int? getCommonVolume() => allRelevantSamples.Select(GetVolumeValue).Distinct().Count() == 1 ? GetVolumeValue(allRelevantSamples.First()) : null; From 4ff58c681803b323b3d4f7844d53908afcc7b97f Mon Sep 17 00:00:00 2001 From: OliBomby Date: Wed, 16 Aug 2023 22:10:59 +0200 Subject: [PATCH 34/45] fix no nodesample test case --- osu.Game.Rulesets.Osu.Tests/TestSceneSlider.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game.Rulesets.Osu.Tests/TestSceneSlider.cs b/osu.Game.Rulesets.Osu.Tests/TestSceneSlider.cs index 4ad78a3190..3fac7c8c6d 100644 --- a/osu.Game.Rulesets.Osu.Tests/TestSceneSlider.cs +++ b/osu.Game.Rulesets.Osu.Tests/TestSceneSlider.cs @@ -133,6 +133,7 @@ namespace osu.Game.Rulesets.Osu.Tests { slider = (DrawableSlider)createSlider(repeats: 1); Add(slider); + slider.HitObject.NodeSamples.Clear(); }); AddStep("change samples", () => slider.HitObject.Samples = new[] From 88e6fe72dc6e679f0c44719fd3db4c15013779ba Mon Sep 17 00:00:00 2001 From: OliBomby Date: Wed, 16 Aug 2023 23:09:04 +0200 Subject: [PATCH 35/45] fix code quality --- .../Edit/Compose/Components/Timeline/SamplePointPiece.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 97397ba2da..268fb073d7 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -394,10 +394,10 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (e.ShiftPressed) { - string? bank = banks.ElementAtOrDefault(rightIndex); - updateBank(bank); + string? newBank = banks.ElementAtOrDefault(rightIndex); + updateBank(newBank); updateBankText(); - updateAdditionBank(bank); + updateAdditionBank(newBank); updateAdditionBankText(); } else From 080d2b62f4f459f33a398ed1878d2ce0dca0e9a6 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Wed, 16 Aug 2023 23:16:57 +0200 Subject: [PATCH 36/45] fix focus test --- .../Editing/TestSceneHitObjectSampleAdjustments.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneHitObjectSampleAdjustments.cs b/osu.Game.Tests/Visual/Editing/TestSceneHitObjectSampleAdjustments.cs index 050593ff94..b6a20dae54 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneHitObjectSampleAdjustments.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneHitObjectSampleAdjustments.cs @@ -81,10 +81,10 @@ namespace osu.Game.Tests.Visual.Editing } [Test] - public void TestPopoverHasFocus() + public void TestPopoverHasNoFocus() { clickSamplePiece(0); - samplePopoverHasFocus(); + samplePopoverHasNoFocus(); } [Test] @@ -417,13 +417,13 @@ namespace osu.Game.Tests.Visual.Editing InputManager.Click(MouseButton.Left); }); - private void samplePopoverHasFocus() => AddUntilStep("sample popover textbox focused", () => + private void samplePopoverHasNoFocus() => AddUntilStep("sample popover textbox not focused", () => { var popover = this.ChildrenOfType().SingleOrDefault(); var slider = popover?.ChildrenOfType>().Single(); var textbox = slider?.ChildrenOfType().Single(); - return textbox?.HasFocus == true; + return textbox?.HasFocus == false; }); private void samplePopoverHasSingleVolume(int volume) => AddUntilStep($"sample popover has volume {volume}", () => @@ -460,7 +460,6 @@ namespace osu.Game.Tests.Visual.Editing private void dismissPopover() { - AddStep("unfocus textbox", () => InputManager.Key(Key.Escape)); AddStep("dismiss popover", () => InputManager.Key(Key.Escape)); AddUntilStep("wait for dismiss", () => !this.ChildrenOfType().Any(popover => popover.IsPresent)); } From 7a8a37dae66e4851c9a63e9fc00fe6ca3e050eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 6 Jun 2024 13:39:32 +0200 Subject: [PATCH 37/45] Use established constants --- .../Edit/Compose/Components/Timeline/SamplePointPiece.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 5e3d6c5239..d90f62f79d 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -63,9 +63,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline { return bank switch { - "normal" => "N", - "soft" => "S", - "drum" => "D", + HitSampleInfo.BANK_NORMAL => @"N", + HitSampleInfo.BANK_SOFT => @"S", + HitSampleInfo.BANK_DRUM => @"D", _ => bank }; } From dd9c77d248ddb5c61f0b90f613f39f512bb24274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 6 Jun 2024 13:50:31 +0200 Subject: [PATCH 38/45] Fix obsoletion warning --- .../Visual/Editing/TestSceneHitObjectSampleAdjustments.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneHitObjectSampleAdjustments.cs b/osu.Game.Tests/Visual/Editing/TestSceneHitObjectSampleAdjustments.cs index 425eddbcdb..f02d2a1bb1 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneHitObjectSampleAdjustments.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneHitObjectSampleAdjustments.cs @@ -502,7 +502,7 @@ namespace osu.Game.Tests.Visual.Editing 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); + ((IFocusManager)InputManager).ChangeFocus(textBox); InputManager.Key(Key.Enter); }); From 71ce400359dc69c1f9af1980e802cd630380eadd Mon Sep 17 00:00:00 2001 From: OliBomby Date: Thu, 6 Jun 2024 14:48:17 +0200 Subject: [PATCH 39/45] Fix wasteful recreating of container --- .../Components/Timeline/TimelineHitObjectBlueprint.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs index ab9ccf6278..753856199a 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs @@ -33,7 +33,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private const float circle_size = 38; private Container? repeatsContainer; - private Container? nodeSamplesContainer; public Action? OnDragHandled = null!; @@ -246,16 +245,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline } // Add node sample pieces - nodeSamplesContainer?.Expire(); - - sampleComponents.Add(nodeSamplesContainer = new Container - { - RelativeSizeAxes = Axes.Both, - }); + sampleComponents.Clear(); for (int i = 0; i < repeats.RepeatCount + 2; i++) { - nodeSamplesContainer.Add(new NodeSamplePointPiece(Item, i) + sampleComponents.Add(new NodeSamplePointPiece(Item, i) { X = (float)i / (repeats.RepeatCount + 1), RelativePositionAxes = Axes.X, From fcc8671cbd5dcb844ff58f50920c3b45ca488e06 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Thu, 6 Jun 2024 14:50:24 +0200 Subject: [PATCH 40/45] undo useless change --- .../Screens/Edit/Compose/Components/EditorSelectionHandler.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs b/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs index c284ee2ebb..7c30b73122 100644 --- a/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs +++ b/osu.Game/Screens/Edit/Compose/Components/EditorSelectionHandler.cs @@ -226,9 +226,7 @@ namespace osu.Game.Screens.Edit.Compose.Components if (h.Samples.Any(s => s.Name == sampleName)) return; - var sampleToAdd = h.CreateHitSampleInfo(sampleName); - - h.Samples.Add(sampleToAdd); + h.Samples.Add(h.CreateHitSampleInfo(sampleName)); EditorBeatmap.Update(h); }); From e87369822182b75f8ee683547ffd3827d224303d Mon Sep 17 00:00:00 2001 From: OliBomby Date: Thu, 6 Jun 2024 14:57:25 +0200 Subject: [PATCH 41/45] Add some in-depth xmldoc to GetSamples --- .../Edit/Compose/Components/Timeline/SamplePointPiece.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index d90f62f79d..64ad840591 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -85,6 +85,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline return samples.Count == 0 ? 0 : samples.Max(o => o.Volume); } + /// + /// Gets the samples to be edited by this sample point piece. + /// This could be the samples of the hit object itself, or of one of the nested hit objects. For example a slider repeat. + /// + /// The samples to be edited. protected virtual IList GetSamples() => HitObject.Samples; public virtual Popover GetPopover() => new SampleEditPopover(HitObject); From 0efa028e0a82dc192303e2b99bead7ce1db66280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 10 Jun 2024 11:51:14 +0200 Subject: [PATCH 42/45] Restructure popover updates to be more centralised --- .../Components/Timeline/SamplePointPiece.cs | 117 ++++++++---------- 1 file changed, 54 insertions(+), 63 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 64ad840591..5f83937986 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -180,26 +180,35 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (commonVolume != null) volume.Current.Value = commonVolume.Value; - updateBankPlaceholderText(); + updatePrimaryBankState(); bank.Current.BindValueChanged(val => { - updateBank(val.NewValue); - updateBankPlaceholderText(); + if (string.IsNullOrEmpty(val.NewValue)) + return; + + setBank(val.NewValue); + updatePrimaryBankState(); }); // 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 += (_, _) => updateBankText(); + bank.OnCommit += (_, _) => updatePrimaryBankState(); - updateAdditionBankText(); - updateAdditionBankVisual(); + updateAdditionBankState(); additionBank.Current.BindValueChanged(val => { - updateAdditionBank(val.NewValue); - updateAdditionBankVisual(); - }); - additionBank.OnCommit += (_, _) => updateAdditionBankText(); + if (string.IsNullOrEmpty(val.NewValue)) + return; - volume.Current.BindValueChanged(val => updateVolume(val.NewValue)); + setAdditionBank(val.NewValue); + updateAdditionBankState(); + }); + additionBank.OnCommit += (_, _) => updateAdditionBankState(); + + volume.Current.BindValueChanged(val => + { + if (val.NewValue != null) + setVolume(val.NewValue.Value); + }); createStateBindables(); updateTernaryStates(); @@ -210,6 +219,26 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private string? getCommonAdditionBank() => allRelevantSamples.Select(GetAdditionBankValue).Distinct().Count() == 1 ? GetAdditionBankValue(allRelevantSamples.First()) : null; private int? getCommonVolume() => allRelevantSamples.Select(GetVolumeValue).Distinct().Count() == 1 ? GetVolumeValue(allRelevantSamples.First()) : null; + private void updatePrimaryBankState() + { + string? commonBank = getCommonBank(); + bank.Current.Value = commonBank; + bank.PlaceholderText = string.IsNullOrEmpty(commonBank) ? "(multiple)" : string.Empty; + } + + private void updateAdditionBankState() + { + string? commonAdditionBank = getCommonAdditionBank(); + additionBank.PlaceholderText = string.IsNullOrEmpty(commonAdditionBank) ? "(multiple)" : string.Empty; + additionBank.Current.Value = commonAdditionBank; + + bool anyAdditions = allRelevantSamples.Any(o => o.Any(s => s.Name != HitSampleInfo.HIT_NORMAL)); + if (anyAdditions) + additionBank.Show(); + else + additionBank.Hide(); + } + /// /// Applies the given update action on all samples of /// and invokes the necessary update notifiers for the beatmap and hit objects. @@ -229,11 +258,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline beatmap.EndChange(); } - private void updateBank(string? newBank) + private void setBank(string newBank) { - if (string.IsNullOrEmpty(newBank)) - return; - updateAllRelevantSamples((_, relevantSamples) => { for (int i = 0; i < relevantSamples.Count; i++) @@ -245,11 +271,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline }); } - private void updateAdditionBank(string? newBank) + private void setAdditionBank(string newBank) { - if (string.IsNullOrEmpty(newBank)) - return; - updateAllRelevantSamples((_, relevantSamples) => { for (int i = 0; i < relevantSamples.Count; i++) @@ -261,47 +284,13 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline }); } - private void updateBankText() + private void setVolume(int newVolume) { - bank.Current.Value = getCommonBank(); - } - - private void updateBankPlaceholderText() - { - string? commonBank = getCommonBank(); - bank.PlaceholderText = string.IsNullOrEmpty(commonBank) ? "(multiple)" : string.Empty; - } - - private void updateAdditionBankVisual() - { - string? commonAdditionBank = getCommonAdditionBank(); - additionBank.PlaceholderText = string.IsNullOrEmpty(commonAdditionBank) ? "(multiple)" : string.Empty; - - bool anyAdditions = allRelevantSamples.Any(o => o.Any(s => s.Name != HitSampleInfo.HIT_NORMAL)); - if (anyAdditions) - additionBank.Show(); - else - additionBank.Hide(); - } - - private void updateAdditionBankText() - { - string? commonAdditionBank = getCommonAdditionBank(); - if (string.IsNullOrEmpty(commonAdditionBank)) return; - - additionBank.Current.Value = commonAdditionBank; - } - - private void updateVolume(int? newVolume) - { - if (newVolume == null) - return; - updateAllRelevantSamples((_, relevantSamples) => { for (int i = 0; i < relevantSamples.Count; i++) { - relevantSamples[i] = relevantSamples[i].With(newVolume: newVolume.Value); + relevantSamples[i] = relevantSamples[i].With(newVolume: newVolume); } }); } @@ -371,8 +360,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline relevantSamples.Add(relevantSample?.With(sampleName) ?? h.CreateHitSampleInfo(sampleName)); }); - updateAdditionBankVisual(); - updateAdditionBankText(); + updateAdditionBankState(); } private void removeHitSample(string sampleName) @@ -389,8 +377,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline } }); - updateAdditionBankText(); - updateAdditionBankVisual(); + updateAdditionBankState(); } protected override bool OnKeyDown(KeyDownEvent e) @@ -401,10 +388,14 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (e.ShiftPressed) { string? newBank = banks.ElementAtOrDefault(rightIndex); - updateBank(newBank); - updateBankText(); - updateAdditionBank(newBank); - updateAdditionBankText(); + + if (string.IsNullOrEmpty(newBank)) + return true; + + setBank(newBank); + updatePrimaryBankState(); + setAdditionBank(newBank); + updateAdditionBankState(); } else { From 7d5dc750e53938d60fa6cffedc1879d32c546118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 10 Jun 2024 12:04:52 +0200 Subject: [PATCH 43/45] Use slightly lighter shade of pink for alternative colour --- .../Edit/Compose/Components/Timeline/SamplePointPiece.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 5f83937986..f318a52b28 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -39,7 +39,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline public bool AlternativeColor { get; init; } - protected override Color4 GetRepresentingColour(OsuColour colours) => AlternativeColor ? colours.PinkDarker : colours.Pink; + protected override Color4 GetRepresentingColour(OsuColour colours) => AlternativeColor ? colours.Pink2 : colours.Pink1; [BackgroundDependencyLoader] private void load() From 12dd60736a37d5c173eb9a7d04e207c4a623d3d5 Mon Sep 17 00:00:00 2001 From: OliBomby Date: Tue, 11 Jun 2024 21:20:42 +0200 Subject: [PATCH 44/45] remove code already covered by updatePrimaryBankState --- .../Edit/Compose/Components/Timeline/SamplePointPiece.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index f318a52b28..0d392e9a99 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -172,10 +172,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline allRelevantSamples = relevantObjects.Select(GetRelevantSamples).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(); - if (!string.IsNullOrEmpty(commonBank)) - bank.Current.Value = commonBank; - int? commonVolume = getCommonVolume(); if (commonVolume != null) volume.Current.Value = commonVolume.Value; From 869cd40195348a8056968bd9ba2f9927a1dc49ea Mon Sep 17 00:00:00 2001 From: OliBomby Date: Tue, 11 Jun 2024 21:31:18 +0200 Subject: [PATCH 45/45] Fixed samples without additions contributing to common addition bank while not having an editable addition bank --- .../Edit/Compose/Components/Timeline/SamplePointPiece.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs index 0d392e9a99..930b78b468 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/SamplePointPiece.cs @@ -77,7 +77,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline public static string? GetAdditionBankValue(IEnumerable samples) { - return samples.FirstOrDefault(o => o.Name != HitSampleInfo.HIT_NORMAL)?.Bank ?? GetBankValue(samples); + return samples.FirstOrDefault(o => o.Name != HitSampleInfo.HIT_NORMAL)?.Bank; } public static int GetVolumeValue(ICollection samples) @@ -212,7 +212,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline } private string? getCommonBank() => allRelevantSamples.Select(GetBankValue).Distinct().Count() == 1 ? GetBankValue(allRelevantSamples.First()) : null; - private string? getCommonAdditionBank() => allRelevantSamples.Select(GetAdditionBankValue).Distinct().Count() == 1 ? GetAdditionBankValue(allRelevantSamples.First()) : null; + private string? getCommonAdditionBank() => allRelevantSamples.Select(GetAdditionBankValue).Where(o => o is not null).Distinct().Count() == 1 ? GetAdditionBankValue(allRelevantSamples.First()) : null; private int? getCommonVolume() => allRelevantSamples.Select(GetVolumeValue).Distinct().Count() == 1 ? GetVolumeValue(allRelevantSamples.First()) : null; private void updatePrimaryBankState()