From b9831451bc00db4f2f0840a1506d2f9645306dae Mon Sep 17 00:00:00 2001 From: fan Date: Mon, 17 Jul 2023 16:30:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=97=E8=BD=A6=E6=9A=82?= =?UTF-8?q?=E6=8F=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- graphic-pixi | 2 +- .../draw-app/dialogs/AddTrainDialog.vue | 73 +++++++++++++++++++ .../graphics/SectionLinkInteraction.ts | 68 ++++++++++++++++- 3 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 src/components/draw-app/dialogs/AddTrainDialog.vue diff --git a/graphic-pixi b/graphic-pixi index 83eab6c..6899504 160000 --- a/graphic-pixi +++ b/graphic-pixi @@ -1 +1 @@ -Subproject commit 83eab6c5b3d7a25adced20ad2e6179d3154c05fb +Subproject commit 6899504fef7c623a9539905812aba3a93a58395f diff --git a/src/components/draw-app/dialogs/AddTrainDialog.vue b/src/components/draw-app/dialogs/AddTrainDialog.vue new file mode 100644 index 0000000..47efe53 --- /dev/null +++ b/src/components/draw-app/dialogs/AddTrainDialog.vue @@ -0,0 +1,73 @@ + + + + + diff --git a/src/drawApp/graphics/SectionLinkInteraction.ts b/src/drawApp/graphics/SectionLinkInteraction.ts index fab7332..6439483 100644 --- a/src/drawApp/graphics/SectionLinkInteraction.ts +++ b/src/drawApp/graphics/SectionLinkInteraction.ts @@ -5,7 +5,17 @@ import { SectionLink, } from 'src/graphics/sectionLink/SectionLink'; import { graphicData } from 'src/protos/stationLayoutGraphics'; -import { IPointData } from 'pixi.js'; +import { DisplayObject, FederatedMouseEvent, IPointData } from 'pixi.js'; +import { + GraphicApp, + GraphicInteractionPlugin, + JlGraphic, +} from 'src/jl-graphic'; +import { ContextMenu } from 'src/jl-graphic/ui/ContextMenu'; +import { MenuItemOptions } from 'src/jl-graphic/ui/Menu'; +import { SignalOperateInteraction } from './SignalInteraction'; +import { Dialog } from 'quasar'; +import AddTrainDialog from '../../components/draw-app/dialogs/AddTrainDialog.vue'; export class SectionLinkData extends GraphicDataBase @@ -86,3 +96,59 @@ export class SectionLinkData return pb_1.Message.equals(this.data, other.data); } } +const addTrainConfig: MenuItemOptions = { + name: '添加列车', +}; +const SectionLinkOperateMenu: ContextMenu = ContextMenu.init({ + name: 'Link操作菜单', + groups: [ + { + items: [addTrainConfig], + }, + ], +}); +export class SectionLinkOperateInteraction extends GraphicInteractionPlugin { + static Name = 'sectionLink_operate_menu'; + constructor(app: GraphicApp) { + super(SectionLinkOperateInteraction.Name, app); + app.registerMenu(SectionLinkOperateMenu); + } + static init(app: GraphicApp) { + return new SignalOperateInteraction(app); + } + filter(...grahpics: JlGraphic[]): SectionLink[] | undefined { + return grahpics + .filter((g) => g.type === SectionLink.Type) + .map((g) => g as SectionLink); + } + bind(g: SectionLink): void { + g.eventMode = 'static'; + g.cursor = 'pointer'; + g.selectable = true; + g.on('_rightclick', this.onContextMenu, this); + } + + unbind(g: SectionLink): void { + g.selectable = false; + g.eventMode = 'none'; + g.off('_rightclick', this.onContextMenu, this); + } + + onContextMenu(e: FederatedMouseEvent) { + const target = e.target as DisplayObject; + const link = target.getGraphic() as SectionLink; + this.app.updateSelected(link); + addTrainConfig.handler = () => { + Dialog.create({ + title: '创建列车', + message: '', + component: AddTrainDialog, + componentProps: link.datas.index, + cancel: true, + persistent: true, + }).onOk((data: { offset: number; dir: 1 | 0 }) => { + console.log(data, 'data'); + }); + }; + } +}