소스 검색

Working on NewProject/CreateProject/Example/Template

Josh Engebretson 10 년 전
부모
커밋
94fa327516

+ 16 - 0
Data/AtomicEditor/Resources/EditorData/AtomicEditor/editor/ui/createproject.tb.txt

@@ -0,0 +1,16 @@
+TBLayout: axis: y, distribution: gravity, position: left
+	TBLayout: distribution: gravity
+	TBTextField: text: "Project Name:"
+	TBEditField: id: project_name, text: "MyGame", autofocus: 1
+		lp: min-width: 220	
+	TBSeparator: gravity: left right, skin: AESeparator
+	TBTextField: text: "Project Directory:"		
+	TBLayout: axis: y, distribution: gravity, position: left
+		TBLayout: gravity: left right, distribution-position: right bottom
+			TBEditField: id: project_path
+				lp: min-width: 380
+			TBButton: text: "Choose" id: choose_path
+	TBSeparator: gravity: left right, skin: AESeparator
+	TBLayout: 
+		TBButton: text: Create, id: create
+		TBButton: text: Cancel, id: cancel

+ 2 - 1
Source/AtomicEditor/Source/Project/ProjectUtils.cpp

@@ -124,10 +124,11 @@ String ProjectUtils::NewProjectFileDialog()
 
 
     nfdchar_t *outPath = NULL;
     nfdchar_t *outPath = NULL;
 
 
-    nfdresult_t result = NFD_SaveDialog( "atomic",
+    nfdresult_t result = NFD_ChooseDirectory( "Please choose the root folder for your project",
                                 NULL,
                                 NULL,
                                 &outPath);
                                 &outPath);
 
 
+
     if (outPath && result == NFD_OKAY)
     if (outPath && result == NFD_OKAY)
     {
     {
         projectPath = outPath;
         projectPath = outPath;

+ 162 - 0
Source/AtomicEditor/Source/UI/Modal/UICreateProject.cpp

@@ -0,0 +1,162 @@
+// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
+// Please see LICENSE.md in repository root for license information
+// https://github.com/AtomicGameEngine/AtomicGameEngine
+
+#include <Poco/File.h>
+
+#include "AtomicEditor.h"
+
+#include <TurboBadger/tb_window.h>
+#include <TurboBadger/tb_select.h>
+#include <TurboBadger/tb_editfield.h>
+
+#include <Atomic/Core/Context.h>
+#include <Atomic/Core/StringUtils.h>
+#include <Atomic/UI/TBUI.h>
+
+#include "Resources/AEResourceOps.h"
+#include "AEPreferences.h"
+
+#include "AEEditor.h"
+#include "AEEvents.h"
+#include "Project/AEProject.h"
+#include "Project/ProjectUtils.h"
+
+#include "UICreateProject.h"
+
+namespace AtomicEditor
+{
+
+// UIBuildSettings------------------------------------------------
+
+UICreateProject::UICreateProject(Context* context, const String &templateFolder):
+    UIModalOpWindow(context)
+  , projectPathField_(0)
+  , templateFolder_(templateFolder)
+{
+    Editor* editor = GetSubsystem<Editor>();
+    Project* project = editor->GetProject();
+
+    TBUI* tbui = GetSubsystem<TBUI>();
+    window_->SetText("Create Project");
+    tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/createproject.tb.txt");
+
+    projectPathField_ = delegate_->GetWidgetByIDAndType<TBEditField>(TBIDC("project_path"));
+    assert(projectPathField_);
+
+    projectNameField_ = delegate_->GetWidgetByIDAndType<TBEditField>(TBIDC("project_name"));
+    assert(projectNameField_);
+
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+
+    String userDocuments = fileSystem->GetUserDocumentsDir();
+
+#if defined(ATOMIC_PLATFORM_OSX)
+    userDocuments += "Documents/AtomicProjects";
+#endif
+
+    projectPathField_->SetText(userDocuments.CString());
+
+
+    window_->ResizeToFitContent();
+    Center();
+}
+
+
+UICreateProject::~UICreateProject()
+{
+
+}
+
+bool UICreateProject::DoCreate(const String& folder, const String& projectName)
+{
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+
+    fileSystem->CopyDir(templateFolder_ + "/Resources", folder + "/Resources");
+
+    File file(context_, folder + "/" + projectName + ".atomic", FILE_WRITE);
+    file.Close();
+
+    return true;
+}
+
+bool UICreateProject::OnEvent(const TBWidgetEvent &ev)
+{
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+    Editor* editor = GetSubsystem<Editor>();
+    UIModalOps* ops = GetSubsystem<UIModalOps>();
+    ProjectUtils* utils = context_->GetSubsystem<ProjectUtils>();
+
+    if (ev.type == EVENT_TYPE_CLICK)
+    {
+
+        if (ev.target->GetID() == TBIDC("choose_path"))
+        {
+            String buildPath = utils->NewProjectFileDialog();
+
+            if (buildPath.Length())
+                projectPathField_->SetText(buildPath.CString());
+
+            return true;
+        }
+        else if (ev.target->GetID() == TBIDC("create"))
+        {
+            String name = projectNameField_->GetText().CStr();
+            name = name.Trimmed();
+            if (!name.Length())
+            {
+                editor->PostModalInfo("New Project Editor Error", "Please enter a project name");
+                return true;
+            }
+            String folder = projectPathField_->GetText().CStr();
+            folder = folder.Trimmed();
+            if (!folder.Length())
+            {
+                editor->PostModalInfo("New Project Editor Error", "Please choose a root project folder");
+                return true;
+            }
+
+            folder += "/" + name;
+
+            if (fileSystem->DirExists(folder) || fileSystem->FileExists(folder))
+            {
+                editor->PostModalInfo("New Project Editor Error",
+                                      ToString("%s exists\n\nPlease choose a different root folder or project name", folder.CString()));
+                return true;
+
+            }
+
+            if (!fileSystem->DirExists(folder))
+            {
+                Poco::File dirs(folder.CString());
+                dirs.createDirectories();
+
+                if (!fileSystem->DirExists(folder))
+                {
+                    editor->PostModalInfo("New Project Editor Error",
+                                          ToString("Unable to create project folder:\n%s", folder.CString()));
+                    return true;
+                }
+
+                if (DoCreate(folder, name))
+                {
+                    SharedPtr<UICreateProject> keepAlive(this);
+                    UIModalOps* ops = GetSubsystem<UIModalOps>();
+                    ops->Hide();
+                    editor->LoadProject(folder + "/" + name + ".atomic");
+                    return true;
+                }
+            }
+
+        }
+        else if (ev.target->GetID() == TBIDC("cancel"))
+        {
+            ops->Hide();
+            return true;
+        }
+    }
+
+    return false;
+}
+
+}

+ 33 - 0
Source/AtomicEditor/Source/UI/Modal/UICreateProject.h

@@ -0,0 +1,33 @@
+
+#pragma once
+
+#include "UIModalOps.h"
+
+#include <TurboBadger/tb_select.h>
+#include <TurboBadger/tb_select_item.h>
+
+namespace AtomicEditor
+{
+
+class UICreateProject: public UIModalOpWindow
+{
+    OBJECT(UICreateProject);
+
+public:
+
+    UICreateProject(Context* context, const String& templateFolder);
+    virtual ~UICreateProject();
+    bool OnEvent(const TBWidgetEvent &ev);
+
+private:
+
+    bool DoCreate(const String& folder, const String& projectName);
+
+    TBEditField* projectNameField_;
+    TBEditField* projectPathField_;
+
+    String templateFolder_;
+
+};
+
+}

+ 10 - 0
Source/AtomicEditor/Source/UI/Modal/UIModalOps.cpp

@@ -26,6 +26,7 @@
 #include "UIBuildSettings.h"
 #include "UIBuildSettings.h"
 #include "UIProgramOutput.h"
 #include "UIProgramOutput.h"
 #include "UINewProject.h"
 #include "UINewProject.h"
+#include "UICreateProject.h"
 #include "UIAbout.h"
 #include "UIAbout.h"
 #include "UIPlatformsInfo.h"
 #include "UIPlatformsInfo.h"
 #include "UIInfoModule3D.h"
 #include "UIInfoModule3D.h"
@@ -201,6 +202,15 @@ void UIModalOps::ShowNewProject()
     opWindow_ = new UINewProject(context_);
     opWindow_ = new UINewProject(context_);
 }
 }
 
 
+void UIModalOps::ShowCreateProject(const String &templateFolder)
+{
+    assert(opWindow_.Null());
+
+    Show();
+    opWindow_ = new UICreateProject(context_, templateFolder);
+}
+
+
 void UIModalOps::SetProgramOutputSubprocess(Object* subprocess)
 void UIModalOps::SetProgramOutputSubprocess(Object* subprocess)
 {
 {
     if (opWindow_.Null())
     if (opWindow_.Null())

+ 1 - 0
Source/AtomicEditor/Source/UI/Modal/UIModalOps.h

@@ -55,6 +55,7 @@ class UIModalOps: public AEWidget, private TBWidgetListener
     void ShowBuildSettings();
     void ShowBuildSettings();
     void ShowBuild();
     void ShowBuild();
     void ShowNewProject();
     void ShowNewProject();
+    void ShowCreateProject(const String& templateFolder);
     void ShowActivation();
     void ShowActivation();
     void ShowActivationSuccess();
     void ShowActivationSuccess();
     void ShowManageLicense();
     void ShowManageLicense();

+ 16 - 50
Source/AtomicEditor/Source/UI/Modal/UINewProject.cpp

@@ -33,7 +33,7 @@ UINewProject::UINewProject(Context* context):
     Project* project = editor->GetProject();
     Project* project = editor->GetProject();
 
 
     TBUI* tbui = GetSubsystem<TBUI>();
     TBUI* tbui = GetSubsystem<TBUI>();
-    window_->SetText("New Project");
+    window_->SetText("Project Type");
     tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/newproject.tb.txt");
     tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/newproject.tb.txt");
 
 
     window_->ResizeToFitContent();
     window_->ResizeToFitContent();
@@ -136,7 +136,7 @@ bool UINewProject::OnEvent(const TBWidgetEvent &ev)
 
 
             if (licenseSystem->IsStarterLicense())
             if (licenseSystem->IsStarterLicense())
             {
             {
-                SharedPtr<UINewProject>(this);
+                SharedPtr<UINewProject> keepAlive(this);
                 UIModalOps* ops = GetSubsystem<UIModalOps>();
                 UIModalOps* ops = GetSubsystem<UIModalOps>();
                 ops->Hide();
                 ops->Hide();
                 ops->ShowInfoModule3D();
                 ops->ShowInfoModule3D();
@@ -149,62 +149,28 @@ bool UINewProject::OnEvent(const TBWidgetEvent &ev)
 
 
         if (projectType != -1)
         if (projectType != -1)
         {
         {
-            String fullProjectPath = GetSubsystem<ProjectUtils>()->NewProjectFileDialog();
-
-            if (!fullProjectPath.Length())
-                return true;
-
-            String projectPath;
-            String fileName;
-            String ext;
-
-            SplitPath(fullProjectPath, projectPath, fileName, ext);
-
             FileSystem* fileSystem = GetSubsystem<FileSystem>();
             FileSystem* fileSystem = GetSubsystem<FileSystem>();
-            if (!fileSystem->DirExists(projectPath))
-            {
-                editor->PostModalInfo("New Project Editor Error", "Project folder does not exist");
-                return true;
-            }
-            Vector<String> results;
-            fileSystem->ScanDir(results, projectPath, "*", SCAN_DIRS | SCAN_FILES, false);
-            while (results.Remove(".")) {}
-            while (results.Remove("..")) {}
-
-            if (results.Size())
-            {
-                editor->PostModalInfo("New Project Editor Error", "Project folder must be empty.\nPlease create a new folder or select an empty one");
-                return true;
-            }
 
 
-            bool result = false;
+        #ifdef ATOMIC_PLATFORM_OSX
+            String templateSourceDir = fileSystem->GetAppBundleResourceFolder();
+        #else
+            String templateSourceDir = fileSystem->GetProgramDir();
+        #endif
 
 
             if (projectType == 0)
             if (projectType == 0)
-            {
-                result = CreateEmptyProject(projectPath, fileName);
-            }
+                templateSourceDir += "/ProjectTemplates/EmptyProject";
             else if (projectType == 1)
             else if (projectType == 1)
-            {
-                result = Create2DProject(projectPath, fileName);
-            }
-            else if (projectType == 2)
-            {
-                result = Create3DProject(projectPath, fileName);
-            }
-
-            if (!result)
-            {
-                editor->PostModalInfo("New Project Editor Error", "Error Creating Project");
-                return true;
-            }
-
-            Vector<String> elements = projectPath.Split('/');
-            String projectName = elements.Back();
-
-            editor->LoadProject(projectPath + "/" + projectName + ".atomic");
+                templateSourceDir += "/ProjectTemplates/Project2D";
+            else
+                templateSourceDir += "/ProjectTemplates/Project3D";
 
 
+            SharedPtr<UINewProject> keepAlive(this);
+            UIModalOps* ops = GetSubsystem<UIModalOps>();
             ops->Hide();
             ops->Hide();
+            ops->ShowCreateProject(templateSourceDir);
+
             return true;
             return true;
+
         }
         }
 
 
     }
     }

+ 4 - 68
Source/AtomicEditor/Source/UI/UIWelcomeFrame.cpp

@@ -219,65 +219,6 @@ void WelcomeFrame::FillExamples()
 
 
 }
 }
 
 
-bool WelcomeFrame::HandleExampleCopy(const String& name, const String& exampleFolder, String& atomicProjectFile)\
-{
-    Editor* editor = GetSubsystem<Editor>();
-
-    String fullProjectPath = GetSubsystem<ProjectUtils>()->NewProjectFileDialog();
-
-    if (!fullProjectPath.Length())
-        return false;
-
-    String projectPath;
-    String fileName;
-    String ext;
-
-    SplitPath(fullProjectPath, projectPath, fileName, ext);
-
-    FileSystem* fileSystem = GetSubsystem<FileSystem>();
-
-    if (!fileSystem->DirExists(projectPath))
-    {
-        editor->PostModalInfo("New Project Editor Error", "Project folder does not exist");
-        return false;
-    }
-
-    Vector<String> results;
-    fileSystem->ScanDir(results, projectPath, "*", SCAN_DIRS | SCAN_FILES, false);
-    while (results.Remove(".")) {}
-    while (results.Remove("..")) {}
-
-    if (results.Size())
-    {
-        editor->PostModalInfo("New Project Editor Error", "Project folder must be empty.\nPlease create a new folder or select an empty one");
-        return false;
-    }
-
-    String exampleSourceDir = exampleSourceDir_ + "/" + exampleFolder;
-
-    bool result = fileSystem->CopyDir(exampleSourceDir + "/" + "Resources", projectPath + "/" + "Resources");
-
-    if (!result)
-    {
-        editor->PostModalInfo("New Project Editor Error", "Error copying example");
-        return false;
-    }
-
-    // example folder name and .atomic must match
-    atomicProjectFile = projectPath + fileName + ".atomic";
-    String sourceProjectFile = exampleSourceDir + "/" + exampleFolder + ".atomic";
-    result = fileSystem->Copy(sourceProjectFile , atomicProjectFile);
-
-    if (!result)
-    {
-        editor->PostModalInfo("New Project Editor Error", "Error copying example project file");
-        return false;
-    }
-
-    return true;
-
-}
-
 void WelcomeFrame::UpdateRecentProjects()
 void WelcomeFrame::UpdateRecentProjects()
 {
 {
     TBSelectList* select = delegate_->GetWidgetByIDAndType<TBSelectList>(TBIDC("recentprojects"));
     TBSelectList* select = delegate_->GetWidgetByIDAndType<TBSelectList>(TBIDC("recentprojects"));
@@ -298,6 +239,7 @@ void WelcomeFrame::UpdateRecentProjects()
 
 
 bool WelcomeFrame::OnEvent(const TBWidgetEvent &ev)
 bool WelcomeFrame::OnEvent(const TBWidgetEvent &ev)
 {
 {
+    UIModalOps* ops = GetSubsystem<UIModalOps>();
     if (ev.type == EVENT_TYPE_CLICK)
     if (ev.type == EVENT_TYPE_CLICK)
     {
     {
         if (ev.target)
         if (ev.target)
@@ -347,20 +289,14 @@ bool WelcomeFrame::OnEvent(const TBWidgetEvent &ev)
                             {
                             {
                                 if ((*itr).module == "3D")
                                 if ((*itr).module == "3D")
                                 {
                                 {
-                                    UIModalOps* ops = GetSubsystem<UIModalOps>();
+
                                     ops->ShowInfoModule3D();
                                     ops->ShowInfoModule3D();
                                     return true;
                                     return true;
                                 }
                                 }
                             }
                             }
 // END LICENSE MANAGEMENT
 // END LICENSE MANAGEMENT
-
-                            String projectPath;
-                            if (HandleExampleCopy((*itr).name, (*itr).folder, projectPath))
-                            {
-                                GetSubsystem<Editor>()->LoadProject(projectPath);
-
-                            }
-
+                            String exampleSourceDir = exampleSourceDir_ + "/" + (*itr).folder;
+                            ops->ShowCreateProject(exampleSourceDir);
                             return true;
                             return true;
                         }
                         }
 
 

+ 1 - 0
Source/AtomicEditor/Vendor/nativefiledialog/nfd.h

@@ -48,6 +48,7 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
 /* save dialog */
 /* save dialog */
 nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
 nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
                             const nfdchar_t *defaultPath,
                             const nfdchar_t *defaultPath,
+                            const nfdchar_t *defaultFilename,
                             nfdchar_t **outPath );
                             nfdchar_t **outPath );
 
 
 nfdresult_t NFD_ChooseDirectory( const nfdchar_t *prompt,
 nfdresult_t NFD_ChooseDirectory( const nfdchar_t *prompt,

+ 19 - 10
Source/AtomicEditor/Vendor/nativefiledialog/nfd_cocoa.mm

@@ -55,14 +55,22 @@ static void AddFilterListToDialog( NSSavePanel *dialog, const char *filterList )
     }
     }
 }
 }
 
 
-static void SetDefaultPath( NSSavePanel *dialog, const nfdchar_t *defaultPath )
+static void SetDefaultPath( NSSavePanel *dialog, const nfdchar_t *defaultPath, const nfdchar_t *defaultFilename )
 {
 {
-    if ( !defaultPath || strlen(defaultPath) == 0 )
-        return;
+    if ( defaultPath && strlen(defaultPath))
+    {
+        NSString *defaultPathString = [NSString stringWithUTF8String: defaultPath];
+        NSURL *url = [NSURL fileURLWithPath:defaultPathString isDirectory:YES];
+        [dialog setDirectoryURL:url];
+    }
+
+
+    if ( defaultFilename && strlen(defaultFilename))
+    {
+        NSString *defaultFilenameString = [NSString stringWithUTF8String: defaultFilename];
+        [dialog setNameFieldStringValue:defaultFilenameString];
+    }
 
 
-    NSString *defaultPathString = [NSString stringWithUTF8String: defaultPath];
-    NSURL *url = [NSURL fileURLWithPath:defaultPathString isDirectory:YES];
-    [dialog setDirectoryURL:url];    
 }
 }
 
 
 
 
@@ -130,7 +138,7 @@ nfdresult_t NFD_OpenDialog( const char *filterList,
     AddFilterListToDialog(dialog, filterList);
     AddFilterListToDialog(dialog, filterList);
 
 
     // Set the starting directory
     // Set the starting directory
-    SetDefaultPath(dialog, defaultPath);
+    SetDefaultPath(dialog, defaultPath, NULL);
 
 
     nfdresult_t nfdResult = NFD_CANCEL;
     nfdresult_t nfdResult = NFD_CANCEL;
     if ( [dialog runModal] == NSModalResponseOK )
     if ( [dialog runModal] == NSModalResponseOK )
@@ -169,7 +177,7 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
     AddFilterListToDialog(dialog, filterList);
     AddFilterListToDialog(dialog, filterList);
 
 
     // Set the starting directory
     // Set the starting directory
-    SetDefaultPath(dialog, defaultPath);
+    SetDefaultPath(dialog, defaultPath, NULL);
     
     
     nfdresult_t nfdResult = NFD_CANCEL;
     nfdresult_t nfdResult = NFD_CANCEL;
     if ( [dialog runModal] == NSModalResponseOK )
     if ( [dialog runModal] == NSModalResponseOK )
@@ -198,6 +206,7 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
 
 
 nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
 nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
                             const nfdchar_t *defaultPath,
                             const nfdchar_t *defaultPath,
+                            const nfdchar_t *defaultFilename,
                             nfdchar_t **outPath )
                             nfdchar_t **outPath )
 {
 {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@@ -210,7 +219,7 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
     AddFilterListToDialog(dialog, filterList);
     AddFilterListToDialog(dialog, filterList);
 
 
     // Set the starting directory
     // Set the starting directory
-    SetDefaultPath(dialog, defaultPath);
+    SetDefaultPath(dialog, defaultPath, defaultFilename);
 
 
     nfdresult_t nfdResult = NFD_CANCEL;
     nfdresult_t nfdResult = NFD_CANCEL;
     if ( [dialog runModal] == NSModalResponseOK )
     if ( [dialog runModal] == NSModalResponseOK )
@@ -248,7 +257,7 @@ nfdresult_t NFD_ChooseDirectory(const nfdchar_t *prompt, const nfdchar_t *defaul
     [dialog setPrompt:@"Ok"];
     [dialog setPrompt:@"Ok"];
 
 
     // Set the starting directory
     // Set the starting directory
-    SetDefaultPath(dialog, defaultPath);
+    SetDefaultPath(dialog, defaultPath, NULL);
 
 
     nfdresult_t nfdResult = NFD_CANCEL;
     nfdresult_t nfdResult = NFD_CANCEL;
     if ( [dialog runModal] == NSModalResponseOK )
     if ( [dialog runModal] == NSModalResponseOK )