From 3cb9513b41ac66969bd0a0e3e30faec12207da79 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Thu, 8 Jun 2023 13:26:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=A6=E7=AB=99=E5=92=8C=E7=AB=99=E5=8F=B0?= =?UTF-8?q?=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/platform/Platform.ts | 47 +++++++++++-------- .../platform/PlatformDrawAssistant.ts | 8 ++-- src/graphics/station/StationDrawAssistant.ts | 12 ++--- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/src/graphics/platform/Platform.ts b/src/graphics/platform/Platform.ts index 30fba64..6c9695c 100644 --- a/src/graphics/platform/Platform.ts +++ b/src/graphics/platform/Platform.ts @@ -1,4 +1,4 @@ -import { Color, Graphics, Rectangle } from 'pixi.js'; +import { Color, Container, Graphics, Rectangle } from 'pixi.js'; import { GraphicData, JlGraphic, @@ -44,20 +44,21 @@ const platformConsts = { besideSpacing: 10, }; -export interface childJlGraphic extends JlGraphic { +export interface childJlGraphic extends Container { clear(): void; + draw(): void; } //子元素--矩形 -export class rectGraphic extends JlGraphic { +export class rectGraphic extends Container { static Type = 'RectPlatForm'; rectGraphic: Graphics; constructor() { - super(Platform.Type); + super(); this.rectGraphic = new Graphics(); this.addChild(this.rectGraphic); } - doRepaint(): void { + draw(): void { const rectGraphic = this.rectGraphic; rectGraphic.clear(); rectGraphic.lineStyle( @@ -84,18 +85,18 @@ export class rectGraphic extends JlGraphic { } } //子元素--门 -export class doorGraphic extends JlGraphic { +export class doorGraphic extends Container { static Type = 'Door'; doorGraphic: Graphics; doorCloseGraphic: Graphics; constructor() { - super(doorGraphic.Type); + super(); this.doorGraphic = new Graphics(); this.doorCloseGraphic = new Graphics(); this.addChild(this.doorGraphic); this.addChild(this.doorCloseGraphic); } - doRepaint(): void { + draw(): void { const doorGraphic = this.doorGraphic; const doorCloseGraphic = this.doorCloseGraphic; doorGraphic.clear(); @@ -139,18 +140,18 @@ export class doorGraphic extends JlGraphic { } } //子元素--字符 -class codeGraph extends JlGraphic { +class codeGraph extends Container { static Type = 'Code'; character: VectorText = new VectorText(''); //站台旁字符H或P characterN: VectorText = new VectorText(''); //站台旁数字 constructor() { - super(codeGraph.Type); + super(); this.addChild(this.character); this.addChild(this.characterN); this.character.setVectorFontSize(platformConsts.besideFontSize); this.characterN.setVectorFontSize(platformConsts.besideFontSize); } - doRepaint(): void { + draw(): void { const character = this.character; character.text = 'H'; character.anchor.set(0.5); @@ -172,17 +173,20 @@ class codeGraph extends JlGraphic { ); characterN.style.fill = PlatformColorEnum.HCharYellow; } + clear(): void { + this.character.destroy(); + } } //子元素--站台旁菱形图标 -class besideGraphic extends JlGraphic { +class besideGraphic extends Container { static Type = 'BesideGraphic'; besideGraphic: Graphics; constructor() { - super(Platform.Type); + super(); this.besideGraphic = new Graphics(); this.addChild(this.besideGraphic); } - doRepaint(): void { + draw(): void { const besideGraphic = this.besideGraphic; besideGraphic.clear(); besideGraphic.lineStyle(1, new Color(PlatformColorEnum.lozengeRed)); @@ -207,14 +211,17 @@ class besideGraphic extends JlGraphic { 0 ); } + clear(): void { + this.besideGraphic.clear(); + } } export class Platform extends JlGraphic { static Type = 'Platform'; platformGraphic: childJlGraphic; doorGraphic: childJlGraphic; - besideGraphic: JlGraphic; - codeGraph: JlGraphic; + besideGraphic: childJlGraphic; + codeGraph: childJlGraphic; constructor() { super(Platform.Type); this.platformGraphic = new rectGraphic(); @@ -233,11 +240,11 @@ export class Platform extends JlGraphic { doRepaint(): void { this.doorGraphic.clear(); if (this.datas.hasdoor) { - this.doorGraphic.doRepaint(); + this.doorGraphic.draw(); } - this.platformGraphic.doRepaint(); - this.besideGraphic.doRepaint(); - this.codeGraph.doRepaint(); + this.platformGraphic.draw(); + this.besideGraphic.draw(); + this.codeGraph.draw(); this.doorGraphic.position.set(0, 0); this.besideGraphic.position.set(0, 0); this.codeGraph.position.set(0, 0); diff --git a/src/graphics/platform/PlatformDrawAssistant.ts b/src/graphics/platform/PlatformDrawAssistant.ts index a149389..404969c 100644 --- a/src/graphics/platform/PlatformDrawAssistant.ts +++ b/src/graphics/platform/PlatformDrawAssistant.ts @@ -43,6 +43,8 @@ export class PlatformDraw extends GraphicDrawAssistant< bind(): void { super.bind(); + this.platformGraphic.draw(); + this.doorGraphic.draw(); } unbind(): void { super.unbind(); @@ -60,10 +62,8 @@ export class PlatformDraw extends GraphicDrawAssistant< } redraw(p: Point): void { - this.platformGraphic.repaint(); - this.doorGraphic.repaint(); - this.doorGraphic.position.set(p.x, p.y); - this.platformGraphic.position.set(p.x, p.y); + this.doorGraphic.position.copyFrom(p); + this.platformGraphic.position.copyFrom(p); } prepareData(data: IPlatformData): boolean { diff --git a/src/graphics/station/StationDrawAssistant.ts b/src/graphics/station/StationDrawAssistant.ts index 9f63ac3..725f2bc 100644 --- a/src/graphics/station/StationDrawAssistant.ts +++ b/src/graphics/station/StationDrawAssistant.ts @@ -34,6 +34,11 @@ export class StationDraw extends GraphicDrawAssistant< bind(): void { super.bind(); + const codeGraph = this.codeGraph; + codeGraph.text = '车站Station'; + codeGraph.anchor.set(0.5); + codeGraph.style.fill = '0xf48815'; + codeGraph.setVectorFontSize(22); } unbind(): void { super.unbind(); @@ -50,12 +55,7 @@ export class StationDraw extends GraphicDrawAssistant< } redraw(p: Point): void { - const codeGraph = this.codeGraph; - codeGraph.text = '车站Station'; - codeGraph.anchor.set(0.5); - codeGraph.style.fill = '0xf48815'; - codeGraph.position.set(p.x, p.y); - codeGraph.setVectorFontSize(22); + this.codeGraph.position.copyFrom(p); } prepareData(data: IStationData): boolean { const template = this.graphicTemplate;