mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 08:52:55 +08:00
Update taiko selection handler with new logic
This commit is contained in:
parent
a859fe78ee
commit
727ab98d22
@ -1,9 +1,10 @@
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
@ -14,75 +15,80 @@ 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()
|
||||
{
|
||||
selectionStrongState.ValueChanged += state =>
|
||||
{
|
||||
switch (state.NewValue)
|
||||
{
|
||||
case TernaryState.False:
|
||||
SetStrongState(false);
|
||||
break;
|
||||
|
||||
case TernaryState.True:
|
||||
SetStrongState(true);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
selectionRimState.ValueChanged += state =>
|
||||
{
|
||||
switch (state.NewValue)
|
||||
{
|
||||
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))
|
||||
{
|
||||
var hits = selection.Select(s => s.HitObject).OfType<Hit>();
|
||||
|
||||
yield return new TernaryStateMenuItem("Rim", action: state =>
|
||||
{
|
||||
ChangeHandler.BeginChange();
|
||||
|
||||
foreach (var h in hits)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case TernaryState.True:
|
||||
h.Type = HitType.Rim;
|
||||
break;
|
||||
|
||||
case TernaryState.False:
|
||||
h.Type = HitType.Centre;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ChangeHandler.EndChange();
|
||||
})
|
||||
{
|
||||
State = { Value = getTernaryState(hits, h => h.Type == HitType.Rim) }
|
||||
};
|
||||
}
|
||||
yield return new TernaryStateMenuItem("Rim") { State = { BindTarget = selectionRimState } };
|
||||
|
||||
if (selection.All(s => s.HitObject is TaikoHitObject))
|
||||
{
|
||||
var hits = selection.Select(s => s.HitObject).OfType<TaikoHitObject>();
|
||||
|
||||
yield return new TernaryStateMenuItem("Strong", action: state =>
|
||||
{
|
||||
ChangeHandler.BeginChange();
|
||||
|
||||
foreach (var h in hits)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case TernaryState.True:
|
||||
h.IsStrong = true;
|
||||
break;
|
||||
|
||||
case TernaryState.False:
|
||||
h.IsStrong = false;
|
||||
break;
|
||||
}
|
||||
|
||||
EditorBeatmap?.UpdateHitObject(h);
|
||||
}
|
||||
|
||||
ChangeHandler.EndChange();
|
||||
})
|
||||
{
|
||||
State = { Value = getTernaryState(hits, h => h.IsStrong) }
|
||||
};
|
||||
}
|
||||
yield return new TernaryStateMenuItem("Strong") { State = { BindTarget = selectionStrongState } };
|
||||
}
|
||||
|
||||
private TernaryState getTernaryState<T>(IEnumerable<T> selection, Func<T, bool> func)
|
||||
protected override void UpdateTernaryStates()
|
||||
{
|
||||
if (selection.Any(func))
|
||||
return selection.All(func) ? TernaryState.True : TernaryState.Indeterminate;
|
||||
base.UpdateTernaryStates();
|
||||
|
||||
return TernaryState.False;
|
||||
selectionRimState.Value = GetStateFromSelection(SelectedHitObjects.OfType<Hit>(), h => h.Type == HitType.Rim);
|
||||
selectionStrongState.Value = GetStateFromSelection(SelectedHitObjects.OfType<TaikoHitObject>(), h => h.IsStrong);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user