diff --git a/CMakeLists.txt b/CMakeLists.txt index 8dbcb38a82..9682083620 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,7 @@ add_subdirectory(${SRC_DIR}/Core/Editor/) add_subdirectory(${SRC_DIR}/Core/Editor/Utils/ERS_Editor_ThemeManager) add_subdirectory(${SRC_DIR}/Core/Editor/Utils/ERS_Editor_FontManager) add_subdirectory(${SRC_DIR}/Core/Editor/Utils/ERS_Editor_UserProfileManager) +add_subdirectory(${SRC_DIR}/Core/Editor/Utils/ERS_Editor_LayoutManager) add_subdirectory(${SRC_DIR}/Core/Editor/Utils/ERS_Editor_3DCursor) add_subdirectory(${SRC_DIR}/Core/Editor/Utils/ERS_Editor_WindowManager) add_subdirectory(${SRC_DIR}/Core/Editor/Windows) diff --git a/Source/Core/Editor/GUI.cpp b/Source/Core/Editor/GUI.cpp index a50bd73d3c..35073335aa 100644 --- a/Source/Core/Editor/GUI.cpp +++ b/Source/Core/Editor/GUI.cpp @@ -109,9 +109,14 @@ void GUISystem::UpdateGUI() { ImGui::EndMainMenuBar(); } + + size_t settings_size = 0; + const char* settings = ImGui::SaveIniSettingsToMemory(&settings_size); + // Updates all the windows, draws their content if enabled WindowManager_->UpdateAllWindows(); + } void GUISystem::DeferredFrameUpdate() { diff --git a/Source/Core/Editor/Utils/ERS_Editor_LayoutManager/CMakeLists.txt b/Source/Core/Editor/Utils/ERS_Editor_LayoutManager/CMakeLists.txt new file mode 100644 index 0000000000..575012f86f --- /dev/null +++ b/Source/Core/Editor/Utils/ERS_Editor_LayoutManager/CMakeLists.txt @@ -0,0 +1,30 @@ +######################################################################## +# This file is part of the BrainGenix-ERS Environment Rendering System # +######################################################################## + + +# Create Library (Name Should Be Parent Dir Name) +add_library(ERS_Editor_LayoutManager + + # Add Source Files (.cpp) + "ERS_Editor_LayoutManager.cpp" + + # Add Header Files (.h) + "ERS_Editor_LayoutManager.h" + + ${BACKWARD_ENABLE} + ) +set_property(TARGET ERS_Editor_LayoutManager PROPERTY CXX_STANDARD 17) + +# Link 3rd Party Libs +target_link_libraries(ERS_Editor_LayoutManager + yaml-cpp + IMGUI + ) + +# Link Internal Libs +target_link_libraries(ERS_Editor_LayoutManager + ERS_CLASS_LoggingSystem + ) + +target_include_directories(ERS_Editor_LayoutManager PUBLIC ./) \ No newline at end of file diff --git a/Source/Core/Editor/Utils/ERS_Editor_LayoutManager/ERS_Editor_LayoutManager.cpp b/Source/Core/Editor/Utils/ERS_Editor_LayoutManager/ERS_Editor_LayoutManager.cpp new file mode 100644 index 0000000000..ab502e3b80 --- /dev/null +++ b/Source/Core/Editor/Utils/ERS_Editor_LayoutManager/ERS_Editor_LayoutManager.cpp @@ -0,0 +1,139 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#include +#include +#include +#include + +ERS_CLASS_LayoutManager::ERS_CLASS_LayoutManager(ERS_CLASS_LoggingSystem* Logger, const char* LayoutDirectory) { + + Logger_ = Logger; + LayoutDirectory_ = LayoutDirectory; + Logger_->Log("Initializing Layout Manager", 5); + + } + + +ERS_CLASS_LayoutManager::~ERS_CLASS_LayoutManager() { + + Logger_->Log("Layout Manager Destructor Called", 6); + +} + +void ERS_CLASS_LayoutManager::LoadLayouts() { + + // Create List Of Files + for (const auto& Entry : std::filesystem::directory_iterator(std::string(LayoutDirectory_))) { + + // Get File Path + std::string FilePath{ Entry.path().u8string() }; + + // Load YAML::Node + YAML::Node LayoutNode = YAML::LoadFile(FilePath.c_str()); + + // Build Temp Layout + ERS_STRUCT_EditorLayout Layout; + Layout.index = Index; + + // Parse Out Display Name From File + std::string LayoutName; + LayoutName = LayoutNode["DisplayName"].as(); + Layout.name = LayoutName; + + // Parse Out Ini String From File + std::string IniStr; + IniStr = LayoutNode["ImGuiIni"].as(); + Layout.IniString = IniStr; + + // Add To Names and Layouts Vector + LayoutNames_.push_back(LayoutName); + Layouts_.push_back(Layout); + + // Log Layout Indexed + Logger_->Log(std::string(std::string("Indexed Layout: ") + FilePath).c_str(), 1); + + Index++; + } + + + Logger_->Log(std::string(std::string("Found ") + std::to_string(LayoutNames_.size()) + std::string(" Layouts")).c_str(), 1); + +} + +void ERS_CLASS_LayoutManager::SaveLayout(std::string LayoutName) { + + // Save the Ini String + std::string IniStr; + size_t settings_size = 0; + IniStr = static_cast (ImGui::SaveIniSettingsToMemory(&settings_size)); + + // Add To Names Vector + LayoutNames_.push_back(LayoutName); + + // Construct the New Layout Struct + ERS_STRUCT_EditorLayout newLayout; + newLayout.index = Index++; + newLayout.name = LayoutName; + newLayout.IniString = IniStr; + Layouts_.push_back(newLayout); + + // Save YAML Node + YAML::Node Layout; + Layout["ImGuiIni"] = IniStr; + Layout["DisplayName"] = LayoutName; + + // Export the YAML string + YAML::Emitter LayoutYAML; + LayoutYAML << YAML::BeginMap; + + // Set Constant Info + LayoutYAML << YAML::Key << "DisplayName" << YAML::Value << LayoutName; + LayoutYAML << YAML::Key << "ImGuiIni" << YAML::Value << IniStr; + + // Stop Writing, Generate LayoutYAML + LayoutYAML << YAML::EndMap; + std::string YAMLstring = std::string(LayoutYAML.c_str()); + + // Write the string into a YAML file in the directory + std::ofstream file(std::string(LayoutDirectory_) + "/" + LayoutName + ".yaml"); + + if (!file.fail()) + file << YAMLstring; + + file.close(); + +} + +void ERS_CLASS_LayoutManager::ApplyLayout(std::string LayoutName) { + + int Index; + bool HasFoundLayout = false; + for (Index = 0; (long)Index < (long)LayoutNames_.size(); Index++) { + if (LayoutNames_[Index] == std::string(LayoutName)) { + HasFoundLayout = true; + break; + } + } + + if (HasFoundLayout) { + ApplyLayout(Index); + } + else { + Logger_->Log("Failed To Find Layout, Skipping", 5); + } + +} + +void ERS_CLASS_LayoutManager::ApplyLayout(int LayoutID) { + + // Get Layout Name + std::string LayoutName = LayoutNames_[LayoutID]; + ERS_STRUCT_EditorLayout Layout = Layouts_[LayoutID]; + + Logger_->Log(std::string(std::string("Applying Layout: ") + LayoutName).c_str(), 4); + + ImGui::LoadIniSettingsFromMemory(Layout.IniString.c_str()); + +} diff --git a/Source/Core/Editor/Utils/ERS_Editor_LayoutManager/ERS_Editor_LayoutManager.h b/Source/Core/Editor/Utils/ERS_Editor_LayoutManager/ERS_Editor_LayoutManager.h new file mode 100644 index 0000000000..87075b8313 --- /dev/null +++ b/Source/Core/Editor/Utils/ERS_Editor_LayoutManager/ERS_Editor_LayoutManager.h @@ -0,0 +1,80 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + + +// Standard Libraries (BG convention: use <> instead of "") +#include + +// Third-Party Libraries (BG convention: use <> instead of "") +#include + +// Internal Libraries (BG convention: use <> instead of "") +#include + +struct ERS_STRUCT_EditorLayout { + int index; + std::string name; + std::string IniString; +}; + +/** + * @brief Creates the user profile manager class. + * + */ +class ERS_CLASS_LayoutManager { + + +private: + + ERS_CLASS_LoggingSystem* Logger_; /** LayoutFiles_; /** LayoutNames_; /** Layouts_; /**Logger_->Log("Starting BrainGenix-ERS Instance", 2); + /*SystemUtils->Logger_->Log("Starting BrainGenix-ERS Instance", 2); SystemUtils->Logger_->Log("", 5); SystemUtils->Logger_->Log("---------------------------------------------------------------------------", 5); SystemUtils->Logger_->Log("\x1b[38;2;0;128;55m██████╗ ██████╗ █████╗ ██╗███╗ ██╗\x1b[38;2;130;68;208m ██████╗ ███████╗███╗ ██╗██╗██╗ ██╗", 5); @@ -170,7 +170,7 @@ int main() { SystemUtils->Logger_->Log(" +-----------------------------------------------------------------+", 4); SystemUtils->Logger_->Log(" | BrainGenix-ERS Real-Time Environment Rendering System |", 4); SystemUtils->Logger_->Log(" +-----------------------------------------------------------------+", 4); - SystemUtils->Logger_->Log("", 4); + SystemUtils->Logger_->Log("", 4);*/ // Initialize Times