信号机碰撞检测调整&状态弹出框关闭逻辑调整

This commit is contained in:
fan 2023-08-08 14:46:34 +08:00
parent 0bbda0dffb
commit bf7ee0a966
3 changed files with 24 additions and 4 deletions

View File

@ -17,6 +17,7 @@ import { MenuItemOptions } from 'src/jl-graphic/ui/Menu';
import { FederatedMouseEvent, DisplayObject } from 'pixi.js';
import { state } from 'src/protos/device_state';
import { useLineStore } from 'src/stores/line-store';
import { SignalGraphicHitArea } from 'src/graphics/signal/SignalDrawAssistant';
export class SignalData extends GraphicDataBase implements ISignalData {
constructor(data?: graphicData.Signal) {
@ -334,6 +335,7 @@ export class SignalOperateInteraction extends GraphicInteractionPlugin<Signal> {
g.eventMode = 'static';
g.cursor = 'pointer';
g.selectable = true;
g.lampMainBody.hitArea = new SignalGraphicHitArea(g);
g.on('_leftclick', this.onLeftClick, this);
}

View File

@ -1,4 +1,4 @@
import { DisplayObject, FederatedPointerEvent, Point } from 'pixi.js';
import { DisplayObject, FederatedPointerEvent, IHitArea, Point } from 'pixi.js';
import {
AbsorbableLine,
AbsorbablePosition,
@ -55,6 +55,22 @@ export class SignalDraw extends GraphicDrawAssistant<
return true;
}
}
export class SignalGraphicHitArea implements IHitArea {
signal: Signal;
constructor(signal: Signal) {
this.signal = signal;
}
contains(x: number, y: number): boolean {
const bound = this.signal.getLocalBounds();
const maxX = bound.x + bound.width;
const minX = bound.x;
const maxY = bound.y + bound.height;
const minY = bound.y;
return maxX >= x && x >= minX && maxY >= y && y >= minY;
}
}
/**
* 线
* @param signal
@ -126,6 +142,7 @@ export class SignalInteraction extends GraphicInteractionPlugin<Signal> {
g.cursor = 'pointer';
g.scalable = true;
g.rotatable = true;
g.lampMainBody.hitArea = new SignalGraphicHitArea(g);
g.on('transformstart', this.transformstart, this);
g.signalCode.on('transformstart', this.codetransformstart, this);
g.signalCode.draggable = true;

View File

@ -59,6 +59,7 @@ function onResize() {
const clientHeight = document.body.clientHeight;
canvasWidth.value = clientWidth;
canvasHeight.value = clientHeight - headerHeight.value;
console.log(canvasHeight.value, canvasWidth.value);
const dom = document.getElementById('line-app-container');
if (dom) {
dom.style.width = canvasWidth.value + 'px';
@ -101,9 +102,9 @@ onUnmounted(() => {
}
});
watch(
() => lineStore.stateProCount,
(count, prevCount) => {
if (count !== prevCount) {
[() => lineStore.stateProCount, () => lineStore.selectedGraphics],
([count, sg], [prevCount]) => {
if (count !== prevCount && sg && sg.length === 1) {
drawerRight.value = true;
} else {
drawerRight.value = false;