From 9c4e5b27355a620d0d170cf9f8986f936bc76d65 Mon Sep 17 00:00:00 2001 From: fengjiayi <12821976+ning_xi@user.noreply.gitee.com> Date: Fri, 30 May 2025 14:05:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E8=BF=9E=E6=8E=A5=E5=85=B3=E7=B3=BB=E6=97=B6?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E8=B0=83=E7=94=A8=E5=85=B3=E7=B3=BB=E4=B9=9F?= =?UTF-8?q?=E8=A2=AB=E5=88=A0=E9=99=A4=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Node/Junction/JunctionControlBase.cs | 27 +++++++++++-------- .../Junction/View/ResultJunctionControl.cs | 2 -- Workbench/Node/View/ConnectionControl.cs | 6 +++-- Workbench/Node/View/ScriptNodeControl.xaml.cs | 7 ----- Workbench/Views/FlowCanvasView.xaml.cs | 8 +++--- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/Workbench/Node/Junction/JunctionControlBase.cs b/Workbench/Node/Junction/JunctionControlBase.cs index 1d810d5..6f3e6a9 100644 --- a/Workbench/Node/Junction/JunctionControlBase.cs +++ b/Workbench/Node/Junction/JunctionControlBase.cs @@ -15,6 +15,7 @@ using System.Threading; using Serein.Workbench.Services; using Serein.Workbench.Tool; using System.ComponentModel; +using System.Diagnostics; namespace Serein.Workbench.Node.View { @@ -48,7 +49,7 @@ namespace Serein.Workbench.Node.View this.MouseDown += ParamsArg_OnMouseDown; // 增加或删除 this.MouseMove += ParamsArgControl_MouseMove; this.MouseLeave += ParamsArgControl_MouseLeave; - AddOrRemoveParamsTask = AddAsync; + AddOrRemoveParamsTask = AddParamAsync; } @@ -120,18 +121,18 @@ namespace Serein.Workbench.Node.View private void ParamsArgControl_MouseMove(object sender, MouseEventArgs e) { isMouseOver = true; - if (cancellationTokenSource.IsCancellationRequested) { - cancellationTokenSource = new CancellationTokenSource(); + if (cts.IsCancellationRequested) { + cts = new CancellationTokenSource(); Task.Run(async () => { await Task.Delay(380); - }, cancellationTokenSource.Token).ContinueWith((t) => + }, cts.Token).ContinueWith((t) => { // 如果焦点仍在控件上时,则改变点击事件 if (isMouseOver) { - AddOrRemoveParamsTask = RemoveAsync; + AddOrRemoveParamsTask = RemoveParamAsync; this.Dispatcher.Invoke(InvalidateVisual);// 触发一次重绘 } @@ -139,24 +140,27 @@ namespace Serein.Workbench.Node.View } } - private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); + + + private CancellationTokenSource cts = new CancellationTokenSource(); private void ParamsArgControl_MouseLeave(object sender, MouseEventArgs e) { isMouseOver = false; - AddOrRemoveParamsTask = AddAsync; // 鼠标焦点离开时恢复点击事件 - cancellationTokenSource?.Cancel(); + AddOrRemoveParamsTask = AddParamAsync; // 鼠标焦点离开时恢复点击事件 + cts?.Cancel(); this.Dispatcher.Invoke(InvalidateVisual);// 触发一次重绘 } - private async Task AddAsync() + + private async Task AddParamAsync() { await this.MyNode.Env.ChangeParameter(MyNode.Guid, true, ArgIndex); } - private async Task RemoveAsync() + private async Task RemoveParamAsync() { await this.MyNode.Env.ChangeParameter(MyNode.Guid, false, ArgIndex); } @@ -347,7 +351,7 @@ namespace Serein.Workbench.Node.View { if (e.LeftButton == MouseButtonState.Pressed) { - var canvas = WpfFuncTool.GetParentOfType(this); + var canvas = WpfFuncTool.GetParentOfType(this); if (canvas != null) { var cd = flowNodeService.ConnectingData; @@ -358,6 +362,7 @@ namespace Serein.Workbench.Node.View cd.StartPoint = this.TranslatePoint(new Point(this.Width / 2, this.Height / 2), canvas); var junctionOfConnectionType = this.JunctionType.ToConnectyionType(); + //Debug.WriteLine(this.JunctionType); ConnectionLineShape bezierLine; // 类别 Brush brushColor; // 临时线的颜色 if (junctionOfConnectionType == JunctionOfConnectionType.Invoke) diff --git a/Workbench/Node/Junction/View/ResultJunctionControl.cs b/Workbench/Node/Junction/View/ResultJunctionControl.cs index aaad0d3..c0d8c88 100644 --- a/Workbench/Node/Junction/View/ResultJunctionControl.cs +++ b/Workbench/Node/Junction/View/ResultJunctionControl.cs @@ -8,8 +8,6 @@ namespace Serein.Workbench.Node.View public class ResultJunctionControl : JunctionControlBase { - //public override JunctionType JunctionType { get; } = JunctionType.ReturnData; - public ResultJunctionControl() { base.JunctionType = JunctionType.ReturnData; diff --git a/Workbench/Node/View/ConnectionControl.cs b/Workbench/Node/View/ConnectionControl.cs index cda5603..22ca675 100644 --- a/Workbench/Node/View/ConnectionControl.cs +++ b/Workbench/Node/View/ConnectionControl.cs @@ -239,11 +239,13 @@ namespace Serein.Workbench.Node.View Canvas.Children.Remove(BezierLine); var env = Start.MyNode.Env; var canvasGuid = Start.MyNode.CanvasDetails.Guid; - if (Start.JunctionType.ToConnectyionType() == JunctionOfConnectionType.Invoke) + var jct = Start.JunctionType.ToConnectyionType(); + var jctEnd = End.JunctionType.ToConnectyionType(); + if (jct == JunctionOfConnectionType.Invoke) { env.RemoveConnectInvokeAsync(canvasGuid, Start.MyNode.Guid, End.MyNode.Guid, InvokeType); } - else if (Start.JunctionType.ToConnectyionType() == JunctionOfConnectionType.Arg) + else if (jct == JunctionOfConnectionType.Arg) { env.RemoveConnectArgSourceAsync(canvasGuid,Start.MyNode.Guid, End.MyNode.Guid, ArgIndex) ; } diff --git a/Workbench/Node/View/ScriptNodeControl.xaml.cs b/Workbench/Node/View/ScriptNodeControl.xaml.cs index a618463..101e255 100644 --- a/Workbench/Node/View/ScriptNodeControl.xaml.cs +++ b/Workbench/Node/View/ScriptNodeControl.xaml.cs @@ -41,13 +41,6 @@ namespace Serein.Workbench.Node.View { DataContext = viewModel; InitializeComponent(); - -#if false - // 初始化定时器 - _debounceTimer = new DispatcherTimer(); - _debounceTimer.Interval = TimeSpan.FromMilliseconds(500); // 停止输入 500ms 后更新 - _debounceTimer.Tick += DebounceTimer_Tick; -#endif } diff --git a/Workbench/Views/FlowCanvasView.xaml.cs b/Workbench/Views/FlowCanvasView.xaml.cs index 7deaf60..975e07a 100644 --- a/Workbench/Views/FlowCanvasView.xaml.cs +++ b/Workbench/Views/FlowCanvasView.xaml.cs @@ -411,10 +411,10 @@ namespace Serein.Workbench.Views JunctionControlBase endJunction = IToJunction.ExecuteJunction; var removeConnections = Connections.Where(c => - c.Start.Equals(startJunction) - && c.End.Equals(endJunction) - && (c.Start.JunctionType.ToConnectyionType() == JunctionOfConnectionType.Invoke - || c.End.JunctionType.ToConnectyionType() == JunctionOfConnectionType.Invoke)) + c.Start.MyNode.Guid == startJunction.MyNode.Guid + && c.End.MyNode.Guid == endJunction.MyNode.Guid + && (c.Start.JunctionType.ToConnectyionType() == JunctionOfConnectionType.Arg + || c.End.JunctionType.ToConnectyionType() == JunctionOfConnectionType.Arg)) .ToList();