diff --git a/Source/Core/Editor/CMakeLists.txt b/Source/Core/Editor/CMakeLists.txt index eb87579ca2..c7c9782312 100644 --- a/Source/Core/Editor/CMakeLists.txt +++ b/Source/Core/Editor/CMakeLists.txt @@ -38,6 +38,7 @@ target_link_libraries(VisualEditor ERS_Editor_UserProfileManager ERS_Editor_3DCursor ERS_Editor_WindowManager + ERS_Editor_LayoutManager ERS_SceneManager diff --git a/Source/Core/Editor/GUI.cpp b/Source/Core/Editor/GUI.cpp index 23c84afe07..d37a2bce4a 100644 --- a/Source/Core/Editor/GUI.cpp +++ b/Source/Core/Editor/GUI.cpp @@ -42,13 +42,16 @@ GUISystem::GUISystem(ERS_STRUCT_SystemUtils* SystemUtils, GLFWwindow* Window, Cu WindowManager_ = std::make_unique(SystemUtils_); WindowManager_->GenerateWindowStruct(ProjectUtils_, HIDUtils_, VisualRenderer_, ThemeManager_.get(), FontManager_.get(), Cursors3D_, SceneManager_); + + LayoutManager_ = std::make_unique(SystemUtils, WindowManager_.get()); + // Initialize Windows SystemUtils_->Logger_->Log("Initializing Editor Menus", 5); Menu_File_ = std::make_unique(SystemUtils_, SceneManager_, ProjectUtils_, WindowManager_->GetWindowsStruct()); Menu_Window_ = std::make_unique(SystemUtils_, WindowManager_->GetWindowsStruct(), VisualRenderer_); Menu_Debug_ = std::make_unique(SystemUtils_, WindowManager_->GetWindowsStruct(), WindowManager_.get()); - Menu_Settings_ = std::make_unique(SystemUtils_, HIDUtils_, WindowManager_->GetWindowsStruct()); + Menu_Settings_ = std::make_unique(SystemUtils_, HIDUtils_, WindowManager_->GetWindowsStruct(), LayoutManager_.get()); // Disable Dragging Except By Title Bar ImGuiIO& IO = ImGui::GetIO(); @@ -107,6 +110,7 @@ void GUISystem::UpdateGUI() { ImGui::EndMainMenuBar(); } + // Updates all the windows, draws their content if enabled WindowManager_->UpdateAllWindows(); diff --git a/Source/Core/Editor/GUI.h b/Source/Core/Editor/GUI.h index 83ad4fdde8..a3f31418c3 100644 --- a/Source/Core/Editor/GUI.h +++ b/Source/Core/Editor/GUI.h @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -63,7 +64,9 @@ class GUISystem { std::unique_ptr FontManager_; /** UserProfileManager_; /** LayoutManager_; /** WindowManager_; /** -GUI_Menu_Settings::GUI_Menu_Settings(ERS_STRUCT_SystemUtils* SystemUtils, ERS_STRUCT_HumanInputDeviceUtils* HIDUtils, ERS_STRUCT_Windows* Windows) { +GUI_Menu_Settings::GUI_Menu_Settings(ERS_STRUCT_SystemUtils* SystemUtils, ERS_STRUCT_HumanInputDeviceUtils* HIDUtils, ERS_STRUCT_Windows* Windows, ERS_CLASS_LayoutManager* LayoutManager) { SystemUtils_ = SystemUtils; HIDUtils_ = HIDUtils; Windows_ = Windows; + LayoutManager_ = LayoutManager; SystemUtils_->Logger_->Log("Editor Setting Up Settings Menu", 4); @@ -28,10 +29,54 @@ void GUI_Menu_Settings::Draw() { // File Menu if (ImGui::BeginMenu("Settings")) { + + + + // Interface Config ImGui::MenuItem("Color Theme", "", &Windows_->GUI_Window_ThemeSelector_->Enabled_); ImGui::MenuItem("System Font", "", &Windows_->GUI_Window_FontSelector_->Enabled_); + + + // Layout Menu + ImGui::Separator(); + if (ImGui::BeginMenu("Editor Layout")) { + + + // Create Submenu with layouts which the user can select from + if (ImGui::BeginMenu("Select Layouts")) { + + std::string ActiveLayoutName = LayoutManager_->GetActiveLayoutName(); + std::vector LayoutNames = LayoutManager_->GetLayoutNames(); + for (unsigned int i = 0; i < LayoutNames.size(); i++) { + if (ImGui::Selectable(LayoutNames[i].c_str(), (LayoutNames[i] == ActiveLayoutName))) { + LayoutManager_->ApplyLayout(LayoutNames[i]); + } + } + + ImGui::EndMenu(); + } + + // Normal buttons that the user can select + if (ImGui::MenuItem("Save Active Layout")) { + std::string ActiveLayoutName = LayoutManager_->GetActiveLayoutName(); + LayoutManager_->SaveLayout(ActiveLayoutName); + } + + if (ImGui::MenuItem("Create New Layout")) { + LayoutManager_->CreateLayout(std::string("Untitled Layout")); + } + + if (ImGui::MenuItem("Rename Active Layout")) { + // Todo later - not part of layout manager + } + + + ImGui::EndMenu(); + } + + ImGui::Separator(); if (ImGui::BeginMenu("Editor Settings")) { ImGui::MenuItem("Editor Camera Settings", "", &Windows_->GUI_Window_EditorCameraSettings_->Enabled_); @@ -46,6 +91,8 @@ void GUI_Menu_Settings::Draw() { } ImGui::Separator(); + + // Controller Settings if (ImGui::BeginMenu("Game Controllers")) { // Refresh diff --git a/Source/Core/Editor/Menus/GUI_Menu_Settings/GUI_Menu_Settings.h b/Source/Core/Editor/Menus/GUI_Menu_Settings/GUI_Menu_Settings.h index 7e0cbce603..7b6782d03a 100644 --- a/Source/Core/Editor/Menus/GUI_Menu_Settings/GUI_Menu_Settings.h +++ b/Source/Core/Editor/Menus/GUI_Menu_Settings/GUI_Menu_Settings.h @@ -21,6 +21,7 @@ #include #include +#include #include @@ -33,11 +34,10 @@ class GUI_Menu_Settings { private: - ERS_STRUCT_SystemUtils* SystemUtils_ = nullptr; /** -#include -#include -#include -ERS_CLASS_LayoutManager::ERS_CLASS_LayoutManager(ERS_CLASS_LoggingSystem* Logger, const char* LayoutDirectory) { - Logger_ = Logger; +ERS_CLASS_LayoutManager::ERS_CLASS_LayoutManager(ERS_STRUCT_SystemUtils* SystemUtils, ERS_CLASS_WindowManager* WindowManager, const char* LayoutDirectory) { + + SystemUtils_ = SystemUtils; + Logger_ = SystemUtils_->Logger_.get(); LayoutDirectory_ = LayoutDirectory; + WindowManager_ = WindowManager; Logger_->Log("Initializing Layout Manager", 5); - } + LoadLayouts(); + +} ERS_CLASS_LayoutManager::~ERS_CLASS_LayoutManager() { @@ -32,7 +34,7 @@ void ERS_CLASS_LayoutManager::LoadLayouts() { // Load YAML::Node YAML::Node LayoutNode = YAML::LoadFile(FilePath.c_str()); - + // Build Temp Layout ERS_STRUCT_EditorLayout Layout; Layout.index = Index; @@ -47,6 +49,18 @@ void ERS_CLASS_LayoutManager::LoadLayouts() { IniStr = LayoutNode["ImGuiIni"].as(); Layout.IniString = IniStr; + // Load the Window names and status + std::vector WindowNames = WindowManager_->GetWindowNames(); + + for (auto i : WindowNames) { + if (LayoutNode[i].as() == "False") { + Layout.WindowNameStatus.insert(std::make_pair(i, false)); + } + else { + Layout.WindowNameStatus.insert(std::make_pair(i, true)); + } + } + // Add To Names and Layouts Vector LayoutNames_.push_back(LayoutName); Layouts_.push_back(Layout); @@ -84,6 +98,19 @@ void ERS_CLASS_LayoutManager::SaveLayout(std::string LayoutName) { Layout["ImGuiIni"] = IniStr; Layout["DisplayName"] = LayoutName; + // Load the Window names and status + std::vector WindowNames = WindowManager_->GetWindowNames(); + + for (auto i : WindowNames) { + bool status; + if (WindowManager_->GetWindowStatus(i, &status)) { + Layout[i] = "True"; + } + else { + Layout[i] = "False"; + } + } + // Export the YAML string YAML::Emitter LayoutYAML; LayoutYAML << YAML::BeginMap; @@ -99,11 +126,17 @@ void ERS_CLASS_LayoutManager::SaveLayout(std::string LayoutName) { // Write the string into a YAML file in the directory std::ofstream file(std::string(LayoutDirectory_) + "/" + LayoutName + ".yaml"); - if (!file.fail()) + if (!file.fail()) { file << YAMLstring; + } else { + Logger_->Log("Failed To Open File, Is Layout Directory Valid?", 8); + } file.close(); + // Update Active Layout String + ActiveLayoutName_ = LayoutName; + } void ERS_CLASS_LayoutManager::ApplyLayout(std::string LayoutName) { @@ -136,4 +169,26 @@ void ERS_CLASS_LayoutManager::ApplyLayout(int LayoutID) { ImGui::LoadIniSettingsFromMemory(Layout.IniString.c_str()); + for (auto i : Layout.WindowNameStatus) { + WindowManager_->SetWindowStatus(i.first, i.second); + } +} + + +std::string ERS_CLASS_LayoutManager::GetActiveLayoutName() { + return ActiveLayoutName_; } + + +std::vector ERS_CLASS_LayoutManager::GetLayoutNames() { + return LayoutNames_; +} + +void ERS_CLASS_LayoutManager::CreateLayout(std::string Name) { + + // Add Name To Layouts List + LayoutNames_.push_back(Name); + + // Save Layout + SaveLayout(Name); +} \ No newline at end of file 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 index 87afb3db4e..ca62a83455 100644 --- a/Source/Core/Editor/Utils/ERS_Editor_LayoutManager/ERS_Editor_LayoutManager.h +++ b/Source/Core/Editor/Utils/ERS_Editor_LayoutManager/ERS_Editor_LayoutManager.h @@ -7,49 +7,65 @@ // Standard Libraries (BG convention: use <> instead of "") #include +#include +#include +#include +#include // Third-Party Libraries (BG convention: use <> instead of "") #include // Internal Libraries (BG convention: use <> instead of "") #include +#include +#include + struct ERS_STRUCT_EditorLayout { int index; std::string name; std::string IniString; + + std::map WindowNameStatus; }; /** * @brief Creates the user profile manager class. - * + * */ class ERS_CLASS_LayoutManager { private: - ERS_CLASS_LoggingSystem* Logger_ = nullptr; /** LayoutFiles_; /** LayoutNames_; /** Layouts_; /** Layouts_; /** + */ + std::vector GetLayoutNames(); + + /** + * @brief Creates a new layout and adds it to the editor's layout choices. + * + * @param Name + */ + void CreateLayout(std::string Name); + }; \ No newline at end of file diff --git a/Source/EditorAssets/Layouts/DefaultLayout.yaml b/Source/EditorAssets/Layouts/DefaultLayout.yaml new file mode 100644 index 0000000000..9b5d0452c2 --- /dev/null +++ b/Source/EditorAssets/Layouts/DefaultLayout.yaml @@ -0,0 +1,2 @@ +DisplayName: Default Layout +ImGuiIni: "[Window][Debug##Default]\nPos=60,60\nSize=400,400\nCollapsed=0\n\n[Window][System Controls]\nPos=0,598\nSize=502,200\nCollapsed=0\nDockId=0x00000004,0\n\n[Window][System Info]\nPos=0,800\nSize=502,372\nCollapsed=0\nDockId=0x00000006,0\n\n[Window][TestWindow]\nPos=562,19\nSize=679,1153\nCollapsed=0\nDockId=0x00000015,0\n\n[Window][Example: Console]\nPos=120,299\nSize=520,600\nCollapsed=1\n\n[Window][Dear ImGui Demo]\nPos=327,146\nSize=770,855\nCollapsed=0\n\n[Window][Dear ImGui Metrics/Debugger]\nPos=283,116\nSize=712,1037\nCollapsed=0\n\n[Window][Dear ImGui Style Editor]\nPos=107,164\nSize=750,1036\nCollapsed=0\n\n[Window][Example: Log]\nPos=60,60\nSize=634,400\nCollapsed=1\n\n[Window][DockSpace Demo]\nPos=0,19\nSize=1920,1153\nCollapsed=0\n\n[Window][Example: Custom rendering]\nPos=849,297\nSize=485,414\nCollapsed=0\n\n[Window][Example: Documents]\nPos=739,108\nSize=607,944\nCollapsed=0\n\n[Window][Eggplant]\nPos=747,204\nSize=591,840\nCollapsed=0\n\n[Window][Carrot]\nPos=747,204\nSize=591,840\nCollapsed=0\n\n[Window][Lettuce]\nPos=134,237\nSize=591,840\nCollapsed=0\n\n[Window][Tomato]\nPos=747,204\nSize=591,840\nCollapsed=0\n\n[Window][Some Document]\nPos=467,324\nSize=591,840\nCollapsed=0\n\n[Window][A Rather Long Title]\nPos=256,385\nSize=591,840\nCollapsed=0\n\n[Window][DockSpaceViewport_11111111]\nPos=0,20\nSize=1920,1060\nCollapsed=0\n\n[Window][TestWindow2]\nPos=1243,19\nSize=677,1153\nCollapsed=0\nDockId=0x00000008,0\n\n[Window][Viewport]\nPos=444,249\nSize=1073,661\nCollapsed=0\nDockId=0x00000017,0\n\n[Window][Viewport 2]\nPos=1141,249\nSize=779,440\nCollapsed=0\nDockId=0x00000017,0\n\n[Window][Framerate Counter]\nPos=601,249\nSize=698,283\nCollapsed=0\nDockId=0x00000001,2\n\n[Window][Rendering Settings]\nPos=0,249\nSize=459,279\nCollapsed=0\nDockId=0x00000001,1\n\n[Window][Framerate Graph]\nPos=0,20\nSize=1071,227\nCollapsed=0\nDockId=0x00000015,0\n\n[Window][Object Properties]\nPos=0,663\nSize=459,417\nCollapsed=0\nDockId=0x00000014,0\n\n[Window][Scene Tree]\nPos=0,249\nSize=459,206\nCollapsed=0\nDockId=0x00000001,0\n\n[Window][Font Selector]\nPos=283,196\nSize=316,498\nCollapsed=0\n\n[Window][System Log]\nPos=601,817\nSize=698,572\nCollapsed=0\nDockId=0x00000014,1\n\n[Window][Pick Color Theme]\nPos=60,60\nSize=266,318\nCollapsed=0\n\n[Window][Frame Latency Graph]\nPos=1073,20\nSize=847,227\nCollapsed=0\nDockId=0x00000016,0\n\n[Window][Viewport 1]\nPos=461,249\nSize=1459,831\nCollapsed=0\nDockId=0x00000017,0\n\n[Window][Viewport 3]\nPos=1141,691\nSize=779,437\nCollapsed=0\nDockId=0x0000001B,0\n\n[Window][Viewport 4]\nPos=444,691\nSize=695,437\nCollapsed=0\nDockId=0x00000009,0\n\n[Window][About Dear ImGui]\nPos=60,60\nSize=589,466\nCollapsed=0\n\n[Window][Asset Explorer]\nPos=0,457\nSize=459,204\nCollapsed=0\nDockId=0x00000002,0\n\n[Window][Shader Editor]\nPos=0,20\nSize=599,952\nCollapsed=0\nDockId=0x0000001F,0\n\n[Window][Shader Tools]\nPos=0,709\nSize=599,680\nCollapsed=0\nDockId=0x00000010,0\n\n[Window][RAM Graph]\nPos=0,20\nSize=599,249\nCollapsed=0\nDockId=0x00000018,0\n\n[Window][Script Editor]\nPos=0,20\nSize=426,580\nCollapsed=0\nDockId=0x0000001C,0\n\n[Window][Script Tools]\nPos=0,602\nSize=426,574\nCollapsed=0\nDockId=0x0000001D,0\n\n[Window][Import##ImportModel]\nPos=60,60\nSize=584,364\nCollapsed=0\n\n[Window][Import Model##Import Model]\nPos=60,60\nSize=435,273\nCollapsed=0\n\n[Window][Compiler Log]\nPos=0,974\nSize=599,400\nCollapsed=0\nDockId=0x00000020,0\n\n[Window][Asset Streaming Settings]\nPos=0,249\nSize=459,206\nCollapsed=0\nDockId=0x00000001,1\n\n[Table][0x0B04C00B,4]\nRefScale=14\nColumn 0 Sort=0v\n\n[Table][0xC04A86C3,4]\nRefScale=14\nColumn 0 Sort=0v\n\n[Table][0x78ED9FB7,4]\nRefScale=14\nColumn 0 Sort=0v\n\n[Table][0x84CB98C9,4]\nRefScale=14\nColumn 0 Sort=0v\n\n[Docking][Data]\nDockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,20 Size=1920,1060 Split=X\n DockNode ID=0x0000001A Parent=0x8B93E3BD SizeRef=426,1156 Split=Y\n DockNode ID=0x0000001C Parent=0x0000001A SizeRef=600,200 Selected=0x02DF5741\n DockNode ID=0x0000001D Parent=0x0000001A SizeRef=600,198 Selected=0xA5B8BA00\n DockNode ID=0x0000001E Parent=0x8B93E3BD SizeRef=1492,1156 Split=X\n DockNode ID=0x0000000B Parent=0x0000001E SizeRef=599,982 Split=Y\n DockNode ID=0x0000000F Parent=0x0000000B SizeRef=600,200 Split=Y Selected=0x919FD48C\n DockNode ID=0x00000018 Parent=0x0000000F SizeRef=599,249 Selected=0x734C7367\n DockNode ID=0x00000019 Parent=0x0000000F SizeRef=599,436 Split=Y Selected=0x919FD48C\n DockNode ID=0x0000001F Parent=0x00000019 SizeRef=599,952 Selected=0x919FD48C\n DockNode ID=0x00000020 Parent=0x00000019 SizeRef=599,400 Selected=0x9B2665CA\n DockNode ID=0x00000010 Parent=0x0000000B SizeRef=600,198 Selected=0xECC4EA8D\n DockNode ID=0x00000011 Parent=0x0000001E SizeRef=1319,982 Split=Y\n DockNode ID=0x0000000C Parent=0x00000011 SizeRef=3440,227 Split=X Selected=0x31F26B5E\n DockNode ID=0x00000015 Parent=0x0000000C SizeRef=832,227 Selected=0x31F26B5E\n DockNode ID=0x00000016 Parent=0x0000000C SizeRef=658,227 Selected=0xE93F57AB\n DockNode ID=0x00000013 Parent=0x00000011 SizeRef=3440,1127 Split=X\n DockNode ID=0x00000003 Parent=0x00000013 SizeRef=502,1153 Split=Y Selected=0x8769D556\n DockNode ID=0x00000004 Parent=0x00000003 SizeRef=560,200 Selected=0xCDAE6D71\n DockNode ID=0x00000006 Parent=0x00000003 SizeRef=560,372 Selected=0x8769D556\n DockNode ID=0x00000005 Parent=0x00000013 SizeRef=1416,1153 Split=X Selected=0x42F3B5AC\n DockNode ID=0x00000007 Parent=0x00000005 SizeRef=679,1153 Split=X Selected=0x995B0CF8\n DockNode ID=0x0000000D Parent=0x00000007 SizeRef=459,901 Split=Y Selected=0xF8780F64\n DockNode ID=0x00000012 Parent=0x0000000D SizeRef=442,458 Split=Y Selected=0x3875EE28\n DockNode ID=0x00000001 Parent=0x00000012 SizeRef=442,283 Selected=0x889B4A2B\n DockNode ID=0x00000002 Parent=0x00000012 SizeRef=442,281 Selected=0x7E9CA0E4\n DockNode ID=0x00000014 Parent=0x0000000D SizeRef=442,463 Selected=0xF8780F64\n DockNode ID=0x0000000E Parent=0x00000007 SizeRef=1031,901 Split=X Selected=0x995B0CF8\n DockNode ID=0x00000009 Parent=0x0000000E SizeRef=695,617 Selected=0x505088A2\n DockNode ID=0x0000000A Parent=0x0000000E SizeRef=779,617 Split=Y Selected=0xC959D918\n DockNode ID=0x00000017 Parent=0x0000000A SizeRef=858,440 CentralNode=1 Selected=0x505088A2\n DockNode ID=0x0000001B Parent=0x0000000A SizeRef=858,437 Selected=0xBE5EE98E\n DockNode ID=0x00000008 Parent=0x00000005 SizeRef=677,1153 Selected=0xC5F7A27B\n\n"