From 618752e037e84e24045b46feef15dee12f872968 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Tue, 30 May 2023 18:06:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=99=E5=8F=B0=E8=AF=A6=E7=BB=86=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/platform/Platform.ts | 109 ++++++++++++++++-- .../platform/PlatformDrawAssistant.ts | 3 +- 2 files changed, 99 insertions(+), 13 deletions(-) diff --git a/src/graphics/platform/Platform.ts b/src/graphics/platform/Platform.ts index 3f74ab5..cd6cd3d 100644 --- a/src/graphics/platform/Platform.ts +++ b/src/graphics/platform/Platform.ts @@ -3,6 +3,7 @@ import { GraphicData, JlGraphic, JlGraphicTemplate, + VectorText, getRectangleCenter, } from 'src/jlgraphic'; @@ -28,43 +29,94 @@ export interface IPlatformData extends GraphicData { eq(other: IPlatformData): boolean; } +//站台颜色 +export enum PlatformColorEnum { + blue = '0x0fe81f', //站台的颜色 + lightBlue = '0x55d15d', + yellow = '0xfbff00', + white = '0xffffff', + lozengeRed = '0xff0000', //站台旁的菱形图标 + whiteNumbers = '0xffffff', //站台旁白色数字 + HCharYellow = '0xfbff00', //站台旁的H字符 + HCharWhite = '0xffffff', + HCharRed = '0xff0000', + doorBlue = '0x008000', //屏蔽门的颜色 + doorRed = '0xff0000', +} + +const platformConsts = { + width: 60, + height: 20, + lineWidth: 3, + besideFontSize: 12, + doorOpenSpacing: 5, + doorPlatformSpacing: 10, + besideSpacing: 10, +}; + export class Platform extends JlGraphic { static Type = 'Platform'; platformGraphic: Graphics; doorGraphic: Graphics; + besideGraphic: Graphics; + codeGraph: VectorText = new VectorText(''); //站台旁数字、字符 constructor() { super(Platform.Type); this.platformGraphic = new Graphics(); this.doorGraphic = new Graphics(); + this.besideGraphic = new Graphics(); this.addChild(this.platformGraphic); this.addChild(this.doorGraphic); + this.addChild(this.besideGraphic); + this.addChild(this.codeGraph); + this.codeGraph.setVectorFontSize(platformConsts.besideFontSize); } get datas(): IPlatformData { return this.getDatas(); } doRepaint(): void { + const width = this.datas.width; + const height = this.datas.height; //屏蔽门 const doorGraphic = this.doorGraphic; doorGraphic.clear(); if (this.datas.hasdoor) { - doorGraphic.clear(); doorGraphic.lineStyle( this.datas.lineWidth, new Color(this.datas.lineColorDoor) ); - const width = this.datas.width; - const height = this.datas.height; doorGraphic.moveTo( -width / 2 - this.datas.lineWidth / 2, -height / 2 - 10 ); - doorGraphic.lineTo( - width / 2 + this.datas.lineWidth / 2, - -height / 2 - 10 - ); + //屏蔽门打开 + if (this.datas.hasdoor) { + doorGraphic.lineTo( + -platformConsts.doorOpenSpacing, + -height / 2 - platformConsts.doorPlatformSpacing + ); + doorGraphic.moveTo( + platformConsts.doorOpenSpacing, + -height / 2 - platformConsts.doorPlatformSpacing + ); + doorGraphic.lineTo( + width / 2 + this.datas.lineWidth / 2, + -height / 2 - platformConsts.doorPlatformSpacing + ); + } else { + doorGraphic.lineTo( + width / 2 + this.datas.lineWidth / 2, + -height / 2 - platformConsts.doorPlatformSpacing + ); + } } + /* doorGraphic.position.set( + 0, + height + platformConsts.doorPlatformSpacing * 2 + ); */ + //站台 const platformGraphic = this.platformGraphic; platformGraphic.clear(); platformGraphic.lineStyle( @@ -77,6 +129,39 @@ export class Platform extends JlGraphic { const rect = new Rectangle(0, 0, this.datas.width, this.datas.height); platformGraphic.pivot = getRectangleCenter(rect); this.position.set(this.datas.point.x, this.datas.point.y); + //站台旁菱形图标 + const besideGraphic = this.besideGraphic; + besideGraphic.clear(); + if (this.datas.hasdoor) { + besideGraphic.lineStyle(1, new Color(PlatformColorEnum.lozengeRed)); + besideGraphic.drawRect( + 0, + 0, + this.datas.height / 4, + this.datas.height / 4 + ); + const rect = new Rectangle( + 0, + 0, + this.datas.height / 4, + this.datas.height / 4 + ); + besideGraphic.pivot = getRectangleCenter(rect); + besideGraphic.rotation = Math.PI / 4; + besideGraphic.position.set( + -width / 2 - this.datas.lineWidth / 2 - platformConsts.besideSpacing, + 0 + ); + } + //站台旁的数字、字符 + const codeGraph = this.codeGraph; + codeGraph.text = 'H'; + codeGraph.anchor.set(0.5); + codeGraph.position.set( + -width / 2 - this.datas.lineWidth / 2 - platformConsts.besideSpacing, + 0 + ); + codeGraph.style.fill = PlatformColorEnum.HCharYellow; } } @@ -89,12 +174,12 @@ export class PlatformTemplate extends JlGraphicTemplate { height: number; constructor() { super(Platform.Type); - this.lineWidth = 2; - this.lineColor = '#000000'; - this.lineColorDoor = '0x008000'; + this.lineWidth = platformConsts.lineWidth; + this.lineColor = PlatformColorEnum.yellow; + this.lineColorDoor = PlatformColorEnum.doorBlue; this.hasdoor = true; - this.width = 100; - this.height = 30; + this.width = platformConsts.width; + this.height = platformConsts.height; } new(): Platform { return new Platform(); diff --git a/src/graphics/platform/PlatformDrawAssistant.ts b/src/graphics/platform/PlatformDrawAssistant.ts index 634dead..e6b9188 100644 --- a/src/graphics/platform/PlatformDrawAssistant.ts +++ b/src/graphics/platform/PlatformDrawAssistant.ts @@ -14,7 +14,7 @@ import { import { IPlatformData, Platform, PlatformTemplate } from './Platform'; -export interface ILinkDrawOptions { +export interface IPlatformDrawOptions { newData: () => IPlatformData; } @@ -85,6 +85,7 @@ export class PlatformDraw extends GraphicDrawAssistant< const height = template.height; doorGraphic.moveTo(-width / 2 - template.lineWidth / 2, -height / 2 - 10); doorGraphic.lineTo(width / 2 + template.lineWidth / 2, -height / 2 - 10); + doorGraphic.position.set(p.x, p.y); } //站台