MainToolbar.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. import EditorEvents = require("../editor/EditorEvents");
  24. class MainToolbar extends Atomic.UIWidget {
  25. translateButton: Atomic.UIButton;
  26. rotateButton: Atomic.UIButton;
  27. scaleButton: Atomic.UIButton;
  28. axisButton: Atomic.UIButton;
  29. playButton: Atomic.UIButton;
  30. pauseButton: Atomic.UIButton;
  31. stepButton: 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.translateButton.value = 1;
  43. parent.addChild(this);
  44. this.subscribeToEvent("GizmoAxisModeChanged", (ev) => this.handleGizmoAxisModeChanged(ev));
  45. this.subscribeToEvent("GizmoEditModeChanged", (ev) => this.handleGizmoEditModeChanged(ev));
  46. this.subscribeToEvent(this, "WidgetEvent", (data) => this.handleWidgetEvent(data));
  47. this.subscribeToEvent(EditorEvents.PlayerStarted, (data) => {
  48. var skin = <Atomic.UISkinImage> this.playButton.getWidget("skin_image");
  49. skin.setSkinBg("StopButton");
  50. skin = <Atomic.UISkinImage> this.pauseButton.getWidget("skin_image");
  51. skin.setSkinBg("PauseButton");
  52. });
  53. this.subscribeToEvent(EditorEvents.PlayerStopped, (data) => {
  54. var skin = <Atomic.UISkinImage> this.playButton.getWidget("skin_image");
  55. skin.setSkinBg("PlayButton");
  56. skin = <Atomic.UISkinImage> this.pauseButton.getWidget("skin_image");
  57. skin.setSkinBg("PauseButton");
  58. });
  59. this.subscribeToEvent(EditorEvents.PlayerPaused, (data) => {
  60. var skin = <Atomic.UISkinImage> this.pauseButton.getWidget("skin_image");
  61. skin.setSkinBg("PlayButton");
  62. });
  63. this.subscribeToEvent(EditorEvents.PlayerResumed, (data) => {
  64. var skin = <Atomic.UISkinImage> this.pauseButton.getWidget("skin_image");
  65. skin.setSkinBg("PauseButton");
  66. });
  67. // TODO: We need better control over playmode during NET compiles
  68. this.subscribeToEvent("NETBuildBegin", (data) => {
  69. this.playButton.disable();
  70. });
  71. this.subscribeToEvent("NETBuildResult", (data) => {
  72. this.playButton.enable();
  73. });
  74. }
  75. handleGizmoAxisModeChanged(ev: Editor.GizmoAxisModeChangedEvent) {
  76. if (ev.mode) {
  77. this.axisButton.value = 0;
  78. this.axisButton.text = "Local";
  79. } else {
  80. this.axisButton.value = 1;
  81. this.axisButton.text = "World";
  82. }
  83. }
  84. handleGizmoEditModeChanged(ev: Editor.GizmoEditModeChangedEvent) {
  85. this.translateButton.value = 0;
  86. this.rotateButton.value = 0;
  87. this.scaleButton.value = 0;
  88. switch (ev.mode) {
  89. case 1:
  90. this.translateButton.value = 1;
  91. break;
  92. case 2:
  93. this.rotateButton.value = 1;
  94. break;
  95. case 3:
  96. this.scaleButton.value = 1;
  97. break;
  98. }
  99. }
  100. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  101. if (ev.type == Atomic.UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK && ev.target) {
  102. if (ev.target.id == "3d_translate" || ev.target.id == "3d_rotate" || ev.target.id == "3d_scale") {
  103. var mode = 1;
  104. if (ev.target.id == "3d_rotate")
  105. mode = 2;
  106. else if (ev.target.id == "3d_scale")
  107. mode = 3;
  108. this.sendEvent("GizmoEditModeChanged", { mode: mode });
  109. return true;
  110. } else if (ev.target.id == "3d_axismode") {
  111. EditorUI.getShortcuts().toggleGizmoAxisMode();
  112. return true;
  113. } else if (ev.target.id == "maintoolbar_play") {
  114. EditorUI.getShortcuts().invokePlayOrStopPlayer();
  115. return true;
  116. } else if (ev.target.id == "maintoolbar_pause") {
  117. EditorUI.getShortcuts().invokePauseOrResumePlayer();
  118. return true;
  119. } else if (ev.target.id == "maintoolbar_step") {
  120. EditorUI.getShortcuts().invokeStepPausedPlayer();
  121. return true;
  122. }
  123. }
  124. }
  125. }
  126. export = MainToolbar;