Skip to content

Commit

Permalink
Merge pull request #272 from carboncopies/271-implement-option-to-cre…
Browse files Browse the repository at this point in the history
…ate-new-project

271 implement option to create new project
  • Loading branch information
datacrystals authored Jul 18, 2022
2 parents 208a0e3 + 16abebc commit 13265d3
Show file tree
Hide file tree
Showing 63 changed files with 3,325 additions and 20 deletions.
18 changes: 8 additions & 10 deletions Source/Core/Editor/Menus/GUI_Menu_File/GUI_Menu_File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,12 @@ void GUI_Menu_File::Draw() {
// File Menu
if (ImGui::BeginMenu("File")) {

ImGui::MenuItem("New", "", &Windows_->GUI_Window_NewProject_->Enabled_);
ImGui::MenuItem("Open", "", &Windows_->GUI_Window_OpenProject_->Enabled_);
ImGui::Separator();

ImGui::MenuItem("About", "", &Windows_->GUI_Window_About_->Enabled_);
ImGui::Separator();

ImGui::MenuItem("Project Settings", "", &Windows_->GUI_Window_ProjectSettings_->Enabled_);
ImGui::Separator();

if (ImGui::MenuItem("Import Model")) {
ImportAsset_->OpenFileDialog();
}
ImGui::Separator();

// Save All
if (ImGui::MenuItem("Save")) {

SystemUtils_->Logger_->Log("Saving Project Data", 4);
Expand All @@ -61,6 +52,13 @@ void GUI_Menu_File::Draw() {
}
}

ImGui::MenuItem("Project Settings", "", &Windows_->GUI_Window_ProjectSettings_->Enabled_);
ImGui::MenuItem("About", "", &Windows_->GUI_Window_About_->Enabled_);
ImGui::Separator();

if (ImGui::MenuItem("Import Model")) {
ImportAsset_->OpenFileDialog();
}
ImGui::Separator();

// Exit Options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ target_link_libraries(ERS_Editor_WindowManager
GUI_Window_ThemeSelector
GUI_Window_FontSelector
GUI_Window_OpenProject
GUI_Window_NewProject

)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ ERS_CLASS_ThemeManager* ThemeManager, ERS_CLASS_FontManager* FontManager, Cursor
Windows_->GUI_Window_TestEditor_ = std::make_unique<GUI_Window_TestEditor>(SystemUtils_);
Windows_->GUI_Window_ThemeSelector_ = std::make_unique<GUI_Window_ThemeSelector>(ThemeManager);
Windows_->GUI_Window_FontSelector_ = std::make_unique<GUI_Window_FontSelector>(FontManager);
Windows_->GUI_Window_OpenProject_ = std::make_unique<GUI_Window_OpenProject>(SystemUtils_);
Windows_->GUI_Window_OpenProject_ = std::make_unique<GUI_Window_OpenProject>(SystemUtils_);
Windows_->GUI_Window_NewProject_ = std::make_unique<GUI_Window_NewProject>(SystemUtils_);

SystemUtils_->Logger_->Log("WindowManager Subsystem Finished Setting Up Window Struct", 3);
SystemUtils_->Logger_->Log("WindowManager Subsystem Setting Up Window Index", 4);
Expand All @@ -81,6 +82,7 @@ ERS_CLASS_ThemeManager* ThemeManager, ERS_CLASS_FontManager* FontManager, Cursor
WindowNames_.push_back("ThemeSelector");
WindowNames_.push_back("FontSelector");
WindowNames_.push_back("OpenProject");
WindowNames_.push_back("NewProject");

SystemUtils_->Logger_->Log("WindowManager Subsystem Finished Setting Up Window Index", 3);

Expand Down Expand Up @@ -113,6 +115,7 @@ void ERS_CLASS_WindowManager::UpdateAllWindows() {
Windows_->GUI_Window_ThemeSelector_->Draw();
Windows_->GUI_Window_FontSelector_->Draw();
Windows_->GUI_Window_OpenProject_->Draw();
Windows_->GUI_Window_NewProject_->Draw();

}

Expand Down Expand Up @@ -183,6 +186,9 @@ bool ERS_CLASS_WindowManager::SetWindowStatus(std::string WindowName, bool Statu
} else if (WindowName == "OpenProject") {
Windows_->GUI_Window_OpenProject_->Enabled_ = Status;
return true;
} else if (WindowName == "NewProject") {
Windows_->GUI_Window_NewProject_->Enabled_ = Status;
return true;
} else {
return false;
}
Expand Down Expand Up @@ -256,6 +262,9 @@ bool ERS_CLASS_WindowManager::GetWindowStatus(std::string WindowName, bool* Stat
} else if (WindowName == "OpenProject") {
*Status = Windows_->GUI_Window_OpenProject_->Enabled_;
return true;
} else if (WindowName == "NewProject") {
*Status = Windows_->GUI_Window_NewProject_->Enabled_;
return true;
} else {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <GUI_Window_ThemeSelector.h>
#include <GUI_Window_FontSelector.h>
#include <GUI_Window_OpenProject.h>
#include <GUI_Window_NewProject.h>



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <GUI_Window_ThemeSelector.h>
#include <GUI_Window_FontSelector.h>
#include <GUI_Window_OpenProject.h>
#include <GUI_Window_NewProject.h>

/**
* @brief This structure holds unique pointers to all windows that are instantiated by the GUI.
Expand Down Expand Up @@ -61,6 +62,7 @@ struct ERS_STRUCT_Windows {
std::unique_ptr<GUI_Window_ThemeSelector> GUI_Window_ThemeSelector_;
std::unique_ptr<GUI_Window_FontSelector> GUI_Window_FontSelector_;
std::unique_ptr<GUI_Window_OpenProject> GUI_Window_OpenProject_;
std::unique_ptr<GUI_Window_NewProject> GUI_Window_NewProject_;


};
1 change: 1 addition & 0 deletions Source/Core/Editor/Windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/GUI_Window_ShaderEditor)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/GUI_Window_ScriptEditor)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/GUI_Window_OpenProject)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/GUI_Window_NewProject)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/GUI_Window_ThemeSelector)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/GUI_Window_FontSelector)
Expand Down
31 changes: 31 additions & 0 deletions Source/Core/Editor/Windows/GUI_Window_NewProject/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
########################################################################
# This file is part of the BrainGenix-ERS Environment Rendering System #
########################################################################

# Create Library (Name Should Be Parent Dir Name)
add_library(GUI_Window_NewProject

# Add Source Files (.cpp)
"GUI_Window_NewProject.cpp"

# Add Header Files (.h)
"GUI_Window_NewProject.h"


${BACKWARD_ENABLE}
)

# Link 3rd Party Libs
target_link_libraries(GUI_Window_NewProject
glad
glfw
IMGUI
ImGuiFileDialog
)

# Link Internal Libs
target_link_libraries(GUI_Window_NewProject
ERS_STRUCT_SystemUtils
)

target_include_directories(GUI_Window_NewProject PUBLIC ./)
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//======================================================================//
// This file is part of the BrainGenix-ERS Environment Rendering System //
//======================================================================//

#include <GUI_Window_NewProject.h>


GUI_Window_NewProject::GUI_Window_NewProject(ERS_STRUCT_SystemUtils* SystemUtils) {

SystemUtils_ = SystemUtils;
SystemUtils_->Logger_->Log("Seting Up New Project Window Dialog", 5);

}


GUI_Window_NewProject::~GUI_Window_NewProject() {

SystemUtils_->Logger_->Log("New Project Window Dialog Destructor Called", 6);

}


void GUI_Window_NewProject::Draw() {

if (Enabled_ && !LastWindowState_) {
ImGuiFileDialog::Instance()->OpenDialog("New Project", "New Project", nullptr, "~", "", 0);

}

if (Enabled_) {

// Draw File Dialog
if (ImGuiFileDialog::Instance()->Display("New Project", ImGuiWindowFlags_None, ImVec2(600, 300))) {


if (ImGuiFileDialog::Instance()->IsOk())
{

std::string Path = ImGuiFileDialog::Instance()->GetCurrentPath();
Path += "/";
SystemUtils_->Logger_->Log(std::string("Creating New Project In Target Directory '") + Path + "'", 5);

// TodO add system to get project dir from config file,
// then have it iterate over all files, copying them to the new selected path
// finally, have the system load that
// check for bugs and edge-cases

std::string DefualtProjectPath = "EditorAssets/Projects/NewProject/";
std::string CurrentExecutablePath = std::filesystem::current_path();

for (const auto &Entry : std::filesystem::recursive_directory_iterator(DefualtProjectPath)) {

// Get The Current Absolute Path To File, As Well As It's Filename
std::string PathRelativeName{Entry.path().u8string()};
std::string File = CurrentExecutablePath + "/" + PathRelativeName;
std::string FileName = PathRelativeName.substr(PathRelativeName.find_last_of("/"), sizeof(PathRelativeName));

SystemUtils_->Logger_->Log(std::string("Copying File '") + File + "' To New Project Directory", 4);
std::filesystem::copy_file(File, Path + FileName);

}


std::string Command;
#if defined(_WIN32)
Command += "";
#elif defined(__APPLE__)
Command += "./";
#else
Command += "./";
#endif
Command += "BrainGenix-ERS -ProjectDirectory ";
Command += '"' + Path + '"' + " &";
std::system(Command.c_str());

// Quit System
SystemUtils_->Logger_->Log("Shutting Down This Editor Window Now, Launching Editor For That Project", 5);
*SystemUtils_->SystemShouldRun_ = false;


}

ImGuiFileDialog::Instance()->Close();
}




}

LastWindowState_ = Enabled_;


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//======================================================================//
// This file is part of the BrainGenix-ERS Environment Rendering System //
//======================================================================//

#pragma once


// Standard Libraries (BG convention: use <> instead of "")
#include <memory>
#include <iostream>

// Third-Party Libraries (BG convention: use <> instead of "")
#include <yaml-cpp/yaml.h>

#include <imgui.h>

#include <ImGuiFileDialog.h>

// Internal Libraries (BG convention: use <> instead of "")
#include <ERS_STRUCT_SystemUtils.h>


/**
* @brief This class provides the GUI to the import asset option within the file menu.
*
*/
class GUI_Window_NewProject {

private:

ERS_STRUCT_SystemUtils* SystemUtils_; /**<used to get access to system utilites like IOmanager, logger, etc.*/
bool LastWindowState_ = false; /**<State of the wiundow last frame*/

public:

bool Enabled_ = false; /**<Show/hide the window*/

/**
* @brief Construct a new gui importasset object.
*
* @param SystemUtils
*/
GUI_Window_NewProject(ERS_STRUCT_SystemUtils* SystemUtils);

/**
* @brief Destroy the gui importasset object.
*
*/
~GUI_Window_NewProject();

/**
* @brief Update Any Windows
*
*/
void Draw();

};
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ GUI_Window_OpenProject::~GUI_Window_OpenProject() {
void GUI_Window_OpenProject::Draw() {

if (Enabled_ && !LastWindowState_) {
ImGuiFileDialog::Instance()->OpenDialog("Open Project", "Open Project", ".ERS", ".", "", 0);
ImGuiFileDialog::Instance()->OpenDialog("Open Project", "Open Project", nullptr, "~", "", 0);
}

if (Enabled_) {

// Draw File Dialog
if (ImGuiFileDialog::Instance()->Display("Open Project", ImGuiWindowFlags_None, ImVec2(400, 200))) {
if (ImGuiFileDialog::Instance()->Display("Open Project", ImGuiWindowFlags_None, ImVec2(600, 300))) {


if (ImGuiFileDialog::Instance()->IsOk())
Expand Down
27 changes: 22 additions & 5 deletions Source/Core/Manager/ERS_ProjectManager/ERS_ProjectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,29 @@ void ERS_CLASS_ProjectManager::LoadProject(long AssetID) {
Project_.ControllerSettings->push_back(Settings);
}

// Load Default Scene
SystemUtils_->Logger_->Log(std::string(std::string("Loading Project Default Scene With ID ") + std::to_string(Project_.SceneIDs[Project_.DefaultScene])).c_str(), 5);
for (unsigned int i = 0; i < Project_.SceneIDs.size(); i++) {
SceneManager_->AddScene(SceneLoader_->ProcessScene(Project_.SceneIDs[i]));
// Handle The Defaut Scene
if (Project_.SceneIDs.size() > 0) {

// Load Default Scene If Applicable
SystemUtils_->Logger_->Log(std::string(std::string("Loading Project Default Scene With ID ") + std::to_string(Project_.SceneIDs[Project_.DefaultScene])).c_str(), 5);
for (unsigned int i = 0; i < Project_.SceneIDs.size(); i++) {
SceneManager_->AddScene(SceneLoader_->ProcessScene(Project_.SceneIDs[i]));
}
SceneManager_->SetActiveScene(Project_.DefaultScene);

} else {

// Create Blank Scene For The System
ERS_STRUCT_Scene NewScene;
NewScene.ScenePath = SystemUtils_->ERS_IOSubsystem_->AllocateAssetID();
NewScene.SceneName = "Untitled Scene";
NewScene.IsSceneLoaded = true;
NewScene.SceneFormatVersion = 1;

Project_.SceneIDs.push_back(NewScene.ScenePath);
SceneManager_->AddScene(NewScene);

}
SceneManager_->SetActiveScene(Project_.DefaultScene);

}

Expand Down
Loading

0 comments on commit 13265d3

Please sign in to comment.