MainToolbar.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. import EditorUI = require("./EditorUI");
  23. class MainToolbar extends Atomic.UIWidget {
  24. translateButton: Atomic.UIButton;
  25. rotateButton: Atomic.UIButton;
  26. scaleButton: Atomic.UIButton;
  27. axisButton: Atomic.UIButton;
  28. playButton: Atomic.UIButton;
  29. pauseButton: Atomic.UIButton;
  30. stepButton: Atomic.UIButton;
  31. jsdebugButton: Atomic.UIButton;
  32. constructor(parent: Atomic.UIWidget) {
  33. super();
  34. this.load("AtomicEditor/editor/ui/maintoolbar.tb.txt");
  35. this.translateButton = <Atomic.UIButton>this.getWidget("3d_translate");
  36. this.rotateButton = <Atomic.UIButton>this.getWidget("3d_rotate");
  37. this.scaleButton = <Atomic.UIButton>this.getWidget("3d_scale");
  38. this.axisButton = <Atomic.UIButton>this.getWidget("3d_axismode");
  39. this.playButton = <Atomic.UIButton>this.getWidget("maintoolbar_play");
  40. this.pauseButton = <Atomic.UIButton>this.getWidget("maintoolbar_pause");
  41. this.stepButton = <Atomic.UIButton>this.getWidget("maintoolbar_step");
  42. this.jsdebugButton = <Atomic.UIButton>this.getWidget("maintoolbar_jsdebug");
  43. this.translateButton.value = 1;
  44. parent.addChild(this);
  45. this.subscribeToEvent(Editor.GizmoAxisModeChangedEvent((ev) => this.handleGizmoAxisModeChanged(ev)));
  46. this.subscribeToEvent(Editor.GizmoEditModeChangedEvent((ev) => this.handleGizmoEditModeChanged(ev)));
  47. this.subscribeToEvent(this, Atomic.UIWidgetEvent((data) => this.handleWidgetEvent(data)));
  48. this.subscribeToEvent(Editor.EditorPlayerStartedEvent(() => {
  49. var skin = <Atomic.UISkinImage> this.playButton.getWidget("skin_image");
  50. skin.setSkinBg("StopButton");
  51. skin = <Atomic.UISkinImage> this.pauseButton.getWidget("skin_image");
  52. skin.setSkinBg("PauseButton");
  53. }));
  54. this.subscribeToEvent(Editor.EditorPlayerStoppedEvent(() => {
  55. var skin = <Atomic.UISkinImage> this.playButton.getWidget("skin_image");
  56. skin.setSkinBg("PlayButton");
  57. skin = <Atomic.UISkinImage> this.pauseButton.getWidget("skin_image");
  58. skin.setSkinBg("PauseButton");
  59. }));
  60. this.subscribeToEvent(Editor.EditorPlayerPausedEvent(() => {
  61. var skin = <Atomic.UISkinImage> this.pauseButton.getWidget("skin_image");
  62. skin.setSkinBg("PlayButton");
  63. }));
  64. this.subscribeToEvent(Editor.EditorPlayerResumedEvent(() => {
  65. var skin = <Atomic.UISkinImage> this.pauseButton.getWidget("skin_image");
  66. skin.setSkinBg("PauseButton");
  67. }));
  68. // TODO: We need better control over playmode during NET compiles
  69. this.subscribeToEvent(ToolCore.NETBuildBeginEvent((data) => {
  70. this.playButton.disable();
  71. }));
  72. this.subscribeToEvent(ToolCore.NETBuildResultEvent((data) => {
  73. this.playButton.enable();
  74. }));
  75. }
  76. handleGizmoAxisModeChanged(ev: Editor.GizmoAxisModeChangedEvent) {
  77. if (ev.mode) {
  78. this.axisButton.value = 0;
  79. this.axisButton.text = "Local";
  80. } else {
  81. this.axisButton.value = 1;
  82. this.axisButton.text = "World";
  83. }
  84. }
  85. handleGizmoEditModeChanged(ev: Editor.GizmoEditModeChangedEvent) {
  86. this.translateButton.value = 0;
  87. this.rotateButton.value = 0;
  88. this.scaleButton.value = 0;
  89. switch (ev.mode) {
  90. case 1:
  91. this.translateButton.value = 1;
  92. break;
  93. case 2:
  94. this.rotateButton.value = 1;
  95. break;
  96. case 3:
  97. this.scaleButton.value = 1;
  98. break;
  99. }
  100. }
  101. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  102. if (ev.type == Atomic.UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK && ev.target) {
  103. if (ev.target.id == "3d_translate" || ev.target.id == "3d_rotate" || ev.target.id == "3d_scale") {
  104. var mode = 1;
  105. if (ev.target.id == "3d_rotate")
  106. mode = 2;
  107. else if (ev.target.id == "3d_scale")
  108. mode = 3;
  109. this.sendEvent(Editor.GizmoEditModeChangedEventData({ mode: mode }));
  110. return true;
  111. } else if (ev.target.id == "3d_axismode") {
  112. EditorUI.getShortcuts().toggleGizmoAxisMode();
  113. return true;
  114. } else if (ev.target.id == "maintoolbar_play") {
  115. EditorUI.getShortcuts().invokePlayOrStopPlayer();
  116. return true;
  117. } else if (ev.target.id == "maintoolbar_pause") {
  118. EditorUI.getShortcuts().invokePauseOrResumePlayer();
  119. return true;
  120. } else if (ev.target.id == "maintoolbar_step") {
  121. EditorUI.getShortcuts().invokeStepPausedPlayer();
  122. return true;
  123. } else if (ev.target.id == "maintoolbar_jsdebug") {
  124. EditorUI.getShortcuts().invokePlayerJSDebug();
  125. return true;
  126. }
  127. }
  128. }
  129. }
  130. export = MainToolbar;