2020-10-01 17:49:48 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2023-05-08 21:14:25 +08:00
|
|
|
using System;
|
2021-11-14 00:21:48 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2023-05-08 21:08:40 +08:00
|
|
|
using Humanizer;
|
2020-10-01 17:49:48 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2021-09-14 17:51:22 +08:00
|
|
|
using osu.Framework.Extensions;
|
2021-11-14 00:21:48 +08:00
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2021-09-14 17:51:22 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Framework.Input.Events;
|
2024-08-28 01:04:16 +08:00
|
|
|
using osu.Framework.Utils;
|
2023-04-26 19:45:58 +08:00
|
|
|
using osu.Game.Audio;
|
2023-04-26 00:12:53 +08:00
|
|
|
using osu.Game.Graphics;
|
2023-05-08 21:08:40 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-09-14 17:51:22 +08:00
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2021-09-14 18:21:23 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2023-05-08 21:08:40 +08:00
|
|
|
using osu.Game.Screens.Edit.Components.TernaryButtons;
|
2023-10-20 20:21:11 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2024-07-23 20:34:48 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2021-09-14 17:51:22 +08:00
|
|
|
using osu.Game.Screens.Edit.Timing;
|
2021-11-14 01:09:40 +08:00
|
|
|
using osuTK;
|
2023-04-26 00:12:53 +08:00
|
|
|
using osuTK.Graphics;
|
2023-05-08 21:08:40 +08:00
|
|
|
using osuTK.Input;
|
2020-10-01 17:49:48 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|
|
|
{
|
2021-09-14 17:51:22 +08:00
|
|
|
public partial class SamplePointPiece : HitObjectPointPiece, IHasPopover
|
2020-10-01 17:49:48 +08:00
|
|
|
{
|
2021-11-13 23:58:24 +08:00
|
|
|
public readonly HitObject HitObject;
|
2020-10-01 18:29:34 +08:00
|
|
|
|
2024-07-04 17:47:45 +08:00
|
|
|
[Resolved]
|
2024-07-05 20:16:51 +08:00
|
|
|
private EditorClock? editorClock { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private Editor? editor { get; set; }
|
2024-07-04 17:47:45 +08:00
|
|
|
|
2021-09-14 18:21:23 +08:00
|
|
|
public SamplePointPiece(HitObject hitObject)
|
2020-10-01 17:49:48 +08:00
|
|
|
{
|
2021-11-13 23:58:24 +08:00
|
|
|
HitObject = hitObject;
|
2024-07-12 16:22:36 +08:00
|
|
|
Y = 2.5f;
|
2020-10-01 17:49:48 +08:00
|
|
|
}
|
|
|
|
|
2023-05-31 20:33:06 +08:00
|
|
|
public bool AlternativeColor { get; init; }
|
|
|
|
|
2024-06-10 18:04:52 +08:00
|
|
|
protected override Color4 GetRepresentingColour(OsuColour colours) => AlternativeColor ? colours.Pink2 : colours.Pink1;
|
2023-04-26 00:12:53 +08:00
|
|
|
|
2024-07-05 20:16:51 +08:00
|
|
|
protected virtual double GetTime() => HitObject is IHasRepeats r ? HitObject.StartTime + r.Duration / r.SpanCount() / 2 : HitObject.StartTime;
|
|
|
|
|
2020-10-01 17:49:48 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2022-01-15 08:06:39 +08:00
|
|
|
private void load()
|
2020-10-01 17:49:48 +08:00
|
|
|
{
|
2023-05-08 17:54:33 +08:00
|
|
|
HitObject.DefaultsApplied += _ => updateText();
|
|
|
|
updateText();
|
2024-07-05 20:16:51 +08:00
|
|
|
|
|
|
|
if (editor != null)
|
2024-07-05 20:33:05 +08:00
|
|
|
editor.ShowSampleEditPopoverRequested += onShowSampleEditPopoverRequested;
|
2024-07-05 20:16:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
if (editor != null)
|
2024-07-05 20:33:05 +08:00
|
|
|
editor.ShowSampleEditPopoverRequested -= onShowSampleEditPopoverRequested;
|
2024-07-05 20:16:51 +08:00
|
|
|
}
|
|
|
|
|
2024-07-05 20:33:05 +08:00
|
|
|
private void onShowSampleEditPopoverRequested(double time)
|
2024-07-05 20:16:51 +08:00
|
|
|
{
|
2024-08-30 01:34:14 +08:00
|
|
|
if (!Precision.AlmostEquals(time, GetTime())) return;
|
2020-10-01 17:49:48 +08:00
|
|
|
|
2024-08-30 01:34:14 +08:00
|
|
|
editorClock?.SeekSmoothlyTo(GetTime());
|
2024-07-04 17:47:45 +08:00
|
|
|
this.ShowPopover();
|
2021-09-10 12:44:39 +08:00
|
|
|
}
|
2020-10-01 17:49:48 +08:00
|
|
|
|
2021-09-14 17:51:22 +08:00
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
{
|
|
|
|
this.ShowPopover();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:44:39 +08:00
|
|
|
private void updateText()
|
|
|
|
{
|
2023-05-08 19:16:30 +08:00
|
|
|
Label.Text = $"{abbreviateBank(GetBankValue(GetSamples()))} {GetVolumeValue(GetSamples())}";
|
|
|
|
}
|
|
|
|
|
|
|
|
private static string? abbreviateBank(string? bank)
|
|
|
|
{
|
|
|
|
return bank switch
|
|
|
|
{
|
2024-06-06 19:39:32 +08:00
|
|
|
HitSampleInfo.BANK_NORMAL => @"N",
|
|
|
|
HitSampleInfo.BANK_SOFT => @"S",
|
|
|
|
HitSampleInfo.BANK_DRUM => @"D",
|
2023-05-08 19:16:30 +08:00
|
|
|
_ => bank
|
|
|
|
};
|
2023-04-26 19:45:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static string? GetBankValue(IEnumerable<HitSampleInfo> samples)
|
|
|
|
{
|
2023-05-08 22:12:03 +08:00
|
|
|
return samples.FirstOrDefault(o => o.Name == HitSampleInfo.HIT_NORMAL)?.Bank;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string? GetAdditionBankValue(IEnumerable<HitSampleInfo> samples)
|
|
|
|
{
|
2024-08-30 03:54:47 +08:00
|
|
|
var firstAddition = samples.FirstOrDefault(o => o.Name != HitSampleInfo.HIT_NORMAL);
|
|
|
|
if (firstAddition == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return firstAddition.EditorAutoBank ? EditorSelectionHandler.HIT_BANK_AUTO : firstAddition.Bank;
|
2023-04-26 19:45:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int GetVolumeValue(ICollection<HitSampleInfo> samples)
|
|
|
|
{
|
|
|
|
return samples.Count == 0 ? 0 : samples.Max(o => o.Volume);
|
2020-10-01 17:49:48 +08:00
|
|
|
}
|
2021-09-14 17:51:22 +08:00
|
|
|
|
2024-06-06 20:57:25 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 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.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The samples to be edited.</returns>
|
2023-05-08 18:38:53 +08:00
|
|
|
protected virtual IList<HitSampleInfo> GetSamples() => HitObject.Samples;
|
|
|
|
|
|
|
|
public virtual Popover GetPopover() => new SampleEditPopover(HitObject);
|
2021-09-14 17:51:22 +08:00
|
|
|
|
|
|
|
public partial class SampleEditPopover : OsuPopover
|
|
|
|
{
|
2021-09-14 18:21:23 +08:00
|
|
|
private readonly HitObject hitObject;
|
2021-09-14 17:51:22 +08:00
|
|
|
|
2021-11-14 00:21:48 +08:00
|
|
|
private LabelledTextBox bank = null!;
|
2023-05-08 22:12:03 +08:00
|
|
|
private LabelledTextBox additionBank = null!;
|
2021-11-14 00:21:48 +08:00
|
|
|
private IndeterminateSliderWithTextBoxInput<int> volume = null!;
|
2021-09-14 17:51:22 +08:00
|
|
|
|
2023-05-08 21:08:40 +08:00
|
|
|
private FillFlowContainer togglesCollection = null!;
|
|
|
|
|
2023-06-01 02:00:19 +08:00
|
|
|
private HitObject[] relevantObjects = null!;
|
2024-07-23 20:34:48 +08:00
|
|
|
private (HitObject hitObject, IList<HitSampleInfo> samples)[] allRelevantSamples = null!;
|
2023-06-01 02:00:19 +08:00
|
|
|
|
2023-06-01 15:34:21 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 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.
|
|
|
|
/// </summary>
|
2024-07-23 20:34:48 +08:00
|
|
|
/// <param name="hitObjects">The hit objects to get the relevant samples from.</param>
|
2023-06-01 15:34:21 +08:00
|
|
|
/// <returns>The relevant list of samples.</returns>
|
2024-07-23 20:34:48 +08:00
|
|
|
protected virtual IEnumerable<(HitObject hitObject, IList<HitSampleInfo> samples)> GetRelevantSamples(HitObject[] hitObjects)
|
|
|
|
{
|
|
|
|
if (hitObjects.Length == 1)
|
|
|
|
{
|
|
|
|
yield return (hitObjects[0], hitObjects[0].Samples);
|
|
|
|
|
|
|
|
yield break;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var ho in hitObjects)
|
|
|
|
{
|
|
|
|
yield return (ho, ho.Samples);
|
|
|
|
|
|
|
|
if (ho is IHasRepeats hasRepeats)
|
|
|
|
{
|
|
|
|
foreach (var node in hasRepeats.NodeSamples)
|
|
|
|
yield return (ho, node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-08 18:38:53 +08:00
|
|
|
|
2021-09-14 17:51:22 +08:00
|
|
|
[Resolved(canBeNull: true)]
|
2021-11-14 00:21:48 +08:00
|
|
|
private EditorBeatmap beatmap { get; set; } = null!;
|
2021-09-14 17:51:22 +08:00
|
|
|
|
2021-09-14 18:21:23 +08:00
|
|
|
public SampleEditPopover(HitObject hitObject)
|
2021-09-14 17:51:22 +08:00
|
|
|
{
|
2021-09-14 18:21:23 +08:00
|
|
|
this.hitObject = hitObject;
|
2021-09-14 17:51:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2022-03-06 08:43:56 +08:00
|
|
|
FillFlowContainer flow;
|
|
|
|
|
2021-09-14 17:51:22 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-03-06 08:43:56 +08:00
|
|
|
flow = new FillFlowContainer
|
2021-09-14 17:51:22 +08:00
|
|
|
{
|
|
|
|
Width = 200,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2021-11-14 01:09:40 +08:00
|
|
|
Spacing = new Vector2(0, 10),
|
2021-09-14 17:51:22 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2023-05-08 21:08:40 +08:00
|
|
|
togglesCollection = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(5, 5),
|
|
|
|
},
|
2021-09-14 17:51:22 +08:00
|
|
|
bank = new LabelledTextBox
|
|
|
|
{
|
|
|
|
Label = "Bank Name",
|
2024-07-10 20:08:36 +08:00
|
|
|
SelectAllOnFocus = true,
|
2021-09-14 17:51:22 +08:00
|
|
|
},
|
2023-05-08 22:12:03 +08:00
|
|
|
additionBank = new LabelledTextBox
|
|
|
|
{
|
|
|
|
Label = "Addition Bank",
|
2024-07-10 20:08:36 +08:00
|
|
|
SelectAllOnFocus = true,
|
2023-05-08 22:12:03 +08:00
|
|
|
},
|
2023-04-26 19:45:58 +08:00
|
|
|
volume = new IndeterminateSliderWithTextBoxInput<int>("Volume", new BindableInt(100)
|
|
|
|
{
|
2023-10-20 20:21:11 +08:00
|
|
|
MinValue = DrawableHitObject.MINIMUM_SAMPLE_VOLUME,
|
2023-04-26 19:45:58 +08:00
|
|
|
MaxValue = 100,
|
|
|
|
})
|
2021-09-14 17:51:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-06 08:43:56 +08:00
|
|
|
bank.TabbableContentContainer = flow;
|
2023-05-08 22:12:03 +08:00
|
|
|
additionBank.TabbableContentContainer = flow;
|
2022-03-06 08:43:56 +08:00
|
|
|
volume.TabbableContentContainer = flow;
|
|
|
|
|
2021-11-14 00:21:48 +08:00
|
|
|
// if the piece belongs to a currently selected object, assume that the user wants to change all selected objects.
|
|
|
|
// if the piece belongs to an unselected object, operate on that object alone, independently of the selection.
|
2023-06-01 02:00:19 +08:00
|
|
|
relevantObjects = (beatmap.SelectedHitObjects.Contains(hitObject) ? beatmap.SelectedHitObjects : hitObject.Yield()).ToArray();
|
2024-07-23 20:34:48 +08:00
|
|
|
allRelevantSamples = GetRelevantSamples(relevantObjects).ToArray();
|
2021-11-14 00:21:48 +08:00
|
|
|
|
|
|
|
// even if there are multiple objects selected, we can still display sample volume or bank if they all have the same value.
|
2023-06-01 02:00:19 +08:00
|
|
|
int? commonVolume = getCommonVolume();
|
2021-11-14 00:21:48 +08:00
|
|
|
if (commonVolume != null)
|
|
|
|
volume.Current.Value = commonVolume.Value;
|
|
|
|
|
2024-06-10 17:51:14 +08:00
|
|
|
updatePrimaryBankState();
|
2021-11-14 01:06:32 +08:00
|
|
|
bank.Current.BindValueChanged(val =>
|
|
|
|
{
|
2024-06-10 17:51:14 +08:00
|
|
|
if (string.IsNullOrEmpty(val.NewValue))
|
|
|
|
return;
|
|
|
|
|
|
|
|
setBank(val.NewValue);
|
|
|
|
updatePrimaryBankState();
|
2021-11-14 01:06:32 +08:00
|
|
|
});
|
2023-04-26 19:45:58 +08:00
|
|
|
// on commit, ensure that the value is correct by sourcing it from the objects' samples again.
|
2021-11-14 01:06:32 +08:00
|
|
|
// this ensures that committing empty text causes a revert to the previous value.
|
2024-06-10 17:51:14 +08:00
|
|
|
bank.OnCommit += (_, _) => updatePrimaryBankState();
|
2021-11-14 01:06:32 +08:00
|
|
|
|
2024-06-10 17:51:14 +08:00
|
|
|
updateAdditionBankState();
|
2023-05-08 22:12:03 +08:00
|
|
|
additionBank.Current.BindValueChanged(val =>
|
|
|
|
{
|
2024-06-10 17:51:14 +08:00
|
|
|
if (string.IsNullOrEmpty(val.NewValue))
|
|
|
|
return;
|
|
|
|
|
|
|
|
setAdditionBank(val.NewValue);
|
|
|
|
updateAdditionBankState();
|
2023-05-08 22:12:03 +08:00
|
|
|
});
|
2024-06-10 17:51:14 +08:00
|
|
|
additionBank.OnCommit += (_, _) => updateAdditionBankState();
|
2023-05-08 22:12:03 +08:00
|
|
|
|
2024-06-10 17:51:14 +08:00
|
|
|
volume.Current.BindValueChanged(val =>
|
|
|
|
{
|
|
|
|
if (val.NewValue != null)
|
|
|
|
setVolume(val.NewValue.Value);
|
|
|
|
});
|
2023-05-08 21:08:40 +08:00
|
|
|
|
2023-06-01 02:00:19 +08:00
|
|
|
createStateBindables();
|
|
|
|
updateTernaryStates();
|
2023-05-08 21:08:40 +08:00
|
|
|
togglesCollection.AddRange(createTernaryButtons().Select(b => new DrawableTernaryButton(b) { RelativeSizeAxes = Axes.None, Size = new Vector2(40, 40) }));
|
2021-11-14 00:21:48 +08:00
|
|
|
}
|
|
|
|
|
2024-07-23 20:34:48 +08:00
|
|
|
private string? getCommonBank() => allRelevantSamples.Select(h => GetBankValue(h.samples)).Distinct().Count() == 1
|
|
|
|
? GetBankValue(allRelevantSamples.First().samples)
|
|
|
|
: null;
|
|
|
|
|
|
|
|
private string? getCommonAdditionBank()
|
|
|
|
{
|
|
|
|
string[] additionBanks = allRelevantSamples.Select(h => GetAdditionBankValue(h.samples)).Where(o => o is not null).Cast<string>().Distinct().ToArray();
|
|
|
|
return additionBanks.Length == 1 ? additionBanks[0] : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int? getCommonVolume() => allRelevantSamples.Select(h => GetVolumeValue(h.samples)).Distinct().Count() == 1
|
|
|
|
? GetVolumeValue(allRelevantSamples.First().samples)
|
|
|
|
: null;
|
2021-11-14 01:06:32 +08:00
|
|
|
|
2024-06-10 17:51:14 +08:00
|
|
|
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;
|
|
|
|
|
2024-07-23 20:34:48 +08:00
|
|
|
bool anyAdditions = allRelevantSamples.Any(o => o.samples.Any(s => s.Name != HitSampleInfo.HIT_NORMAL));
|
2024-06-10 17:51:14 +08:00
|
|
|
if (anyAdditions)
|
|
|
|
additionBank.Show();
|
|
|
|
else
|
|
|
|
additionBank.Hide();
|
|
|
|
}
|
|
|
|
|
2023-06-01 15:50:14 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Applies the given update action on all samples of <see cref="allRelevantSamples"/>
|
|
|
|
/// and invokes the necessary update notifiers for the beatmap and hit objects.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="updateAction">The action to perform on each element of <see cref="allRelevantSamples"/>.</param>
|
|
|
|
private void updateAllRelevantSamples(Action<HitObject, IList<HitSampleInfo>> updateAction)
|
2021-11-14 00:21:48 +08:00
|
|
|
{
|
|
|
|
beatmap.BeginChange();
|
|
|
|
|
2024-07-23 20:34:48 +08:00
|
|
|
foreach (var (relevantHitObject, relevantSamples) in GetRelevantSamples(relevantObjects))
|
2021-11-14 00:21:48 +08:00
|
|
|
{
|
2023-06-01 15:50:14 +08:00
|
|
|
updateAction(relevantHitObject, relevantSamples);
|
|
|
|
beatmap.Update(relevantHitObject);
|
2023-05-08 21:14:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
beatmap.EndChange();
|
|
|
|
}
|
|
|
|
|
2024-06-10 17:51:14 +08:00
|
|
|
private void setBank(string newBank)
|
2023-05-08 21:14:25 +08:00
|
|
|
{
|
2023-06-01 15:50:14 +08:00
|
|
|
updateAllRelevantSamples((_, relevantSamples) =>
|
2023-05-08 21:14:25 +08:00
|
|
|
{
|
2023-06-01 15:50:14 +08:00
|
|
|
for (int i = 0; i < relevantSamples.Count; i++)
|
2023-04-26 19:45:58 +08:00
|
|
|
{
|
2024-08-30 03:54:47 +08:00
|
|
|
if (relevantSamples[i].Name != HitSampleInfo.HIT_NORMAL && !relevantSamples[i].EditorAutoBank) continue;
|
2023-05-08 22:12:03 +08:00
|
|
|
|
2023-06-01 15:50:14 +08:00
|
|
|
relevantSamples[i] = relevantSamples[i].With(newBank: newBank);
|
2023-05-08 22:12:03 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-10 17:51:14 +08:00
|
|
|
private void setAdditionBank(string newBank)
|
2023-05-08 22:12:03 +08:00
|
|
|
{
|
2023-06-01 15:50:14 +08:00
|
|
|
updateAllRelevantSamples((_, relevantSamples) =>
|
2023-05-08 22:12:03 +08:00
|
|
|
{
|
2024-08-30 03:54:47 +08:00
|
|
|
string normalBank = relevantSamples.FirstOrDefault(s => s.Name == HitSampleInfo.HIT_NORMAL)?.Bank ?? HitSampleInfo.BANK_SOFT;
|
|
|
|
|
2023-06-01 15:50:14 +08:00
|
|
|
for (int i = 0; i < relevantSamples.Count; i++)
|
2023-05-08 22:12:03 +08:00
|
|
|
{
|
2024-08-30 03:54:47 +08:00
|
|
|
if (relevantSamples[i].Name == HitSampleInfo.HIT_NORMAL)
|
|
|
|
continue;
|
2023-05-08 22:12:03 +08:00
|
|
|
|
2024-08-30 03:54:47 +08:00
|
|
|
// Addition samples with bank set to auto should inherit the bank of the normal sample
|
|
|
|
if (newBank == EditorSelectionHandler.HIT_BANK_AUTO)
|
|
|
|
{
|
|
|
|
relevantSamples[i] = relevantSamples[i].With(newBank: normalBank, newEditorAutoBank: true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
relevantSamples[i] = relevantSamples[i].With(newBank: newBank, newEditorAutoBank: false);
|
2023-04-26 19:45:58 +08:00
|
|
|
}
|
2023-05-08 21:14:25 +08:00
|
|
|
});
|
2021-11-14 00:21:48 +08:00
|
|
|
}
|
|
|
|
|
2024-06-10 17:51:14 +08:00
|
|
|
private void setVolume(int newVolume)
|
2021-11-14 00:21:48 +08:00
|
|
|
{
|
2023-06-01 15:50:14 +08:00
|
|
|
updateAllRelevantSamples((_, relevantSamples) =>
|
2021-11-14 00:21:48 +08:00
|
|
|
{
|
2023-06-01 15:50:14 +08:00
|
|
|
for (int i = 0; i < relevantSamples.Count; i++)
|
2023-04-26 19:45:58 +08:00
|
|
|
{
|
2024-06-10 17:51:14 +08:00
|
|
|
relevantSamples[i] = relevantSamples[i].With(newVolume: newVolume);
|
2023-04-26 19:45:58 +08:00
|
|
|
}
|
2023-05-08 21:14:25 +08:00
|
|
|
});
|
2021-09-14 17:51:22 +08:00
|
|
|
}
|
2023-05-08 21:08:40 +08:00
|
|
|
|
|
|
|
#region hitsound toggles
|
|
|
|
|
|
|
|
private readonly Dictionary<string, Bindable<TernaryState>> selectionSampleStates = new Dictionary<string, Bindable<TernaryState>>();
|
|
|
|
|
2023-08-17 04:07:36 +08:00
|
|
|
private readonly List<string> banks = new List<string>();
|
|
|
|
|
2023-06-01 02:00:19 +08:00
|
|
|
private void createStateBindables()
|
2023-05-08 21:08:40 +08:00
|
|
|
{
|
|
|
|
foreach (string sampleName in HitSampleInfo.AllAdditions)
|
|
|
|
{
|
|
|
|
var bindable = new Bindable<TernaryState>
|
|
|
|
{
|
|
|
|
Description = sampleName.Replace("hit", string.Empty).Titleize()
|
|
|
|
};
|
|
|
|
|
|
|
|
bindable.ValueChanged += state =>
|
|
|
|
{
|
|
|
|
switch (state.NewValue)
|
|
|
|
{
|
|
|
|
case TernaryState.False:
|
2023-06-01 02:00:19 +08:00
|
|
|
removeHitSample(sampleName);
|
2023-05-08 21:08:40 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TernaryState.True:
|
2023-06-01 02:00:19 +08:00
|
|
|
addHitSample(sampleName);
|
2023-05-08 21:08:40 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
selectionSampleStates[sampleName] = bindable;
|
|
|
|
}
|
2023-08-17 04:07:36 +08:00
|
|
|
|
2024-08-30 03:54:47 +08:00
|
|
|
banks.AddRange(HitSampleInfo.AllBanks.Prepend(EditorSelectionHandler.HIT_BANK_AUTO));
|
2023-05-08 21:08:40 +08:00
|
|
|
}
|
|
|
|
|
2023-06-01 02:00:19 +08:00
|
|
|
private void updateTernaryStates()
|
2023-05-08 21:08:40 +08:00
|
|
|
{
|
|
|
|
foreach ((string sampleName, var bindable) in selectionSampleStates)
|
|
|
|
{
|
2024-07-23 20:34:48 +08:00
|
|
|
bindable.Value = SelectionHandler<HitObject>.GetStateFromSelection(GetRelevantSamples(relevantObjects), h => h.samples.Any(s => s.Name == sampleName));
|
2023-05-08 21:08:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerable<TernaryButton> createTernaryButtons()
|
|
|
|
{
|
|
|
|
foreach ((string sampleName, var bindable) in selectionSampleStates)
|
|
|
|
yield return new TernaryButton(bindable, string.Empty, () => ComposeBlueprintContainer.GetIconForSample(sampleName));
|
|
|
|
}
|
|
|
|
|
2023-06-01 02:00:19 +08:00
|
|
|
private void addHitSample(string sampleName)
|
2023-05-08 21:08:40 +08:00
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(sampleName))
|
|
|
|
return;
|
|
|
|
|
2023-06-01 15:50:14 +08:00
|
|
|
updateAllRelevantSamples((h, relevantSamples) =>
|
2023-05-08 21:08:40 +08:00
|
|
|
{
|
|
|
|
// Make sure there isn't already an existing sample
|
2023-06-01 15:50:14 +08:00
|
|
|
if (relevantSamples.Any(s => s.Name == sampleName))
|
2023-05-08 21:08:40 +08:00
|
|
|
return;
|
|
|
|
|
2023-05-31 22:28:43 +08:00
|
|
|
// First try inheriting the sample info from the node samples instead of the samples of the hitobject
|
2023-06-01 15:50:14 +08:00
|
|
|
var relevantSample = relevantSamples.FirstOrDefault(s => s.Name != HitSampleInfo.HIT_NORMAL) ?? relevantSamples.FirstOrDefault();
|
|
|
|
relevantSamples.Add(relevantSample?.With(sampleName) ?? h.CreateHitSampleInfo(sampleName));
|
2023-05-08 21:14:25 +08:00
|
|
|
});
|
2023-06-01 02:00:19 +08:00
|
|
|
|
2024-06-10 17:51:14 +08:00
|
|
|
updateAdditionBankState();
|
2023-05-08 21:08:40 +08:00
|
|
|
}
|
|
|
|
|
2023-06-01 02:00:19 +08:00
|
|
|
private void removeHitSample(string sampleName)
|
2023-05-08 21:08:40 +08:00
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(sampleName))
|
|
|
|
return;
|
|
|
|
|
2023-06-01 15:50:14 +08:00
|
|
|
updateAllRelevantSamples((_, relevantSamples) =>
|
2023-05-08 21:08:40 +08:00
|
|
|
{
|
2023-06-01 15:50:14 +08:00
|
|
|
for (int i = 0; i < relevantSamples.Count; i++)
|
2023-05-08 21:08:40 +08:00
|
|
|
{
|
2023-06-01 15:50:14 +08:00
|
|
|
if (relevantSamples[i].Name == sampleName)
|
|
|
|
relevantSamples.RemoveAt(i--);
|
2023-05-08 21:08:40 +08:00
|
|
|
}
|
2023-05-08 21:14:25 +08:00
|
|
|
});
|
2023-06-01 02:00:19 +08:00
|
|
|
|
2024-06-10 17:51:14 +08:00
|
|
|
updateAdditionBankState();
|
2023-05-08 21:08:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
{
|
2024-07-15 02:59:46 +08:00
|
|
|
if (e.ControlPressed || e.SuperPressed || !checkRightToggleFromKey(e.Key, out int rightIndex))
|
2023-05-08 21:08:40 +08:00
|
|
|
return base.OnKeyDown(e);
|
|
|
|
|
2024-07-15 02:59:46 +08:00
|
|
|
if (e.ShiftPressed || e.AltPressed)
|
2023-08-17 04:07:36 +08:00
|
|
|
{
|
2023-08-17 05:09:04 +08:00
|
|
|
string? newBank = banks.ElementAtOrDefault(rightIndex);
|
2024-06-10 17:51:14 +08:00
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(newBank))
|
|
|
|
return true;
|
|
|
|
|
2024-08-30 03:54:47 +08:00
|
|
|
if (e.ShiftPressed && newBank != EditorSelectionHandler.HIT_BANK_AUTO)
|
2024-07-15 02:59:46 +08:00
|
|
|
{
|
|
|
|
setBank(newBank);
|
|
|
|
updatePrimaryBankState();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e.AltPressed)
|
|
|
|
{
|
|
|
|
setAdditionBank(newBank);
|
|
|
|
updateAdditionBankState();
|
|
|
|
}
|
2023-08-17 04:07:36 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-08-30 03:54:47 +08:00
|
|
|
var item = togglesCollection.ElementAtOrDefault(rightIndex - 1);
|
2023-05-08 21:08:40 +08:00
|
|
|
|
2023-08-17 04:07:36 +08:00
|
|
|
if (item is not DrawableTernaryButton button) return base.OnKeyDown(e);
|
|
|
|
|
|
|
|
button.Button.Toggle();
|
|
|
|
}
|
2023-05-08 21:08:40 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool checkRightToggleFromKey(Key key, out int index)
|
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
2024-08-30 03:54:47 +08:00
|
|
|
case Key.Q:
|
2023-05-08 21:08:40 +08:00
|
|
|
index = 0;
|
|
|
|
break;
|
|
|
|
|
2024-08-30 03:54:47 +08:00
|
|
|
case Key.W:
|
2023-05-08 21:08:40 +08:00
|
|
|
index = 1;
|
|
|
|
break;
|
|
|
|
|
2024-08-30 03:54:47 +08:00
|
|
|
case Key.E:
|
2023-05-08 21:08:40 +08:00
|
|
|
index = 2;
|
|
|
|
break;
|
|
|
|
|
2024-08-30 03:54:47 +08:00
|
|
|
case Key.R:
|
|
|
|
index = 3;
|
|
|
|
break;
|
|
|
|
|
2023-05-08 21:08:40 +08:00
|
|
|
default:
|
|
|
|
index = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return index >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2021-09-14 17:51:22 +08:00
|
|
|
}
|
2020-10-01 17:49:48 +08:00
|
|
|
}
|
|
|
|
}
|