osu/osu.Game.Rulesets.Taiko/Edit/TaikoSelectionHandler.cs

95 lines
3.0 KiB
C#
Raw Normal View History

2020-05-29 07:40:10 +00: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.
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2020-05-29 07:40:10 +00:00
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Taiko.Objects;
using osu.Game.Screens.Edit.Compose.Components;
namespace osu.Game.Rulesets.Taiko.Edit
{
public class TaikoSelectionHandler : SelectionHandler
{
private readonly Bindable<TernaryState> selectionRimState = new Bindable<TernaryState>();
private readonly Bindable<TernaryState> selectionStrongState = new Bindable<TernaryState>();
[BackgroundDependencyLoader]
private void load()
2020-05-29 07:40:10 +00:00
{
selectionStrongState.ValueChanged += state =>
2020-05-29 07:40:10 +00:00
{
switch (state.NewValue)
2020-05-29 07:40:10 +00:00
{
case TernaryState.False:
SetStrongState(false);
break;
2020-05-29 07:40:10 +00:00
case TernaryState.True:
SetStrongState(true);
break;
}
};
2020-05-29 07:40:10 +00:00
selectionRimState.ValueChanged += state =>
{
switch (state.NewValue)
2020-05-29 07:40:10 +00:00
{
case TernaryState.False:
SetRimState(false);
break;
case TernaryState.True:
SetRimState(true);
break;
}
};
}
public void SetStrongState(bool state)
{
var hits = SelectedHitObjects.OfType<Hit>();
ChangeHandler.BeginChange();
foreach (var h in hits)
h.IsStrong = state;
ChangeHandler.EndChange();
}
public void SetRimState(bool state)
{
var hits = SelectedHitObjects.OfType<Hit>();
ChangeHandler.BeginChange();
foreach (var h in hits)
h.Type = state ? HitType.Rim : HitType.Centre;
ChangeHandler.EndChange();
}
protected override IEnumerable<MenuItem> GetContextMenuItemsForSelection(IEnumerable<SelectionBlueprint> selection)
{
if (selection.All(s => s.HitObject is Hit))
yield return new TernaryStateMenuItem("Rim") { State = { BindTarget = selectionRimState } };
if (selection.All(s => s.HitObject is TaikoHitObject))
yield return new TernaryStateMenuItem("Strong") { State = { BindTarget = selectionStrongState } };
2020-05-29 07:40:10 +00:00
}
protected override void UpdateTernaryStates()
2020-05-29 07:40:10 +00:00
{
base.UpdateTernaryStates();
2020-05-29 07:40:10 +00:00
selectionRimState.Value = GetStateFromSelection(SelectedHitObjects.OfType<Hit>(), h => h.Type == HitType.Rim);
selectionStrongState.Value = GetStateFromSelection(SelectedHitObjects.OfType<TaikoHitObject>(), h => h.IsStrong);
2020-05-29 07:40:10 +00:00
}
}
}