Add right-click menu item to change path type

This commit is contained in:
smoogipoo 2019-12-10 00:07:07 +09:00
parent 0ee303f7d6
commit 9b318d2869
2 changed files with 45 additions and 2 deletions

View File

@ -118,7 +118,7 @@ private void updateDisplay()
protected override bool OnHover(HoverEvent e)
{
updateMarkerDisplay();
return true;
return false;
}
protected override void OnHoverLost(HoverLostEvent e)

View File

@ -1,6 +1,7 @@
// 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 Humanizer;
@ -15,6 +16,7 @@
using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit.Compose;
using osuTK;
@ -161,9 +163,50 @@ public MenuItem[] ContextMenuItems
return new MenuItem[]
{
new OsuMenuItem($"Delete {"control point".ToQuantity(selectedPoints)}", MenuItemType.Destructive, () => deleteSelected())
new OsuMenuItem($"Delete {"control point".ToQuantity(selectedPoints)}", MenuItemType.Destructive, () => deleteSelected()),
new OsuMenuItem("Type")
{
Items = new[]
{
createMenuItemForPathType(null),
createMenuItemForPathType(PathType.Linear),
createMenuItemForPathType(PathType.PerfectCurve),
createMenuItemForPathType(PathType.Catmull)
}
}
};
}
}
private MenuItem createMenuItemForPathType(PathType? type)
{
int totalCount = Pieces.Count(p => p.IsSelected.Value);
int countOfState = Pieces.Where(p => p.IsSelected.Value).Count(p => p.ControlPoint.Type.Value == type);
var item = new PathTypeMenuItem(type, () =>
{
foreach (var p in Pieces.Where(p => p.IsSelected.Value))
p.ControlPoint.Type.Value = type;
});
if (countOfState == totalCount)
item.State.Value = TernaryState.True;
else if (countOfState > 0)
item.State.Value = TernaryState.Indeterminate;
else
item.State.Value = TernaryState.False;
return item;
}
private class PathTypeMenuItem : TernaryStateMenuItem
{
public PathTypeMenuItem(PathType? type, Action action)
: base(type == null ? "Inherit" : type.ToString().Humanize(), changeState, MenuItemType.Standard, _ => action?.Invoke())
{
}
private static TernaryState changeState(TernaryState state) => TernaryState.True;
}
}
}