Browse Source

完善允许编辑

zhuzhou
徐振升 4 years ago
parent
commit
dc57d61303
  1. 112
      src/app/working-area/model/axGrid.ts
  2. 13
      src/app/working-area/model/axSelection.ts
  3. 10
      src/app/working-area/model/axShape.ts
  4. 19
      src/app/working-area/working-area.component.ts

112
src/app/working-area/model/axGrid.ts

@ -8,58 +8,38 @@ const DEFAULT_LINE_STYLE = {
native: true, native: true,
}; };
/**
* @description
* @extends PIXI.Graphics
*/
export class AxGrid extends PIXI.Graphics { export class AxGrid extends PIXI.Graphics {
private _cellSize: number; private _cellSize: number;
private _correctedWidth: number; private _correctedWidth: number;
private _gridWidth: number; private _gridWidth: number;
private _useCorrectedWidth: boolean; private _useCorrectedWidth: boolean;
private _drawBoundaries: any; private _drawBoundaries: any;
private _amtLines: any; private _amtLines: any;
/**
* @param {number} cellSize 默认值:网格边长的平方根
*/
set cellSize(cellSize) { set cellSize(cellSize) {
this._cellSize = cellSize || Math.sqrt(this._correctedWidth); this._cellSize = cellSize || Math.sqrt(this._correctedWidth);
} }
get cellSize() { get cellSize() {
return this._cellSize; return this._cellSize;
} }
/**
* 线
*/
get amtLines() { get amtLines() {
return Math.floor(this.gridWidth / this.cellSize); return Math.floor(this.gridWidth / this.cellSize);
} }
/**
* ' width '
*/
get originalWidth() { get originalWidth() {
return this._gridWidth; return this._gridWidth;
} }
/** /**
* *
*
*/ */
get correctedWidth() { get correctedWidth() {
return this._correctedWidth; return this._correctedWidth;
} }
get useCorrectedWidth() { get useCorrectedWidth() {
return this._useCorrectedWidth; return this._useCorrectedWidth;
} }
/** /**
* *
* @returns {{ x1: number, y1: number, x2: number, y2: number}}
* (**x1**)(**y1**)(**x2**)(**y2**)
*/ */
get bounds() { get bounds() {
return { return {
@ -78,50 +58,11 @@ export class AxGrid extends PIXI.Graphics {
return this._drawBoundaries; return this._drawBoundaries;
} }
/**
*
* ' cellSize '
* ' width '
*/
get gridWidth() { get gridWidth() {
if (!this.useCorrectedWidth) { return this._gridWidth; } if (!this.useCorrectedWidth) { return this._gridWidth; }
return Math.abs(this.cellSize - Math.sqrt(this._correctedWidth)) <= 1e-6 ? this._correctedWidth : this._gridWidth; return Math.abs(this.cellSize - Math.sqrt(this._correctedWidth)) <= 1e-6 ? this._correctedWidth : this._gridWidth;
} }
/**
*
* @param {number} width number. Required.
*
* The target sidelength of the grid. It is best for `width` to be a perfect square (i.e., 2, 4, 9, 16, 25, etc.). If
* not and the parameter `useCorrectedWidth` is set to **false**, then the grid will use a corrected width,
* which is the smallest perfect square greater than `width`.
*
* @param {number} cellSize number, null. Optional, default: square root of corrected width
*
* The size of each cell in the grid.
* If the value is **null**, the grid will use the default value.
*
* @param {{ width: number, color: number, alpha: number, alignment: number, native: boolean }}. Object. Optional.
*
* default:
* **{
* width: 1,
* color: 0xffffff,
* alpha: 1,
* alignment: 0.5,
* native: true
* }**
*
* Configuration for the line style on the object. See documentation on `PIXI.Graphics` for more on the `LineStyle` class.
*
* @param {boolean} useCorrectedWidth boolean. Optional. default: **true**
* If **true**, the grid will use the smallest perfect square greater than `width`.
* Otherwise, the grid will use the exact value given by `width`.
*
* @param {boolean} drawBoundaries boolean. Optional. default: **true**
* If **true**, the grid will draw its boundaries.
* Otherwise, the grid will not draw its boundaries. Mouse pointer detection is not affected.
*/
constructor( constructor(
width, width,
cellSize= null, cellSize= null,
@ -151,12 +92,9 @@ export class AxGrid extends PIXI.Graphics {
lConfig.alignment, lConfig.alignment,
lConfig.native lConfig.native
); );
// handle mouse move
this.interactive = true; this.interactive = true;
this.on('mousemove', (evt) => { this.on('mousemove', (evt) => {
const mouseCoords = evt.data.getLocalPosition(evt.currentTarget.parent); const mouseCoords = evt.data.getLocalPosition(evt.currentTarget.parent);
// 检查鼠标是否在此网格的范围内。如果不是,那就什么都不做。
if ( if (
mouseCoords.x >= this.bounds.x1 && mouseCoords.x >= this.bounds.x1 &&
mouseCoords.x <= this.bounds.x2 && mouseCoords.x <= this.bounds.x2 &&
@ -192,11 +130,6 @@ export class AxGrid extends PIXI.Graphics {
/** /**
* *
*
* @param {boolean} retainLineStyle true
*
* **true**线
* ' PIXI '
*/ */
clearGrid(retainLineStyle = true) { clearGrid(retainLineStyle = true) {
const { width, alignment, color, alpha, native } = this.line; const { width, alignment, color, alpha, native } = this.line;
@ -207,14 +140,10 @@ export class AxGrid extends PIXI.Graphics {
return this; return this;
} }
/** /**
* Transforms global coordinates to grid coordinates. *
* @param {number} x * @param x x
* The global X coordinate. * @param y y
*
* @param {number} y
* The global Y coordinate.
*/ */
getCellCoordinates(x, y) { getCellCoordinates(x, y) {
return { return {
@ -222,22 +151,15 @@ export class AxGrid extends PIXI.Graphics {
y: Math.floor((y - this.bounds.y1) / this.cellSize), y: Math.floor((y - this.bounds.y1) / this.cellSize),
}; };
} }
/** /**
* mousemove事件后触发的回调 *
* * @param evt
* @param {PIXI.InteractionData} evt * @param gridCoords
* 'PIXI.InteractionData '
*
* @param {{x: number, y: number}} gridCoords
*
*/ */
onMousemove(evt, gridCoords) { onMousemove(evt, gridCoords) {
} }
// 默认宽度
// 计算修正后的宽度。如果`useCorrectedWidth`构造函数参数设置为**false**,
// 然后,它简单地保持“width”的给定值作为修正后的宽度。
_correctWidth() { _correctWidth() {
if (!this._useCorrectedWidth) { if (!this._useCorrectedWidth) {
this._correctedWidth = this._gridWidth; this._correctedWidth = this._gridWidth;
@ -245,9 +167,7 @@ export class AxGrid extends PIXI.Graphics {
this._correctedWidth = Math.ceil(Math.sqrt(this._gridWidth)) ** 2; this._correctedWidth = Math.ceil(Math.sqrt(this._gridWidth)) ** 2;
} }
// 自定义宽度
// 计算修正后的宽度。如果`useCorrectedWidth`构造函数参数设置为**false**,
// 然后,它简单地保持“width”的给定值作为修正后的宽度。
correctWidth(width: number) { correctWidth(width: number) {
if (!this._useCorrectedWidth) { if (!this._useCorrectedWidth) {
this._correctedWidth = width; this._correctedWidth = width;

13
src/app/working-area/model/axSelection.ts

@ -1,3 +1,5 @@
import { allowedNodeEnvironmentFlags } from "process";
/** /**
* *
*/ */
@ -17,6 +19,17 @@ export class AxSelection {
public has(obj: any): boolean { public has(obj: any): boolean {
return this.objects.has(obj); return this.objects.has(obj);
} }
// 是否所有选择对象都允许编辑
public allowEdit(): boolean {
let allowEdit = true;
for (const item of this.objects) {
if (!item.allowEdit) {
allowEdit = false;
break;
}
}
return allowEdit;
}
// 获得所有对象 // 获得所有对象
public all() { public all() {
return [...this.objects]; return [...this.objects];

10
src/app/working-area/model/axShape.ts

@ -10,10 +10,8 @@ export class AxShape extends Graphics {
assetData: any; assetData: any;
pointTexture: PIXI.Texture = PIXI.Texture.from('assets/images/handle-main.png'); pointTexture: PIXI.Texture = PIXI.Texture.from('assets/images/handle-main.png');
workingArea: WorkingAreaComponent; workingArea: WorkingAreaComponent;
// 可以被移动的 // 允许选择
moveable = true; allowSelect = true;
// 可以被选中的
selectable = true;
// 允许编辑 // 允许编辑
allowEdit = true; allowEdit = true;
// 是否显示名称 // 是否显示名称
@ -38,10 +36,10 @@ export class AxShape extends Graphics {
this this
.on('pointerdown', event => { .on('pointerdown', event => {
event.stopPropagation(); event.stopPropagation();
if (this.selectable) { if (this.allowSelect) {
this.workingArea.select(this); this.workingArea.select(this);
} }
if (this.moveable) { if (this.allowEdit) {
this.mouseDragging = true; this.mouseDragging = true;
this.mousePosition = new PIXI.Point(event.data.global.x, event.data.global.y); this.mousePosition = new PIXI.Point(event.data.global.x, event.data.global.y);
} }

19
src/app/working-area/working-area.component.ts

@ -490,21 +490,26 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
switch (floorData[key].InteractiveMode) { switch (floorData[key].InteractiveMode) {
case 0: case 0:
const singleIcon = new AxImageShape(floorData[key], this); const singleIcon = new AxImageShape(floorData[key], this);
singleIcon.moveable = this.allowEdit && this.canvasData.gameMode === singleIcon.assetData.GameMode; singleIcon.allowEdit = this.allowEdit && this.canvasData.gameMode === singleIcon.assetData.GameMode;
break; break;
case 1: case 1:
const icon = new MultipointIcon(floorData[key], this); const icon = new MultipointIcon(floorData[key], this);
icon.allowEdit = this.allowEdit && this.canvasData.gameMode === icon.assetData.GameMode;
break; break;
case 2: case 2:
const polygonIcon = new PolygonIcon(floorData[key], this); const polygonIcon = new PolygonIcon(floorData[key], this);
polygonIcon.allowEdit = this.allowEdit && this.canvasData.gameMode === polygonIcon.assetData.GameMode;
break; break;
case 3: case 3:
if (floorData[key].Name === '水带') { if (floorData[key].Name === '水带') {
const distance = new AxArrowConnector(floorData[key], this, false, true); const waterLine = new AxArrowConnector(floorData[key], this, false, true);
waterLine.allowEdit = this.allowEdit && this.canvasData.gameMode === waterLine.assetData.GameMode;
} else if (floorData[key].Name === '距离') { } else if (floorData[key].Name === '距离') {
const distance = new AxArrowConnector(floorData[key], this, true, true); const distance = new AxArrowConnector(floorData[key], this, true, true);
distance.allowEdit = this.allowEdit && this.canvasData.gameMode === distance.assetData.GameMode;
} else if (floorData[key].Name === '普通墙' || floorData[key].Name === '承重墙') { } else if (floorData[key].Name === '普通墙' || floorData[key].Name === '承重墙') {
const wall = new AxArrowConnector(floorData[key], this, false, false); const wall = new AxArrowConnector(floorData[key], this, false, false);
wall.allowEdit = this.allowEdit && this.canvasData.gameMode === wall.assetData.GameMode;
} }
break; break;
} }
@ -522,22 +527,24 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
switch (nodeData[key][tempKey].InteractiveMode) { switch (nodeData[key][tempKey].InteractiveMode) {
case 0: case 0:
const singleIcon = new AxImageShape(nodeData[key][tempKey], this); const singleIcon = new AxImageShape(nodeData[key][tempKey], this);
singleIcon.moveable = this.allowEdit && this.canvasData.gameMode === singleIcon.assetData.GameMode; singleIcon.allowEdit = this.allowEdit && this.canvasData.gameMode === singleIcon.assetData.GameMode;
break; break;
case 1: case 1:
const icon = new MultipointIcon(nodeData[key][tempKey], this); const icon = new MultipointIcon(nodeData[key][tempKey], this);
break; icon.allowEdit = this.allowEdit && this.canvasData.gameMode === icon.assetData.GameMode;
break;
case 2: case 2:
const polygonIcon = new PolygonIcon(nodeData[key][tempKey], this); const polygonIcon = new PolygonIcon(nodeData[key][tempKey], this);
polygonIcon.allowEdit = this.allowEdit && this.canvasData.gameMode === polygonIcon.assetData.GameMode;
break; break;
case 3: case 3:
const pipeline = new AxArrowConnector(nodeData[key][tempKey], this, false, true); const pipeline = new AxArrowConnector(nodeData[key][tempKey], this, false, true);
pipeline.allowEdit = this.allowEdit && this.canvasData.gameMode === pipeline.assetData.GameMode;
break; break;
} }
}); });
}); });
} }
// this.emit('backgroundScale', this.backgroundImage.scale.x);
} }
/** /**
* *

Loading…
Cancel
Save