InspectorFrame.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 AssemblyInspector = require("./AssemblyInspector");
  28. import PrefabInspector = require("./PrefabInspector");
  29. import TextureInspector = require("./TextureInspector");
  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_TOP_BOTTOM;
  41. this.load("AtomicEditor/editor/ui/inspectorframe.tb.txt");
  42. var container = this.getWidget("inspectorcontainer");
  43. this.subscribeToEvent(EditorEvents.EditResource, (data) => this.handleEditResource(data));
  44. this.subscribeToEvent(EditorEvents.ProjectUnloadedNotification, (data) => this.handleProjectUnloaded(data));
  45. this.subscribeToEvent(EditorEvents.ActiveSceneEditorChange, (data) => this.handleActiveSceneEditorChanged(data));
  46. }
  47. handleActiveSceneEditorChanged(event: EditorEvents.ActiveSceneEditorChangeEvent) {
  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, "SceneNodeSelected", (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( { node: selection.getSelectedNode(i), scene: this.scene, selected: true, quiet: true} );
  66. }
  67. }
  68. }
  69. closeSelectionInspector() {
  70. if (!this.selectionInspector)
  71. return;
  72. var container = this.getWidget("inspectorcontainer");
  73. container.deleteAllChildren();
  74. this.selectionInspector = null;
  75. }
  76. handleSceneNodeSelected(ev: Editor.SceneNodeSelectedEvent) {
  77. var selection = this.sceneEditor.selection;
  78. if (this.selectionInspector) {
  79. if (ev.selected) {
  80. this.selectionInspector.addNode(ev.node);
  81. } else {
  82. this.selectionInspector.removeNode(ev.node);
  83. }
  84. } else if (ev.selected) {
  85. var container = this.getWidget("inspectorcontainer");
  86. container.deleteAllChildren();
  87. var inspector = this.selectionInspector = new SelectionInspector(this.sceneEditor);
  88. inspector.addNode(ev.node);
  89. container.addChild(inspector);
  90. }
  91. // close last, so state is saved
  92. if (!selection.selectedNodeCount) {
  93. this.closeSelectionInspector();
  94. }
  95. }
  96. handleProjectUnloaded(data) {
  97. this.closeSelectionInspector();
  98. var container = this.getWidget("inspectorcontainer");
  99. container.deleteAllChildren();
  100. }
  101. handleEditResource(ev: EditorEvents.EditResourceEvent) {
  102. var path = ev.path;
  103. var db = ToolCore.getAssetDatabase();
  104. var asset = db.getAssetByPath(path);
  105. if (asset) {
  106. this.inspectAsset(asset);
  107. }
  108. }
  109. inspectAsset(asset: ToolCore.Asset) {
  110. this.closeSelectionInspector();
  111. var container = this.getWidget("inspectorcontainer");
  112. container.deleteAllChildren();
  113. if (asset.importerTypeName == "ModelImporter") {
  114. var inspector = new ModelInspector();
  115. container.addChild(inspector);
  116. inspector.inspect(asset);
  117. }
  118. if (asset.importerTypeName == "MaterialImporter") {
  119. var cache = Atomic.getResourceCache();
  120. var material = <Atomic.Material>cache.getResource("Material", asset.path);
  121. if (!material) {
  122. return;
  123. }
  124. var materialInspector = new MaterialInspector();
  125. container.addChild(materialInspector);
  126. materialInspector.inspect(asset, material);
  127. }
  128. if (asset.importerTypeName == "NETAssemblyImporter") {
  129. var assemblyInspector = new AssemblyInspector();
  130. container.addChild(assemblyInspector);
  131. assemblyInspector.inspect(asset);
  132. }
  133. if (asset.importerTypeName == "PrefabImporter") {
  134. var prefabInspector = new PrefabInspector();
  135. container.addChild(prefabInspector);
  136. prefabInspector.inspect(asset);
  137. }
  138. if (asset.importerTypeName == "TextureImporter") {
  139. var thumbnail = asset.cachePath + "_thumbnail.png";
  140. var cache = Atomic.getResourceCache();
  141. var texture = <Atomic.Texture2D>cache.getResource("Texture2D", thumbnail);
  142. if (!texture) {
  143. return;
  144. }
  145. var textureInspector = new TextureInspector();
  146. container.addChild(textureInspector);
  147. textureInspector.inspect(texture, asset);
  148. }
  149. }
  150. }
  151. export = InspectorFrame;