/* * ******************************************************************************************************************** * * :*$@@%$*: ;: ;; ;; * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@ * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$ * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$= * =@* %! @ $= % %@= =%@! %= * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =% * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%* * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$ * $@* ;@@@%=!: *@* * =@$ ;;;!=%@@@@=! =@! * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司 * ;%@@$=$@@%* *@@@$=%@@%; * ::;:: ::;:: All rights reserved. * * ******************************************************************************************************************** */ import { 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; if (keyCode == 32) { // 空格按键 this.spaceKey = true; } else if (keyCode == 87) { // w按键 this.origin.y -= 10; } else if (keyCode == 83) { // s按键 this.origin.y += 10; } else if (keyCode == 68) { // d按键 this.origin.x += 10; } else if (keyCode == 65) { // a按键 this.origin.x -= 10; } else { super.onKeyDown(event); } } // Function onKeyDown() /** * 按键松开事件 * * @param event 事件参数 */ protected onKeyUp(event: KeyboardEvent): void { this.spaceKey = false; super.onKeyUp(event); } // Function onKeyUp() /** * 鼠标按下事件 * * @param event 事件参数 */ protected onMouseDown(event: MouseEvent): void { let se = new SMouseEvent(event); if (this.spaceKey) { if (se.buttons & SMouseButton.LeftButton) { this._leftKeyPos.x = se.x; this._leftKeyPos.y = se.y; } } else { super.onMouseDown(event); } } // Function onMouseDown() /** * 鼠标移动事件 * * @param event 事件参数 */ protected onMouseMove(event: MouseEvent): void { // 如果可以移动 if (this.moveable) { // 按左键移动 let se = new SMouseEvent(event); if (this.spaceKey) { if (se.buttons & SMouseButton.LeftButton) { 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; return; } } else { super.onMouseMove(event); } } } // Function onMouseMove() } // Class FloorScene