diff --git a/public/drawIcon.svg b/public/drawIcon.svg index 5fff84a..0639126 100644 --- a/public/drawIcon.svg +++ b/public/drawIcon.svg @@ -27,15 +27,30 @@ + + + + + - - - + + + + + + + + + + + + + diff --git a/rts-sim-testing-message b/rts-sim-testing-message index f232ff6..16d15c8 160000 --- a/rts-sim-testing-message +++ b/rts-sim-testing-message @@ -1 +1 @@ -Subproject commit f232ff605d44f4c989a823f2416215e4c3bb60b9 +Subproject commit 16d15c8515368725a811c9349c95ffdafb4dd991 diff --git a/src/components/draw-app/DrawProperties.vue b/src/components/draw-app/DrawProperties.vue index 7d29d25..b583138 100644 --- a/src/components/draw-app/DrawProperties.vue +++ b/src/components/draw-app/DrawProperties.vue @@ -148,6 +148,12 @@ + + diff --git a/src/components/draw-app/properties/UnattengedButtonProperty.vue b/src/components/draw-app/properties/UnattengedButtonProperty.vue new file mode 100644 index 0000000..f067ae7 --- /dev/null +++ b/src/components/draw-app/properties/UnattengedButtonProperty.vue @@ -0,0 +1,55 @@ + + + diff --git a/src/drawApp/common.ts b/src/drawApp/common.ts index f1d3927..7e40f91 100644 --- a/src/drawApp/common.ts +++ b/src/drawApp/common.ts @@ -24,6 +24,8 @@ import { PslBox } from 'src/graphics/pslBox/PslBox'; import { GarageDoor } from 'src/graphics/garageDoor/GarageDoor'; import { CarWashing } from 'src/graphics/carWashing/CarWashing'; import { FloodGate } from 'src/graphics/floodGate/FloodGate'; +import { HoldButton } from 'src/graphics/holdButton/HoldButton'; +import { UnattengedButton } from 'src/graphics/unattengedButton/UnattengedButton'; export const drawCommonLayerList = [ // 图层列表 默认显示的图层defaultShow: true @@ -61,4 +63,6 @@ export const drawCommonLayerList = [ { label: '车库门', value: GarageDoor.Type, defaultShow: true }, { label: '洗车机', value: CarWashing.Type, defaultShow: true }, { label: '防淹门', value: FloodGate.Type, defaultShow: true }, + { label: '扣车按钮', value: HoldButton.Type, defaultShow: true }, + { label: '无人折返按钮', value: UnattengedButton.Type, defaultShow: true }, ]; diff --git a/src/drawApp/commonApp.ts b/src/drawApp/commonApp.ts index c1995a6..67f0494 100644 --- a/src/drawApp/commonApp.ts +++ b/src/drawApp/commonApp.ts @@ -91,6 +91,10 @@ import { SpksSwitchData, DrawSpksSwitchInteraction, } from './graphics/SpksSwitchInteraction'; +import { HoldButton, HoldButtonTemplate } from 'src/graphics/holdButton/HoldButton'; +import { DrawHoldButtonInteraction, HoldButtonData } from './graphics/HoldButtonInteraction'; +import { UnattengedButton, UnattengedButtonTemplate } from 'src/graphics/unattengedButton/UnattengedButton'; +import { UnattengedButtonData, DrawUnattengedButtonInteraction } from './graphics/UnattengedButtonInteraction'; import { GatedBox, GatedBoxTemplate } from 'src/graphics/gatedBox/GatedBox'; import { GatedBoxData, @@ -103,6 +107,8 @@ import { // EsbButtonState, // } from './graphics/EsbButtonInteraction'; import { SpksSwitchDraw } from 'src/graphics/spksSwitch/SpksSwitchDrawAssistant'; +import { HoldButtonDraw } from 'src/graphics/holdButton/HoldButtonDrawAssistant'; +import { UnattengedButtonDraw } from 'src/graphics/unattengedButton/UnattengedButtonDrawAssistant'; import { GatedBoxDraw } from 'src/graphics/gatedBox/GatedBoxDrawAssistant'; // import { EsbButtonDraw } from 'src/graphics/esbButton/EsbButtonDrawAssistant'; import { TransponderDraw } from 'src/graphics/transponder/TransponderDrawAssistant'; @@ -228,6 +234,8 @@ export function initCommonDrawApp(app: IDrawApp) { ); new StopPositionDraw(app, new StopPositionTemplate(new StopPositionData())); new SpksSwitchDraw(app, new SpksSwitchTemplate(new SpksSwitchData())); + new HoldButtonDraw(app, new HoldButtonTemplate(new HoldButtonData())); + new UnattengedButtonDraw(app, new UnattengedButtonTemplate(new UnattengedButtonData())); new GatedBoxDraw(app, new GatedBoxTemplate(new GatedBoxData())); // new EsbButtonDraw( // app, @@ -264,6 +272,8 @@ export function initCommonDrawApp(app: IDrawApp) { DrawSignalInteraction.init(app); DrawStopPositionInteraction.init(app); DrawSpksSwitchInteraction.init(app); + DrawHoldButtonInteraction.init(app); + DrawUnattengedButtonInteraction.init(app); DrawGatedBoxInteraction.init(app); // DrawEsbButtonInteraction.init(app); @@ -352,10 +362,10 @@ export function initCommonDrawApp(app: IDrawApp) { prev.localToCanvasPoint(prev.getStartPoint()), mousePos ) > - distance2( - cur.localToCanvasPoint(cur.getStartPoint()), - mousePos - )) + distance2( + cur.localToCanvasPoint(cur.getStartPoint()), + mousePos + )) ? cur : prev; }); @@ -447,6 +457,12 @@ export function loadCommonDrawDatas( storage.spksSwitchs.forEach((spksSwitch) => { datas.push(new SpksSwitchData(spksSwitch)); }); + storage.holdButtons.forEach((holdButton) => { + datas.push(new HoldButtonData(holdButton)); + }) + storage.unattengedButtons.forEach((unattengedButton) => { + datas.push(new UnattengedButtonData(unattengedButton)); + }) storage.gateBoxs.forEach((gatedBox) => { datas.push(new GatedBoxData(gatedBox)); }); @@ -536,6 +552,14 @@ export function saveCommonDrawDatas(app: IDrawApp) { } else if (SpksSwitch.Type === g.type) { const spksSwitchData = (g as SpksSwitch).saveData(); storage.spksSwitchs.push((spksSwitchData as SpksSwitchData).data); + } else if (HoldButton.Type === g.type) { + const holdButtonData = (g as HoldButton).saveData(); + storage.holdButtons.push((holdButtonData as HoldButtonData).data); + } else if (UnattengedButton.Type === g.type) { + const unattengedButtonData = (g as UnattengedButton).saveData(); + storage.unattengedButtons.push( + (unattengedButtonData as UnattengedButtonData).data + ); } else if (GatedBox.Type === g.type) { const gatedBoxData = (g as GatedBox).saveData(); storage.gateBoxs.push((gatedBoxData as GatedBoxData).data); diff --git a/src/drawApp/graphics/HoldButtonInteraction.ts b/src/drawApp/graphics/HoldButtonInteraction.ts new file mode 100644 index 0000000..a122ec9 --- /dev/null +++ b/src/drawApp/graphics/HoldButtonInteraction.ts @@ -0,0 +1,107 @@ +import * as pb_1 from 'google-protobuf'; +import { DisplayObject, FederatedMouseEvent } from 'pixi.js'; +import { IHoldButtonData, HoldButton } from 'src/graphics/holdButton/HoldButton'; +import { + IGraphicApp, + GraphicInteractionPlugin, + JlGraphic, + IGraphicScene, + MenuItemOptions, + ContextMenu, +} from 'jl-graphic'; + +import { graphicData } from 'src/protos/stationLayoutGraphics'; +import { GraphicDataBase } from './GraphicDataBase'; +import { useIbpStore } from 'src/stores/ibp-store'; +import { Station } from 'src/graphics/station/Station'; +import { Platform } from 'src/graphics/platform/Platform'; + +export class HoldButtonData extends GraphicDataBase implements IHoldButtonData { + constructor(data?: graphicData.HoldButton) { + let holdButton; + if (!data) { + holdButton = new graphicData.HoldButton({ + common: GraphicDataBase.defaultCommonInfo(HoldButton.Type), + }); + } else { + holdButton = data; + } + super(holdButton); + } + + public get data(): graphicData.HoldButton { + return this.getData(); + } + get code(): string { + return this.data.code; + } + set code(v: string) { + this.data.code = v; + } + get flip(): boolean { + return this.data.flip; + } + set flip(v: boolean) { + this.data.flip = v; + } + get refStand(): number { + return this.data.refStand; + } + set refStand(v: number) { + this.data.refStand = v; + } + clone(): HoldButtonData { + return new HoldButtonData(this.data.cloneMessage()); + } + copyFrom(data: HoldButtonData): void { + pb_1.Message.copyInto(data.data, this.data); + } + eq(other: HoldButtonData): boolean { + return pb_1.Message.equals(this.data, other.data); + } +} + +const flipConfig: MenuItemOptions = { + name: '上下翻转', +}; +const HoldButtonEditMenu: ContextMenu = ContextMenu.init({ + name: '扣车按钮编辑菜单', + groups: [ + { + items: [flipConfig], + }, + ], +}); +export class DrawHoldButtonInteraction extends GraphicInteractionPlugin { + static Name = 'hold_button_draw_right_menu'; + constructor(app: IGraphicApp) { + super(DrawHoldButtonInteraction.Name, app); + app.registerMenu(HoldButtonEditMenu); + } + static init(app: IGraphicApp) { + return new DrawHoldButtonInteraction(app); + } + filter(...grahpics: JlGraphic[]): HoldButton[] | undefined { + return grahpics + .filter((g) => g.type === HoldButton.Type) + .map((g) => g as HoldButton); + } + bind(g: HoldButton): void { + g.on('_rightclick', this.onContextMenu, this); + } + + unbind(g: HoldButton): void { + g.off('_rightclick', this.onContextMenu, this); + } + + onContextMenu(e: FederatedMouseEvent) { + const target = e.target as DisplayObject; + const holdButton = target.getGraphic() as HoldButton; + this.app.updateSelected(holdButton); + flipConfig.handler = () => { + holdButton.datas.flip = !holdButton.datas.flip; + holdButton.repaint(); + }; + HoldButtonEditMenu.open(e.global); + } +} diff --git a/src/drawApp/graphics/SpksSwitchInteraction.ts b/src/drawApp/graphics/SpksSwitchInteraction.ts index b7d31b6..fc9ccb9 100644 --- a/src/drawApp/graphics/SpksSwitchInteraction.ts +++ b/src/drawApp/graphics/SpksSwitchInteraction.ts @@ -53,12 +53,12 @@ export class SpksSwitchData extends GraphicDataBase implements ISpksSwitchData { set refStand(v: number) { this.data.refStand = v; } - get refSections(): number[] { - return this.data.refSections; - } - set refSections(v: number[]) { - this.data.refSections = v; - } + // get refSections(): number[] { + // return this.data.refSections; + // } + // set refSections(v: number[]) { + // this.data.refSections = v; + // } clone(): SpksSwitchData { return new SpksSwitchData(this.data.cloneMessage()); } @@ -114,36 +114,3 @@ export class DrawSpksSwitchInteraction extends GraphicInteractionPlugin { - static Name = 'spks_switch_operation'; - constructor(app: IGraphicScene) { - super(SpksSwitchOperationInteraction.Name, app); - } - static init(app: IGraphicScene) { - return new SpksSwitchOperationInteraction(app); - } - filter(...grahpics: JlGraphic[]): SpksSwitch[] | undefined { - return grahpics.filter((g): g is SpksSwitch => g instanceof SpksSwitch); - } - bind(g: SpksSwitch): void { - g.eventMode = 'static'; - g.cursor = 'pointer'; - g.on('_leftclick', this.onLeftClick, this); - } - unbind(g: SpksSwitch): void { - g.off('_leftclick', this.onLeftClick, this); - } - onLeftClick(e: FederatedMouseEvent) { - const target = e.target as DisplayObject; - const spksSwitch = target.getGraphic() as SpksSwitch; - const stand = this.app.queryStore.queryById( - spksSwitch.datas.refStand - ); - const station = this.app.queryStore.queryById( - stand.datas.refStation - ); - - useIbpStore().openIbpScene(station); - } -} diff --git a/src/drawApp/graphics/UnattengedButtonInteraction.ts b/src/drawApp/graphics/UnattengedButtonInteraction.ts new file mode 100644 index 0000000..aec3eb8 --- /dev/null +++ b/src/drawApp/graphics/UnattengedButtonInteraction.ts @@ -0,0 +1,107 @@ +import * as pb_1 from 'google-protobuf'; +import { DisplayObject, FederatedMouseEvent } from 'pixi.js'; +import { IUnattengedButtonData, UnattengedButton } from 'src/graphics/unattengedButton/UnattengedButton'; +import { + IGraphicApp, + GraphicInteractionPlugin, + JlGraphic, + IGraphicScene, + MenuItemOptions, + ContextMenu, +} from 'jl-graphic'; + +import { graphicData } from 'src/protos/stationLayoutGraphics'; +import { GraphicDataBase } from './GraphicDataBase'; +import { useIbpStore } from 'src/stores/ibp-store'; +import { Station } from 'src/graphics/station/Station'; +import { Platform } from 'src/graphics/platform/Platform'; + +export class UnattengedButtonData extends GraphicDataBase implements IUnattengedButtonData { + constructor(data?: graphicData.UnattengedButton) { + let unattengedButton; + if (!data) { + unattengedButton = new graphicData.UnattengedButton({ + common: GraphicDataBase.defaultCommonInfo(UnattengedButton.Type), + }); + } else { + unattengedButton = data; + } + super(unattengedButton); + } + + public get data(): graphicData.UnattengedButton { + return this.getData(); + } + get code(): string { + return this.data.code; + } + set code(v: string) { + this.data.code = v; + } + get flip(): boolean { + return this.data.flip; + } + set flip(v: boolean) { + this.data.flip = v; + } + get refStand(): number { + return this.data.refStand; + } + set refStand(v: number) { + this.data.refStand = v; + } + clone(): UnattengedButtonData { + return new UnattengedButtonData(this.data.cloneMessage()); + } + copyFrom(data: UnattengedButtonData): void { + pb_1.Message.copyInto(data.data, this.data); + } + eq(other: UnattengedButtonData): boolean { + return pb_1.Message.equals(this.data, other.data); + } +} + +const flipConfig: MenuItemOptions = { + name: '上下翻转', +}; +const UnattengedButtonEditMenu: ContextMenu = ContextMenu.init({ + name: '无人折返按钮编辑菜单', + groups: [ + { + items: [flipConfig], + }, + ], +}); +export class DrawUnattengedButtonInteraction extends GraphicInteractionPlugin { + static Name = 'unattenged_button_draw_right_menu'; + constructor(app: IGraphicApp) { + super(DrawUnattengedButtonInteraction.Name, app); + app.registerMenu(UnattengedButtonEditMenu); + } + static init(app: IGraphicApp) { + return new DrawUnattengedButtonInteraction(app); + } + filter(...grahpics: JlGraphic[]): UnattengedButton[] | undefined { + return grahpics + .filter((g) => g.type === UnattengedButton.Type) + .map((g) => g as UnattengedButton); + } + bind(g: UnattengedButton): void { + g.on('_rightclick', this.onContextMenu, this); + } + + unbind(g: UnattengedButton): void { + g.off('_rightclick', this.onContextMenu, this); + } + + onContextMenu(e: FederatedMouseEvent) { + const target = e.target as DisplayObject; + const unattengedButton = target.getGraphic() as UnattengedButton; + this.app.updateSelected(unattengedButton); + flipConfig.handler = () => { + unattengedButton.datas.flip = !unattengedButton.datas.flip; + unattengedButton.repaint(); + }; + UnattengedButtonEditMenu.open(e.global); + } +} diff --git a/src/drawApp/lineScene.ts b/src/drawApp/lineScene.ts index d94d2c9..91d4832 100644 --- a/src/drawApp/lineScene.ts +++ b/src/drawApp/lineScene.ts @@ -122,7 +122,6 @@ import { EsbButton, EsbButtonTemplate } from 'src/graphics/esbButton/EsbButton'; import { StopPositionData } from './graphics/StopPositionInteraction'; import { SpksSwitchData, - SpksSwitchOperationInteraction, } from './graphics/SpksSwitchInteraction'; import { GatedBoxData } from './graphics/GatedBoxInteraction'; import { @@ -195,6 +194,8 @@ import { FloodGateOperationInteraction, FloodGateState, } from './graphics/FloodGateInteraction'; +import { HoldButton } from 'src/graphics/holdButton/HoldButton'; +import { UnattengedButton } from 'src/graphics/unattengedButton/UnattengedButton'; const showOptions: MenuItemOptions = { name: '显示控制', @@ -260,6 +261,8 @@ export const layerList = [ { label: '车库门', value: GarageDoor.Type, defaultShow: true }, { label: '洗车机', value: CarWashing.Type, defaultShow: true }, { label: '防淹门', value: FloodGate.Type, defaultShow: true }, + { label: '扣车按钮', value: HoldButton.Type, defaultShow: true }, + { label: '无人折返按钮', value: UnattengedButton.Type, defaultShow: true }, ]; let lineScene: IGraphicScene; @@ -343,7 +346,6 @@ export function initLineScene(lineApp: IGraphicApp, sceneName: string) { TurnoutOperationPlugin.init(lineScene); TransponderOperationPlugin.init(lineScene); EsbButtonOperationInteraction.init(lineScene); - SpksSwitchOperationInteraction.init(lineScene); AutoReturnBoxOperationInteraction.init(lineScene); PslBoxOperateInteraction.init(lineScene); IbpBoxOperateInteraction.init(lineScene); diff --git a/src/graphics/esbButton/EsbButton.ts b/src/graphics/esbButton/EsbButton.ts index f5071cd..3a38ef3 100644 --- a/src/graphics/esbButton/EsbButton.ts +++ b/src/graphics/esbButton/EsbButton.ts @@ -42,7 +42,7 @@ const esbButtonConsts = { export class EsbButton extends JlGraphic { static Type = 'esbButton'; codeGraph: VectorText = new VectorText(''); - circleBody: Graphics = new Graphics(); + textGraph: VectorText = new VectorText('E'); rectBody: Graphics = new Graphics(); lineBody: Graphics = new Graphics(); @@ -51,7 +51,7 @@ export class EsbButton extends JlGraphic { this.addChild(this.codeGraph); this.addChild(this.rectBody); this.addChild(this.lineBody); - this.addChild(this.circleBody); + this.addChild(this.textGraph); this.codeGraph.name = 'esb_code'; } get code(): string { @@ -80,15 +80,9 @@ export class EsbButton extends JlGraphic { } else { codeGraph.position.set(-30, 0); } - this.circleBody.clear(); - this.circleBody.beginFill( - this.state.down - ? esbButtonConsts.pressedColor - : esbButtonConsts.bodyCircleColor, - 1 - ); - this.circleBody.drawCircle(0, 0, esbButtonConsts.bodyCircleRadius); - this.circleBody.endFill(); + this.textGraph.style.fill = esbButtonConsts.codeColor; + this.textGraph.setVectorFontSize(esbButtonConsts.codeFontSize); + this.textGraph.anchor.set(0.5); this.rectBody.clear(); this.rectBody.beginFill(esbButtonConsts.bodyColor, 0); this.rectBody.lineStyle( diff --git a/src/graphics/holdButton/HoldButton.ts b/src/graphics/holdButton/HoldButton.ts new file mode 100644 index 0000000..8bd371d --- /dev/null +++ b/src/graphics/holdButton/HoldButton.ts @@ -0,0 +1,102 @@ +import { Graphics } from 'pixi.js'; +import { + GraphicData, + JlGraphic, + JlGraphicTemplate, + VectorText, +} from 'jl-graphic'; + +export interface IHoldButtonData extends GraphicData { + get code(): string; + set code(v: string); + get flip(): boolean; + set flip(v: boolean); + get refStand(): number; + set refStand(v: number); +} + +const holdButtonConsts = { + codeFontSize: 12, + codeColor: 0xffffff, + bodyLineColor: 0xffffff, + bodyLineWidth: 4, + bodyRectLineColor: 0xffffff, + bodyRectLineWidth: 2, + bodyRectWidth: 20, + bodyRectHeight: 20, + bodyColor: 0x000000, +}; +export class HoldButton extends JlGraphic { + static Type = 'holdButton'; + codeGraph: VectorText = new VectorText(''); + rectBody: Graphics = new Graphics(); + lineBody: Graphics = new Graphics(); + textGraph: VectorText = new VectorText('H'); + + constructor() { + super(HoldButton.Type); + this.addChild(this.codeGraph); + this.addChild(this.rectBody); + this.addChild(this.lineBody); + this.addChild(this.textGraph); + this.codeGraph.name = 'hold_button_code'; + } + get datas(): IHoldButtonData { + return this.getDatas(); + } + doRepaint(): void { + const codeGraph = this.codeGraph; + codeGraph.text = this.datas.code; + codeGraph.style.fill = holdButtonConsts.codeColor; + codeGraph.setVectorFontSize(holdButtonConsts.codeFontSize); + const codeTransform = this.datas?.childTransforms?.find( + (item) => item.name === 'hold_button_code' + ); + if (codeTransform) { + const position = codeTransform?.transform.position; + const rotation = codeTransform?.transform?.rotation; + codeGraph.position.set(position?.x, position?.y); + codeGraph.rotation = rotation || 0; + } else { + codeGraph.position.set(20, 0); + } + codeGraph.anchor.set(0.5); + this.textGraph.style.fill = holdButtonConsts.codeColor; + this.textGraph.setVectorFontSize(holdButtonConsts.codeFontSize); + this.textGraph.anchor.set(0.5); + this.rectBody.clear(); + this.rectBody.beginFill(holdButtonConsts.bodyColor, 0); + this.rectBody.lineStyle( + holdButtonConsts.bodyRectLineWidth, + holdButtonConsts.bodyRectLineColor + ); + this.rectBody.drawRect( + -holdButtonConsts.bodyRectWidth / 2, + -holdButtonConsts.bodyRectHeight / 2, + holdButtonConsts.bodyRectWidth, + holdButtonConsts.bodyRectHeight + ); + this.rectBody.endFill(); + this.lineBody.clear(); + const lineY = this.datas.flip + ? holdButtonConsts.bodyRectHeight / 2 + : -holdButtonConsts.bodyRectHeight / 2; + this.lineBody.lineStyle( + holdButtonConsts.bodyLineWidth, + holdButtonConsts.bodyLineColor + ); + this.lineBody.moveTo(-holdButtonConsts.bodyRectWidth / 2, lineY); + this.lineBody.lineTo(holdButtonConsts.bodyRectWidth / 2, lineY); + } +} + +export class HoldButtonTemplate extends JlGraphicTemplate { + constructor(dataTemplate: IHoldButtonData) { + super(HoldButton.Type, { dataTemplate }); + } + new(): HoldButton { + const holdButton = new HoldButton(); + holdButton.loadData(this.datas); + return holdButton; + } +} diff --git a/src/graphics/holdButton/HoldButtonDrawAssistant.ts b/src/graphics/holdButton/HoldButtonDrawAssistant.ts new file mode 100644 index 0000000..cfbd6a6 --- /dev/null +++ b/src/graphics/holdButton/HoldButtonDrawAssistant.ts @@ -0,0 +1,128 @@ +import { DisplayObject, FederatedMouseEvent, Point } from 'pixi.js'; +import { + AbsorbableLine, + AbsorbablePosition, + GraphicDrawAssistant, + GraphicInteractionPlugin, + GraphicTransformEvent, + IDrawApp, + JlGraphic, +} from 'jl-graphic'; +import { IHoldButtonData, HoldButton, HoldButtonTemplate } from './HoldButton'; + +export interface IHoldButtonDataDrawOptions { + newData: () => IHoldButtonData; +} +export class HoldButtonDraw extends GraphicDrawAssistant< + HoldButtonTemplate, + IHoldButtonData +> { + _holdButton: HoldButton | null = null; + constructor(app: IDrawApp, template: HoldButtonTemplate) { + super( + app, + template, + 'svguse:../../drawIcon.svg#icon-hold-button', + '扣车按钮HoldButton' + ); + HoldButtonInteraction.init(app); + } + public get holdButton(): HoldButton { + if (!this._holdButton) { + this._holdButton = this.graphicTemplate.new(); + this._holdButton.loadData(this.graphicTemplate.datas); + this.container.addChild(this._holdButton); + } + return this._holdButton; + } + + onLeftUp(e: FederatedMouseEvent): void { + this.container.position.copyFrom(this.toCanvasCoordinates(e.global)); + this.createAndStore(true); + } + + redraw(p: Point): void { + this.holdButton.repaint(); + this.container.position.set(p.x, p.y); + } + + prepareData(data: IHoldButtonData): boolean { + data.transform = this.container.saveTransform(); + data.code = 'H'; + return true; + } +} +/** + * 构建吸附线 + * @param holdButton + */ +function buildAbsorbablePositions( + holdButton: HoldButton +): AbsorbablePosition[] { + const aps: AbsorbablePosition[] = []; + const holdButtons = holdButton.queryStore.queryByType( + HoldButton.Type + ); + const canvas = holdButton.getCanvas(); + holdButtons.forEach((item) => { + if (item.id === holdButton.id) { + return; + } + const ala = new AbsorbableLine( + new Point(item.x, 0), + new Point(item.x, canvas.height) + ); + const alb = new AbsorbableLine( + new Point(0, item.y), + new Point(canvas.width, item.y) + ); + aps.push(ala); + aps.push(alb); + }); + return aps; +} + +export class HoldButtonInteraction extends GraphicInteractionPlugin { + static Name = 'hold_button_transform'; + constructor(app: IDrawApp) { + super(HoldButtonInteraction.Name, app); + } + static init(app: IDrawApp) { + return new HoldButtonInteraction(app); + } + filter(...grahpics: JlGraphic[]): HoldButton[] | undefined { + return grahpics + .filter((g) => g.type === HoldButton.Type) + .map((g) => g as HoldButton); + } + bind(g: HoldButton): void { + g.eventMode = 'static'; + g.cursor = 'pointer'; + g.scalable = true; + g.rotatable = true; + g.codeGraph.draggable = true; + g.codeGraph.selectable = true; + g.codeGraph.rotatable = true; + g.codeGraph.transformSave = true; + g.codeGraph.eventMode = 'static'; + g.on('transformstart', this.transformstart, this); + } + unbind(g: HoldButton): void { + g.eventMode = 'none'; + g.scalable = false; + g.rotatable = false; + g.codeGraph.draggable = false; + g.codeGraph.selectable = false; + g.codeGraph.rotatable = false; + g.codeGraph.transformSave = false; + g.codeGraph.eventMode = 'none'; + g.off('transformstart', this.transformstart, this); + } + transformstart(e: GraphicTransformEvent) { + const target = e.target as DisplayObject; + const holdButton = target.getGraphic() as HoldButton; + holdButton.getGraphicApp().setOptions({ + absorbablePositions: buildAbsorbablePositions(holdButton), + }); + } +} diff --git a/src/graphics/ibpBox/IbpBoxDrawAssistant.ts b/src/graphics/ibpBox/IbpBoxDrawAssistant.ts index ea60003..816d133 100644 --- a/src/graphics/ibpBox/IbpBoxDrawAssistant.ts +++ b/src/graphics/ibpBox/IbpBoxDrawAssistant.ts @@ -16,7 +16,7 @@ export interface IIbpBoxDrawOptions { export class IbpBoxDraw extends GraphicDrawAssistant { _gatedBox: IbpBox | null = null; constructor(app: IDrawApp, template: IbpBoxTemplate) { - super(app, template, 'svguse:../../drawIcon.svg#icon-spks-switch', 'Ibp'); + super(app, template, 'svguse:../../drawIcon.svg#icon-ibp-box', 'Ibp'); IbpBoxInteraction.init(app); } public get gatedBox(): IbpBox { diff --git a/src/graphics/spksSwitch/SpksSwitch.ts b/src/graphics/spksSwitch/SpksSwitch.ts index 4d1a475..4ea4325 100644 --- a/src/graphics/spksSwitch/SpksSwitch.ts +++ b/src/graphics/spksSwitch/SpksSwitch.ts @@ -13,8 +13,8 @@ export interface ISpksSwitchData extends GraphicData { set flip(v: boolean); get refStand(): number; set refStand(v: number); - get refSections(): number[]; - set refSections(v: number[]); + // get refSections(): number[]; + // set refSections(v: number[]); } const spksSwitchConsts = { diff --git a/src/graphics/unattengedButton/UnattengedButton.ts b/src/graphics/unattengedButton/UnattengedButton.ts new file mode 100644 index 0000000..af3ff9b --- /dev/null +++ b/src/graphics/unattengedButton/UnattengedButton.ts @@ -0,0 +1,103 @@ +import { Graphics } from 'pixi.js'; +import { + GraphicData, + JlGraphic, + JlGraphicTemplate, + VectorText, +} from 'jl-graphic'; + +export interface IUnattengedButtonData extends GraphicData { + get code(): string; + set code(v: string); + get flip(): boolean; + set flip(v: boolean); + get refStand(): number; + set refStand(v: number); +} + +const unattengedButtonConsts = { + codeFontSize: 12, + codeColor: 0xffffff, + bodyLineColor: 0xffffff, + bodyLineWidth: 4, + bodyRectLineColor: 0xffffff, + bodyRectLineWidth: 2, + bodyRectWidth: 20, + bodyRectHeight: 20, + bodyColor: 0x000000, +}; +export class UnattengedButton extends JlGraphic { + static Type = 'unattengedButton'; + codeGraph: VectorText = new VectorText(''); + rectBody: Graphics = new Graphics(); + lineBody: Graphics = new Graphics(); + textGraph: VectorText = new VectorText('W'); + + constructor() { + super(UnattengedButton.Type); + this.addChild(this.codeGraph); + this.addChild(this.rectBody); + this.addChild(this.lineBody); + this.addChild(this.textGraph); + this.codeGraph.name = 'unattenged_button_code'; + } + get datas(): IUnattengedButtonData { + return this.getDatas(); + } + doRepaint(): void { + console.log('111111111') + const codeGraph = this.codeGraph; + codeGraph.text = this.datas.code; + codeGraph.style.fill = unattengedButtonConsts.codeColor; + codeGraph.setVectorFontSize(unattengedButtonConsts.codeFontSize); + const codeTransform = this.datas?.childTransforms?.find( + (item) => item.name === 'unattenged_button_code' + ); + if (codeTransform) { + const position = codeTransform?.transform.position; + const rotation = codeTransform?.transform?.rotation; + codeGraph.position.set(position?.x, position?.y); + codeGraph.rotation = rotation || 0; + } else { + codeGraph.position.set(20, 0); + } + codeGraph.anchor.set(0.5); + this.textGraph.style.fill = unattengedButtonConsts.codeColor; + this.textGraph.setVectorFontSize(unattengedButtonConsts.codeFontSize); + this.textGraph.anchor.set(0.5); + this.rectBody.clear(); + this.rectBody.beginFill(unattengedButtonConsts.bodyColor, 0); + this.rectBody.lineStyle( + unattengedButtonConsts.bodyRectLineWidth, + unattengedButtonConsts.bodyRectLineColor + ); + this.rectBody.drawRect( + -unattengedButtonConsts.bodyRectWidth / 2, + -unattengedButtonConsts.bodyRectHeight / 2, + unattengedButtonConsts.bodyRectWidth, + unattengedButtonConsts.bodyRectHeight + ); + this.rectBody.endFill(); + this.lineBody.clear(); + const lineY = this.datas.flip + ? unattengedButtonConsts.bodyRectHeight / 2 + : -unattengedButtonConsts.bodyRectHeight / 2; + this.lineBody.lineStyle( + unattengedButtonConsts.bodyLineWidth, + unattengedButtonConsts.bodyLineColor + ); + this.lineBody.moveTo(-unattengedButtonConsts.bodyRectWidth / 2, lineY); + this.lineBody.lineTo(unattengedButtonConsts.bodyRectWidth / 2, lineY); + } +} + +export class UnattengedButtonTemplate extends JlGraphicTemplate { + constructor(dataTemplate: IUnattengedButtonData) { + super(UnattengedButton.Type, { dataTemplate }); + } + new(): UnattengedButton { + const unattengedButton = new UnattengedButton(); + unattengedButton.loadData(this.datas); + return unattengedButton; + } +} diff --git a/src/graphics/unattengedButton/UnattengedButtonDrawAssistant.ts b/src/graphics/unattengedButton/UnattengedButtonDrawAssistant.ts new file mode 100644 index 0000000..2f2d175 --- /dev/null +++ b/src/graphics/unattengedButton/UnattengedButtonDrawAssistant.ts @@ -0,0 +1,128 @@ +import { DisplayObject, FederatedMouseEvent, Point } from 'pixi.js'; +import { + AbsorbableLine, + AbsorbablePosition, + GraphicDrawAssistant, + GraphicInteractionPlugin, + GraphicTransformEvent, + IDrawApp, + JlGraphic, +} from 'jl-graphic'; +import { IUnattengedButtonData, UnattengedButton, UnattengedButtonTemplate } from './UnattengedButton'; + +export interface IUnattengedButtonDataOptions { + newData: () => IUnattengedButtonData; +} +export class UnattengedButtonDraw extends GraphicDrawAssistant< + UnattengedButtonTemplate, + IUnattengedButtonData +> { + _unattengedButton: UnattengedButton | null = null; + constructor(app: IDrawApp, template: UnattengedButtonTemplate) { + super( + app, + template, + 'svguse:../../drawIcon.svg#icon-unattenged-button', + '无人折返按钮UnattengedButton' + ); + UnattengedButtonInteraction.init(app); + } + public get unattengedButton(): UnattengedButton { + if (!this._unattengedButton) { + this._unattengedButton = this.graphicTemplate.new(); + this._unattengedButton.loadData(this.graphicTemplate.datas); + this.container.addChild(this._unattengedButton); + } + return this._unattengedButton; + } + + onLeftUp(e: FederatedMouseEvent): void { + this.container.position.copyFrom(this.toCanvasCoordinates(e.global)); + this.createAndStore(true); + } + + redraw(p: Point): void { + this.unattengedButton.repaint(); + this.container.position.set(p.x, p.y); + } + + prepareData(data: IUnattengedButtonData): boolean { + data.transform = this.container.saveTransform(); + data.code = 'W'; + return true; + } +} +/** + * 构建吸附线 + * @param unattengedButton + */ +function buildAbsorbablePositions( + unattengedButton: UnattengedButton +): AbsorbablePosition[] { + const aps: AbsorbablePosition[] = []; + const unattengedButtons = unattengedButton.queryStore.queryByType( + UnattengedButton.Type + ); + const canvas = unattengedButton.getCanvas(); + unattengedButtons.forEach((item) => { + if (item.id === unattengedButton.id) { + return; + } + const ala = new AbsorbableLine( + new Point(item.x, 0), + new Point(item.x, canvas.height) + ); + const alb = new AbsorbableLine( + new Point(0, item.y), + new Point(canvas.width, item.y) + ); + aps.push(ala); + aps.push(alb); + }); + return aps; +} + +export class UnattengedButtonInteraction extends GraphicInteractionPlugin { + static Name = 'unattenged_button_transform'; + constructor(app: IDrawApp) { + super(UnattengedButtonInteraction.Name, app); + } + static init(app: IDrawApp) { + return new UnattengedButtonInteraction(app); + } + filter(...grahpics: JlGraphic[]): UnattengedButton[] | undefined { + return grahpics + .filter((g) => g.type === UnattengedButton.Type) + .map((g) => g as UnattengedButton); + } + bind(g: UnattengedButton): void { + g.eventMode = 'static'; + g.cursor = 'pointer'; + g.scalable = true; + g.rotatable = true; + g.codeGraph.draggable = true; + g.codeGraph.selectable = true; + g.codeGraph.rotatable = true; + g.codeGraph.transformSave = true; + g.codeGraph.eventMode = 'static'; + g.on('transformstart', this.transformstart, this); + } + unbind(g: UnattengedButton): void { + g.eventMode = 'none'; + g.scalable = false; + g.rotatable = false; + g.codeGraph.draggable = false; + g.codeGraph.selectable = false; + g.codeGraph.rotatable = false; + g.codeGraph.transformSave = false; + g.codeGraph.eventMode = 'none'; + g.off('transformstart', this.transformstart, this); + } + transformstart(e: GraphicTransformEvent) { + const target = e.target as DisplayObject; + const unattengedButton = target.getGraphic() as UnattengedButton; + unattengedButton.getGraphicApp().setOptions({ + absorbablePositions: buildAbsorbablePositions(unattengedButton), + }); + } +} diff --git a/src/layouts/DrawLayout.vue b/src/layouts/DrawLayout.vue index 4e620b7..752c2a9 100644 --- a/src/layouts/DrawLayout.vue +++ b/src/layouts/DrawLayout.vue @@ -278,6 +278,8 @@ import { PslBox } from 'src/graphics/pslBox/PslBox'; import { CarWashing } from 'src/graphics/carWashing/CarWashing'; import { GarageDoor } from 'src/graphics/garageDoor/GarageDoor'; import { FloodGate } from 'src/graphics/floodGate/FloodGate'; +import { HoldButton } from 'src/graphics/holdButton/HoldButton'; +import { UnattengedButton } from 'src/graphics/unattengedButton/UnattengedButton'; const $q = useQuasar(); const route = useRoute(); @@ -450,6 +452,8 @@ onMounted(() => { CarWashing.Type, GarageDoor.Type, FloodGate.Type, + HoldButton.Type, + UnattengedButton.Type, ]; switch (drawStore.categoryType) { case CategoryType.TH: diff --git a/src/protos/stationLayoutGraphics.ts b/src/protos/stationLayoutGraphics.ts index 32bbd2a..68d0358 100644 --- a/src/protos/stationLayoutGraphics.ts +++ b/src/protos/stationLayoutGraphics.ts @@ -56,9 +56,11 @@ export namespace graphicData { garageDoors?: GarageDoor[]; floodGates?: GarageDoor[]; lianSuoData?: LianSuoData; + holdButtons?: HoldButton[]; + unattengedButtons?: UnattengedButton[]; }) { super(); - pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 32, 33, 34, 35, 37, 39, 40, 41, 42, 43, 44, 45, 46, 47], this.#one_of_decls); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 32, 33, 34, 35, 37, 39, 40, 41, 42, 43, 44, 45, 46, 47, 50, 51], this.#one_of_decls); if (!Array.isArray(data) && typeof data == "object") { if ("canvas" in data && data.canvas != undefined) { this.canvas = data.canvas; @@ -189,6 +191,12 @@ export namespace graphicData { if ("lianSuoData" in data && data.lianSuoData != undefined) { this.lianSuoData = data.lianSuoData; } + if ("holdButtons" in data && data.holdButtons != undefined) { + this.holdButtons = data.holdButtons; + } + if ("unattengedButtons" in data && data.unattengedButtons != undefined) { + this.unattengedButtons = data.unattengedButtons; + } } } get canvas() { @@ -464,6 +472,18 @@ export namespace graphicData { get has_lianSuoData() { return pb_1.Message.getField(this, 49) != null; } + get holdButtons() { + return pb_1.Message.getRepeatedWrapperField(this, HoldButton, 50) as HoldButton[]; + } + set holdButtons(value: HoldButton[]) { + pb_1.Message.setRepeatedWrapperField(this, 50, value); + } + get unattengedButtons() { + return pb_1.Message.getRepeatedWrapperField(this, UnattengedButton, 51) as UnattengedButton[]; + } + set unattengedButtons(value: UnattengedButton[]) { + pb_1.Message.setRepeatedWrapperField(this, 51, value); + } static fromObject(data: { canvas?: ReturnType; Platforms?: ReturnType[]; @@ -508,6 +528,8 @@ export namespace graphicData { garageDoors?: ReturnType[]; floodGates?: ReturnType[]; lianSuoData?: ReturnType; + holdButtons?: ReturnType[]; + unattengedButtons?: ReturnType[]; }): RtssGraphicStorage { const message = new RtssGraphicStorage({}); if (data.canvas != null) { @@ -639,6 +661,12 @@ export namespace graphicData { if (data.lianSuoData != null) { message.lianSuoData = LianSuoData.fromObject(data.lianSuoData); } + if (data.holdButtons != null) { + message.holdButtons = data.holdButtons.map(item => HoldButton.fromObject(item)); + } + if (data.unattengedButtons != null) { + message.unattengedButtons = data.unattengedButtons.map(item => UnattengedButton.fromObject(item)); + } return message; } toObject() { @@ -686,6 +714,8 @@ export namespace graphicData { garageDoors?: ReturnType[]; floodGates?: ReturnType[]; lianSuoData?: ReturnType; + holdButtons?: ReturnType[]; + unattengedButtons?: ReturnType[]; } = {}; if (this.canvas != null) { data.canvas = this.canvas.toObject(); @@ -816,6 +846,12 @@ export namespace graphicData { if (this.lianSuoData != null) { data.lianSuoData = this.lianSuoData.toObject(); } + if (this.holdButtons != null) { + data.holdButtons = this.holdButtons.map((item: HoldButton) => item.toObject()); + } + if (this.unattengedButtons != null) { + data.unattengedButtons = this.unattengedButtons.map((item: UnattengedButton) => item.toObject()); + } return data; } serialize(): Uint8Array; @@ -908,6 +944,10 @@ export namespace graphicData { writer.writeRepeatedMessage(47, this.floodGates, (item: GarageDoor) => item.serialize(writer)); if (this.has_lianSuoData) writer.writeMessage(49, this.lianSuoData, () => this.lianSuoData.serialize(writer)); + if (this.holdButtons.length) + writer.writeRepeatedMessage(50, this.holdButtons, (item: HoldButton) => item.serialize(writer)); + if (this.unattengedButtons.length) + writer.writeRepeatedMessage(51, this.unattengedButtons, (item: UnattengedButton) => item.serialize(writer)); if (!w) return writer.getResultBuffer(); } @@ -1046,6 +1086,12 @@ export namespace graphicData { case 49: reader.readMessage(message.lianSuoData, () => message.lianSuoData = LianSuoData.deserialize(reader)); break; + case 50: + reader.readMessage(message.holdButtons, () => pb_1.Message.addToRepeatedWrapperField(message, 50, HoldButton.deserialize(reader), HoldButton)); + break; + case 51: + reader.readMessage(message.unattengedButtons, () => pb_1.Message.addToRepeatedWrapperField(message, 51, UnattengedButton.deserialize(reader), UnattengedButton)); + break; default: reader.skipField(); } } @@ -6418,11 +6464,10 @@ export namespace graphicData { common?: CommonInfo; code?: string; flip?: boolean; - refSections?: number[]; refStand?: number; }) { super(); - pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [8], this.#one_of_decls); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); if (!Array.isArray(data) && typeof data == "object") { if ("common" in data && data.common != undefined) { this.common = data.common; @@ -6433,9 +6478,6 @@ export namespace graphicData { if ("flip" in data && data.flip != undefined) { this.flip = data.flip; } - if ("refSections" in data && data.refSections != undefined) { - this.refSections = data.refSections; - } if ("refStand" in data && data.refStand != undefined) { this.refStand = data.refStand; } @@ -6462,12 +6504,6 @@ export namespace graphicData { set flip(value: boolean) { pb_1.Message.setField(this, 3, value); } - get refSections() { - return pb_1.Message.getFieldWithDefault(this, 8, []) as number[]; - } - set refSections(value: number[]) { - pb_1.Message.setField(this, 8, value); - } get refStand() { return pb_1.Message.getFieldWithDefault(this, 9, 0) as number; } @@ -6478,7 +6514,6 @@ export namespace graphicData { common?: ReturnType; code?: string; flip?: boolean; - refSections?: number[]; refStand?: number; }): SpksSwitch { const message = new SpksSwitch({}); @@ -6491,9 +6526,6 @@ export namespace graphicData { if (data.flip != null) { message.flip = data.flip; } - if (data.refSections != null) { - message.refSections = data.refSections; - } if (data.refStand != null) { message.refStand = data.refStand; } @@ -6504,7 +6536,6 @@ export namespace graphicData { common?: ReturnType; code?: string; flip?: boolean; - refSections?: number[]; refStand?: number; } = {}; if (this.common != null) { @@ -6516,9 +6547,6 @@ export namespace graphicData { if (this.flip != null) { data.flip = this.flip; } - if (this.refSections != null) { - data.refSections = this.refSections; - } if (this.refStand != null) { data.refStand = this.refStand; } @@ -6534,8 +6562,6 @@ export namespace graphicData { writer.writeString(2, this.code); if (this.flip != false) writer.writeBool(3, this.flip); - if (this.refSections.length) - writer.writePackedUint32(8, this.refSections); if (this.refStand != 0) writer.writeUint32(9, this.refStand); if (!w) @@ -6556,9 +6582,6 @@ export namespace graphicData { case 3: message.flip = reader.readBool(); break; - case 8: - message.refSections = reader.readPackedUint32(); - break; case 9: message.refStand = reader.readUint32(); break; @@ -9605,4 +9628,282 @@ export namespace graphicData { return LianSuoData.deserialize(bytes); } } + export class UnattengedButton extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + common?: CommonInfo; + code?: string; + flip?: boolean; + refStand?: number; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("common" in data && data.common != undefined) { + this.common = data.common; + } + if ("code" in data && data.code != undefined) { + this.code = data.code; + } + if ("flip" in data && data.flip != undefined) { + this.flip = data.flip; + } + if ("refStand" in data && data.refStand != undefined) { + this.refStand = data.refStand; + } + } + } + get common() { + return pb_1.Message.getWrapperField(this, CommonInfo, 1) as CommonInfo; + } + set common(value: CommonInfo) { + pb_1.Message.setWrapperField(this, 1, value); + } + get has_common() { + return pb_1.Message.getField(this, 1) != null; + } + get code() { + return pb_1.Message.getFieldWithDefault(this, 2, "") as string; + } + set code(value: string) { + pb_1.Message.setField(this, 2, value); + } + get flip() { + return pb_1.Message.getFieldWithDefault(this, 3, false) as boolean; + } + set flip(value: boolean) { + pb_1.Message.setField(this, 3, value); + } + get refStand() { + return pb_1.Message.getFieldWithDefault(this, 4, 0) as number; + } + set refStand(value: number) { + pb_1.Message.setField(this, 4, value); + } + static fromObject(data: { + common?: ReturnType; + code?: string; + flip?: boolean; + refStand?: number; + }): UnattengedButton { + const message = new UnattengedButton({}); + if (data.common != null) { + message.common = CommonInfo.fromObject(data.common); + } + if (data.code != null) { + message.code = data.code; + } + if (data.flip != null) { + message.flip = data.flip; + } + if (data.refStand != null) { + message.refStand = data.refStand; + } + return message; + } + toObject() { + const data: { + common?: ReturnType; + code?: string; + flip?: boolean; + refStand?: number; + } = {}; + if (this.common != null) { + data.common = this.common.toObject(); + } + if (this.code != null) { + data.code = this.code; + } + if (this.flip != null) { + data.flip = this.flip; + } + if (this.refStand != null) { + data.refStand = this.refStand; + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_common) + writer.writeMessage(1, this.common, () => this.common.serialize(writer)); + if (this.code.length) + writer.writeString(2, this.code); + if (this.flip != false) + writer.writeBool(3, this.flip); + if (this.refStand != 0) + writer.writeUint32(4, this.refStand); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): UnattengedButton { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new UnattengedButton(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.common, () => message.common = CommonInfo.deserialize(reader)); + break; + case 2: + message.code = reader.readString(); + break; + case 3: + message.flip = reader.readBool(); + break; + case 4: + message.refStand = reader.readUint32(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): UnattengedButton { + return UnattengedButton.deserialize(bytes); + } + } + export class HoldButton extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + common?: CommonInfo; + code?: string; + flip?: boolean; + refStand?: number; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("common" in data && data.common != undefined) { + this.common = data.common; + } + if ("code" in data && data.code != undefined) { + this.code = data.code; + } + if ("flip" in data && data.flip != undefined) { + this.flip = data.flip; + } + if ("refStand" in data && data.refStand != undefined) { + this.refStand = data.refStand; + } + } + } + get common() { + return pb_1.Message.getWrapperField(this, CommonInfo, 1) as CommonInfo; + } + set common(value: CommonInfo) { + pb_1.Message.setWrapperField(this, 1, value); + } + get has_common() { + return pb_1.Message.getField(this, 1) != null; + } + get code() { + return pb_1.Message.getFieldWithDefault(this, 2, "") as string; + } + set code(value: string) { + pb_1.Message.setField(this, 2, value); + } + get flip() { + return pb_1.Message.getFieldWithDefault(this, 3, false) as boolean; + } + set flip(value: boolean) { + pb_1.Message.setField(this, 3, value); + } + get refStand() { + return pb_1.Message.getFieldWithDefault(this, 4, 0) as number; + } + set refStand(value: number) { + pb_1.Message.setField(this, 4, value); + } + static fromObject(data: { + common?: ReturnType; + code?: string; + flip?: boolean; + refStand?: number; + }): HoldButton { + const message = new HoldButton({}); + if (data.common != null) { + message.common = CommonInfo.fromObject(data.common); + } + if (data.code != null) { + message.code = data.code; + } + if (data.flip != null) { + message.flip = data.flip; + } + if (data.refStand != null) { + message.refStand = data.refStand; + } + return message; + } + toObject() { + const data: { + common?: ReturnType; + code?: string; + flip?: boolean; + refStand?: number; + } = {}; + if (this.common != null) { + data.common = this.common.toObject(); + } + if (this.code != null) { + data.code = this.code; + } + if (this.flip != null) { + data.flip = this.flip; + } + if (this.refStand != null) { + data.refStand = this.refStand; + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_common) + writer.writeMessage(1, this.common, () => this.common.serialize(writer)); + if (this.code.length) + writer.writeString(2, this.code); + if (this.flip != false) + writer.writeBool(3, this.flip); + if (this.refStand != 0) + writer.writeUint32(4, this.refStand); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): HoldButton { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new HoldButton(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.common, () => message.common = CommonInfo.deserialize(reader)); + break; + case 2: + message.code = reader.readString(); + break; + case 3: + message.flip = reader.readBool(); + break; + case 4: + message.refStand = reader.readUint32(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): HoldButton { + return HoldButton.deserialize(bytes); + } + } }