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'); + }); + }; + } +}