|
@@ -0,0 +1,103 @@
|
|
|
+import { SGraphyItem, SGraphyView } from "@saga-web/graphy/lib";
|
|
|
+import { SMouseButton, SMouseEvent, SNetUtil } from "@saga-web/base/lib";
|
|
|
+import { SPoint } from "@saga-web/draw/lib";
|
|
|
+
|
|
|
+/**
|
|
|
+ * 楼层场景
|
|
|
+ *
|
|
|
+ * @author 郝建龙
|
|
|
+ */
|
|
|
+export class FloorView extends SGraphyView {
|
|
|
+ /** 鼠标左键键按下时位置 */
|
|
|
+ private _leftKeyPos = new SPoint();
|
|
|
+ /** 空格是否被按下 */
|
|
|
+ private spaceKey: boolean = false;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存底图json
|
|
|
+ *
|
|
|
+ * @param name 文件名
|
|
|
+ */
|
|
|
+ saveFloorJson(name: string): void {
|
|
|
+ // @ts-ignore
|
|
|
+ if (!this.scene || !this.scene.json) return;
|
|
|
+ // @ts-ignore
|
|
|
+ let url = URL.createObjectURL(new Blob([this.scene.json]));
|
|
|
+ SNetUtil.downLoad(name, url);
|
|
|
+ } // Function saveSceneSvg()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按键按下事件
|
|
|
+ *
|
|
|
+ * @param event 事件参数
|
|
|
+ */
|
|
|
+ protected onKeyDown(event: KeyboardEvent): void {
|
|
|
+ let keyCode = event.keyCode;
|
|
|
+ this.spaceKey = false;
|
|
|
+ switch (keyCode) {
|
|
|
+ case 32:
|
|
|
+ this.spaceKey = true;
|
|
|
+ break;
|
|
|
+ case 87:
|
|
|
+ this.origin.y -= 10;
|
|
|
+ break;
|
|
|
+ case 83:
|
|
|
+ this.origin.y += 10;
|
|
|
+ break;
|
|
|
+ case 68:
|
|
|
+ this.origin.x += 10;
|
|
|
+ break;
|
|
|
+ case 65:
|
|
|
+ this.origin.x -= 10;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ super.onKeyDown(event);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } // Function onKeyDown()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按键松开事件
|
|
|
+ *
|
|
|
+ * @param event 事件参数
|
|
|
+ */
|
|
|
+ protected onKeyUp(event: KeyboardEvent): void {
|
|
|
+ this.spaceKey = false;
|
|
|
+ super.onKeyUp(event);
|
|
|
+ } // Function onKeyUp()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 鼠标按下事件
|
|
|
+ *
|
|
|
+ * @param event 事件参数
|
|
|
+ */
|
|
|
+ protected onMouseDown(event: MouseEvent): void {
|
|
|
+ console.log(event)
|
|
|
+ let se = new SMouseEvent(event);
|
|
|
+ if (se.buttons & SMouseButton.LeftButton) {
|
|
|
+ this._leftKeyPos.x = se.x;
|
|
|
+ this._leftKeyPos.y = se.y;
|
|
|
+ }
|
|
|
+ super.onMouseDown(event);
|
|
|
+ } // Function onMouseDown()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 鼠标移动事件
|
|
|
+ *
|
|
|
+ * @param event 事件参数
|
|
|
+ */
|
|
|
+ protected onMouseMove(event: MouseEvent): void {
|
|
|
+ // 按左键移动
|
|
|
+ let se = new SMouseEvent(event);
|
|
|
+ if (se.buttons & SMouseButton.LeftButton) {
|
|
|
+ if (this.spaceKey) {
|
|
|
+ this.origin.x += se.x - this._leftKeyPos.x;
|
|
|
+ this.origin.y += se.y - this._leftKeyPos.y;
|
|
|
+ }
|
|
|
+ this._leftKeyPos.x = se.x;
|
|
|
+ this._leftKeyPos.y = se.y;
|
|
|
+ this.update();
|
|
|
+ }
|
|
|
+ super.onMouseMove(event);
|
|
|
+ } // Function onMouseMove()
|
|
|
+} // Class FloorScene
|