InspectorFrame.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 EditorEvents = require("editor/EditorEvents");
  23. import ScriptWidget = require("ui/ScriptWidget");
  24. // inspectors
  25. import MaterialInspector = require("./MaterialInspector");
  26. import ModelInspector = require("./ModelInspector");
  27. import PrefabInspector = require("./PrefabInspector");
  28. import TextureInspector = require("./TextureInspector");
  29. import AssemblyInspector = require("./AssemblyInspector");
  30. import ServiceLocator from "../../../hostExtensions/ServiceLocator";
  31. import SelectionInspector = require("./SelectionInspector");
  32. // make sure these are hooked in
  33. import "./SelectionEditTypes";
  34. import "./SelectionSectionCoreUI";
  35. class InspectorFrame extends ScriptWidget {
  36. scene: Atomic.Scene = null;
  37. sceneEditor: Editor.SceneEditor3D;
  38. selectionInspector: SelectionInspector;
  39. constructor() {
  40. super();
  41. this.gravity = Atomic.UI_GRAVITY.UI_GRAVITY_TOP_BOTTOM;
  42. this.load("AtomicEditor/editor/ui/inspectorframe.tb.txt");
  43. var container = this.getWidget("inspectorcontainer");
  44. this.subscribeToEvent(EditorEvents.EditResource, (data) => this.handleEditResource(data));
  45. this.subscribeToEvent(EditorEvents.ProjectUnloadedNotification, (data) => this.handleProjectUnloaded(data));
  46. this.subscribeToEvent(EditorEvents.ActiveSceneEditorChange, (data) => this.handleActiveSceneEditorChanged(data));
  47. }
  48. handleActiveSceneEditorChanged(event: EditorEvents.ActiveSceneEditorChangeEvent) {
  49. if (this.sceneEditor == event.sceneEditor) {
  50. return;
  51. }
  52. if (this.scene)
  53. this.unsubscribeFromEvents(this.scene);
  54. this.closeSelectionInspector();
  55. this.sceneEditor = null;
  56. this.scene = null;
  57. if (!event.sceneEditor)
  58. return;
  59. this.sceneEditor = event.sceneEditor;
  60. this.scene = event.sceneEditor.scene;
  61. if (this.scene) {
  62. this.subscribeToEvent(this.scene, "SceneNodeSelected", (event: Editor.SceneNodeSelectedEvent) => this.handleSceneNodeSelected(event));
  63. // add the current selection
  64. var selection = this.sceneEditor.selection;
  65. for (var i = 0; i < selection.getSelectedNodeCount(); i++) {
  66. this.handleSceneNodeSelected( <Editor.SceneNodeSelectedEvent> { node: selection.getSelectedNode(i), scene: this.scene, selected: true, quiet: true} );
  67. }
  68. // FIXME: Duktape is leaking selection object without nulling out
  69. selection = null;
  70. }
  71. }
  72. closeSelectionInspector() {
  73. if (!this.selectionInspector)
  74. return;
  75. var container = this.getWidget("inspectorcontainer");
  76. container.deleteAllChildren();
  77. this.selectionInspector = null;
  78. }
  79. handleSceneNodeSelected(ev: Editor.SceneNodeSelectedEvent) {
  80. var selection = this.sceneEditor.selection;
  81. if (this.selectionInspector) {
  82. if (ev.selected) {
  83. this.selectionInspector.addNode(ev.node);
  84. } else {
  85. this.selectionInspector.removeNode(ev.node);
  86. }
  87. } else if (ev.selected) {
  88. var container = this.getWidget("inspectorcontainer");
  89. container.deleteAllChildren();
  90. var inspector = this.selectionInspector = new SelectionInspector(this.sceneEditor);
  91. inspector.addNode(ev.node);
  92. container.addChild(inspector);
  93. }
  94. // close last, so state is saved
  95. if (!selection.selectedNodeCount) {
  96. this.closeSelectionInspector();
  97. }
  98. }
  99. handleProjectUnloaded(data) {
  100. this.closeSelectionInspector();
  101. var container = this.getWidget("inspectorcontainer");
  102. container.deleteAllChildren();
  103. }
  104. handleEditResource(ev: EditorEvents.EditResourceEvent) {
  105. var path = ev.path;
  106. var db = ToolCore.getAssetDatabase();
  107. var asset = db.getAssetByPath(path);
  108. if (asset) {
  109. this.inspectAsset(asset);
  110. }
  111. }
  112. inspectAsset(asset: ToolCore.Asset) {
  113. this.closeSelectionInspector();
  114. var container = this.getWidget("inspectorcontainer");
  115. container.deleteAllChildren();
  116. if (asset.importerTypeName == "ModelImporter") {
  117. var inspector = new ModelInspector();
  118. container.addChild(inspector);
  119. inspector.inspect(asset);
  120. }
  121. if (asset.importerTypeName == "MaterialImporter") {
  122. var cache = Atomic.getResourceCache();
  123. var material = <Atomic.Material>cache.getResource("Material", asset.path);
  124. if (!material) {
  125. return;
  126. }
  127. var materialInspector = new MaterialInspector();
  128. container.addChild(materialInspector);
  129. materialInspector.inspect(asset, material);
  130. }
  131. if (asset.importerTypeName == "PrefabImporter") {
  132. var prefabInspector = new PrefabInspector();
  133. container.addChild(prefabInspector);
  134. prefabInspector.inspect(asset);
  135. }
  136. if (asset.importerTypeName == "TextureImporter") {
  137. var thumbnail = asset.cachePath + "_thumbnail.png";
  138. var cache = Atomic.getResourceCache();
  139. var texture = <Atomic.Texture2D>cache.getResource("Texture2D", thumbnail);
  140. if (!texture) {
  141. return;
  142. }
  143. var textureInspector = new TextureInspector();
  144. container.addChild(textureInspector);
  145. textureInspector.inspect(texture, asset);
  146. }
  147. if (asset.importerTypeName == "NETAssemblyImporter") {
  148. var assemblyInspector = new AssemblyInspector();
  149. container.addChild(assemblyInspector);
  150. assemblyInspector.inspect(asset);
  151. }
  152. // Check if there are inspector plugins available for unknown asset types.
  153. if (asset.importerType == null) {
  154. ServiceLocator.uiServices.projectAssetClicked(asset);
  155. }
  156. }
  157. loadCustomInspectorWidget(rootWidget: Atomic.UIWidget) {
  158. var container = this.getWidget("inspectorcontainer");
  159. container.deleteAllChildren();
  160. container.addChild(rootWidget);
  161. }
  162. }
  163. export = InspectorFrame;