MainFrame.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. });
  54. this.subscribeToEvent(EditorEvents.ProjectUnloadedNotification, (data) => {
  55. this.showWelcomeFrame(true);
  56. this.disableProjectMenus();
  57. });
  58. // Allow the service locator to hook into the event system
  59. ServiceLocator.uiServices.setMainFrameMenu(this.menu);
  60. ServiceLocator.subscribeToEvents(this);
  61. this.showWelcomeFrame(true);
  62. }
  63. frameVisible(frame: Atomic.UIWidget): boolean {
  64. var container = <Atomic.UILayout> this.getWidget("resourceviewcontainer");
  65. var child = null;
  66. for (child = container.firstChild; child; child = child.next) {
  67. if (child == frame)
  68. return true;
  69. }
  70. return false;
  71. }
  72. showWelcomeFrame(show: boolean) {
  73. if (show) {
  74. this.showInspectorFrame(false);
  75. this.welcomeFrame.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  76. this.resourceframe.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  77. }
  78. else {
  79. this.showInspectorFrame(true);
  80. this.resourceframe.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  81. this.welcomeFrame.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  82. }
  83. }
  84. showInspectorFrame(show: boolean) {
  85. if (show) {
  86. this.inspectorlayout.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  87. this.inspectorframe.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  88. } else {
  89. this.inspectorframe.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  90. this.inspectorlayout.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  91. }
  92. }
  93. onEventClick(target: Atomic.UIWidget, refid: string): boolean {
  94. if (this.menu.handlePopupMenu(target, refid))
  95. return true;
  96. var src = MenuItemSources.getMenuItemSource(target.id);
  97. if (src) {
  98. var menu = new Atomic.UIMenuWindow(target, target.id + " popup");
  99. menu.show(src);
  100. return true;
  101. }
  102. return false;
  103. }
  104. disableProjectMenus() {
  105. this.getWidget("menu edit").setStateRaw(Atomic.UI_WIDGET_STATE_DISABLED);
  106. this.getWidget("menu build").setStateRaw(Atomic.UI_WIDGET_STATE_DISABLED);
  107. this.getWidget("menu tools").setStateRaw(Atomic.UI_WIDGET_STATE_DISABLED);
  108. }
  109. enableProjectMenus() {
  110. this.getWidget("menu edit").setStateRaw(Atomic.UI_WIDGET_STATE_NONE);
  111. this.getWidget("menu build").setStateRaw(Atomic.UI_WIDGET_STATE_NONE);
  112. this.getWidget("menu tools").setStateRaw(Atomic.UI_WIDGET_STATE_NONE);
  113. }
  114. shutdown() {
  115. this.resourceframe.shutdown();
  116. this.deleteAllChildren();
  117. }
  118. handleResourceEditorChanged(data): void {
  119. var editor = <Editor.ResourceEditor> data.editor;
  120. if (editor) {
  121. //this.showInspectorFrame(editor.requiresInspector());
  122. } else {
  123. //this.showInspectorFrame(false);
  124. }
  125. }
  126. projectframe: ProjectFrame;
  127. resourceframe: ResourceFrame;
  128. inspectorframe: InspectorFrame;
  129. hierarchyFrame: HierarchyFrame;
  130. welcomeFrame: WelcomeFrame;
  131. inspectorlayout: Atomic.UILayout;
  132. mainToolbar: MainToolbar;
  133. menu: MainFrameMenu;
  134. }
  135. export = MainFrame;