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

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 { FederatedMouseEvent, DisplayObject } from 'pixi.js';
import { state } from 'src/protos/device_state'; import { state } from 'src/protos/device_state';
import { useLineStore } from 'src/stores/line-store'; import { useLineStore } from 'src/stores/line-store';
import { SignalGraphicHitArea } from 'src/graphics/signal/SignalDrawAssistant';
export class SignalData extends GraphicDataBase implements ISignalData { export class SignalData extends GraphicDataBase implements ISignalData {
constructor(data?: graphicData.Signal) { constructor(data?: graphicData.Signal) {
@ -334,6 +335,7 @@ export class SignalOperateInteraction extends GraphicInteractionPlugin<Signal> {
g.eventMode = 'static'; g.eventMode = 'static';
g.cursor = 'pointer'; g.cursor = 'pointer';
g.selectable = true; g.selectable = true;
g.lampMainBody.hitArea = new SignalGraphicHitArea(g);
g.on('_leftclick', this.onLeftClick, this); 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 { import {
AbsorbableLine, AbsorbableLine,
AbsorbablePosition, AbsorbablePosition,
@ -55,6 +55,22 @@ export class SignalDraw extends GraphicDrawAssistant<
return true; 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 * @param signal
@ -126,6 +142,7 @@ export class SignalInteraction extends GraphicInteractionPlugin<Signal> {
g.cursor = 'pointer'; g.cursor = 'pointer';
g.scalable = true; g.scalable = true;
g.rotatable = true; g.rotatable = true;
g.lampMainBody.hitArea = new SignalGraphicHitArea(g);
g.on('transformstart', this.transformstart, this); g.on('transformstart', this.transformstart, this);
g.signalCode.on('transformstart', this.codetransformstart, this); g.signalCode.on('transformstart', this.codetransformstart, this);
g.signalCode.draggable = true; g.signalCode.draggable = true;

View File

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