InspectorFrame.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 SelectionInspector = require("./SelectionInspector");
  30. // make sure these are hooked in
  31. import "./SelectionEditTypes";
  32. import "./SelectionSectionCoreUI";
  33. class InspectorFrame extends ScriptWidget {
  34. scene: Atomic.Scene = null;
  35. sceneEditor: Editor.SceneEditor3D;
  36. selectionInspector: SelectionInspector;
  37. constructor() {
  38. super();
  39. this.gravity = Atomic.UI_GRAVITY_TOP_BOTTOM;
  40. this.load("AtomicEditor/editor/ui/inspectorframe.tb.txt");
  41. var container = this.getWidget("inspectorcontainer");
  42. this.subscribeToEvent(EditorEvents.EditResource, (data) => this.handleEditResource(data));
  43. this.subscribeToEvent("ProjectUnloaded", (data) => this.handleProjectUnloaded(data));
  44. this.subscribeToEvent(EditorEvents.ActiveSceneEditorChange, (data) => this.handleActiveSceneEditorChanged(data));
  45. }
  46. handleActiveSceneEditorChanged(event: EditorEvents.ActiveSceneEditorChangeEvent) {
  47. if (this.sceneEditor == event.sceneEditor) {
  48. return;
  49. }
  50. if (this.scene)
  51. this.unsubscribeFromEvents(this.scene);
  52. this.closeSelectionInspector();
  53. this.sceneEditor = null;
  54. this.scene = null;
  55. if (!event.sceneEditor)
  56. return;
  57. this.sceneEditor = event.sceneEditor;
  58. this.scene = event.sceneEditor.scene;
  59. if (this.scene) {
  60. this.subscribeToEvent(this.scene, "SceneNodeSelected", (event: Editor.SceneNodeSelectedEvent) => this.handleSceneNodeSelected(event));
  61. // add the current selection
  62. var selection = this.sceneEditor.selection;
  63. for (var i = 0; i < selection.getSelectedNodeCount(); i++) {
  64. this.handleSceneNodeSelected( { node: selection.getSelectedNode(i), scene: this.scene, selected: true, quiet: true} );
  65. }
  66. }
  67. }
  68. closeSelectionInspector() {
  69. if (!this.selectionInspector)
  70. return;
  71. var container = this.getWidget("inspectorcontainer");
  72. container.deleteAllChildren();
  73. this.selectionInspector = null;
  74. }
  75. handleSceneNodeSelected(ev: Editor.SceneNodeSelectedEvent) {
  76. var selection = this.sceneEditor.selection;
  77. if (this.selectionInspector) {
  78. if (ev.selected) {
  79. this.selectionInspector.addNode(ev.node);
  80. } else {
  81. this.selectionInspector.removeNode(ev.node);
  82. }
  83. } else if (ev.selected) {
  84. var container = this.getWidget("inspectorcontainer");
  85. container.deleteAllChildren();
  86. var inspector = this.selectionInspector = new SelectionInspector(this.sceneEditor);
  87. inspector.addNode(ev.node);
  88. container.addChild(inspector);
  89. }
  90. // close last, so state is saved
  91. if (!selection.selectedNodeCount) {
  92. this.closeSelectionInspector();
  93. }
  94. }
  95. handleProjectUnloaded(data) {
  96. this.closeSelectionInspector();
  97. var container = this.getWidget("inspectorcontainer");
  98. container.deleteAllChildren();
  99. }
  100. handleEditResource(ev: EditorEvents.EditResourceEvent) {
  101. var path = ev.path;
  102. var db = ToolCore.getAssetDatabase();
  103. var asset = db.getAssetByPath(path);
  104. if (asset) {
  105. this.inspectAsset(asset);
  106. }
  107. }
  108. inspectAsset(asset: ToolCore.Asset) {
  109. this.closeSelectionInspector();
  110. var container = this.getWidget("inspectorcontainer");
  111. container.deleteAllChildren();
  112. if (asset.importerTypeName == "ModelImporter") {
  113. var inspector = new ModelInspector();
  114. container.addChild(inspector);
  115. inspector.inspect(asset);
  116. }
  117. if (asset.importerTypeName == "MaterialImporter") {
  118. var cache = Atomic.getResourceCache();
  119. var material = <Atomic.Material>cache.getResource("Material", asset.path);
  120. if (!material) {
  121. return;
  122. }
  123. var materialInspector = new MaterialInspector();
  124. container.addChild(materialInspector);
  125. materialInspector.inspect(asset, material);
  126. }
  127. if (asset.importerTypeName == "NETAssemblyImporter") {
  128. var assemblyInspector = new AssemblyInspector();
  129. container.addChild(assemblyInspector);
  130. assemblyInspector.inspect(asset);
  131. }
  132. if (asset.importerTypeName == "PrefabImporter") {
  133. var prefabInspector = new PrefabInspector();
  134. container.addChild(prefabInspector);
  135. prefabInspector.inspect(asset);
  136. }
  137. }
  138. }
  139. export = InspectorFrame;