Add "auto" bank selection during placement

This commit is contained in:
Dean Herbert 2023-05-24 17:11:12 +09:00
parent fc22c75464
commit 3a05dffa50
3 changed files with 30 additions and 6 deletions

View File

@ -32,6 +32,11 @@ namespace osu.Game.Rulesets.Edit
/// </summary>
public PlacementState PlacementActive { get; private set; }
/// <summary>
/// Whether the sample bank should be taken from the previous hit object.
/// </summary>
public bool AutomaticBankAssignment;
/// <summary>
/// The <see cref="HitObject"/> that is being placed.
/// </summary>
@ -86,11 +91,6 @@ namespace osu.Game.Rulesets.Edit
/// <param name="commitStart">Whether this call is committing a value for HitObject.StartTime and continuing with further adjustments.</param>
protected void BeginPlacement(bool commitStart = false)
{
// Take the hitnormal sample of the last hit object
var lastHitNormal = getPreviousHitObject()?.Samples?.FirstOrDefault(o => o.Name == HitSampleInfo.HIT_NORMAL);
if (lastHitNormal != null)
HitObject.Samples[0] = lastHitNormal;
placementHandler.BeginPlacement(HitObject);
if (commitStart)
PlacementActive = PlacementState.Active;
@ -155,6 +155,14 @@ namespace osu.Game.Rulesets.Edit
if (HitObject is IHasComboInformation comboInformation)
comboInformation.UpdateComboInformation(getPreviousHitObject() as IHasComboInformation);
}
if (AutomaticBankAssignment)
{
// Take the hitnormal sample of the last hit object
var lastHitNormal = getPreviousHitObject()?.Samples?.FirstOrDefault(o => o.Name == HitSampleInfo.HIT_NORMAL);
if (lastHitNormal != null)
HitObject.Samples[0] = lastHitNormal;
}
}
/// <summary>

View File

@ -201,6 +201,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
{
if (CurrentPlacement == null) return;
if (bankName == EditorSelectionHandler.HIT_BANK_AUTO)
CurrentPlacement.AutomaticBankAssignment = state == TernaryState.True;
if (state == TernaryState.True)
CurrentPlacement.HitObject.Samples = CurrentPlacement.HitObject.Samples.Select(s => s.With(newBank: bankName)).ToList();
}

View File

@ -21,6 +21,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
{
public partial class EditorSelectionHandler : SelectionHandler<HitObject>
{
/// <summary>
/// A special bank name that is only used in the editor UI.
/// When selected and in placement mode, the bank of the last hit object will always be used.
/// </summary>
public const string HIT_BANK_AUTO = "auto";
[Resolved]
protected EditorBeatmap EditorBeatmap { get; private set; }
@ -59,7 +65,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </summary>
private void createStateBindables()
{
foreach (string bankName in HitSampleInfo.AllBanks)
foreach (string bankName in HitSampleInfo.AllBanks.Prepend(HIT_BANK_AUTO))
{
var bindable = new Bindable<TernaryState>
{
@ -100,6 +106,14 @@ namespace osu.Game.Screens.Edit.Compose.Components
}
else
{
// Auto should just not apply if there's a selection already made.
// Maybe we could make it a disabled button in the future, but right now the editor buttons don't support disabled state.
if (bankName == HIT_BANK_AUTO)
{
bindable.Value = TernaryState.False;
break;
}
AddSampleBank(bankName);
}