FloorView.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * ********************************************************************************************************************
  3. *
  4. * :*$@@%$*: ;: ;; ;;
  5. * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
  6. * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
  7. * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
  8. * =@* %! @ $= % %@= =%@! %=
  9. * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
  10. * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
  11. * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
  12. * $@* ;@@@%=!: *@*
  13. * =@$ ;;;!=%@@@@=! =@!
  14. * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司
  15. * ;%@@$=$@@%* *@@@$=%@@%;
  16. * ::;:: ::;:: All rights reserved.
  17. *
  18. * ********************************************************************************************************************
  19. */
  20. import { SGraphyView } from "@saga-web/graphy/lib";
  21. import {
  22. SMouseButton,
  23. SMouseEvent,
  24. SNetUtil,
  25. STouchState
  26. } from "@saga-web/base/lib";
  27. import { SPoint } from "@saga-web/draw/lib";
  28. /**
  29. * 楼层场景
  30. *
  31. * @author 郝建龙
  32. */
  33. export class FloorView extends SGraphyView {
  34. /** 鼠标左键键按下时位置 */
  35. private _leftKeyPos = new SPoint();
  36. /** 空格是否被按下 */
  37. private spaceKey: boolean = false;
  38. /**
  39. * 保存底图json
  40. *
  41. * @param name 文件名
  42. */
  43. saveFloorJson(name: string): void {
  44. // @ts-ignore
  45. if (!this.scene || !this.scene.json) return;
  46. // @ts-ignore
  47. let url = URL.createObjectURL(new Blob([this.scene.json]));
  48. SNetUtil.downLoad(name, url);
  49. } // Function saveSceneSvg()
  50. /**
  51. * 按键按下事件
  52. *
  53. * @param event 事件参数
  54. */
  55. protected onKeyDown(event: KeyboardEvent): void {
  56. let keyCode = event.keyCode;
  57. this.spaceKey = false;
  58. if (keyCode == 32) {
  59. // 空格按键
  60. this.spaceKey = true;
  61. } else if (keyCode == 87) {
  62. // w按键
  63. this.origin.y -= 10;
  64. } else if (keyCode == 83) {
  65. // s按键
  66. this.origin.y += 10;
  67. } else if (keyCode == 68) {
  68. // d按键
  69. this.origin.x += 10;
  70. } else if (keyCode == 65) {
  71. // a按键
  72. this.origin.x -= 10;
  73. } else {
  74. super.onKeyDown(event);
  75. }
  76. } // Function onKeyDown()
  77. /**
  78. * 按键松开事件
  79. *
  80. * @param event 事件参数
  81. */
  82. protected onKeyUp(event: KeyboardEvent): void {
  83. this.spaceKey = false;
  84. super.onKeyUp(event);
  85. } // Function onKeyUp()
  86. /**
  87. * 鼠标按下事件
  88. *
  89. * @param event 事件参数
  90. */
  91. protected onMouseDown(event: MouseEvent): void {
  92. let se = new SMouseEvent(event);
  93. if (se.buttons & SMouseButton.LeftButton) {
  94. this._leftKeyPos.x = se.x;
  95. this._leftKeyPos.y = se.y;
  96. }
  97. super.onMouseDown(event);
  98. } // Function onMouseDown()
  99. /**
  100. * 鼠标移动事件
  101. *
  102. * @param event 事件参数
  103. */
  104. protected onMouseMove(event: MouseEvent): void {
  105. // 按左键移动
  106. let se = new SMouseEvent(event);
  107. if (se.buttons & SMouseButton.LeftButton) {
  108. if (this.spaceKey) {
  109. this.origin.x += se.x - this._leftKeyPos.x;
  110. this.origin.y += se.y - this._leftKeyPos.y;
  111. }
  112. this._leftKeyPos.x = se.x;
  113. this._leftKeyPos.y = se.y;
  114. }
  115. super.onMouseMove(event);
  116. } // Function onMouseMove()
  117. } // Class FloorScene