Bladeren bron

Working on project creation modal

Josh Engebretson 10 jaren geleden
bovenliggende
commit
831be1aea7

+ 1 - 0
Script/AtomicEditor/tsconfig.json

@@ -37,6 +37,7 @@
         "./ui/inspector/ModelInspector.ts",
         "./ui/inspector/ModelInspector.ts",
         "./ui/inspector/NodeInspector.ts",
         "./ui/inspector/NodeInspector.ts",
         "./ui/inspector/TextureSelector.ts",
         "./ui/inspector/TextureSelector.ts",
+        "./ui/modal/CreateProject.ts",
         "./ui/modal/MessageModal.ts",
         "./ui/modal/MessageModal.ts",
         "./ui/modal/ModalOps.ts",
         "./ui/modal/ModalOps.ts",
         "./ui/modal/ModalWindow.ts",
         "./ui/modal/ModalWindow.ts",

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

@@ -23,6 +23,11 @@ export function initialize() {
   editorUI = new EditorUI();
   editorUI = new EditorUI();
 }
 }
 
 
+export function showModalError(windowText:string, message:string) {
+  editorUI.showModalError(windowText, message);
+}
+
+
 class EditorUI extends Atomic.ScriptObject {
 class EditorUI extends Atomic.ScriptObject {
 
 
   constructor() {
   constructor() {
@@ -44,6 +49,12 @@ class EditorUI extends Atomic.ScriptObject {
 
 
   }
   }
 
 
+  showModalError(windowText:string, message:string)
+  {
+      var window = new Atomic.UIMessageWindow(this.view, "modal_error");
+      window.show(windowText, message, 640, 360);
+  }
+
   view: Atomic.UIView;
   view: Atomic.UIView;
   mainframe: MainFrame;
   mainframe: MainFrame;
   modalOps: ModalOps;
   modalOps: ModalOps;

+ 109 - 0
Script/AtomicEditor/ui/modal/CreateProject.ts

@@ -0,0 +1,109 @@
+
+import EditorUI = require("../EditorUI");
+import ModalWindow = require("./ModalWindow");
+
+class CreateProject extends ModalWindow {
+
+    constructor(templateSourceDir: string, imagePath: string = "") {
+
+        super();
+
+        this.templateSourceDir = templateSourceDir;
+
+        this.init("Create Project", "AtomicEditor/editor/ui/createproject.tb.txt");
+
+        this.projectPathField = <Atomic.UIEditField> this.getWidget("project_path");
+        this.projectNameField = <Atomic.UIEditField> this.getWidget("project_name");
+        this.image = <Atomic.UIImageWidget> this.getWidget("project_image");
+
+        if (!imagePath)
+            this.image.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
+        else
+            this.image.image = imagePath;
+
+
+        var fileSystem = Atomic.getFileSystem();
+
+        var userDocuments = fileSystem.userDocumentsDir;
+
+        if (Atomic.platform == "MacOSX") {
+
+            userDocuments += "Documents/AtomicProjects";
+
+        } else {
+
+            userDocuments += "AtomicProjects";
+
+        }
+
+        this.projectPathField.text = userDocuments;
+
+        this.resizeToFitContent();
+        this.center();
+
+    }
+
+    checkProjectCreate(): boolean {
+
+        var name = this.projectNameField.text.trim();
+
+        if (!name) {
+            EditorUI.showModalError("New Project Editor Error", "Please enter a project name");
+            return false;
+        }
+
+        var folder = this.projectPathField.text.trim();
+
+        if (!folder)
+        {
+            EditorUI.showModalError("New Project Editor Error", "Please choose a root project folder");
+            return false;
+        }
+
+        return true;
+
+    }
+
+    handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
+
+        if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
+
+            var id = ev.target.id;
+
+            if (id == "cancel") {
+                this.hide();
+                return true;
+            }
+            else if (id == "choose_path") {
+                var utils = new Editor.FileUtils();
+                var path = utils.newProjectFileDialog();
+
+                if (path.length)
+                    this.projectPathField.text = path;
+
+                return true;
+            }
+            else if (id == "create") {
+
+                if (this.checkProjectCreate()) {
+
+                }
+
+                return true;
+
+            }
+
+
+
+        }
+    }
+
+    projectPathField: Atomic.UIEditField;
+    projectNameField: Atomic.UIEditField;
+    image: Atomic.UIImageWidget;
+
+    templateSourceDir: string;
+}
+
+
+export = CreateProject;

+ 23 - 9
Script/AtomicEditor/ui/modal/ModalOps.ts

@@ -1,6 +1,7 @@
 import EditorUI = require("../EditorUI");
 import EditorUI = require("../EditorUI");
 import ModalWindow = require("./ModalWindow");
 import ModalWindow = require("./ModalWindow");
 import NewProject = require("./NewProject");
 import NewProject = require("./NewProject");
+import CreateProject = require("./CreateProject");
 
 
 class ModalOps extends Atomic.ScriptObject {
 class ModalOps extends Atomic.ScriptObject {
 
 
@@ -12,6 +13,25 @@ class ModalOps extends Atomic.ScriptObject {
 
 
     }
     }
 
 
+    showCreateProject(projectTemplateFolder:string) {
+
+      if (this.show()) {
+
+          this.opWindow = new CreateProject(projectTemplateFolder);
+
+      }
+
+    }
+
+    showNewProject() {
+
+        if (this.show()) {
+
+            this.opWindow = new NewProject();
+
+        }
+    }
+
     private show(): boolean {
     private show(): boolean {
 
 
         if (this.dimmer.parent) {
         if (this.dimmer.parent) {
@@ -42,6 +62,9 @@ class ModalOps extends Atomic.ScriptObject {
             var window = this.opWindow;
             var window = this.opWindow;
             this.opWindow = null;
             this.opWindow = null;
 
 
+            if (window.parent)
+              window.parent.removeChild(window, false);
+
             var view = EditorUI.getView();
             var view = EditorUI.getView();
             view.setFocusRecursive();
             view.setFocusRecursive();
 
 
@@ -56,15 +79,6 @@ class ModalOps extends Atomic.ScriptObject {
 
 
     }
     }
 
 
-    showNewProject() {
-
-        if (this.show()) {
-
-            this.opWindow = new NewProject();
-
-        }
-    }
-
     dimmer: Atomic.UIDimmer;
     dimmer: Atomic.UIDimmer;
     opWindow: ModalWindow;
     opWindow: ModalWindow;
 
 

+ 23 - 2
Script/AtomicEditor/ui/modal/ModalWindow.ts

@@ -14,11 +14,32 @@ class ModalWindow extends Atomic.UIWindow {
 
 
     this.subscribeToEvent(this, "WidgetDeleted", (event:Atomic.UIWidgetDeletedEvent) => {
     this.subscribeToEvent(this, "WidgetDeleted", (event:Atomic.UIWidgetDeletedEvent) => {
 
 
-      var modalOps = EditorUI.getModelOps();
-      modalOps.hide();
+      this.hide();
 
 
     });
     });
 
 
+    this.subscribeToEvent(this, "WidgetEvent", (data) => this.handleWidgetEvent(data));
+
+  }
+
+  hide() {
+
+    var modalOps = EditorUI.getModelOps();
+    modalOps.hide();
+
+  }
+
+  handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
+
+  }
+
+  init(windowText:string, uifilename:string) {
+
+    this.text = windowText;
+    this.load(uifilename);
+    this.resizeToFitContent();
+    this.center();
+
   }
   }
 
 
 }
 }

+ 40 - 6
Script/AtomicEditor/ui/modal/NewProject.ts

@@ -1,21 +1,55 @@
 
 
+import EditorUI = require("../EditorUI");
 import ModalWindow = require("./ModalWindow");
 import ModalWindow = require("./ModalWindow");
 
 
 class NewProject extends ModalWindow {
 class NewProject extends ModalWindow {
 
 
     constructor() {
     constructor() {
 
 
-      super();
+        super();
 
 
-      this.text = "Project Type";
+        this.init("Project Type", "AtomicEditor/editor/ui/newproject.tb.txt");
 
 
-      this.load("AtomicEditor/editor/ui/newproject.tb.txt");
+    }
 
 
-      this.resizeToFitContent();
-      this.center();
+    handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
 
 
-    }
+        if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
+
+            var id = ev.target.id;
+
+            if (id == "cancel") {
+                this.hide();
+                return true;
+            }
+
+            var projectType = "";
+
+            if (id == "project_empty") {
+                projectType = "EmptyProject/";
+            }
+            else if (id == "project_2d") {
+                projectType = "Project2D/";
+            }
+            else if (id == "project_2d") {
+                projectType = "Project3D/";
+            }
+
+            if (projectType) {
 
 
+                var env = ToolCore.getToolEnvironment();
+                var projectTemplateFolder = env.projectTemplatesDir + projectType;
+
+                this.hide();
+
+                var ops = EditorUI.getModelOps();
+                ops.showCreateProject(projectTemplateFolder);
+
+
+            }
+
+        }
+    }
 }
 }
 
 
 
 

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

@@ -7045,8 +7045,11 @@ declare module Atomic {
 
 
    export class UIImageWidget extends UIWidget {
    export class UIImageWidget extends UIWidget {
 
 
+      image: string;
+
       constructor(createWidget?: boolean);
       constructor(createWidget?: boolean);
 
 
+      setImage(imagePath: string): void;
 
 
    }
    }
 
 

+ 3 - 1
Script/TypeScript/AtomicWork.d.ts

@@ -7,6 +7,8 @@ declare module Atomic {
 
 
     export function print(...args:any[]);
     export function print(...args:any[]);
 
 
+    export var platform:string;
+
 
 
     export interface PathInfo {
     export interface PathInfo {
 
 
@@ -55,7 +57,7 @@ declare module Atomic {
     }
     }
 
 
     export interface UIWidgetDeletedEvent {
     export interface UIWidgetDeletedEvent {
-      
+
         widget: UIWidget;
         widget: UIWidget;
     }
     }
 
 

+ 5 - 12
Script/TypeScript/Editor.d.ts

@@ -25,14 +25,15 @@ declare module Editor {
 //----------------------------------------------------
 //----------------------------------------------------
 
 
 
 
-   export class MyJSClass extends Atomic.AObject {
-
-      aha: string;
+   export class FileUtils extends Atomic.AObject {
 
 
       // Construct.
       // Construct.
       constructor();
       constructor();
 
 
-      getAha(): string;
+      createDirs(folder: string): boolean;
+      openProjectFileDialog(): void;
+      newProjectFileDialog(): string;
+      revealInFinder(fullpath: string): void;
 
 
    }
    }
 
 
@@ -100,14 +101,6 @@ declare module Editor {
 
 
    }
    }
 
 
-   export class InspectorFrame extends Atomic.UIWidget {
-
-      // Construct.
-      constructor();
-
-
-   }
-
 
 
 
 
 }
 }

+ 2 - 0
Script/TypeScript/ToolCore.d.ts

@@ -35,6 +35,7 @@ declare module ToolCore {
       playerDataDir: string;
       playerDataDir: string;
       editorDataDir: string;
       editorDataDir: string;
       deploymentDataDir: string;
       deploymentDataDir: string;
+      projectTemplatesDir: string;
       examplesDir: string;
       examplesDir: string;
       devConfigFilename: string;
       devConfigFilename: string;
 
 
@@ -52,6 +53,7 @@ declare module ToolCore {
       getPlayerDataDir(): string;
       getPlayerDataDir(): string;
       getEditorDataDir(): string;
       getEditorDataDir(): string;
       getDeploymentDataDir(): string;
       getDeploymentDataDir(): string;
+      getProjectTemplatesDir(): string;
       getExamplesDir(): string;
       getExamplesDir(): string;
       getDevConfigFilename(): string;
       getDevConfigFilename(): string;
       dump(): void;
       dump(): void;

+ 9 - 0
Source/Atomic/UI/UIImageWidget.cpp

@@ -29,6 +29,15 @@ UIImageWidget::~UIImageWidget()
 {
 {
 }
 }
 
 
+void UIImageWidget::SetImage(const String& imagePath)
+{
+    if (!widget_)
+        return;
+
+    ((TBImageWidget*) widget_)->SetImage(imagePath.CString());
+
+}
+
 bool UIImageWidget::OnEvent(const tb::TBWidgetEvent &ev)
 bool UIImageWidget::OnEvent(const tb::TBWidgetEvent &ev)
 {
 {
     return UIWidget::OnEvent(ev);
     return UIWidget::OnEvent(ev);

+ 2 - 0
Source/Atomic/UI/UIImageWidget.h

@@ -16,6 +16,8 @@ public:
     UIImageWidget(Context* context, bool createWidget = true);
     UIImageWidget(Context* context, bool createWidget = true);
     virtual ~UIImageWidget();
     virtual ~UIImageWidget();
 
 
+    void SetImage(const String& imagePath);
+
 protected:
 protected:
 
 
     virtual bool OnEvent(const tb::TBWidgetEvent &ev);
     virtual bool OnEvent(const tb::TBWidgetEvent &ev);

+ 95 - 0
Source/AtomicEditorWork/Utils/FileUtils.cpp

@@ -0,0 +1,95 @@
+
+#include <Poco/File.h>
+
+#include "AtomicEditor.h"
+
+#include <Atomic/Core/Context.h>
+#include <Atomic/Core/StringUtils.h>
+#include <Atomic/IO/FileSystem.h>
+#include <Atomic/Graphics/Graphics.h>
+#include "FileUtils.h"
+#include "nfd.h"
+
+namespace AtomicEditor
+{
+
+FileUtils::FileUtils(Context* context) :
+    Object(context)
+{
+
+}
+
+FileUtils::~FileUtils()
+{
+}
+
+void FileUtils::OpenProjectFileDialog()
+{
+    nfdchar_t *outPath = NULL;
+
+    nfdresult_t result = NFD_OpenDialog( "atomic",
+                                NULL,
+                                &outPath);
+
+    if (outPath && result == NFD_OKAY)
+    {
+        String fullpath = outPath;
+        //Editor* editor = GetSubsystem<Editor>();
+        //editor->LoadProject(fullpath);
+    }
+
+    GetSubsystem<Graphics>()->RaiseWindow();
+
+    if (outPath)
+        free(outPath);
+
+}
+
+bool FileUtils::CreateDirs(const String& folder)
+{
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+
+    Poco::File dirs(folder.CString());
+    dirs.createDirectories();
+
+    return fileSystem->DirExists(folder);
+
+}
+
+String FileUtils::NewProjectFileDialog()
+{
+
+    String projectPath;
+
+    nfdchar_t *outPath = NULL;
+
+    nfdresult_t result = NFD_ChooseDirectory( "Please choose the root folder for your project",
+                                NULL,
+                                &outPath);
+
+
+    if (outPath && result == NFD_OKAY)
+    {
+        projectPath = outPath;
+    }
+
+    GetSubsystem<Graphics>()->RaiseWindow();
+
+    if (outPath)
+        free(outPath);
+
+    return projectPath;
+
+}
+
+void FileUtils::RevealInFinder(const String& fullpath)
+{
+    FileSystem* fs = GetSubsystem<FileSystem>();
+    if (fs->DirExists(fullpath))
+        fs->SystemOpen(fullpath);
+    else if (fs->FileExists(fullpath))
+        fs->SystemOpen(GetPath(fullpath));
+}
+
+
+}

+ 33 - 0
Source/AtomicEditorWork/Utils/FileUtils.h

@@ -0,0 +1,33 @@
+
+#pragma once
+
+#include <Atomic/Core/Object.h>
+
+using namespace Atomic;
+
+namespace AtomicEditor
+{
+
+class FileUtils : public Object
+{
+    OBJECT(FileUtils);
+
+public:
+
+    /// Construct.
+    FileUtils(Context* context);
+    /// Destruct.
+    ~FileUtils();
+
+    bool CreateDirs(const String& folder);
+
+    void OpenProjectFileDialog();
+    String NewProjectFileDialog();
+    void RevealInFinder(const String& fullpath);
+
+private:
+
+};
+
+
+}

+ 2 - 4
Source/AtomicJS/Packages/Editor/Editor.json

@@ -1,7 +1,5 @@
 {
 {
 	"name" : "Editor",
 	"name" : "Editor",
-	"sources" : ["Source/AtomicEditorWork/JSTest", "Source/AtomicEditorWork/Editors", "Source/AtomicEditorWork/Editors/SceneEditor3D",
-		           "Source/AtomicEditorWork/Inspector"],
-	"classes" : ["MyJSClass", "ResourceEditor", "JSResourceEditor", "SceneEditor3D", "SceneView3D",
-								"InspectorFrame"]
+	"sources" : ["Source/AtomicEditorWork/Utils", "Source/AtomicEditorWork/Editors", "Source/AtomicEditorWork/Editors/SceneEditor3D"],
+	"classes" : ["FileUtils", "ResourceEditor", "JSResourceEditor", "SceneEditor3D", "SceneView3D"]
 }
 }

+ 2 - 0
Source/ToolCore/ToolEnvironment.cpp

@@ -106,6 +106,8 @@ void ToolEnvironment::SetRootSourceDir(const String& sourceDir)
     resourceCoreDataDir_ = rootSourceDir_ + "Resources/CoreData";
     resourceCoreDataDir_ = rootSourceDir_ + "Resources/CoreData";
     resourcePlayerDataDir_ = rootSourceDir_ + "Resources/PlayerData";
     resourcePlayerDataDir_ = rootSourceDir_ + "Resources/PlayerData";
     resourceEditorDataDir_ = rootSourceDir_ + "Resources/EditorData";
     resourceEditorDataDir_ = rootSourceDir_ + "Resources/EditorData";
+
+    projectTemplatesDir_ = rootSourceDir_ + "Data/AtomicEditor/ProjectTemplates/";
 }
 }
 
 
 void ToolEnvironment::SetRootBuildDir(const String& buildDir, bool setBinaryPaths)
 void ToolEnvironment::SetRootBuildDir(const String& buildDir, bool setBinaryPaths)

+ 4 - 0
Source/ToolCore/ToolEnvironment.h

@@ -42,6 +42,7 @@ public:
 
 
     const String& GetDeploymentDataDir() { return toolBinary_; }
     const String& GetDeploymentDataDir() { return toolBinary_; }
 
 
+    const String& GetProjectTemplatesDir() { return projectTemplatesDir_; }
     const String& GetExamplesDir() { return examplesDir_; }
     const String& GetExamplesDir() { return examplesDir_; }
 
 
     const String& GetDevConfigFilename();
     const String& GetDevConfigFilename();
@@ -68,6 +69,9 @@ private:
     // examples directory
     // examples directory
     String examplesDir_;
     String examplesDir_;
 
 
+    // project templates directory
+    String projectTemplatesDir_;
+
     // resources
     // resources
     String resourceCoreDataDir_;
     String resourceCoreDataDir_;
     String resourcePlayerDataDir_;
     String resourcePlayerDataDir_;