From 592ba7890a827b43eae8dacffeacc4f4448be915 Mon Sep 17 00:00:00 2001 From: MikiraSora Date: Tue, 29 Oct 2024 03:54:45 +0800 Subject: [PATCH] add KeyboardAction_ChangeDockableLaneType --- .../KeyBindingDefinitions.cs | 5 ++ ...lEditorViewModel.UserInteractionActions.cs | 87 ++++++++++++++++++- .../Views/FumenVisualEditorView.xaml | 1 + .../Properties/Resources.Designer.cs | 18 ++++ OngekiFumenEditor/Properties/Resources.resx | 6 ++ .../Properties/Resources.zh-Hans.resx | 3 + 6 files changed, 117 insertions(+), 3 deletions(-) diff --git a/OngekiFumenEditor/Modules/FumenVisualEditor/KeyBindingDefinitions.cs b/OngekiFumenEditor/Modules/FumenVisualEditor/KeyBindingDefinitions.cs index f8e1bf78..fc00b11e 100644 --- a/OngekiFumenEditor/Modules/FumenVisualEditor/KeyBindingDefinitions.cs +++ b/OngekiFumenEditor/Modules/FumenVisualEditor/KeyBindingDefinitions.cs @@ -12,6 +12,11 @@ namespace OngekiFumenEditor.Modules.FumenVisualEditor { public static class KeyBindingDefinitions { + [Export] + public static KeyBindingDefinition KBD_ChangeDockableLaneType = new KeyBindingDefinition( + "kbd_editor_ChangeDockableLaneType", + Key.S); + [Export] public static KeyBindingDefinition KBD_FastSetObjectIsCritical = new KeyBindingDefinition( "kbd_editor_FastSetObjectIsCritical", diff --git a/OngekiFumenEditor/Modules/FumenVisualEditor/ViewModels/FumenVisualEditorViewModel.UserInteractionActions.cs b/OngekiFumenEditor/Modules/FumenVisualEditor/ViewModels/FumenVisualEditorViewModel.UserInteractionActions.cs index 32b03b90..1a07221f 100644 --- a/OngekiFumenEditor/Modules/FumenVisualEditor/ViewModels/FumenVisualEditorViewModel.UserInteractionActions.cs +++ b/OngekiFumenEditor/Modules/FumenVisualEditor/ViewModels/FumenVisualEditorViewModel.UserInteractionActions.cs @@ -514,6 +514,84 @@ public void KeyboardAction_FastPlaceNewHold(ActionExecutionContext e) KeyboardAction_FastPlaceNewObject(position); } + public void KeyboardAction_ChangeDockableLaneType(ActionExecutionContext e) + { + if (!( + SelectObjects.IsOnlyOne(out var r) && + r is ConnectableObjectBase connectable && + connectable.ReferenceStartObject is LaneStartBase start && + start.IsDockableLane)) + { + ToastNotify(Resources.SelectOneDockableLaneOnly); + return; + } + + LaneStartBase genStart = start.LaneType switch + { + LaneType.Left => new LaneCenterStart(), + LaneType.Center => new LaneRightStart(), + LaneType.Right => new LaneLeftStart(), + + LaneType.WallRight => new WallLeftStart(), + LaneType.WallLeft => new WallRightStart(), + + _ => throw new NotSupportedException(), + }; + + void CopyCommon(ConnectableObjectBase s, ConnectableObjectBase t) + { + t.TGrid = s.TGrid; + t.XGrid = s.XGrid; + } + + void CopyChild(ConnectableChildObjectBase s, ConnectableChildObjectBase t) + { + CopyCommon(s, t); + + t.CurveInterpolaterFactory = s.CurveInterpolaterFactory; + t.CurvePrecision = s.CurvePrecision; + foreach (var ctrl in s.PathControls) + { + var cp = (LaneCurvePathControlObject)ctrl.CopyNew(); + cp.TGrid = cp.TGrid; + cp.XGrid = cp.XGrid; + t.AddControlObject(cp); + } + } + + //generate and setup new lane. + CopyCommon(start, genStart); + foreach (var child in start.Children) + { + var cpChild = genStart.CreateChildObject(); + CopyChild(child, cpChild); + genStart.AddChildObject(cpChild); + } + + var affactedDockableObjects = Fumen.GetAllDisplayableObjects() + .OfType() + .Where(x => x.ReferenceLaneStart == start) + .ToArray(); + + UndoRedoManager.ExecuteAction(LambdaUndoAction.Create(Resources.kbd_editor_ChangeDockableLaneType, () => + { + RemoveObject(start); + Fumen.AddObject(genStart); + NotifyObjectClicked(genStart); + + foreach (var obj in affactedDockableObjects) + obj.ReferenceLaneStart = genStart; + }, () => + { + RemoveObject(genStart); + Fumen.AddObject(start); + NotifyObjectClicked(start); + + foreach (var obj in affactedDockableObjects) + obj.ReferenceLaneStart = start; + })); + } + private void KeyboardAction_FastPlaceNewObject(Point position) where T : OngekiObjectBase, new() { var tap = new T(); @@ -1113,7 +1191,8 @@ public void OnMouseDown(ActionExecutionContext e) TryCancelAllObjectSelecting(); Log.LogInfo($"SelectionArea ${CurrentCursorPosition}"); - if (!SelectionArea.IsActive) { + if (!SelectionArea.IsActive) + { InitializeSelectionArea(SelectionAreaKind.Select); } } @@ -1173,7 +1252,8 @@ public void InitializeSelectionArea(SelectionAreaKind kind, Point? position = nu { var cursor = position ?? CurrentCursorPosition!.Value; - if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Shift)) { + if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Shift)) + { TryCancelAllObjectSelecting(); } @@ -1709,7 +1789,8 @@ public void ToastNotify(string message) // Check coordinates are the same if (tX.TGrid != obj.TGrid) return false; - if (obj is OngekiMovableObjectBase movable) { + if (obj is OngekiMovableObjectBase movable) + { var mX = (OngekiMovableObjectBase)x; if (movable.XGrid != mX.XGrid) return false; } diff --git a/OngekiFumenEditor/Modules/FumenVisualEditor/Views/FumenVisualEditorView.xaml b/OngekiFumenEditor/Modules/FumenVisualEditor/Views/FumenVisualEditorView.xaml index a2af9afb..92d12d6b 100644 --- a/OngekiFumenEditor/Modules/FumenVisualEditor/Views/FumenVisualEditorView.xaml +++ b/OngekiFumenEditor/Modules/FumenVisualEditor/Views/FumenVisualEditorView.xaml @@ -61,6 +61,7 @@ + diff --git a/OngekiFumenEditor/Properties/Resources.Designer.cs b/OngekiFumenEditor/Properties/Resources.Designer.cs index 64f4e461..e2498713 100644 --- a/OngekiFumenEditor/Properties/Resources.Designer.cs +++ b/OngekiFumenEditor/Properties/Resources.Designer.cs @@ -2967,6 +2967,15 @@ public static string kbd_editor_CancelSelectingObjects { } } + /// + /// 查找类似 Change type of dockable lane 的本地化字符串。 + /// + public static string kbd_editor_ChangeDockableLaneType { + get { + return ResourceManager.GetString("kbd_editor_ChangeDockableLaneType", resourceCulture); + } + } + /// /// 查找类似 Copy selection to clipboard 的本地化字符串。 /// @@ -4848,6 +4857,15 @@ public static string SelectMusicXmlFile { } } + /// + /// 查找类似 的本地化字符串。 + /// + public static string SelectOneDockableLaneOnly { + get { + return ResourceManager.GetString("SelectOneDockableLaneOnly", resourceCulture); + } + } + /// /// 查找类似 Select output folder 的本地化字符串。 /// diff --git a/OngekiFumenEditor/Properties/Resources.resx b/OngekiFumenEditor/Properties/Resources.resx index 91bc7f1a..852dc9a9 100644 --- a/OngekiFumenEditor/Properties/Resources.resx +++ b/OngekiFumenEditor/Properties/Resources.resx @@ -1992,4 +1992,10 @@ Batch + + Change type of dockable lane + + + + \ No newline at end of file diff --git a/OngekiFumenEditor/Properties/Resources.zh-Hans.resx b/OngekiFumenEditor/Properties/Resources.zh-Hans.resx index 08dac1f7..43eb8b9a 100644 --- a/OngekiFumenEditor/Properties/Resources.zh-Hans.resx +++ b/OngekiFumenEditor/Properties/Resources.zh-Hans.resx @@ -1875,4 +1875,7 @@ 批量模式 + + 请选择单独选择一个可击打轨道节点 + \ No newline at end of file