2020-05-29 15:40:10 +08: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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-05-29 15:40:10 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2020-09-25 14:32:45 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2020-05-29 15:40:10 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Rulesets.Edit;
|
2021-04-27 14:40:35 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2020-05-29 15:40:10 +08:00
|
|
|
using osu.Game.Rulesets.Taiko.Objects;
|
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.Edit
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class TaikoSelectionHandler : EditorSelectionHandler
|
2020-05-29 15:40:10 +08:00
|
|
|
{
|
2020-09-25 14:32:45 +08:00
|
|
|
private readonly Bindable<TernaryState> selectionRimState = new Bindable<TernaryState>();
|
|
|
|
private readonly Bindable<TernaryState> selectionStrongState = new Bindable<TernaryState>();
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
2020-05-29 15:40:10 +08:00
|
|
|
{
|
2020-09-25 14:32:45 +08:00
|
|
|
selectionStrongState.ValueChanged += state =>
|
2020-05-29 15:40:10 +08:00
|
|
|
{
|
2020-09-25 14:32:45 +08:00
|
|
|
switch (state.NewValue)
|
2020-05-29 15:40:10 +08:00
|
|
|
{
|
2020-09-25 14:32:45 +08:00
|
|
|
case TernaryState.False:
|
|
|
|
SetStrongState(false);
|
|
|
|
break;
|
2020-05-29 15:40:10 +08:00
|
|
|
|
2020-09-25 14:32:45 +08:00
|
|
|
case TernaryState.True:
|
|
|
|
SetStrongState(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2020-05-29 15:40:10 +08:00
|
|
|
|
2020-09-25 14:32:45 +08:00
|
|
|
selectionRimState.ValueChanged += state =>
|
|
|
|
{
|
|
|
|
switch (state.NewValue)
|
2020-05-29 15:40:10 +08:00
|
|
|
{
|
2020-09-25 14:32:45 +08:00
|
|
|
case TernaryState.False:
|
|
|
|
SetRimState(false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TernaryState.True:
|
|
|
|
SetRimState(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetStrongState(bool state)
|
|
|
|
{
|
2021-02-26 13:15:12 +08:00
|
|
|
EditorBeatmap.PerformOnSelection(h =>
|
2020-09-28 13:45:36 +08:00
|
|
|
{
|
2021-02-26 13:15:12 +08:00
|
|
|
if (!(h is Hit taikoHit)) return;
|
|
|
|
|
|
|
|
if (taikoHit.IsStrong != state)
|
2020-09-28 13:45:36 +08:00
|
|
|
{
|
2021-02-26 13:15:12 +08:00
|
|
|
taikoHit.IsStrong = state;
|
|
|
|
EditorBeatmap.Update(taikoHit);
|
2020-09-28 13:45:36 +08:00
|
|
|
}
|
2021-02-26 13:15:12 +08:00
|
|
|
});
|
2020-09-25 14:32:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetRimState(bool state)
|
|
|
|
{
|
2021-02-26 13:15:12 +08:00
|
|
|
EditorBeatmap.PerformOnSelection(h =>
|
|
|
|
{
|
2021-05-23 20:19:38 +08:00
|
|
|
if (h is Hit taikoHit)
|
|
|
|
{
|
|
|
|
taikoHit.Type = state ? HitType.Rim : HitType.Centre;
|
|
|
|
EditorBeatmap.Update(h);
|
|
|
|
}
|
2021-02-26 13:15:12 +08:00
|
|
|
});
|
2020-09-25 14:32:45 +08:00
|
|
|
}
|
|
|
|
|
2021-04-27 14:40:35 +08:00
|
|
|
protected override IEnumerable<MenuItem> GetContextMenuItemsForSelection(IEnumerable<SelectionBlueprint<HitObject>> selection)
|
2020-09-25 14:32:45 +08:00
|
|
|
{
|
2021-04-27 14:40:35 +08:00
|
|
|
if (selection.All(s => s.Item is Hit))
|
2021-05-20 18:34:53 +08:00
|
|
|
yield return new TernaryStateToggleMenuItem("Rim") { State = { BindTarget = selectionRimState } };
|
2020-09-25 14:32:45 +08:00
|
|
|
|
2021-04-27 14:40:35 +08:00
|
|
|
if (selection.All(s => s.Item is TaikoHitObject))
|
2021-05-20 18:34:53 +08:00
|
|
|
yield return new TernaryStateToggleMenuItem("Strong") { State = { BindTarget = selectionStrongState } };
|
2021-04-28 12:43:16 +08:00
|
|
|
|
|
|
|
foreach (var item in base.GetContextMenuItemsForSelection(selection))
|
|
|
|
yield return item;
|
2020-05-29 15:40:10 +08:00
|
|
|
}
|
|
|
|
|
2021-04-27 14:40:35 +08:00
|
|
|
public override bool HandleMovement(MoveSelectionEvent<HitObject> moveEvent) => true;
|
2020-10-08 17:17:57 +08:00
|
|
|
|
2020-09-25 14:32:45 +08:00
|
|
|
protected override void UpdateTernaryStates()
|
2020-05-29 15:40:10 +08:00
|
|
|
{
|
2020-09-25 14:32:45 +08:00
|
|
|
base.UpdateTernaryStates();
|
2020-05-29 15:40:10 +08:00
|
|
|
|
2020-10-09 17:50:05 +08:00
|
|
|
selectionRimState.Value = GetStateFromSelection(EditorBeatmap.SelectedHitObjects.OfType<Hit>(), h => h.Type == HitType.Rim);
|
2020-12-15 04:46:02 +08:00
|
|
|
selectionStrongState.Value = GetStateFromSelection(EditorBeatmap.SelectedHitObjects.OfType<TaikoStrongableHitObject>(), h => h.IsStrong);
|
2020-05-29 15:40:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|