Browse Source

Added ability to use customized inspectors through plugin support

Johnny 9 years ago
parent
commit
341dc635f6

+ 35 - 0
Script/AtomicEditor/hostExtensions/HostExtensionServices.ts

@@ -23,6 +23,7 @@
 import * as EditorEvents from "../editor/EditorEvents";
 import * as EditorUI from "../ui/EditorUI";
 import MainFrame = require("../ui/frames/MainFrame");
+import InspectorFrame = require("../ui/frames/inspector/InspectorFrame");
 import ModalOps = require("../ui/modal/ModalOps");
 import ResourceOps = require("../resources/ResourceOps");
 import Editor = require("../editor/Editor");
@@ -327,12 +328,14 @@ export class UIServicesProvider extends ServicesProvider<Editor.HostExtensions.U
     }
 
     private mainFrame: MainFrame = null;
+    private inspectorFrame: InspectorFrame = null;
     private modalOps: ModalOps;
 
     init(mainFrame: MainFrame, modalOps: ModalOps) {
         // Only set these once
         if (this.mainFrame == null) {
             this.mainFrame = mainFrame;
+            this.inspectorFrame = this.mainFrame.inspectorframe;
         }
         if (this.modalOps == null) {
             this.modalOps = modalOps;
@@ -409,6 +412,15 @@ export class UIServicesProvider extends ServicesProvider<Editor.HostExtensions.U
         this.mainFrame.hierarchyFrame.populate();
     }
 
+    /**
+     * Loads Custom Inspector Widget
+     * @param  {Atomic.UIWidget} customInspector
+     */
+    loadCustomInspector(customInspector: Atomic.UIWidget) {
+        if (this.inspectorFrame) {
+            this.inspectorFrame.loadCustomInspectorWidget(customInspector);
+        }
+    }
     /**
      * Disaplays a modal window
      * @param  {Editor.Modal.ModalWindow} window
@@ -527,7 +539,30 @@ export class UIServicesProvider extends ServicesProvider<Editor.HostExtensions.U
             }
         });
     }
+    /**
+ * Called when a project asset in the hierarchy pane has been clicked
+ * @param  {ToolCore.Asset} asset
+ * @type {boolean} return true if handled
+ */
+    projectAssetClicked(asset: ToolCore.Asset):boolean {
 
+        if (!asset) {
+            return false;
+        }
+        // run through and find any services that can handle this.
+        return this.registeredServices.some((service) => {
+            try {
+                // Verify that the service contains the appropriate methods and that it can handle it
+                if (service.projectAssetClicked) {
+                    if (service.projectAssetClicked(asset)) {
+                        return true;
+                    }
+                }
+            } catch (e) {
+                EditorUI.showModalError("Extension Error", `Error detected in extension ${service.name}:\n${e}\n\n ${e.stack}`);
+            }
+        });
+    }
     /**
      * Hooks into web messages coming in from web views
      * @param  {[String|Object]} data

+ 12 - 1
Script/AtomicEditor/ui/frames/inspector/InspectorFrame.ts

@@ -30,7 +30,7 @@ import ModelInspector = require("./ModelInspector");
 import PrefabInspector = require("./PrefabInspector");
 import TextureInspector = require("./TextureInspector");
 import AssemblyInspector = require("./AssemblyInspector");
-
+import ServiceLocator from "../../../hostExtensions/ServiceLocator";
 import SelectionInspector = require("./SelectionInspector");
 // make sure these are hooked in
 import "./SelectionEditTypes";
@@ -231,8 +231,19 @@ class InspectorFrame extends ScriptWidget {
 
         }
 
+        // Check if there are inspector plugins available for unknown asset types.
+        if (asset.importerType == null) {
+
+            ServiceLocator.uiServices.projectAssetClicked(asset);
+        }
     }
 
+    loadCustomInspectorWidget(rootWidget: Atomic.UIWidget) {
+
+        var container = this.getWidget("inspectorcontainer");
+        container.deleteAllChildren();
+        container.addChild(rootWidget);
+    }
 }
 
 export = InspectorFrame;

+ 3 - 0
Script/TypeScript/EditorWork.d.ts

@@ -8,6 +8,7 @@
 /// <reference path="Atomic.d.ts" />
 /// <reference path="Editor.d.ts" />
 /// <reference path="ToolCore.d.ts" />
+/// <reference path="WebView.d.ts" />
 
 declare module Editor.EditorEvents {
 
@@ -342,6 +343,7 @@ declare module Editor.HostExtensions {
     export interface UIServicesEventListener extends Editor.Extensions.ServiceEventListener {
         menuItemClicked?(refid: string): boolean;
         projectContextItemClicked?(asset: ToolCore.Asset, refid: string): boolean;
+        projectAssetClicked?(asset: ToolCore.Asset): boolean;
         hierarchyContextItemClicked?(node: Atomic.Node, refid: string): boolean;
 
         /**
@@ -360,6 +362,7 @@ declare module Editor.HostExtensions {
         createProjectContextMenuItemSource(id: string, items: any): Atomic.UIMenuItemSource;
         removeProjectContextMenuItemSource(id: string);
         refreshHierarchyFrame();
+        loadCustomInspector(customInspector: Atomic.UIWidget);
         showModalWindow(windowText: string, uifilename: string, handleWidgetEventCB: (ev: Atomic.UIWidgetEvent) => void): Editor.Modal.ExtensionWindow;
         showModalError(windowText: string, message: string);
         showResourceSelection(windowText: string, importerType: string, resourceType: string, callback: (retObject: any, args: any) => void, args?: any);