MainFrame.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 ProjectFrame = require("./ProjectFrame");
  23. import ResourceFrame = require("./ResourceFrame");
  24. import WelcomeFrame = require("./WelcomeFrame");
  25. import InspectorFrame = require("./inspector/InspectorFrame");
  26. import HierarchyFrame = require("./HierarchyFrame");
  27. import MainToolbar = require("ui//MainToolbar");
  28. import UIEvents = require("ui/UIEvents");
  29. import ScriptWidget = require("ui/ScriptWidget");
  30. import MainFrameMenu = require("./menus/MainFrameMenu");
  31. import MenuItemSources = require("./menus/MenuItemSources");
  32. import ServiceLocator from "../../extensionServices/ServiceLocator";
  33. class MainFrame extends ScriptWidget {
  34. constructor() {
  35. super();
  36. this.load("AtomicEditor/editor/ui/mainframe.tb.txt");
  37. this.inspectorlayout = <Atomic.UILayout> this.getWidget("inspectorlayout");
  38. this.getWidget("consolecontainer").visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  39. this.inspectorframe = new InspectorFrame();
  40. this.inspectorlayout.addChild(this.inspectorframe);
  41. this.projectframe = new ProjectFrame(this);
  42. this.hierarchyFrame = new HierarchyFrame(this);
  43. this.welcomeFrame = new WelcomeFrame(this);
  44. this.resourceframe = new ResourceFrame(this);
  45. this.mainToolbar = new MainToolbar(this.getWidget("maintoolbarcontainer"));
  46. this.menu = new MainFrameMenu();
  47. this.disableProjectMenus();
  48. this.subscribeToEvent(UIEvents.ResourceEditorChanged, (data) => this.handleResourceEditorChanged(data));
  49. this.subscribeToEvent("ProjectLoaded", (data) => {
  50. this.showWelcomeFrame(false);
  51. this.enableProjectMenus();
  52. });
  53. this.subscribeToEvent("ProjectUnloaded", (data) => {
  54. this.showWelcomeFrame(true);
  55. this.disableProjectMenus();
  56. });
  57. // Allow the service locator to hook into the event system
  58. ServiceLocator.subscribeToEvents(this);
  59. this.showWelcomeFrame(true);
  60. }
  61. frameVisible(frame: Atomic.UIWidget): boolean {
  62. var container = <Atomic.UILayout> this.getWidget("resourceviewcontainer");
  63. var child = null;
  64. for (child = container.firstChild; child; child = child.next) {
  65. if (child == frame)
  66. return true;
  67. }
  68. return false;
  69. }
  70. showWelcomeFrame(show: boolean) {
  71. if (show) {
  72. this.showInspectorFrame(false);
  73. this.welcomeFrame.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  74. this.resourceframe.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  75. }
  76. else {
  77. this.showInspectorFrame(true);
  78. this.resourceframe.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  79. this.welcomeFrame.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  80. }
  81. }
  82. showInspectorFrame(show: boolean) {
  83. if (show) {
  84. this.inspectorlayout.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  85. this.inspectorframe.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  86. } else {
  87. this.inspectorframe.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  88. this.inspectorlayout.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  89. }
  90. }
  91. onEventClick(target: Atomic.UIWidget, refid: string): boolean {
  92. if (this.menu.handlePopupMenu(target, refid))
  93. return true;
  94. var src = MenuItemSources.getMenuItemSource(target.id);
  95. if (src) {
  96. var menu = new Atomic.UIMenuWindow(target, target.id + " popup");
  97. menu.show(src);
  98. return true;
  99. }
  100. return false;
  101. }
  102. disableProjectMenus() {
  103. this.getWidget("menu edit").setStateRaw(Atomic.UI_WIDGET_STATE_DISABLED);
  104. this.getWidget("menu build").setStateRaw(Atomic.UI_WIDGET_STATE_DISABLED);
  105. this.getWidget("menu tools").setStateRaw(Atomic.UI_WIDGET_STATE_DISABLED);
  106. }
  107. enableProjectMenus() {
  108. this.getWidget("menu edit").setStateRaw(Atomic.UI_WIDGET_STATE_NONE);
  109. this.getWidget("menu build").setStateRaw(Atomic.UI_WIDGET_STATE_NONE);
  110. this.getWidget("menu tools").setStateRaw(Atomic.UI_WIDGET_STATE_NONE);
  111. }
  112. shutdown() {
  113. this.resourceframe.shutdown();
  114. this.deleteAllChildren();
  115. }
  116. handleResourceEditorChanged(data): void {
  117. var editor = <Editor.ResourceEditor> data.editor;
  118. if (editor) {
  119. //this.showInspectorFrame(editor.requiresInspector());
  120. } else {
  121. //this.showInspectorFrame(false);
  122. }
  123. }
  124. projectframe: ProjectFrame;
  125. resourceframe: ResourceFrame;
  126. inspectorframe: InspectorFrame;
  127. hierarchyFrame: HierarchyFrame;
  128. welcomeFrame: WelcomeFrame;
  129. inspectorlayout: Atomic.UILayout;
  130. mainToolbar: MainToolbar;
  131. menu: MainFrameMenu;
  132. }
  133. export = MainFrame;