mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 09:07:25 +08:00
Merge pull request #10214 from peppy/new-combo-editor-toggle
Add the ability to toggle new combo state from composer context menu
This commit is contained in:
commit
d1e41e41f7
@ -81,7 +81,7 @@ namespace osu.Game.Tests.Gameplay
|
||||
|
||||
private class TestHitObjectWithCombo : ConvertHitObject, IHasComboInformation
|
||||
{
|
||||
public bool NewCombo { get; } = false;
|
||||
public bool NewCombo { get; set; } = false;
|
||||
public int ComboOffset { get; } = 0;
|
||||
|
||||
public Bindable<int> IndexInCurrentComboBindable { get; } = new Bindable<int>();
|
||||
|
@ -24,6 +24,11 @@ namespace osu.Game.Rulesets.Objects.Types
|
||||
/// </summary>
|
||||
int ComboIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the HitObject starts a new combo.
|
||||
/// </summary>
|
||||
new bool NewCombo { get; set; }
|
||||
|
||||
Bindable<bool> LastInComboBindable { get; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -20,6 +20,7 @@ using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Compose.Components
|
||||
@ -268,6 +269,29 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
changeHandler?.EndChange();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the new combo state of all selected <see cref="HitObject"/>s.
|
||||
/// </summary>
|
||||
/// <param name="state">Whether to set or unset.</param>
|
||||
/// <exception cref="InvalidOperationException">Throws if any selected object doesn't implement <see cref="IHasComboInformation"/></exception>
|
||||
public void SetNewCombo(bool state)
|
||||
{
|
||||
changeHandler?.BeginChange();
|
||||
|
||||
foreach (var h in SelectedHitObjects)
|
||||
{
|
||||
var comboInfo = h as IHasComboInformation;
|
||||
|
||||
if (comboInfo == null)
|
||||
throw new InvalidOperationException($"Tried to change combo state of a {h.GetType()}, which doesn't implement {nameof(IHasComboInformation)}");
|
||||
|
||||
comboInfo.NewCombo = state;
|
||||
EditorBeatmap?.UpdateHitObject(h);
|
||||
}
|
||||
|
||||
changeHandler?.EndChange();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a hit sample from all selected <see cref="HitObject"/>s.
|
||||
/// </summary>
|
||||
@ -297,6 +321,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
|
||||
items.AddRange(GetContextMenuItemsForSelection(selectedBlueprints));
|
||||
|
||||
if (selectedBlueprints.All(b => b.HitObject is IHasComboInformation))
|
||||
items.Add(createNewComboMenuItem());
|
||||
|
||||
if (selectedBlueprints.Count == 1)
|
||||
items.AddRange(selectedBlueprints[0].ContextMenuItems);
|
||||
|
||||
@ -326,6 +353,41 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
protected virtual IEnumerable<MenuItem> GetContextMenuItemsForSelection(IEnumerable<SelectionBlueprint> selection)
|
||||
=> Enumerable.Empty<MenuItem>();
|
||||
|
||||
private MenuItem createNewComboMenuItem()
|
||||
{
|
||||
return new TernaryStateMenuItem("New combo", MenuItemType.Standard, setNewComboState)
|
||||
{
|
||||
State = { Value = getHitSampleState() }
|
||||
};
|
||||
|
||||
void setNewComboState(TernaryState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case TernaryState.False:
|
||||
SetNewCombo(false);
|
||||
break;
|
||||
|
||||
case TernaryState.True:
|
||||
SetNewCombo(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TernaryState getHitSampleState()
|
||||
{
|
||||
int countExisting = selectedBlueprints.Select(b => (IHasComboInformation)b.HitObject).Count(h => h.NewCombo);
|
||||
|
||||
if (countExisting == 0)
|
||||
return TernaryState.False;
|
||||
|
||||
if (countExisting < SelectedHitObjects.Count())
|
||||
return TernaryState.Indeterminate;
|
||||
|
||||
return TernaryState.True;
|
||||
}
|
||||
}
|
||||
|
||||
private MenuItem createHitSampleMenuItem(string name, string sampleName)
|
||||
{
|
||||
return new TernaryStateMenuItem(name, MenuItemType.Standard, setHitSampleState)
|
||||
|
Loading…
Reference in New Issue
Block a user