MainFrame.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 AnimationToolbar = require("ui//AnimationToolbar");
  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.UI_WIDGET_VISIBILITY_GONE;
  38. this.statusText = <Atomic.UIEditField>this.getWidget("editorStatusText");
  39. this.statusText.subscribeToEvent(Atomic.UpdateEvent((ev) => this.handleStatusAging(ev)));
  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(Editor.EditorResourceEditorChangedEvent((data) => this.handleResourceEditorChanged(data)));
  50. this.subscribeToEvent(ToolCore.ProjectLoadedEvent((data) => {
  51. this.showWelcomeFrame(false);
  52. this.enableProjectMenus();
  53. }));
  54. this.subscribeToEvent(Editor.ProjectUnloadedNotificationEvent((data) => {
  55. this.showWelcomeFrame(true);
  56. this.disableProjectMenus();
  57. }));
  58. this.showWelcomeFrame(true);
  59. }
  60. frameVisible(frame: Atomic.UIWidget): boolean {
  61. var container = <Atomic.UILayout> this.getWidget("resourceviewcontainer");
  62. var child = null;
  63. for (child = container.firstChild; child; child = child.next) {
  64. if (child == frame)
  65. return true;
  66. }
  67. return false;
  68. }
  69. showWelcomeFrame(show: boolean) {
  70. if (show) {
  71. this.showInspectorFrame(false);
  72. this.welcomeFrame.visibility = Atomic.UI_WIDGET_VISIBILITY.UI_WIDGET_VISIBILITY_VISIBLE;
  73. this.resourceframe.visibility = Atomic.UI_WIDGET_VISIBILITY.UI_WIDGET_VISIBILITY_GONE;
  74. }
  75. else {
  76. this.showInspectorFrame(true);
  77. this.resourceframe.visibility = Atomic.UI_WIDGET_VISIBILITY.UI_WIDGET_VISIBILITY_VISIBLE;
  78. this.welcomeFrame.visibility = Atomic.UI_WIDGET_VISIBILITY.UI_WIDGET_VISIBILITY_GONE;
  79. }
  80. }
  81. showInspectorFrame(show: boolean) {
  82. if (show) {
  83. this.inspectorlayout.visibility = Atomic.UI_WIDGET_VISIBILITY.UI_WIDGET_VISIBILITY_VISIBLE;
  84. this.inspectorframe.visibility = Atomic.UI_WIDGET_VISIBILITY.UI_WIDGET_VISIBILITY_VISIBLE;
  85. } else {
  86. this.inspectorframe.visibility = Atomic.UI_WIDGET_VISIBILITY.UI_WIDGET_VISIBILITY_GONE;
  87. this.inspectorlayout.visibility = Atomic.UI_WIDGET_VISIBILITY.UI_WIDGET_VISIBILITY_GONE;
  88. }
  89. }
  90. onEventClick(target: Atomic.UIWidget, refid: string): boolean {
  91. if (this.menu.handlePopupMenu(target, refid))
  92. return true;
  93. var src = MenuItemSources.getMenuItemSource(target.id);
  94. if (src) {
  95. var menu = new Atomic.UIMenuWindow(target, target.id + " popup");
  96. menu.show(src);
  97. return true;
  98. }
  99. return false;
  100. }
  101. disableProjectMenus() {
  102. this.getWidget("menu edit").setStateRaw(Atomic.UI_WIDGET_STATE.UI_WIDGET_STATE_DISABLED);
  103. this.getWidget("menu build").setStateRaw(Atomic.UI_WIDGET_STATE.UI_WIDGET_STATE_DISABLED);
  104. }
  105. enableProjectMenus() {
  106. this.getWidget("menu edit").setStateRaw(Atomic.UI_WIDGET_STATE.UI_WIDGET_STATE_NONE);
  107. this.getWidget("menu build").setStateRaw(Atomic.UI_WIDGET_STATE.UI_WIDGET_STATE_NONE);
  108. }
  109. shutdown() {
  110. this.resourceframe.shutdown();
  111. this.deleteAllChildren();
  112. }
  113. handleResourceEditorChanged(data: Editor.EditorResourceEditorChangedEvent): void {
  114. var editor = data.resourceEditor;
  115. if (editor) {
  116. //this.showInspectorFrame(editor.requiresInspector());
  117. } else {
  118. //this.showInspectorFrame(false);
  119. }
  120. }
  121. showAnimationToolbar(asset: ToolCore.Asset) {
  122. if (this.animationToolbar != null) {
  123. this.animationToolbar.closeViewer();
  124. this.animationToolbar = new AnimationToolbar(this.getWidget("animationtoolbarcontainer"), this.getWidget("animationpropertiescontainer"), asset);
  125. }
  126. else {
  127. this.animationToolbar = new AnimationToolbar(this.getWidget("animationtoolbarcontainer"), this.getWidget("animationpropertiescontainer"), asset);
  128. }
  129. }
  130. showStatusText(message: string) {
  131. this.statusText.text = message; // display the status message
  132. this.updateDelta = 10.0; // start the clock for removing the text
  133. }
  134. handleStatusAging(ev) { // to avoid showing stale status text
  135. if ( this.updateDelta > 0 ) {
  136. this.updateDelta -= ev.timeStep;
  137. if ( this.updateDelta < 0 )
  138. this.statusText.text = ""; // remove it after 10 seconds.
  139. }
  140. }
  141. projectframe: ProjectFrame;
  142. resourceframe: ResourceFrame;
  143. inspectorframe: InspectorFrame;
  144. hierarchyFrame: HierarchyFrame;
  145. welcomeFrame: WelcomeFrame;
  146. inspectorlayout: Atomic.UILayout;
  147. mainToolbar: MainToolbar;
  148. animationToolbar: AnimationToolbar;
  149. menu: MainFrameMenu;
  150. statusText: Atomic.UIEditField;
  151. updateDelta: number;
  152. }
  153. export = MainFrame;