浙大网新esb调整

This commit is contained in:
fan 2023-11-13 17:45:55 +08:00
parent 0d7a80f399
commit 6655cdf865
4 changed files with 72 additions and 18 deletions

View File

@ -148,6 +148,7 @@ export class DrawZdwxEsbInteraction extends GraphicInteractionPlugin<ZdwxEsb> {
this.app.updateSelected(esbButton); this.app.updateSelected(esbButton);
flipConfig.handler = () => { flipConfig.handler = () => {
esbButton.datas.flip = !esbButton.datas.flip; esbButton.datas.flip = !esbButton.datas.flip;
console.log(esbButton.datas, 'data');
esbButton.repaint(); esbButton.repaint();
}; };
EsbButtonEditMenu.open(e.global); EsbButtonEditMenu.open(e.global);

View File

@ -41,7 +41,7 @@ import { SignalData, SignalState } from './graphics/SignalInteraction';
import { getCategoryConsts } from './gategoryConsts'; import { getCategoryConsts } from './gategoryConsts';
import { CategoryType } from 'src/components/CategoryType'; import { CategoryType } from 'src/components/CategoryType';
import { ZdwxEsbDraw } from 'src/graphics/esbButton/ZdwxEsbDrawAssistant'; import { ZdwxEsbDraw } from 'src/graphics/esbButton/ZdwxEsbDrawAssistant';
import { ZdwxEsbTemplate } from 'src/graphics/esbButton/ZdwxEsb'; import { ZdwxEsb, ZdwxEsbTemplate } from 'src/graphics/esbButton/ZdwxEsb';
import { import {
DrawZdwxEsbInteraction, DrawZdwxEsbInteraction,
ZdwxEsbData, ZdwxEsbData,
@ -152,6 +152,9 @@ export async function loadZdwxDrawDatas(): Promise<IGraphicStorage> {
storage.beacons.forEach((beacon) => { storage.beacons.forEach((beacon) => {
datas.push(new BeaconData(beacon)); datas.push(new BeaconData(beacon));
}); });
storage.esbButtons.forEach((esbButton) => {
datas.push(new ZdwxEsbData(esbButton));
});
refDevicesList = storage.stationRelateDeviceList; refDevicesList = storage.stationRelateDeviceList;
return Promise.resolve({ return Promise.resolve({
canvasProperty: storage.canvas, canvasProperty: storage.canvas,
@ -180,6 +183,9 @@ export function saveZdwxDrawDatas(app: IDrawApp) {
} else if (Beacon.Type === g.type) { } else if (Beacon.Type === g.type) {
const beaconData = (g as Beacon).saveData(); const beaconData = (g as Beacon).saveData();
storage.beacons.push((beaconData as BeaconData).data); storage.beacons.push((beaconData as BeaconData).data);
} else if (ZdwxEsb.Type === g.type) {
const zdwxEsbData = (g as ZdwxEsb).saveData();
storage.esbButtons.push((zdwxEsbData as ZdwxEsbData).data);
} }
}); });
const base64 = fromUint8Array(storage.serialize()); const base64 = fromUint8Array(storage.serialize());

View File

@ -27,19 +27,19 @@ export interface IZdwxEsbState extends GraphicState {
set down(v: boolean); set down(v: boolean);
} }
const zdwxEsbConsts = { export const zdwxEsbConsts = {
codeFontSize: 12, codeFontSize: 12,
codeColor: 0xffffff, codeColor: 0xffffff,
bodyLineColor: 0xff0000, bodyLineColor: 0xff0000,
bodyLineWidth: 2, lineWidth: 2,
bodyRectLineColor: 0xff0000, bodyRectLineColor: 0xff0000,
bodyRectLineWidth: 1, bodyRectLineWidth: 1,
bodyRectWidth: 20, bodyRectWidth: 20,
bodyRectHeight: 20, bodyRectHeight: 20,
bodyCircleRadius: 4, bodyCircleRadius: 4,
bodyCircleColor: 0xff0000, bodyColor: 0xff0000,
bodyColor: 0x000000, rectOffset1: -9,
pressedColor: 0xff0000, rectOffset2: -12,
}; };
export class ZdwxEsb extends JlGraphic { export class ZdwxEsb extends JlGraphic {
static Type = 'esbButton'; static Type = 'esbButton';
@ -76,17 +76,32 @@ export class ZdwxEsb extends JlGraphic {
codeGraph.position.set(-30, 0); codeGraph.position.set(-30, 0);
} }
this.circleBody.clear(); this.circleBody.clear();
this.circleBody.lineStyle( this.circleBody.lineStyle(zdwxEsbConsts.lineWidth, zdwxEsbConsts.bodyColor);
zdwxEsbConsts.bodyLineWidth, if (this.datas.flip) {
zdwxEsbConsts.bodyCircleColor this.circleBody.arc(0, 0, zdwxEsbConsts.bodyCircleRadius, 0, Math.PI);
); this.circleBody.moveTo(0, 0);
this.circleBody.lineTo(0, -6);
this.circleBody.moveTo(-4, 0);
this.circleBody.lineTo(4, 0);
} else {
this.circleBody.arc(0, 0, zdwxEsbConsts.bodyCircleRadius, Math.PI, 0); this.circleBody.arc(0, 0, zdwxEsbConsts.bodyCircleRadius, Math.PI, 0);
this.circleBody.moveTo(0, 0); this.circleBody.moveTo(0, 0);
this.circleBody.lineTo(0, 6); this.circleBody.lineTo(0, 6);
this.circleBody.moveTo(-4, 0); this.circleBody.moveTo(-4, 0);
this.circleBody.lineTo(4, 0); this.circleBody.lineTo(4, 0);
this.circleBody.drawRect(-9, -9, 20, 20); }
this.circleBody.drawRect(-12, -12, 20, 20); this.circleBody.drawRect(
zdwxEsbConsts.rectOffset1,
zdwxEsbConsts.rectOffset1,
zdwxEsbConsts.bodyRectWidth,
zdwxEsbConsts.bodyRectHeight
);
this.circleBody.drawRect(
zdwxEsbConsts.rectOffset2,
zdwxEsbConsts.rectOffset2,
zdwxEsbConsts.bodyRectWidth,
zdwxEsbConsts.bodyRectHeight
);
} }
} }

View File

@ -1,4 +1,4 @@
import { DisplayObject, FederatedMouseEvent, Point } from 'pixi.js'; import { DisplayObject, FederatedMouseEvent, IHitArea, Point } from 'pixi.js';
import { import {
AbsorbableLine, AbsorbableLine,
AbsorbablePosition, AbsorbablePosition,
@ -8,7 +8,12 @@ import {
IDrawApp, IDrawApp,
JlGraphic, JlGraphic,
} from 'src/jl-graphic'; } from 'src/jl-graphic';
import { ZdwxEsb, ZdwxEsbTemplate, IZdwxEsbData } from './ZdwxEsb'; import {
ZdwxEsb,
ZdwxEsbTemplate,
IZdwxEsbData,
zdwxEsbConsts,
} from './ZdwxEsb';
export interface IZdwxEsbDataDrawOptions { export interface IZdwxEsbDataDrawOptions {
newData: () => IZdwxEsbData; newData: () => IZdwxEsbData;
@ -78,6 +83,32 @@ function buildAbsorbablePositions(zdwxEsb: ZdwxEsb): AbsorbablePosition[] {
return aps; return aps;
} }
export class EsbBodyHitArea implements IHitArea {
zdwxEsb: ZdwxEsb;
constructor(zdwxEsb: ZdwxEsb) {
this.zdwxEsb = zdwxEsb;
}
contains(x: number, y: number): boolean {
let flag = false;
if (
x >= zdwxEsbConsts.rectOffset1 &&
x <= zdwxEsbConsts.rectOffset1 + zdwxEsbConsts.bodyRectWidth &&
y >= zdwxEsbConsts.rectOffset1 &&
y <= zdwxEsbConsts.rectOffset1 + zdwxEsbConsts.bodyRectHeight
) {
flag = true;
} else if (
x >= zdwxEsbConsts.rectOffset2 &&
x <= zdwxEsbConsts.rectOffset2 + zdwxEsbConsts.bodyRectWidth &&
y >= zdwxEsbConsts.rectOffset2 &&
y <= zdwxEsbConsts.rectOffset2 + zdwxEsbConsts.bodyRectHeight
) {
flag = true;
}
return flag;
}
}
export class ZdwxEsbInteraction extends GraphicInteractionPlugin<ZdwxEsb> { export class ZdwxEsbInteraction extends GraphicInteractionPlugin<ZdwxEsb> {
static Name = 'zdwx_esb_transform'; static Name = 'zdwx_esb_transform';
constructor(app: IDrawApp) { constructor(app: IDrawApp) {
@ -96,6 +127,7 @@ export class ZdwxEsbInteraction extends GraphicInteractionPlugin<ZdwxEsb> {
g.cursor = 'pointer'; g.cursor = 'pointer';
g.scalable = true; g.scalable = true;
g.rotatable = true; g.rotatable = true;
g.circleBody.hitArea = new EsbBodyHitArea(g);
g.on('transformstart', this.transformstart, this); g.on('transformstart', this.transformstart, this);
} }
unbind(g: ZdwxEsb): void { unbind(g: ZdwxEsb): void {