MainToolbar.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. import EditorUI = require("./EditorUI");
  8. import EditorEvents = require("../editor/EditorEvents");
  9. class MainToolbar extends Atomic.UIWidget {
  10. translateButton: Atomic.UIButton;
  11. rotateButton: Atomic.UIButton;
  12. scaleButton: Atomic.UIButton;
  13. axisButton: Atomic.UIButton;
  14. playButton: Atomic.UIButton;
  15. constructor(parent: Atomic.UIWidget) {
  16. super();
  17. this.load("AtomicEditor/editor/ui/maintoolbar.tb.txt");
  18. this.translateButton = <Atomic.UIButton>this.getWidget("3d_translate");
  19. this.rotateButton = <Atomic.UIButton>this.getWidget("3d_rotate");
  20. this.scaleButton = <Atomic.UIButton>this.getWidget("3d_scale");
  21. this.axisButton = <Atomic.UIButton>this.getWidget("3d_axismode");
  22. this.playButton = <Atomic.UIButton>this.getWidget("maintoolbar_play");
  23. this.translateButton.value = 1;
  24. parent.addChild(this);
  25. this.subscribeToEvent("GizmoAxisModeChanged", (ev) => this.handleGizmoAxisModeChanged(ev));
  26. this.subscribeToEvent("GizmoEditModeChanged", (ev) => this.handleGizmoEditModeChanged(ev));
  27. this.subscribeToEvent(this, "WidgetEvent", (data) => this.handleWidgetEvent(data));
  28. this.subscribeToEvent(EditorEvents.PlayerStarted, (data) => {
  29. var skin = <Atomic.UISkinImage> this.playButton.getWidget("skin_image");
  30. skin.setSkinBg("StopButton");
  31. });
  32. this.subscribeToEvent(EditorEvents.PlayerStopped, (data) => {
  33. var skin = <Atomic.UISkinImage> this.playButton.getWidget("skin_image");
  34. skin.setSkinBg("PlayButton");
  35. });
  36. }
  37. handleGizmoAxisModeChanged(ev: Editor.GizmoAxisModeChangedEvent) {
  38. if (ev.mode) {
  39. this.axisButton.value = 0;
  40. this.axisButton.text = "Local";
  41. } else {
  42. this.axisButton.value = 1;
  43. this.axisButton.text = "World";
  44. }
  45. }
  46. handleGizmoEditModeChanged(ev: Editor.GizmoEditModeChangedEvent) {
  47. this.translateButton.value = 0;
  48. this.rotateButton.value = 0;
  49. this.scaleButton.value = 0;
  50. switch (ev.mode) {
  51. case 1:
  52. this.translateButton.value = 1;
  53. break;
  54. case 2:
  55. this.rotateButton.value = 1;
  56. break;
  57. case 3:
  58. this.scaleButton.value = 1;
  59. break;
  60. }
  61. }
  62. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  63. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK && ev.target) {
  64. if (ev.target.id == "3d_translate" || ev.target.id == "3d_rotate" || ev.target.id == "3d_scale") {
  65. var mode = 1;
  66. if (ev.target.id == "3d_rotate")
  67. mode = 2;
  68. else if (ev.target.id == "3d_scale")
  69. mode = 3;
  70. this.sendEvent("GizmoEditModeChanged", { mode: mode });
  71. return true;
  72. } else if (ev.target.id == "3d_axismode") {
  73. EditorUI.getShortcuts().toggleGizmoAxisMode();
  74. return true;
  75. } else if (ev.target.id == "maintoolbar_play") {
  76. EditorUI.getShortcuts().invokePlayOrStopPlayer();
  77. return true;
  78. }
  79. }
  80. }
  81. }
  82. export = MainToolbar;