MainToolbar.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. constructor(parent: Atomic.UIWidget) {
  32. super();
  33. this.load("AtomicEditor/editor/ui/maintoolbar.tb.txt");
  34. this.translateButton = <Atomic.UIButton>this.getWidget("3d_translate");
  35. this.rotateButton = <Atomic.UIButton>this.getWidget("3d_rotate");
  36. this.scaleButton = <Atomic.UIButton>this.getWidget("3d_scale");
  37. this.axisButton = <Atomic.UIButton>this.getWidget("3d_axismode");
  38. this.playButton = <Atomic.UIButton>this.getWidget("maintoolbar_play");
  39. this.pauseButton = <Atomic.UIButton>this.getWidget("maintoolbar_pause");
  40. this.stepButton = <Atomic.UIButton>this.getWidget("maintoolbar_step");
  41. this.translateButton.value = 1;
  42. parent.addChild(this);
  43. this.subscribeToEvent(Editor.GizmoAxisModeChangedEvent((ev) => this.handleGizmoAxisModeChanged(ev)));
  44. this.subscribeToEvent(Editor.GizmoEditModeChangedEvent((ev) => this.handleGizmoEditModeChanged(ev)));
  45. this.subscribeToEvent(this, Atomic.UIWidgetEvent((data) => this.handleWidgetEvent(data)));
  46. this.subscribeToEvent(Editor.EditorPlayerStartedEvent(() => {
  47. var skin = <Atomic.UISkinImage> this.playButton.getWidget("skin_image");
  48. skin.setSkinBg("StopButton");
  49. skin = <Atomic.UISkinImage> this.pauseButton.getWidget("skin_image");
  50. skin.setSkinBg("PauseButton");
  51. }));
  52. this.subscribeToEvent(Editor.EditorPlayerStoppedEvent(() => {
  53. var skin = <Atomic.UISkinImage> this.playButton.getWidget("skin_image");
  54. skin.setSkinBg("PlayButton");
  55. skin = <Atomic.UISkinImage> this.pauseButton.getWidget("skin_image");
  56. skin.setSkinBg("PauseButton");
  57. }));
  58. this.subscribeToEvent(Editor.EditorPlayerPausedEvent(() => {
  59. var skin = <Atomic.UISkinImage> this.pauseButton.getWidget("skin_image");
  60. skin.setSkinBg("PlayButton");
  61. }));
  62. this.subscribeToEvent(Editor.EditorPlayerResumedEvent(() => {
  63. var skin = <Atomic.UISkinImage> this.pauseButton.getWidget("skin_image");
  64. skin.setSkinBg("PauseButton");
  65. }));
  66. // TODO: We need better control over playmode during NET compiles
  67. this.subscribeToEvent(ToolCore.NETBuildBeginEvent((data) => {
  68. this.playButton.disable();
  69. }));
  70. this.subscribeToEvent(ToolCore.NETBuildResultEvent((data) => {
  71. this.playButton.enable();
  72. }));
  73. }
  74. handleGizmoAxisModeChanged(ev: Editor.GizmoAxisModeChangedEvent) {
  75. if (ev.mode) {
  76. this.axisButton.value = 0;
  77. this.axisButton.text = "Local";
  78. } else {
  79. this.axisButton.value = 1;
  80. this.axisButton.text = "World";
  81. }
  82. }
  83. handleGizmoEditModeChanged(ev: Editor.GizmoEditModeChangedEvent) {
  84. this.translateButton.value = 0;
  85. this.rotateButton.value = 0;
  86. this.scaleButton.value = 0;
  87. switch (ev.mode) {
  88. case 1:
  89. this.translateButton.value = 1;
  90. break;
  91. case 2:
  92. this.rotateButton.value = 1;
  93. break;
  94. case 3:
  95. this.scaleButton.value = 1;
  96. break;
  97. }
  98. }
  99. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  100. if (ev.type == Atomic.UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK && ev.target) {
  101. if (ev.target.id == "3d_translate" || ev.target.id == "3d_rotate" || ev.target.id == "3d_scale") {
  102. var mode = 1;
  103. if (ev.target.id == "3d_rotate")
  104. mode = 2;
  105. else if (ev.target.id == "3d_scale")
  106. mode = 3;
  107. this.sendEvent(Editor.GizmoEditModeChangedEventData({ mode: mode }));
  108. return true;
  109. } else if (ev.target.id == "3d_axismode") {
  110. EditorUI.getShortcuts().toggleGizmoAxisMode();
  111. return true;
  112. } else if (ev.target.id == "maintoolbar_play") {
  113. EditorUI.getShortcuts().invokePlayOrStopPlayer();
  114. return true;
  115. } else if (ev.target.id == "maintoolbar_pause") {
  116. EditorUI.getShortcuts().invokePauseOrResumePlayer();
  117. return true;
  118. } else if (ev.target.id == "maintoolbar_step") {
  119. EditorUI.getShortcuts().invokeStepPausedPlayer();
  120. return true;
  121. }
  122. }
  123. }
  124. }
  125. export = MainToolbar;