|
|
|
@ -9,9 +9,9 @@ import { AxShape } from './axShape';
|
|
|
|
|
*/ |
|
|
|
|
export class PolygonIcon extends AxShape { |
|
|
|
|
public pointsData: PIXI.Point[]; |
|
|
|
|
public pointsGraphics: PIXI.Graphics[] = []; |
|
|
|
|
public pointsGraphics: PIXI.Sprite[] = []; |
|
|
|
|
public polygonGraphics: PIXI.Graphics = new PIXI.Graphics(); |
|
|
|
|
public polygonLineGraphics: PIXI.Graphics = new PIXI.Graphics(); |
|
|
|
|
// public polygonLineGraphics: PIXI.Graphics = new PIXI.Graphics();
|
|
|
|
|
style = new PIXI.TextStyle({ |
|
|
|
|
fontFamily: 'Arial', |
|
|
|
|
fontSize: 18, |
|
|
|
@ -46,13 +46,14 @@ export class PolygonIcon extends AxShape {
|
|
|
|
|
this.sortableChildren = true; |
|
|
|
|
// 画点
|
|
|
|
|
this.pointsData.forEach((item, index, array) => { |
|
|
|
|
const iconPoint = new PIXI.Graphics(); |
|
|
|
|
iconPoint.lineStyle(1, 0xFFBD01, 1); |
|
|
|
|
iconPoint.beginFill(0xFFFFFF, 1); |
|
|
|
|
iconPoint.drawCircle(0, 0, 15); |
|
|
|
|
const iconPoint = PIXI.Sprite.from(this.pointTexture); |
|
|
|
|
// iconPoint.lineStyle(1, 0xFFBD01, 1);
|
|
|
|
|
// iconPoint.beginFill(0xFFFFFF, 1);
|
|
|
|
|
// iconPoint.drawCircle(0, 0, 15);
|
|
|
|
|
iconPoint.anchor.set(0.5); |
|
|
|
|
iconPoint.x = item.x; |
|
|
|
|
iconPoint.y = item.y; |
|
|
|
|
iconPoint.endFill(); |
|
|
|
|
// iconPoint.endFill();
|
|
|
|
|
iconPoint.visible = false; |
|
|
|
|
this.pointsGraphics.push(iconPoint); |
|
|
|
|
this.addChild(iconPoint); |
|
|
|
@ -66,10 +67,10 @@ export class PolygonIcon extends AxShape {
|
|
|
|
|
this.polygonGraphics.endFill(); |
|
|
|
|
this.addChild(this.polygonGraphics); |
|
|
|
|
// 画多边形
|
|
|
|
|
this.polygonLineGraphics.lineStyle(5, 0xFFBD01, 1); |
|
|
|
|
this.polygonLineGraphics.drawPolygon(this.getPoints()); |
|
|
|
|
this.polygonLineGraphics.closePath(); |
|
|
|
|
this.addChild(this.polygonLineGraphics); |
|
|
|
|
// this.polygonLineGraphics.lineStyle(5, 0xFFBD01, 1);
|
|
|
|
|
// this.polygonLineGraphics.drawPolygon(this.getPoints());
|
|
|
|
|
// this.polygonLineGraphics.closePath();
|
|
|
|
|
// this.addChild(this.polygonLineGraphics);
|
|
|
|
|
|
|
|
|
|
this.text.anchor.set(0.5); |
|
|
|
|
this.text.position = this.calculatePolygonGravityCenter(this.pointsData); |
|
|
|
@ -81,7 +82,7 @@ export class PolygonIcon extends AxShape {
|
|
|
|
|
item.interactive = true; |
|
|
|
|
item.buttonMode = true; |
|
|
|
|
item.zIndex = 1; |
|
|
|
|
item.on('mousedown', event => { |
|
|
|
|
item.on('pointerdown', event => { |
|
|
|
|
event.stopPropagation(); |
|
|
|
|
if (this.workingArea.allowEdit && this.assetData.GameMode === this.workingArea.canvasData.gameMode) { |
|
|
|
|
event.currentTarget.data = event.data; |
|
|
|
@ -89,21 +90,21 @@ export class PolygonIcon extends AxShape {
|
|
|
|
|
event.currentTarget.dragging = true; |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.on('mouseup', event => { |
|
|
|
|
.on('pointerup', event => { |
|
|
|
|
if (event.currentTarget.dragging) { |
|
|
|
|
event.currentTarget.alpha = 1; |
|
|
|
|
event.currentTarget.dragging = false; |
|
|
|
|
event.currentTarget.data = null; |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.on('mouseupoutside', event => { |
|
|
|
|
.on('pointerupoutside', event => { |
|
|
|
|
if (event.currentTarget.dragging) { |
|
|
|
|
event.currentTarget.alpha = 1; |
|
|
|
|
event.currentTarget.dragging = false; |
|
|
|
|
event.currentTarget.data = null; |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.on('mousemove', event => { |
|
|
|
|
.on('pointermove', event => { |
|
|
|
|
if (event.currentTarget.dragging) { |
|
|
|
|
const newPosition = event.currentTarget.data.getLocalPosition(event.currentTarget.parent); |
|
|
|
|
event.currentTarget.x = newPosition.x; |
|
|
|
@ -117,13 +118,14 @@ export class PolygonIcon extends AxShape {
|
|
|
|
|
this.polygonGraphics.beginFill(color, angle); |
|
|
|
|
this.polygonGraphics.drawPolygon(this.getPoints()); |
|
|
|
|
this.polygonGraphics.endFill(); |
|
|
|
|
// 画多边形
|
|
|
|
|
this.polygonLineGraphics.clear(); |
|
|
|
|
this.polygonLineGraphics.lineStyle(5, 0xFFBD01, 1); |
|
|
|
|
this.polygonLineGraphics.drawPolygon(this.getPoints()); |
|
|
|
|
this.polygonLineGraphics.closePath(); |
|
|
|
|
// // 画多边形
|
|
|
|
|
// this.polygonLineGraphics.clear();
|
|
|
|
|
// this.polygonLineGraphics.lineStyle(5, 0xFFBD01, 1);
|
|
|
|
|
// this.polygonLineGraphics.drawPolygon(this.getPoints());
|
|
|
|
|
// this.polygonLineGraphics.closePath();
|
|
|
|
|
|
|
|
|
|
this.text.position = this.calculatePolygonGravityCenter(this.pointsData); |
|
|
|
|
this.drawBorder(1 / this.workingArea.backgroundImage.scale.x); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.on('rightclick', event => { |
|
|
|
@ -134,7 +136,7 @@ export class PolygonIcon extends AxShape {
|
|
|
|
|
this.workingArea.previewImage.visible = false; |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.on('mouseout', event => { |
|
|
|
|
.on('pointerout', event => { |
|
|
|
|
event.stopPropagation(); |
|
|
|
|
if (this.workingArea.previewImage !== null |
|
|
|
|
&& this.workingArea.getPaintMode() === PaintMode.singlePointIcon) { |
|
|
|
@ -142,64 +144,6 @@ export class PolygonIcon extends AxShape {
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
// // 添加选中事件
|
|
|
|
|
// this.polygonGraphics.interactive = true;
|
|
|
|
|
// this.polygonGraphics.buttonMode = true;
|
|
|
|
|
// this.polygonGraphics
|
|
|
|
|
// .on('mousedown', event => {
|
|
|
|
|
// event.stopPropagation();
|
|
|
|
|
// this.workingArea.selection.selectOne(this);
|
|
|
|
|
// if (this.workingArea.allowEdit && this.assetData.GameMode === this.workingArea.canvasData.gameMode) {
|
|
|
|
|
// event.currentTarget.parent.data = event.data;
|
|
|
|
|
// event.currentTarget.parent.alpha = 0.5;
|
|
|
|
|
// event.currentTarget.parent.dragging = true;
|
|
|
|
|
|
|
|
|
|
// event.currentTarget.parent.dragPoint = event.data.getLocalPosition(event.currentTarget.parent.parent);
|
|
|
|
|
// event.currentTarget.parent.dragPoint.x -= event.currentTarget.parent.x;
|
|
|
|
|
// event.currentTarget.parent.dragPoint.y -= event.currentTarget.parent.y;
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// .on('mouseup', event => {
|
|
|
|
|
// if (event.currentTarget.parent.dragging) {
|
|
|
|
|
// event.currentTarget.parent.alpha = 1;
|
|
|
|
|
// event.currentTarget.parent.dragging = false;
|
|
|
|
|
// event.currentTarget.parent.data = null;
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// .on('mouseupoutside', event => {
|
|
|
|
|
// if (event.currentTarget.parent.dragging) {
|
|
|
|
|
// event.currentTarget.parent.alpha = 1;
|
|
|
|
|
// event.currentTarget.parent.dragging = false;
|
|
|
|
|
// event.currentTarget.parent.data = null;
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// .on('mousemove', event => {
|
|
|
|
|
// if (event.currentTarget.parent.dragging) {
|
|
|
|
|
// const newPosition = event.currentTarget.parent.data.getLocalPosition(event.currentTarget.parent.parent);
|
|
|
|
|
// event.currentTarget.parent.x = newPosition.x - event.currentTarget.parent.dragPoint.x;
|
|
|
|
|
// event.currentTarget.parent.y = newPosition.y - event.currentTarget.parent.dragPoint.y;
|
|
|
|
|
|
|
|
|
|
// this.assetData.Point = new PIXI.Point(this.x, this.y);
|
|
|
|
|
// this.workingArea.canvasData.isChange = true;
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// .on('rightclick', event => {
|
|
|
|
|
// // this.workingArea.selection.deselectAll();
|
|
|
|
|
// })
|
|
|
|
|
// .on('mouseover', event => {
|
|
|
|
|
// event.stopPropagation();
|
|
|
|
|
// if (this.workingArea.previewImage !== null
|
|
|
|
|
// && this.workingArea.getPaintMode() === PaintMode.singlePointIcon) {
|
|
|
|
|
// this.workingArea.previewImage.visible = false;
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// .on('mouseout', event => {
|
|
|
|
|
// event.stopPropagation();
|
|
|
|
|
// if (this.workingArea.previewImage !== null
|
|
|
|
|
// && this.workingArea.getPaintMode() === PaintMode.singlePointIcon) {
|
|
|
|
|
// this.workingArea.previewImage.visible = true;
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 设置点显示状态 |
|
|
|
@ -210,31 +154,14 @@ export class PolygonIcon extends AxShape {
|
|
|
|
|
item.visible = value; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public calculatePolygonGravityCenter(points: PIXI.Point[]) { |
|
|
|
|
let area = 0.0; // 多边形面积
|
|
|
|
|
let gravityLat = 0.0; // 重心点 latitude
|
|
|
|
|
let gravityLng = 0.0; // 重心点 longitude
|
|
|
|
|
points.forEach((item, index) => { |
|
|
|
|
// 1
|
|
|
|
|
const lat = item.x; |
|
|
|
|
const lng = item.y; |
|
|
|
|
const nextLat = points[(index + 1) % points.length].x; |
|
|
|
|
const nextLng = points[(index + 1) % points.length].y; |
|
|
|
|
// 2
|
|
|
|
|
const tempArea = (nextLat * lng - nextLng * lat) / 2.0; |
|
|
|
|
// 3
|
|
|
|
|
area += tempArea; |
|
|
|
|
// 4
|
|
|
|
|
gravityLat += tempArea * (lat + nextLat) / 3; |
|
|
|
|
gravityLng += tempArea * (lng + nextLng) / 3; |
|
|
|
|
// 设置缩放
|
|
|
|
|
public setItemScale(scale: number) { |
|
|
|
|
this.text.scale.set(scale); |
|
|
|
|
this.pointsGraphics.forEach(point => { |
|
|
|
|
point.scale.set(scale); |
|
|
|
|
}); |
|
|
|
|
// 5
|
|
|
|
|
gravityLat = gravityLat / area; |
|
|
|
|
gravityLng = gravityLng / area; |
|
|
|
|
|
|
|
|
|
return new PIXI.Point(gravityLat, gravityLng); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取点集合 |
|
|
|
|
*/ |
|
|
|
|