Browse Source

-Added Scene service provider for Editor plugins
-Added UI service functions

JohnnyWahib 9 years ago
parent
commit
0031c450f0

+ 107 - 21
Script/AtomicEditor/hostExtensions/HostExtensionServices.ts

@@ -22,10 +22,9 @@
 
 import * as EditorEvents from "../editor/EditorEvents";
 import * as EditorUI from "../ui/EditorUI";
-import MainFramMenu = require("../ui/frames/menus/MainFrameMenu");
-import HierarchyFrameMenu = require("../ui/frames/menus/HierarchyFrameMenu");
-import ProjectFrameMenu = require("../ui/frames/menus/ProjectFrameMenu");
+import MainFrame = require("../ui/frames/MainFrame");
 import ModalOps = require("../ui/modal/ModalOps");
+import ResourceOps = require("../resources/ResourceOps");
 /**
  * Generic registry for storing Editor Extension Services
  */
@@ -142,6 +141,7 @@ export class ResourceServicesProvider extends ServicesProvider<Editor.HostExtens
         eventDispatcher.subscribeToEvent(EditorEvents.SaveResourceNotification, (ev) => this.saveResource(ev));
         eventDispatcher.subscribeToEvent(EditorEvents.DeleteResourceNotification, (ev) => this.deleteResource(ev));
         eventDispatcher.subscribeToEvent(EditorEvents.RenameResourceNotification, (ev) => this.renameResource(ev));
+
     }
 
     /**
@@ -195,6 +195,70 @@ export class ResourceServicesProvider extends ServicesProvider<Editor.HostExtens
         });
     }
 
+    /**
+     * Create New Material 
+     * @param  {string} resourcePath
+     * @param  {string} materialName
+     * @param  {boolean} reportError
+     */
+    createMaterial(resourcePath: string, materialName: string, reportError: boolean): boolean {
+        return ResourceOps.CreateNewMaterial(resourcePath, materialName, reportError);
+    }
+
+}
+
+/**
+ * Registry for service extensions that are concerned about Scenes
+ */
+export class SceneServicesProvider extends ServicesProvider<Editor.HostExtensions.SceneServicesEventListener> implements Editor.HostExtensions.SceneServicesProvider {
+    constructor() {
+        super();
+    }
+
+    /**
+     * Allow this service registry to subscribe to events that it is interested in
+     * @param  {Atomic.UIWidget} topLevelWindow The top level window that will be receiving these events
+     */
+    subscribeToEvents(eventDispatcher: Editor.Extensions.EventDispatcher) {
+        eventDispatcher.subscribeToEvent(EditorEvents.ActiveSceneEditorChange, (ev) => this.activeSceneEditorChange(ev));
+        eventDispatcher.subscribeToEvent(EditorEvents.SceneClosed, (ev) => this.sceneClosed(ev));
+    }
+
+    /**
+     * Called after an active scene editor change
+     * @param  {Editor.EditorEvents.ActiveSceneEditorChangeEvent} ev
+     */
+    activeSceneEditorChange(ev: Editor.EditorEvents.ActiveSceneEditorChangeEvent) {
+        // run through and find any services that can handle this.
+        this.registeredServices.forEach((service) => {
+            try {
+                // Verify that the service contains the appropriate methods and that it can save
+                if (service.activeSceneEditorChanged) {
+                    service.activeSceneEditorChanged(ev);
+                }
+            } catch (e) {
+                EditorUI.showModalError("Extension Error", `Error detected in extension ${service.name}:\n${e}\n\n ${e.stack}`);
+            }
+        });
+    }
+
+    /**
+     * Called after a scene is closed
+     * @param  {Editor.EditorEvents.SceneClosedEvent} ev
+     */
+    sceneClosed(ev: Editor.EditorEvents.SceneClosedEvent) {
+        // run through and find any services that can handle this.
+        this.registeredServices.forEach((service) => {
+            try {
+                // Verify that the service contains the appropriate methods and that it can save
+                if (service.editorSceneClosed) {
+                    service.editorSceneClosed(ev);
+                }
+            } catch (e) {
+                EditorUI.showModalError("Extension Error", `Error detected in extension ${service.name}:\n${e}\n\n ${e.stack}`);
+            }
+        });
+    }
 }
 
 /**
@@ -206,21 +270,13 @@ export class UIServicesProvider extends ServicesProvider<Editor.HostExtensions.U
         super();
     }
 
-    private mainFrameMenu: MainFramMenu = null;
-    private hierarchyFrameMenu: HierarchyFrameMenu = null;
-    private projectFrameMenu: ProjectFrameMenu = null;
+    private mainFrame: MainFrame = null;
     private modalOps: ModalOps;
 
-    init(mainFrameMenu: MainFramMenu, hierarchyFrameMenu: HierarchyFrameMenu, projectFrameMenu: ProjectFrameMenu, modalOps: ModalOps) {
+    init(mainFrame: MainFrame, modalOps: ModalOps) {
         // Only set these once
-        if (this.mainFrameMenu == null) {
-            this.mainFrameMenu = mainFrameMenu;
-        }
-        if (this.hierarchyFrameMenu == null) {
-            this.hierarchyFrameMenu = hierarchyFrameMenu;
-        }
-        if (this.projectFrameMenu == null) {
-            this.projectFrameMenu = projectFrameMenu;
+        if (this.mainFrame == null) {
+            this.mainFrame = mainFrame;
         }
         if (this.modalOps == null) {
             this.modalOps = modalOps;
@@ -234,7 +290,7 @@ export class UIServicesProvider extends ServicesProvider<Editor.HostExtensions.U
      * @return {Atomic.UIMenuItemSource}
      */
     createPluginMenuItemSource(id: string, items: any): Atomic.UIMenuItemSource {
-        return this.mainFrameMenu.createPluginMenuItemSource(id, items);
+        return this.mainFrame.menu.createPluginMenuItemSource(id, items);
     }
 
     /**
@@ -242,7 +298,7 @@ export class UIServicesProvider extends ServicesProvider<Editor.HostExtensions.U
      * @param  {string} id
      */
     removePluginMenuItemSource(id: string) {
-        this.mainFrameMenu.removePluginMenuItemSource(id);
+        this.mainFrame.menu.removePluginMenuItemSource(id);
     }
 
     /**
@@ -252,7 +308,7 @@ export class UIServicesProvider extends ServicesProvider<Editor.HostExtensions.U
      * @return {Atomic.UIMenuItemSource}
      */
     createHierarchyContextMenuItemSource(id: string, items: any): Atomic.UIMenuItemSource {
-        return this.hierarchyFrameMenu.createPluginItemSource(id, items);
+        return this.mainFrame.hierarchyFrame.menu.createPluginItemSource(id, items);
     }
 
     /**
@@ -260,7 +316,7 @@ export class UIServicesProvider extends ServicesProvider<Editor.HostExtensions.U
      * @param  {string} id
      */
     removeHierarchyContextMenuItemSource(id: string) {
-        this.hierarchyFrameMenu.removePluginItemSource(id);
+        this.mainFrame.hierarchyFrame.menu.removePluginItemSource(id);
     }
 
     /**
@@ -270,7 +326,7 @@ export class UIServicesProvider extends ServicesProvider<Editor.HostExtensions.U
      * @return {Atomic.UIMenuItemSource}
      */
     createProjectContextMenuItemSource(id: string, items: any): Atomic.UIMenuItemSource {
-        return this.projectFrameMenu.createPluginItemSource(id, items);
+        return this.mainFrame.projectframe.menu.createPluginItemSource(id, items);
     }
 
     /**
@@ -278,7 +334,14 @@ export class UIServicesProvider extends ServicesProvider<Editor.HostExtensions.U
      * @param  {string} id
      */
     removeProjectContextMenuItemSource(id: string) {
-        this.projectFrameMenu.removePluginItemSource(id);
+        this.mainFrame.projectframe.menu.removePluginItemSource(id);
+    }
+
+    /**
+     * Refreshes the hierarchy frame
+     */
+    refreshHierarchyFrame() {
+        this.mainFrame.hierarchyFrame.populate();
     }
 
     /**
@@ -289,6 +352,29 @@ export class UIServicesProvider extends ServicesProvider<Editor.HostExtensions.U
         return this.modalOps.showExtensionWindow(windowText, uifilename, handleWidgetEventCB);
     }
 
+    /**
+     * Disaplays a modal error window
+     * @param  {string} windowText
+     * @param  {string} message
+     */
+    showModalError(windowText: string, message: string) {
+        return this.modalOps.showError(windowText, message);
+    }
+
+    /**
+ * Disaplays a resource slection window
+ * @param  {string} windowText
+ * @param  {string} importerType
+ * @param  {string} resourceType
+ * @param  {function} callback
+ * @param  {any} retObject
+ * @param  {any} args
+ */
+    showResourceSelection(windowText: string, importerType: string, resourceType: string, callback: (retObject: any, args: any) => void, args: any = undefined) {
+
+        this.modalOps.showResourceSelection(windowText, importerType, resourceType, callback);
+    }
+
     /**
      * Called when a menu item has been clicked
      * @param  {string} refId

+ 3 - 0
Script/AtomicEditor/hostExtensions/ServiceLocator.ts

@@ -34,6 +34,7 @@ export class ServiceLocatorType implements Editor.HostExtensions.HostServiceLoca
     constructor() {
         this.resourceServices = new HostExtensionServices.ResourceServicesProvider();
         this.projectServices = new HostExtensionServices.ProjectServicesProvider();
+        this.sceneServices = new HostExtensionServices.SceneServicesProvider();
         this.uiServices = new HostExtensionServices.UIServicesProvider();
     }
 
@@ -41,6 +42,7 @@ export class ServiceLocatorType implements Editor.HostExtensions.HostServiceLoca
 
     resourceServices: HostExtensionServices.ResourceServicesProvider;
     projectServices: HostExtensionServices.ProjectServicesProvider;
+    sceneServices: HostExtensionServices.SceneServicesProvider;
     uiServices: HostExtensionServices.UIServicesProvider;
 
     loadService(service: Editor.HostExtensions.HostEditorService) {
@@ -59,6 +61,7 @@ export class ServiceLocatorType implements Editor.HostExtensions.HostServiceLoca
         this.eventDispatcher = frame;
         this.resourceServices.subscribeToEvents(this);
         this.projectServices.subscribeToEvents(this);
+        this.sceneServices.subscribeToEvents(this);
         this.uiServices.subscribeToEvents(this);
     }
 

+ 3 - 6
Script/AtomicEditor/ui/EditorUI.ts

@@ -97,9 +97,7 @@ class EditorUI extends Atomic.ScriptObject {
 
     // Hook the service locator into the event system and give it the ui objects it needs
     ServiceLocator.uiServices.init(
-      this.mainframe.menu, 
-      this.mainframe.hierarchyFrame.menu,
-      this.mainframe.projectframe.menu,
+      this.mainframe, 
       this.modalOps);
     ServiceLocator.subscribeToEvents(this.mainframe);
 
@@ -109,9 +107,8 @@ class EditorUI extends Atomic.ScriptObject {
 
   }
 
-  showModalError(windowText:string, message:string) {
-      var window = new Atomic.UIMessageWindow(this.view, "modal_error");
-      window.show(windowText, message, Atomic.UI_MESSAGEWINDOW_SETTINGS_OK, true, 640, 360);
+  showModalError(windowText: string, message: string) {
+      this.modalOps.showError(windowText, message);
   }
 
   view: Atomic.UIView;

+ 7 - 0
Script/AtomicEditor/ui/modal/ModalOps.ts

@@ -282,6 +282,13 @@ class ModalOps extends Atomic.ScriptObject {
 
     }
 
+    // TODO: standardize  to same pattern as other modal windows
+    showError(windowText: string, message: string) {
+        var view = EditorUI.getView();
+        var window = new Atomic.UIMessageWindow(view, "modal_error");
+        window.show(windowText, message, Atomic.UI_MESSAGEWINDOW_SETTINGS_OK, true, 640, 360);
+    }
+
     showExtensionWindow(windowText: string, uifilename: string, handleWidgetEventCB: (ev: Atomic.UIWidgetEvent) => void): Editor.Modal.ExtensionWindow {
         if (this.show()) {
 

+ 15 - 1
Script/TypeScript/EditorWork.d.ts

@@ -230,6 +230,7 @@ declare module Editor.HostExtensions {
     export interface HostServiceLocator extends Editor.Extensions.ServiceLoader {
         resourceServices: ResourceServicesProvider;
         projectServices: ProjectServicesProvider;
+        sceneServices: SceneServicesProvider;
         uiServices: UIServicesProvider;
     }
 
@@ -245,7 +246,10 @@ declare module Editor.HostExtensions {
         delete?(ev: EditorEvents.DeleteResourceEvent);
         rename?(ev: EditorEvents.RenameResourceEvent);
     }
-    export interface ResourceServicesProvider extends Editor.Extensions.ServicesProvider<ResourceServicesEventListener> { }
+
+    export interface ResourceServicesProvider extends Editor.Extensions.ServicesProvider<ResourceServicesEventListener> {
+        createMaterial(resourcePath: string, materialName: string, reportError: boolean): boolean;
+    }
 
     export interface ProjectServicesEventListener extends Editor.Extensions.ServiceEventListener {
         projectUnloaded?();
@@ -254,6 +258,12 @@ declare module Editor.HostExtensions {
     }
     export interface ProjectServicesProvider extends Editor.Extensions.ServicesProvider<ProjectServicesEventListener> { }
 
+    export interface SceneServicesEventListener extends Editor.Extensions.ServiceEventListener {
+        activeSceneEditorChanged?(ev: EditorEvents.ActiveSceneEditorChangeEvent);
+        editorSceneClosed?(ev: EditorEvents.SceneClosedEvent);
+    }
+    export interface SceneServicesProvider extends Editor.Extensions.ServicesProvider<SceneServicesEventListener> { }
+
     export interface UIServicesEventListener extends Editor.Extensions.ServiceEventListener {
         menuItemClicked?(refid: string): boolean;
         projectContextItemClicked?(asset: ToolCore.Asset, refid: string): boolean;
@@ -266,7 +276,11 @@ declare module Editor.HostExtensions {
         removeHierarchyContextMenuItemSource(id: string);
         createProjectContextMenuItemSource(id: string, items: any): Atomic.UIMenuItemSource;
         removeProjectContextMenuItemSource(id: string);
+        refreshHierarchyFrame();
         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);
+
     }
 }