pslButton状态调整

This commit is contained in:
fan 2023-10-20 11:04:03 +08:00
parent 0451397be2
commit 9e0f9296ae
4 changed files with 30 additions and 19 deletions

View File

@ -63,7 +63,6 @@ export class PslButtonData extends GraphicDataBase implements IPslButtonData {
return pb_1.Message.equals(this.data, other.data);
}
}
//GraphicStateBase
export class PslButtonState
extends GraphicStateBase
implements IPslButtonState
@ -127,7 +126,6 @@ export class PslButtonOperateInteraction extends GraphicInteractionPlugin<PslBut
// g.off('mousedown', this.onMouseDown, this);
g.on('mouseup', this.onMouseUp, this);
}
//FederatedMouseEvent
// onMouseDown(e: FederatedMouseEvent) {
// const simulationId = useLineStore().simulationId;
// const mapId = useLineStore().mapId;

View File

@ -23,7 +23,7 @@ import { PslLightDraw } from 'src/graphics/pslLight/pslLightDrawAssistant';
import { PslKey, PslKeyTemplate } from 'src/graphics/pslKey/pslKey';
import { PslKeyData } from './graphics/PslKeyInteraction';
import { PslButton, PslButtonTemplate } from 'src/graphics/pslButton/pslButton';
import { PslButtonData } from './graphics/PslButtonInteraction';
import { PslButtonData, PslButtonState } from './graphics/PslButtonInteraction';
import { PslLight, PslLightTemplate } from 'src/graphics/pslLight/pslLight';
import { PslLightData } from './graphics/PslLightInteraction';
import {
@ -75,7 +75,10 @@ export function initPslDrawApp(): IDrawApp {
const app = drawApp;
//根据草稿图类型加载绘图工具
new PslKeyDraw(app, new PslKeyTemplate(new PslKeyData()));
new PslButtonDraw(app, new PslButtonTemplate(new PslButtonData()));
new PslButtonDraw(
app,
new PslButtonTemplate(new PslButtonData(), new PslButtonState())
);
new PslLightDraw(app, new PslLightTemplate(new PslLightData()));
new TextContentDraw(app, new TextContentTemplate(new PslTextData()));

View File

@ -36,7 +36,7 @@ export function initPslScene(lineApp: IGraphicApp, sceneName: string) {
});
const graphicTemplate = [
new PslKeyTemplate(new PslKeyData()),
new PslButtonTemplate(new PslButtonData()),
new PslButtonTemplate(new PslButtonData(), new PslButtonState()),
new PslLightTemplate(new PslLightData()),
new TextContentTemplate(new PslTextData()),
];
@ -67,15 +67,14 @@ function handleSubscribe(pslScene: IGraphicScene) {
messageConverter: (message: Uint8Array) => {
// console.log('收到消息', message);
const states: GraphicState[] = [];
// const storage = state.PushedDevicesStatus.deserialize(message);
// if (storage.all) {
// storage.allStatus.buttonState.forEach((item) => {
// // 道岔
// if (item.id) {
// states.push(new PslButtonState(item));
// }
// });
// }
const storage = state.PushedDevicesStatus.deserialize(message);
if (storage.all) {
// storage.allStatus.buttonState.forEach((item) => {
// if (item.id) {
// states.push(new PslButtonState(item));
// }
// });
}
// console.log(states, 'states');
return states;
},

View File

@ -50,27 +50,38 @@ export class PslButton extends JlGraphic {
get datas(): IPslButtonData {
return this.getDatas<IPslButtonData>();
}
get states(): IPslButtonState {
return this.getStates<IPslButtonState>();
}
doRepaint(): void {
this._pslButton.rotation = 0;
if (this.datas.buttonColor === pslGraphicData.PslElementColor.green) {
this._pslButton.texture = this.pslButtonTextures.greenBtn;
if (this.states.down) {
this._pslButton.texture = this.pslButtonTextures.greenBtnPress;
} else {
this._pslButton.texture = this.pslButtonTextures.greenBtn;
}
} else {
this._pslButton.texture = this.pslButtonTextures.redBtn;
if (this.states.down) {
this._pslButton.texture = this.pslButtonTextures.redBtnPress;
} else {
this._pslButton.texture = this.pslButtonTextures.redBtn;
}
}
}
}
export class PslButtonTemplate extends JlGraphicTemplate<PslButton> {
pslButtonTextures?: PslButtonTextures;
constructor(dataTemplate: IPslButtonData) {
super(PslButton.Type, { dataTemplate });
constructor(dataTemplate: IPslButtonData, stateTemplate: IPslButtonState) {
super(PslButton.Type, { dataTemplate, stateTemplate });
this.loadAssets();
}
new(): PslButton {
if (this.pslButtonTextures) {
const g = new PslButton(this.pslButtonTextures);
g.loadData(this.datas);
// g.loadState(this.states);
g.loadState(this.states);
return g;
}
throw new Error('资源未加载/加载失败');