1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 13:22:55 +08:00

Add the ability to toggle new combo state from composer context menu

This commit is contained in:
Dean Herbert 2020-09-23 16:38:16 +09:00
parent 7efaa37447
commit a1ec167982
3 changed files with 63 additions and 1 deletions

View File

@ -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>();

View File

@ -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>

View File

@ -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,24 @@ namespace osu.Game.Screens.Edit.Compose.Components
changeHandler?.EndChange();
}
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 +316,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 +348,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 => b.HitObject as IHasComboInformation).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)