Browse Source

Moved ServiceLocator initialization into EditorUI to give it access to ModalOps without having init spread all over. Added a showModalOps method to UIServices to allow extensions to show modal windows.

ExtensionWindow added to facilitate this. Currently havng extensions decalare classes that extend ModalWindow directly is not possible, so this class handles passed in delegates to achieve the same goal.

Moved services into Resources/EditorData so they're able to load assets.
Matt Benic 9 years ago
parent
commit
54fdbc7bf0

+ 15 - 3
Script/AtomicEditor/hostExtensions/HostExtensionServices.ts

@@ -23,7 +23,7 @@
 import * as EditorEvents from "../editor/EditorEvents";
 import * as EditorUI from "../ui/EditorUI";
 import MainFramMenu = require("../ui/frames/menus/MainFrameMenu");
-
+import ModalOps = require("../ui/modal/ModalOps");
 /**
  * Generic registry for storing Editor Extension Services
  */
@@ -205,12 +205,16 @@ export class UIServiceRegistry extends ServiceRegistry<Editor.HostExtensions.UIS
     }
 
     private mainFrameMenu: MainFramMenu = null;
+    private modalOps: ModalOps;
 
-    setMainFrameMenu(menu: MainFramMenu) {
-        // Only set this once
+    init(menu: MainFramMenu, modalOps: ModalOps) {
+        // Only set these once
         if (this.mainFrameMenu == null) {
             this.mainFrameMenu = menu;
         }
+        if (this.modalOps == null) {
+            this.modalOps = modalOps;
+        }
     }
 
     /**
@@ -231,6 +235,14 @@ export class UIServiceRegistry extends ServiceRegistry<Editor.HostExtensions.UIS
         this.mainFrameMenu.removePluginMenuItemSource(id);
     }
 
+    /**
+     * Disaplays a modal window
+     * @param  {Editor.Modal.ModalWindow} window
+     */
+    showModalWindow(windowText: string, uifilename: string, handleWidgetEventCB: (ev: Atomic.UIWidgetEvent) => void): Editor.Modal.ExtensionWindow {
+        return this.modalOps.showExtensionWindow(windowText, uifilename, handleWidgetEventCB);
+    }
+
     /**
      * Called when a menu item has been clicked
      * @param  {string} refId

+ 1 - 1
Script/AtomicEditor/hostExtensions/coreExtensions/ProjectBasedExtensionLoader.ts

@@ -103,7 +103,7 @@ export default class ProjectBasedExtensionLoader implements Editor.HostExtension
         let system = ToolCore.getToolSystem();
         if (system.project) {
             let fileSystem = Atomic.getFileSystem();
-            let editorScriptsPath = Atomic.addTrailingSlash(system.project.projectPath) + "Editor/";
+            let editorScriptsPath = Atomic.addTrailingSlash(system.project.resourcePath) + "EditorData/";
             if (fileSystem.dirExists(editorScriptsPath)) {
                 let filenames = fileSystem.scanDir(editorScriptsPath, "*.js", Atomic.SCAN_FILES, true);
                 filenames.forEach((filename) => {

+ 5 - 0
Script/AtomicEditor/ui/EditorUI.ts

@@ -24,6 +24,7 @@ import EditorEvents = require("editor/EditorEvents");
 import MainFrame = require("./frames/MainFrame");
 import ModalOps = require("./modal/ModalOps");
 import Shortcuts = require("./Shortcuts");
+import ServiceLocator from "../hostExtensions/ServiceLocator";
 
 // this is designed with public get functions to solve
 // circular dependency issues in TS
@@ -94,6 +95,10 @@ class EditorUI extends Atomic.ScriptObject {
     this.modalOps = new ModalOps();
     this.shortcuts = new Shortcuts();
 
+    // Hook the service locator into the event system and give it the ui objects it needs
+    ServiceLocator.uiServices.init(this.mainframe.menu, this.modalOps);
+    ServiceLocator.subscribeToEvents(this.mainframe);
+
     this.subscribeToEvent(EditorEvents.ModalError, (event:EditorEvents.ModalErrorEvent) => {
       this.showModalError(event.title, event.message);
     });

+ 0 - 5
Script/AtomicEditor/ui/frames/MainFrame.ts

@@ -33,7 +33,6 @@ import ScriptWidget = require("ui/ScriptWidget");
 import MainFrameMenu = require("./menus/MainFrameMenu");
 
 import MenuItemSources = require("./menus/MenuItemSources");
-import ServiceLocator from "../../hostExtensions/ServiceLocator";
 import * as EditorEvents from "../../editor/EditorEvents";
 
 class MainFrame extends ScriptWidget {
@@ -75,10 +74,6 @@ class MainFrame extends ScriptWidget {
             this.disableProjectMenus();
         });
 
-        // Allow the service locator to hook into the event system
-        ServiceLocator.uiServices.setMainFrameMenu(this.menu);
-        ServiceLocator.subscribeToEvents(this);
-
         this.showWelcomeFrame(true);
 
     }

+ 45 - 0
Script/AtomicEditor/ui/modal/ExtensionWindow.ts

@@ -0,0 +1,45 @@
+//
+// Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+import EditorUI = require("../EditorUI");
+import ModalWindow = require("./ModalWindow");
+
+class ExtensionWindow extends ModalWindow {
+
+    private handleWidgetEventCB: (ev: Atomic.UIWidgetEvent) => void;
+
+    constructor(windowText: string, uifilename: string, handleWidgetEventCB: (ev: Atomic.UIWidgetEvent) => void) {
+
+        super();
+
+        this.init(windowText, uifilename);
+
+        this.handleWidgetEventCB = handleWidgetEventCB;
+    }
+
+    handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
+        if (this.handleWidgetEventCB)
+            this.handleWidgetEventCB(ev);
+    }
+}
+
+export = ExtensionWindow;

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

@@ -43,6 +43,8 @@ import UIResourceOps = require("./UIResourceOps");
 
 import SnapSettingsWindow = require("./SnapSettingsWindow");
 
+import ExtensionWindow = require("./ExtensionWindow");
+
 import ProjectTemplates = require("../../resources/ProjectTemplates");
 
 
@@ -280,6 +282,14 @@ class ModalOps extends Atomic.ScriptObject {
 
     }
 
+    showExtensionWindow(windowText: string, uifilename: string, handleWidgetEventCB: (ev: Atomic.UIWidgetEvent) => void): Editor.Modal.ExtensionWindow {
+        if (this.show()) {
+
+            this.opWindow = new ExtensionWindow(windowText, uifilename, handleWidgetEventCB);
+            return this.opWindow;
+        }
+    }
+
     private show(): boolean {
 
         if (this.dimmer.parent) {

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

@@ -5,6 +5,7 @@
 // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
 //
 
+/// <reference path="Atomic.d.ts" />
 /// <reference path="Editor.d.ts" />
 
 declare module Editor.EditorEvents {
@@ -203,6 +204,12 @@ declare module Editor.Extensions {
     }
 }
 
+declare module Editor.Modal {
+    export interface ExtensionWindow extends Atomic.UIWindow {
+        hide();
+    }
+}
+
 declare module Editor.HostExtensions {
 
     /**
@@ -242,6 +249,7 @@ declare module Editor.HostExtensions {
     export interface UIServiceRegistry extends Editor.Extensions.ServiceRegistry<UIService> {
         createPluginMenuItemSource(id: string, items: any): Atomic.UIMenuItemSource;
         removePluginMenuItemSource(id: string);
+        showModalWindow(windowText: string, uifilename: string, handleWidgetEventCB: (ev: Atomic.UIWidgetEvent) => void): Editor.Modal.ExtensionWindow;
         menuItemClicked(refId: string): boolean;
     }
 }