MainToolbar.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. constructor(parent: Atomic.UIWidget) {
  31. super();
  32. this.load("AtomicEditor/editor/ui/maintoolbar.tb.txt");
  33. this.translateButton = <Atomic.UIButton>this.getWidget("3d_translate");
  34. this.rotateButton = <Atomic.UIButton>this.getWidget("3d_rotate");
  35. this.scaleButton = <Atomic.UIButton>this.getWidget("3d_scale");
  36. this.axisButton = <Atomic.UIButton>this.getWidget("3d_axismode");
  37. this.playButton = <Atomic.UIButton>this.getWidget("maintoolbar_play");
  38. this.translateButton.value = 1;
  39. parent.addChild(this);
  40. this.subscribeToEvent("GizmoAxisModeChanged", (ev) => this.handleGizmoAxisModeChanged(ev));
  41. this.subscribeToEvent("GizmoEditModeChanged", (ev) => this.handleGizmoEditModeChanged(ev));
  42. this.subscribeToEvent(this, "WidgetEvent", (data) => this.handleWidgetEvent(data));
  43. this.subscribeToEvent(EditorEvents.PlayerStarted, (data) => {
  44. var skin = <Atomic.UISkinImage> this.playButton.getWidget("skin_image");
  45. skin.setSkinBg("StopButton");
  46. });
  47. this.subscribeToEvent(EditorEvents.PlayerStopped, (data) => {
  48. var skin = <Atomic.UISkinImage> this.playButton.getWidget("skin_image");
  49. skin.setSkinBg("PlayButton");
  50. });
  51. }
  52. handleGizmoAxisModeChanged(ev: Editor.GizmoAxisModeChangedEvent) {
  53. if (ev.mode) {
  54. this.axisButton.value = 0;
  55. this.axisButton.text = "Local";
  56. } else {
  57. this.axisButton.value = 1;
  58. this.axisButton.text = "World";
  59. }
  60. }
  61. handleGizmoEditModeChanged(ev: Editor.GizmoEditModeChangedEvent) {
  62. this.translateButton.value = 0;
  63. this.rotateButton.value = 0;
  64. this.scaleButton.value = 0;
  65. switch (ev.mode) {
  66. case 1:
  67. this.translateButton.value = 1;
  68. break;
  69. case 2:
  70. this.rotateButton.value = 1;
  71. break;
  72. case 3:
  73. this.scaleButton.value = 1;
  74. break;
  75. }
  76. }
  77. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  78. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK && ev.target) {
  79. if (ev.target.id == "3d_translate" || ev.target.id == "3d_rotate" || ev.target.id == "3d_scale") {
  80. var mode = 1;
  81. if (ev.target.id == "3d_rotate")
  82. mode = 2;
  83. else if (ev.target.id == "3d_scale")
  84. mode = 3;
  85. this.sendEvent("GizmoEditModeChanged", { mode: mode });
  86. return true;
  87. } else if (ev.target.id == "3d_axismode") {
  88. EditorUI.getShortcuts().toggleGizmoAxisMode();
  89. return true;
  90. } else if (ev.target.id == "maintoolbar_play") {
  91. EditorUI.getShortcuts().invokePlayOrStopPlayer();
  92. return true;
  93. }
  94. }
  95. }
  96. }
  97. export = MainToolbar;