Skip to content

Commit

Permalink
add more keybinding
Browse files Browse the repository at this point in the history
  • Loading branch information
MikiraSora committed Oct 19, 2024
1 parent dc64a56 commit 4bc8361
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,55 +228,62 @@ public async void PasteCopiesObjects(PasteOption mirrorOption, Point? placePoint

await IoC.Get<IFumenEditorClipboard>().PasteObjects(this, mirrorOption, placePoint);
}

public void MenuItemAction_MirrorSelectionXGridZero()
{
var selection = SelectObjects.OfType<OngekiMovableObjectBase>().ToList();
if (selection.Count == 0) {
if (selection.Count == 0)
{
return;
}

var func = () => MirrorObjectsXGrid(selection, true);
UndoRedoManager.ExecuteAction(new LambdaUndoAction(Resources.MirrorSelectionXGridZero, func, func));
}

public void MenuItemAction_MirrorSelectionXGrid()
{
var selection = SelectObjects.OfType<OngekiMovableObjectBase>().ToList();
if (selection.Count == 0) {
if (selection.Count == 0)
{
return;
}

var func = () => MirrorObjectsXGrid(selection, false);
UndoRedoManager.ExecuteAction(new LambdaUndoAction(Resources.MirrorSelectionXGrid, func, func));
}

private void MirrorObjectsXGrid(IList<OngekiMovableObjectBase> objects, bool zeroCenter)
{
int center;
if (zeroCenter) {
if (zeroCenter)
{
center = 0;
}
else {
else
{
var selectionBounds = objects.Aggregate((int.MaxValue, int.MinValue), (bounds, o) =>
{
var min = bounds.Item1;
var max = bounds.Item2;

if (o.XGrid.TotalGrid < min) {

if (o.XGrid.TotalGrid < min)
{
min = o.XGrid.TotalGrid;
}

if (o.XGrid.TotalGrid > max) {
if (o.XGrid.TotalGrid > max)
{
max = o.XGrid.TotalGrid;
}

return (min, max);
});
center = (selectionBounds.MinValue + selectionBounds.MaxValue) / 2;
}

foreach (var obj in objects) {

foreach (var obj in objects)
{
var diff = obj.XGrid.TotalGrid - center;
obj.XGrid = XGrid.FromTotalGrid(center - diff);
}
Expand All @@ -289,23 +296,26 @@ public void MenuItemAction_MirrorLaneColors()
.Where(o => o.Children.All(c => c.IsSelected))
.ToList();

if (laneObjects.Count == 0) {
if (laneObjects.Count == 0)
{
return;
}

List<ConnectableStartObject> newLaneObjects = null;
var executeOrRedo = () =>
{
if (newLaneObjects is null) {
if (newLaneObjects is null)
{
newLaneObjects = MirrorLaneColors(laneObjects).ToList();
}
else {
else
{
Fumen.RemoveObjects(laneObjects);
Fumen.AddObjects(newLaneObjects);
}
newLaneObjects.ForEach(SelectLaneObjects);
};

var undo = () =>
{
Fumen.RemoveObjects(newLaneObjects!);
Expand All @@ -318,7 +328,8 @@ public void MenuItemAction_MirrorLaneColors()

private IEnumerable<ConnectableStartObject> MirrorLaneColors(List<ConnectableStartObject> laneObjects)
{
foreach (var obj in laneObjects) {
foreach (var obj in laneObjects)
{
LaneStartBase startNode = obj.LaneType switch
{
LaneType.Left => new LaneRightStart(),
Expand All @@ -334,14 +345,16 @@ private IEnumerable<ConnectableStartObject> MirrorLaneColors(List<ConnectableSta
startNode.TGrid = obj.TGrid;
startNode.Tag = obj.Tag;

foreach (var child in obj.Children) {
foreach (var child in obj.Children)
{
var newChild = startNode.CreateChildObject();
newChild.XGrid = child.XGrid;
newChild.TGrid = child.TGrid;
newChild.Tag = child.Tag;
newChild.CurvePrecision = child.CurvePrecision;

foreach (var curvePoint in child.PathControls) {
foreach (var curvePoint in child.PathControls)
{
newChild.AddControlObject(new LaneCurvePathControlObject()
{
RefCurveObject = newChild,
Expand All @@ -354,11 +367,13 @@ private IEnumerable<ConnectableStartObject> MirrorLaneColors(List<ConnectableSta
startNode.AddChildObject(newChild);
}

foreach (var tap in Fumen.Taps.Where(t => t.ReferenceLaneStart == obj)) {
foreach (var tap in Fumen.Taps.Where(t => t.ReferenceLaneStart == obj))
{
tap.ReferenceLaneStart = startNode;
}

foreach (var hold in Fumen.Holds.Where(h => h.ReferenceLaneStart == obj)) {
foreach (var hold in Fumen.Holds.Where(h => h.ReferenceLaneStart == obj))
{
hold.ReferenceLaneStart = startNode;
}

Expand Down Expand Up @@ -531,6 +546,42 @@ public void KeyboardAction_FastPlaceDockableObjectToWallLeft()
public void KeyboardAction_FastPlaceDockableObjectToWallRight()
=> KeyboardAction_FastPlaceDockableObject(LaneType.WallRight);

public void KeyboardAction_FastPlaceNewTap(ActionExecutionContext e)
{
var position = Mouse.GetPosition(e.View as FrameworkElement);
position.Y = ViewHeight - position.Y + Rect.MinY;

KeyboardAction_FastPlaceNewObject<Tap>(position);
}

public void KeyboardAction_FastPlaceNewHold(ActionExecutionContext e)
{
var position = Mouse.GetPosition(e.View as FrameworkElement);
position.Y = ViewHeight - position.Y + Rect.MinY;

KeyboardAction_FastPlaceNewObject<Hold>(position);
}

private void KeyboardAction_FastPlaceNewObject<T>(Point position) where T : OngekiObjectBase, new()
{
var tap = new T();
var isFirst = true;
UndoRedoManager.ExecuteAction(LambdaUndoAction.Create("Add {0}".Format(typeof(T).Name), () =>
{
MoveObjectTo(tap, position);
Fumen.AddObject(tap);

if (isFirst)
{
NotifyObjectClicked(tap);
isFirst = false;
}
}, () =>
{
RemoveObject(tap);
}));
}

public void KeyboardAction_FastPlaceDockableObject(LaneType targetType)
{
if ((!SelectObjects.AtCount(1)) || SelectObjects.FirstOrDefault() is not ILaneDockable dockable)
Expand Down Expand Up @@ -820,7 +871,6 @@ public void KeyboardAction_FastAddConnectableChild(ActionExecutionContext e)
return;
var propertyBrowser = IoC.Get<IFumenObjectPropertyBrowser>();


var position = Mouse.GetPosition(e.View as FrameworkElement);
position.Y = ViewHeight - position.Y + Rect.MinY;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:valueconverters="clr-namespace:OngekiFumenEditor.UI.ValueConverters"
xmlns:viewmodels="clr-namespace:OngekiFumenEditor.Modules.FumenVisualEditor.ViewModels"
cal:Message.Attach="[Key OemTilde] = [Action KeyboardAction_FastPlaceDockableObjectToWallLeft]; [Key D4] = [Action KeyboardAction_FastPlaceDockableObjectToWallRight]; [Key D3] = [Action KeyboardAction_FastPlaceDockableObjectToRight]; [Key D2] = [Action KeyboardAction_FastPlaceDockableObjectToCenter]; [Key D1] = [Action KeyboardAction_FastPlaceDockableObjectToLeft]; [Event DragEnter] = [Action Grid_DragEnter($executionContext)]; [Event Drop] = [Action Grid_Drop($executionContext)]; [Event FocusableChanged] = [Action OnFocusableChanged($executionContext)]; [Key Delete] = [Action KeyboardAction_DeleteSelectingObjects]; [Gesture Ctrl+A] = [Action KeyboardAction_SelectAllObjects]; [Key Escape] = [Action KeyboardAction_CancelSelectingObjects]; [Key C] = [Action KeyboardAction_FastSetObjectIsCritical($executionContext)]; [Key Q] = [Action KeyboardAction_HideOrShow];[Key A] = [Action KeyboardAction_FastAddConnectableChild($executionContext)]; [Key F] = [Action KeyboardAction_FastSwitchFlickDirection($executionContext)]; [Gesture Ctrl+C]=[Action MenuItemAction_CopySelectedObjects]; [Gesture Ctrl+V]=[Action MenuItemAction_PasteCopiesObjects]; "
cal:Message.Attach="[Key OemTilde] = [Action KeyboardAction_FastPlaceDockableObjectToWallLeft]; [Key D4] = [Action KeyboardAction_FastPlaceDockableObjectToWallRight]; [Key D3] = [Action KeyboardAction_FastPlaceDockableObjectToRight];[Key H] = [Action KeyboardAction_FastPlaceNewHold($executionContext)];[Key T] = [Action KeyboardAction_FastPlaceNewTap($executionContext)]; [Key D2] = [Action KeyboardAction_FastPlaceDockableObjectToCenter]; [Key D1] = [Action KeyboardAction_FastPlaceDockableObjectToLeft]; [Event DragEnter] = [Action Grid_DragEnter($executionContext)]; [Event Drop] = [Action Grid_Drop($executionContext)]; [Event FocusableChanged] = [Action OnFocusableChanged($executionContext)]; [Key Delete] = [Action KeyboardAction_DeleteSelectingObjects]; [Gesture Ctrl+A] = [Action KeyboardAction_SelectAllObjects]; [Key Escape] = [Action KeyboardAction_CancelSelectingObjects]; [Key C] = [Action KeyboardAction_FastSetObjectIsCritical($executionContext)]; [Key Q] = [Action KeyboardAction_HideOrShow];[Key A] = [Action KeyboardAction_FastAddConnectableChild($executionContext)]; [Key F] = [Action KeyboardAction_FastSwitchFlickDirection($executionContext)]; [Gesture Ctrl+C]=[Action MenuItemAction_CopySelectedObjects]; [Gesture Ctrl+V]=[Action MenuItemAction_PasteCopiesObjects]; "
d:DataContext="{d:DesignInstance Type=viewmodels:FumenVisualEditorViewModel}"
d:DesignHeight="450"
d:DesignWidth="800"
Expand Down Expand Up @@ -60,12 +60,21 @@
<MenuItem cal:Message.Attach="MenuItemAction_RememberSelectedObjectAudioTime()" Header="{markup:Translate [RememberAudioTime]}" />
<MenuItem cal:Message.Attach="MenuItemAction_RecoverySelectedObjectToAudioTime()" Header="{markup:Translate [RecoveryAudioTime]}" />
</MenuItem>

<Separator />

<MenuItem cal:Message.Attach="MenuItemAction_MirrorSelectionXGridZero()" Header="{markup:Translate [MenuMirrorSelectionXGridZero]}" IsEnabled="{Binding SelectObjects, Converter={StaticResource SelectionMovableItemsCheckConverter}}" />
<MenuItem cal:Message.Attach="MenuItemAction_MirrorSelectionXGrid()" Header="{markup:Translate [MenuMirrorSelectionXGrid]}" IsEnabled="{Binding SelectObjects, Converter={StaticResource SelectionMovableItemsCheckConverter}}" />
<MenuItem cal:Message.Attach="MenuItemAction_MirrorLaneColors()" Header="{markup:Translate [MenuMirrorSelectionLaneColors]}" IsEnabled="{Binding SelectObjects, Converter={StaticResource SelectionFullLaneCheckConverter}}" />

<MenuItem
cal:Message.Attach="MenuItemAction_MirrorSelectionXGridZero()"
Header="{markup:Translate [MenuMirrorSelectionXGridZero]}"
IsEnabled="{Binding SelectObjects, Converter={StaticResource SelectionMovableItemsCheckConverter}}" />
<MenuItem
cal:Message.Attach="MenuItemAction_MirrorSelectionXGrid()"
Header="{markup:Translate [MenuMirrorSelectionXGrid]}"
IsEnabled="{Binding SelectObjects, Converter={StaticResource SelectionMovableItemsCheckConverter}}" />
<MenuItem
cal:Message.Attach="MenuItemAction_MirrorLaneColors()"
Header="{markup:Translate [MenuMirrorSelectionLaneColors]}"
IsEnabled="{Binding SelectObjects, Converter={StaticResource SelectionFullLaneCheckConverter}}" />
</MenuItem>
<MenuItem Header="{markup:Translate [ToCopiedObjects]}">
<MenuItem Header="{markup:Translate [ToPaste]}">
Expand Down

0 comments on commit 4bc8361

Please sign in to comment.