MainToolbar.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. var 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. var 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. }
  68. handleGizmoAxisModeChanged(ev: Editor.GizmoAxisModeChangedEvent) {
  69. if (ev.mode) {
  70. this.axisButton.value = 0;
  71. this.axisButton.text = "Local";
  72. } else {
  73. this.axisButton.value = 1;
  74. this.axisButton.text = "World";
  75. }
  76. }
  77. handleGizmoEditModeChanged(ev: Editor.GizmoEditModeChangedEvent) {
  78. this.translateButton.value = 0;
  79. this.rotateButton.value = 0;
  80. this.scaleButton.value = 0;
  81. switch (ev.mode) {
  82. case 1:
  83. this.translateButton.value = 1;
  84. break;
  85. case 2:
  86. this.rotateButton.value = 1;
  87. break;
  88. case 3:
  89. this.scaleButton.value = 1;
  90. break;
  91. }
  92. }
  93. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  94. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK && ev.target) {
  95. if (ev.target.id == "3d_translate" || ev.target.id == "3d_rotate" || ev.target.id == "3d_scale") {
  96. var mode = 1;
  97. if (ev.target.id == "3d_rotate")
  98. mode = 2;
  99. else if (ev.target.id == "3d_scale")
  100. mode = 3;
  101. this.sendEvent("GizmoEditModeChanged", { mode: mode });
  102. return true;
  103. } else if (ev.target.id == "3d_axismode") {
  104. EditorUI.getShortcuts().toggleGizmoAxisMode();
  105. return true;
  106. } else if (ev.target.id == "maintoolbar_play") {
  107. EditorUI.getShortcuts().invokePlayOrStopPlayer();
  108. return true;
  109. } else if (ev.target.id == "maintoolbar_pause") {
  110. EditorUI.getShortcuts().invokePauseOrResumePlayer();
  111. return true;
  112. } else if (ev.target.id == "maintoolbar_step") {
  113. EditorUI.getShortcuts().invokeStepPausedPlayer();
  114. return true;
  115. }
  116. }
  117. }
  118. }
  119. export = MainToolbar;