MainFrame.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 "../../hostExtensions/ServiceLocator";
  33. import * as EditorEvents from "../../editor/EditorEvents";
  34. class MainFrame extends ScriptWidget {
  35. constructor() {
  36. super();
  37. this.load("AtomicEditor/editor/ui/mainframe.tb.txt");
  38. this.inspectorlayout = <Atomic.UILayout> this.getWidget("inspectorlayout");
  39. this.getWidget("consolecontainer").visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  40. this.inspectorframe = new InspectorFrame();
  41. this.inspectorlayout.addChild(this.inspectorframe);
  42. this.projectframe = new ProjectFrame(this);
  43. this.hierarchyFrame = new HierarchyFrame(this);
  44. this.welcomeFrame = new WelcomeFrame(this);
  45. this.resourceframe = new ResourceFrame(this);
  46. this.mainToolbar = new MainToolbar(this.getWidget("maintoolbarcontainer"));
  47. this.menu = new MainFrameMenu();
  48. this.disableProjectMenus();
  49. this.subscribeToEvent(UIEvents.ResourceEditorChanged, (data) => this.handleResourceEditorChanged(data));
  50. this.subscribeToEvent("ProjectLoaded", (data) => {
  51. this.showWelcomeFrame(false);
  52. this.enableProjectMenus();
  53. this.resourcePath = ToolCore.toolSystem.project.getResourcePath();
  54. this.resourceCache = Atomic.getResourceCache();
  55. //Check if a 'Techniques' folder exists within a project, if so, add it to ResourceCache Directory
  56. if (Atomic.fileSystem.dirExists(this.resourcePath + "Techniques")){
  57. this.resourceCache.addResourceDir(this.resourcePath + "Techniques");
  58. }
  59. //Check if a 'Shaders' folder exists within a project, if so, add it to ResourceCache Directory
  60. if (Atomic.fileSystem.dirExists(this.resourcePath + "Shaders")) {
  61. this.resourceCache.addResourceDir(this.resourcePath + "Shaders");
  62. }
  63. });
  64. this.subscribeToEvent(EditorEvents.ProjectUnloadedNotification, (data) => {
  65. this.showWelcomeFrame(true);
  66. this.disableProjectMenus();
  67. });
  68. // Allow the service locator to hook into the event system
  69. ServiceLocator.subscribeToEvents(this);
  70. this.showWelcomeFrame(true);
  71. }
  72. frameVisible(frame: Atomic.UIWidget): boolean {
  73. var container = <Atomic.UILayout> this.getWidget("resourceviewcontainer");
  74. var child = null;
  75. for (child = container.firstChild; child; child = child.next) {
  76. if (child == frame)
  77. return true;
  78. }
  79. return false;
  80. }
  81. showWelcomeFrame(show: boolean) {
  82. if (show) {
  83. this.showInspectorFrame(false);
  84. this.welcomeFrame.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  85. this.resourceframe.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  86. }
  87. else {
  88. this.showInspectorFrame(true);
  89. this.resourceframe.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  90. this.welcomeFrame.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  91. }
  92. }
  93. showInspectorFrame(show: boolean) {
  94. if (show) {
  95. this.inspectorlayout.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  96. this.inspectorframe.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  97. } else {
  98. this.inspectorframe.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  99. this.inspectorlayout.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  100. }
  101. }
  102. onEventClick(target: Atomic.UIWidget, refid: string): boolean {
  103. if (this.menu.handlePopupMenu(target, refid))
  104. return true;
  105. var src = MenuItemSources.getMenuItemSource(target.id);
  106. if (src) {
  107. var menu = new Atomic.UIMenuWindow(target, target.id + " popup");
  108. menu.show(src);
  109. return true;
  110. }
  111. return false;
  112. }
  113. disableProjectMenus() {
  114. this.getWidget("menu edit").setStateRaw(Atomic.UI_WIDGET_STATE_DISABLED);
  115. this.getWidget("menu build").setStateRaw(Atomic.UI_WIDGET_STATE_DISABLED);
  116. this.getWidget("menu tools").setStateRaw(Atomic.UI_WIDGET_STATE_DISABLED);
  117. }
  118. enableProjectMenus() {
  119. this.getWidget("menu edit").setStateRaw(Atomic.UI_WIDGET_STATE_NONE);
  120. this.getWidget("menu build").setStateRaw(Atomic.UI_WIDGET_STATE_NONE);
  121. this.getWidget("menu tools").setStateRaw(Atomic.UI_WIDGET_STATE_NONE);
  122. }
  123. shutdown() {
  124. this.resourceframe.shutdown();
  125. this.deleteAllChildren();
  126. }
  127. handleResourceEditorChanged(data): void {
  128. var editor = <Editor.ResourceEditor> data.editor;
  129. if (editor) {
  130. //this.showInspectorFrame(editor.requiresInspector());
  131. } else {
  132. //this.showInspectorFrame(false);
  133. }
  134. }
  135. projectframe: ProjectFrame;
  136. resourceframe: ResourceFrame;
  137. inspectorframe: InspectorFrame;
  138. hierarchyFrame: HierarchyFrame;
  139. welcomeFrame: WelcomeFrame;
  140. inspectorlayout: Atomic.UILayout;
  141. mainToolbar: MainToolbar;
  142. menu: MainFrameMenu;
  143. resourceCache: Atomic.ResourceCache;
  144. resourcePath: String;
  145. }
  146. export = MainFrame;