| | |
| | | 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); |
| | |
| | | break |
| | | } |
| | | } |
| | | // right |
| | | if (event.button === 2 && rightEvent) { |
| | | if (rightEvent && event.button === 2) { |
| | | switch (rightEvent) { |
| | | default: |
| | | break |
| | |
| | | |
| | | 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 }; |
| | |
| | | |
| | | 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 } |
| | |
| | | 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(); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | 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); |
| | |
| | | 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 |