Add ternary toggle buttons to editor toolbox selection

This commit is contained in:
Dean Herbert
2020-09-25 16:33:22 +09:00
parent 0f8551e9ea
commit ae68dcd962
6 changed files with 194 additions and 38 deletions

View File

@ -7,12 +7,16 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Tools;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Screens.Edit.Components.TernaryButtons;
using osuTK;
namespace osu.Game.Screens.Edit.Compose.Components
@ -57,35 +61,26 @@ namespace osu.Game.Screens.Edit.Compose.Components
inputManager = GetContainingInputManager();
Beatmap.SelectedHitObjects.CollectionChanged += (_, __) => updateTogglesFromSelection();
// the updated object may be in the selection
Beatmap.HitObjectUpdated += _ => updateTogglesFromSelection();
// updates to selected are handled for us by SelectionHandler.
NewCombo.BindTo(SelectionHandler.SelectionNewComboState);
// we are responsible for current placement blueprint updated based on state changes.
NewCombo.ValueChanged += combo =>
{
if (Beatmap.SelectedHitObjects.Count > 0)
if (currentPlacement != null)
{
SelectionHandler.SetNewCombo(combo.NewValue);
}
else if (currentPlacement != null)
{
// update placement object from toggle
if (currentPlacement.HitObject is IHasComboInformation c)
c.NewCombo = combo.NewValue;
c.NewCombo = combo.NewValue == TernaryState.True;
}
};
}
private void updateTogglesFromSelection() =>
NewCombo.Value = Beatmap.SelectedHitObjects.OfType<IHasComboInformation>().All(c => c.NewCombo);
public readonly Bindable<TernaryState> NewCombo = new Bindable<TernaryState> { Description = "New Combo" };
public readonly Bindable<bool> NewCombo = new Bindable<bool> { Description = "New Combo" };
public virtual IEnumerable<Bindable<bool>> Toggles => new[]
public virtual IEnumerable<TernaryButton> Toggles => new[]
{
//TODO: this should only be enabled (visible?) for rulesets that provide combo-supporting HitObjects.
NewCombo
new TernaryButton(NewCombo, "New combo", () => new SpriteIcon { Icon = FontAwesome.Regular.DotCircle })
};
#region Placement

View File

@ -316,9 +316,15 @@ namespace osu.Game.Screens.Edit.Compose.Components
#region Selection State
private readonly Bindable<TernaryState> selectionNewComboState = new Bindable<TernaryState>();
/// <summary>
/// The state of "new combo" for all selected hitobjects.
/// </summary>
public readonly Bindable<TernaryState> SelectionNewComboState = new Bindable<TernaryState>();
private readonly Dictionary<string, Bindable<TernaryState>> selectionSampleStates = new Dictionary<string, Bindable<TernaryState>>();
/// <summary>
/// The state of each sample type for all selected hitobjects. Keys match with <see cref="HitSampleInfo"/> constant specifications.
/// </summary>
public readonly Dictionary<string, Bindable<TernaryState>> SelectionSampleStates = new Dictionary<string, Bindable<TernaryState>>();
/// <summary>
/// Set up ternary state bindables and bind them to selection/hitobject changes (in both directions)
@ -349,11 +355,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
}
};
selectionSampleStates[sampleName] = bindable;
SelectionSampleStates[sampleName] = bindable;
}
// new combo
selectionNewComboState.ValueChanged += state =>
SelectionNewComboState.ValueChanged += state =>
{
switch (state.NewValue)
{
@ -377,9 +383,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </summary>
protected virtual void UpdateTernaryStates()
{
selectionNewComboState.Value = GetStateFromSelection(SelectedHitObjects.OfType<IHasComboInformation>(), h => h.NewCombo);
SelectionNewComboState.Value = GetStateFromSelection(SelectedHitObjects.OfType<IHasComboInformation>(), h => h.NewCombo);
foreach (var (sampleName, bindable) in selectionSampleStates)
foreach (var (sampleName, bindable) in SelectionSampleStates)
{
bindable.Value = GetStateFromSelection(SelectedHitObjects, h => h.Samples.Any(s => s.Name == sampleName));
}
@ -413,7 +419,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (selectedBlueprints.All(b => b.HitObject is IHasComboInformation))
{
items.Add(new TernaryStateMenuItem("New combo") { State = { BindTarget = selectionNewComboState } });
items.Add(new TernaryStateMenuItem("New combo") { State = { BindTarget = SelectionNewComboState } });
}
if (selectedBlueprints.Count == 1)
@ -423,7 +429,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
{
new OsuMenuItem("Sound")
{
Items = selectionSampleStates.Select(kvp =>
Items = SelectionSampleStates.Select(kvp =>
new TernaryStateMenuItem(kvp.Value.Description) { State = { BindTarget = kvp.Value } }).ToArray()
},
new OsuMenuItem("Delete", MenuItemType.Destructive, deleteSelected),