From a444f3086127e3c26b7177c9339d32b2312d3060 Mon Sep 17 00:00:00 2001 From: MikiraSora Date: Wed, 11 Sep 2024 14:38:44 +0800 Subject: [PATCH] implement drag move for player location recording --- ...tPalleteReferencableBatchDrawTargetBase.cs | 2 +- ...lEditorViewModel.UserInteractionActions.cs | 149 ++++++++++-------- 2 files changed, 80 insertions(+), 71 deletions(-) diff --git a/OngekiFumenEditor/Modules/FumenVisualEditor/Graphics/Drawing/TargetImpl/OngekiObjects/BulletBell/BulletPalleteReferencableBatchDrawTargetBase.cs b/OngekiFumenEditor/Modules/FumenVisualEditor/Graphics/Drawing/TargetImpl/OngekiObjects/BulletBell/BulletPalleteReferencableBatchDrawTargetBase.cs index 895abacf..dd217050 100644 --- a/OngekiFumenEditor/Modules/FumenVisualEditor/Graphics/Drawing/TargetImpl/OngekiObjects/BulletBell/BulletPalleteReferencableBatchDrawTargetBase.cs +++ b/OngekiFumenEditor/Modules/FumenVisualEditor/Graphics/Drawing/TargetImpl/OngekiObjects/BulletBell/BulletPalleteReferencableBatchDrawTargetBase.cs @@ -25,7 +25,7 @@ public abstract class BulletPalleteReferencableBatchDrawTargetBase : CommonBa protected Dictionary> selectedDrawList = new(); protected List<(Vector2 pos, IBulletPalleteReferencable obj)> drawStrList = new(); - private readonly SoflanList nonSoflanList = new(new ISoflan[] { new Soflan() { TGrid = TGrid.Zero, Speed = 1 } }); + private readonly SoflanList nonSoflanList = new([new Soflan() { TGrid = TGrid.Zero, Speed = 1 }]); private readonly IStringDrawing stringDrawing; private readonly IHighlightBatchTextureDrawing highlightDrawing; private readonly IBatchTextureDrawing batchTextureDrawing; diff --git a/OngekiFumenEditor/Modules/FumenVisualEditor/ViewModels/FumenVisualEditorViewModel.UserInteractionActions.cs b/OngekiFumenEditor/Modules/FumenVisualEditor/ViewModels/FumenVisualEditorViewModel.UserInteractionActions.cs index b883dc40..59109a9a 100644 --- a/OngekiFumenEditor/Modules/FumenVisualEditor/ViewModels/FumenVisualEditorViewModel.UserInteractionActions.cs +++ b/OngekiFumenEditor/Modules/FumenVisualEditor/ViewModels/FumenVisualEditorViewModel.UserInteractionActions.cs @@ -1008,92 +1008,101 @@ public async void OnMouseMove(Point pos) if (IsLocked) return; - if (!IsDesignMode) - return; - - if (isMiddleMouseDown) + if (IsDesignMode) { - isCanvasDragging = true; + if (isMiddleMouseDown) + { + isCanvasDragging = true; - var diffX = pos.X - mouseCanvasStartPosition.X; - Setting.XOffset = startXOffset + diffX; + var diffX = pos.X - mouseCanvasStartPosition.X; + Setting.XOffset = startXOffset + diffX; - var curY = pos.Y; - var diffY = curY - mouseCanvasStartPosition.Y; + var curY = pos.Y; + var diffY = curY - mouseCanvasStartPosition.Y; - var canvasY = startScrollOffset + diffY; - var audioTime = TGridCalculator.ConvertYToAudioTime_DesignMode(canvasY, this); - //ScrollViewerVerticalOffset = Math.Max(0, Math.Min(TotalDurationHeight, startScrollOffset + diffY)); - ScrollTo(audioTime); + var canvasY = startScrollOffset + diffY; + var audioTime = TGridCalculator.ConvertYToAudioTime_DesignMode(canvasY, this); + //ScrollViewerVerticalOffset = Math.Max(0, Math.Min(TotalDurationHeight, startScrollOffset + diffY)); + ScrollTo(audioTime); - //Log.LogInfo($"diffY: {diffY:F2} ScrollViewerVerticalOffset: {ScrollViewerVerticalOffset:F2}"); - } + //Log.LogInfo($"diffY: {diffY:F2} ScrollViewerVerticalOffset: {ScrollViewerVerticalOffset:F2}"); + } - if (isLeftMouseDown) - { - var r = isSelectRangeDragging; - isSelectRangeDragging = true; - var dragCall = new Action((vm, pos) => + if (isLeftMouseDown) { - var action = InteractiveManager.GetInteractive(vm); - if (r) - action.OnDragMove(vm, pos, this); - else - action.OnDragStart(vm, pos, this); - }); + var r = isSelectRangeDragging; + isSelectRangeDragging = true; + var dragCall = new Action((vm, pos) => + { + var action = InteractiveManager.GetInteractive(vm); + if (r) + action.OnDragMove(vm, pos, this); + else + action.OnDragStart(vm, pos, this); + }); - var rp = 1 - pos.Y / ViewHeight; - var srp = 1 - mouseSelectRangeStartPosition.Y / ViewHeight; - var offsetY = 0d; + var rp = 1 - pos.Y / ViewHeight; + var srp = 1 - mouseSelectRangeStartPosition.Y / ViewHeight; + var offsetY = 0d; - //const double dragDist = 0.7; - const double trigPrecent = 0.15; - const double autoScrollSpeed = 7; + //const double dragDist = 0.7; + const double trigPrecent = 0.15; + const double autoScrollSpeed = 7; - var offsetYAcc = 0d; - if (rp >= (1 - trigPrecent) && dragOutBound) - offsetYAcc = (rp - (1 - trigPrecent)) / trigPrecent; - else if (rp <= trigPrecent && dragOutBound) - offsetYAcc = rp / trigPrecent - 1; - else if (rp < 1 - trigPrecent && rp > trigPrecent) - dragOutBound = true; //当指针在滑动范围外面,那么就可以进行任何的滑动操作了,避免指针从滑动范围内开始就滚动 - offsetY = offsetYAcc * autoScrollSpeed; + var offsetYAcc = 0d; + if (rp >= (1 - trigPrecent) && dragOutBound) + offsetYAcc = (rp - (1 - trigPrecent)) / trigPrecent; + else if (rp <= trigPrecent && dragOutBound) + offsetYAcc = rp / trigPrecent - 1; + else if (rp < 1 - trigPrecent && rp > trigPrecent) + dragOutBound = true; //当指针在滑动范围外面,那么就可以进行任何的滑动操作了,避免指针从滑动范围内开始就滚动 + offsetY = offsetYAcc * autoScrollSpeed; - var prev = CurrentPlayTime; - var y = Rect.MinY + Setting.JudgeLineOffsetY + offsetY; + var prev = CurrentPlayTime; + var y = Rect.MinY + Setting.JudgeLineOffsetY + offsetY; - //Log.LogDebug($"pos={pos.X:F2},{pos.Y:F2} offsetYAcc={offsetYAcc:F2} dragOutBound={dragOutBound} y={y:F2}"); + //Log.LogDebug($"pos={pos.X:F2},{pos.Y:F2} offsetYAcc={offsetYAcc:F2} dragOutBound={dragOutBound} y={y:F2}"); - if (offsetY != 0) - { - var audioTime = TGridCalculator.ConvertYToAudioTime_DesignMode(y, this); - ScrollTo(audioTime); - } + if (offsetY != 0) + { + var audioTime = TGridCalculator.ConvertYToAudioTime_DesignMode(y, this); + ScrollTo(audioTime); + } - //检查判断,确定是拖动已选物品位置,还是说拉框选择区域 - if (IsRangeSelecting) - { - //拉框 - var p = pos; - p.Y = Math.Min(TotalDurationHeight, Math.Max(0, Rect.MaxY - p.Y + offsetY)); - SelectionCurrentCursorPosition = new Vector2((float)p.X, (float)p.Y); - } - else - { - //拖动已选物件 - var cp = pos; - cp.Y = ViewHeight - cp.Y + Rect.MinY; - //Log.LogDebug($"SelectObjects: {SelectObjects.Count()}"); - SelectObjects.ToArray().ForEach(x => dragCall(x as OngekiObjectBase, cp)); - } + //检查判断,确定是拖动已选物品位置,还是说拉框选择区域 + if (IsRangeSelecting) + { + //拉框 + var p = pos; + p.Y = Math.Min(TotalDurationHeight, Math.Max(0, Rect.MaxY - p.Y + offsetY)); + SelectionCurrentCursorPosition = new Vector2((float)p.X, (float)p.Y); + } + else + { + //拖动已选物件 + var cp = pos; + cp.Y = ViewHeight - cp.Y + Rect.MinY; + //Log.LogDebug($"SelectObjects: {SelectObjects.Count()}"); + SelectObjects.ToArray().ForEach(x => dragCall(x as OngekiObjectBase, cp)); + } - //持续性的 - if (offsetY != 0) + //持续性的 + if (offsetY != 0) + { + var currentid = currentDraggingActionId = MathUtils.Random(int.MaxValue - 1); + await Task.Delay(1000 / 60); + if (currentDraggingActionId == currentid) + OnMouseMove(pos); + } + } + } + else + { + //preview mode + if (isDraggingPlayerLocation) { - var currentid = currentDraggingActionId = MathUtils.Random(int.MaxValue - 1); - await Task.Delay(1000 / 60); - if (currentDraggingActionId == currentid) - OnMouseMove(pos); + //update current dragging player location + draggingPlayerLocationCurrentX = XGridCalculator.ConvertXToXGrid(pos.X, this); } } }