FloorView.ts 4.4 KB

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