From e29fffcbf6cbc426c459156f072ba2edac1716e5 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期三, 06 三月 2024 09:13:44 +0800
Subject: [PATCH] #

---
 zy-asrs-flow/src/pages/map/player.js |   32 ++++++++++++++++----------------
 1 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/zy-asrs-flow/src/pages/map/player.js b/zy-asrs-flow/src/pages/map/player.js
index 2188253..7888d27 100644
--- a/zy-asrs-flow/src/pages/map/player.js
+++ b/zy-asrs-flow/src/pages/map/player.js
@@ -33,8 +33,7 @@
             this.mapEvent = null;
         }
         this.mapEvent = (event) => {
-            // left
-            if (event.button === 0 && leftEvent) {
+            if (leftEvent && event.button === 0) {
                 switch (leftEvent) {
                     case Utils.MapEvent.SELECTION_BOX:
                         this.mapSelect(event);
@@ -43,8 +42,7 @@
                         break
                 }
             }
-            // right
-            if (event.button === 2 && rightEvent) {
+            if (rightEvent && event.button === 2) {
                 switch (rightEvent) {
                     default:
                         break
@@ -56,11 +54,12 @@
 
     mapSelect = (event) => {
         let isSelecting = false;
+        if (!this.selectionBox) {
+            this.selectionBox = new PIXI.Graphics();
+            this.app.stage.addChild(this.selectionBox);
+        }
 
-        const selectionBox = new PIXI.Graphics();
-        this.app.stage.addChild(selectionBox);
-
-        // start
+        // select start pos
         const startPoint = new PIXI.Point();
         this.app.renderer.events.mapPositionToPoint(startPoint, event.clientX, event.clientY);
         let selectionStart = { x: startPoint.x, y: startPoint.y };
@@ -69,7 +68,7 @@
 
         const handleMouseMove = (event) => {
             if (isSelecting && !this.didClickSprite) {
-                // end
+                // select end pos
                 const endPoint = new PIXI.Point();
                 this.app.renderer.events.mapPositionToPoint(endPoint, event.clientX, event.clientY);
                 const selectionEnd = { x: endPoint.x, y: endPoint.y }
@@ -77,11 +76,11 @@
                 const width = Math.abs(selectionEnd.x - selectionStart.x);
                 const height = Math.abs(selectionEnd.y - selectionStart.y);
 
-                selectionBox.clear();
-                selectionBox.lineStyle(2, 0xCCCCCC, 1);
-                selectionBox.beginFill(0xCCCCCC, 0.2);
-                selectionBox.drawRect(Math.min(selectionStart.x, selectionEnd.x), Math.min(selectionStart.y, selectionEnd.y), width, height);
-                selectionBox.endFill();
+                this.selectionBox.clear();
+                this.selectionBox.lineStyle(2, 0xCCCCCC, 1);
+                this.selectionBox.beginFill(0xCCCCCC, 0.2);
+                this.selectionBox.drawRect(Math.min(selectionStart.x, selectionEnd.x), Math.min(selectionStart.y, selectionEnd.y), width, height);
+                this.selectionBox.endFill();
             }
         }
 
@@ -89,6 +88,7 @@
 
         this.mapContainer.parent.on('mouseup', (event) => {
             if (isSelecting) {
+                // sprite show style which be selected
                 if (this.selectedSprites && this.selectedSprites.length > 0) {
                     this.selectedSprites.forEach(child => {
                         Utils.unMarkSprite(child);
@@ -97,13 +97,13 @@
                 this.selectedSprites = [];
 
                 this.mapContainer.children.forEach(child => {
-                    if (Utils.isSpriteInSelectionBox(child, selectionBox)) {
+                    if (Utils.isSpriteInSelectionBox(child, this.selectionBox)) {
                         this.selectedSprites.push(child);
                         Utils.markSprite(child);
                     }
                 })
                 isSelecting = false;
-                selectionBox.clear();
+                this.selectionBox.clear();
 
 
                 // batch move

--
Gitblit v1.9.1