@@ -12,15 +12,19 @@ import { ControllerClass } from "../ControllerClass";
1212 * 拖拽节点使其移动的控制器
1313 *
1414 */
15- export const ControllerEntityMove = new ControllerClass ( ) ;
15+ export const ControllerEntityClickSelectAndMove = new ControllerClass ( ) ;
1616
17- ControllerEntityMove . mousedown = ( event : MouseEvent ) => {
17+ let isMovingEntity = false ;
18+ let mouseDownViewLocation = Vector . getZero ( ) ;
19+
20+ ControllerEntityClickSelectAndMove . mousedown = ( event : MouseEvent ) => {
1821 if ( event . button !== 0 ) {
1922 return ;
2023 }
24+ mouseDownViewLocation = new Vector ( event . clientX , event . clientY ) ;
2125
22- const pressWorldLocation = Renderer . transformView2World ( new Vector ( event . clientX , event . clientY ) ) ;
23- ControllerEntityMove . lastMoveLocation = pressWorldLocation . clone ( ) ;
26+ const pressWorldLocation = Renderer . transformView2World ( mouseDownViewLocation ) ;
27+ ControllerEntityClickSelectAndMove . lastMoveLocation = pressWorldLocation . clone ( ) ;
2428 const clickedEntity = StageManager . findConnectableEntityByLocation ( pressWorldLocation ) ;
2529
2630 // 防止跳跃式移动的时候改变选中内容
@@ -30,7 +34,7 @@ ControllerEntityMove.mousedown = (event: MouseEvent) => {
3034
3135 // 单击选中
3236 if ( clickedEntity !== null ) {
33- Controller . isMovingEntity = true ;
37+ isMovingEntity = true ;
3438
3539 if ( Controller . pressingKeySet . has ( "shift" ) && Controller . pressingKeySet . has ( "control" ) ) {
3640 // ctrl + shift 同时按下
@@ -72,19 +76,19 @@ ControllerEntityMove.mousedown = (event: MouseEvent) => {
7276 }
7377} ;
7478
75- ControllerEntityMove . mousemove = ( event : MouseEvent ) => {
79+ ControllerEntityClickSelectAndMove . mousemove = ( event : MouseEvent ) => {
7680 if ( Stage . selectMachine . isUsing || Stage . cuttingMachine . isUsing || Controller . pressingKeySet . has ( "alt" ) ) {
7781 return ;
7882 }
79- if ( ! Controller . isMovingEntity ) {
83+ if ( ! isMovingEntity ) {
8084 return ;
8185 }
8286 const worldLocation = Renderer . transformView2World ( new Vector ( event . clientX , event . clientY ) ) ;
83- const diffLocation = worldLocation . subtract ( ControllerEntityMove . lastMoveLocation ) ;
87+ const diffLocation = worldLocation . subtract ( ControllerEntityClickSelectAndMove . lastMoveLocation ) ;
8488
8589 if ( StageManager . isHaveEntitySelected ( ) ) {
8690 // 移动节点
87- Controller . isMovingEntity = true ;
91+ isMovingEntity = true ;
8892 // 暂不监听alt键。因为windows下切换窗口时,alt键释放监听不到
8993 if ( Controller . pressingKeySet . has ( "control" ) ) {
9094 // 和子节点一起移动
@@ -104,21 +108,28 @@ ControllerEntityMove.mousemove = (event: MouseEvent) => {
104108 StageManager . preAlignAllSelected ( ) ;
105109 }
106110
107- ControllerEntityMove . lastMoveLocation = worldLocation . clone ( ) ;
111+ ControllerEntityClickSelectAndMove . lastMoveLocation = worldLocation . clone ( ) ;
108112 }
109113} ;
110114
111- ControllerEntityMove . mouseup = ( event : MouseEvent ) => {
115+ ControllerEntityClickSelectAndMove . mouseup = ( event : MouseEvent ) => {
112116 if ( event . button !== 0 ) {
113117 return ;
114118 }
115- if ( Controller . isMovingEntity ) {
116- // 这个时候可以触发对齐吸附事件
117- if ( Stage . enableDragAutoAlign ) {
118- StageManager . alignAllSelected ( ) ;
119- }
120119
121- StageManager . moveEntityFinished ( ) ;
120+ const mouseUpViewLocation = new Vector ( event . clientX , event . clientY ) ;
121+ const diffLocation = mouseUpViewLocation . subtract ( mouseDownViewLocation ) ;
122+ if ( diffLocation . magnitude ( ) > 5 ) {
123+ // 判定为有效吸附的拖拽操作
124+ if ( isMovingEntity ) {
125+ // 这个时候可以触发对齐吸附事件
126+ if ( Stage . enableDragAutoAlign ) {
127+ StageManager . alignAllSelected ( ) ;
128+ }
129+
130+ StageManager . moveEntityFinished ( ) ;
131+ }
122132 }
123- Controller . isMovingEntity = false ;
133+
134+ isMovingEntity = false ;
124135} ;
0 commit comments