MainFrame.ts 5.7 KB

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