InspectorFrame.ts 7.2 KB

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