Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

100 add layout menu to create preset editor layouts #365

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
57868a2
Update CMake Lists
allenyangcc Jul 31, 2022
39d4265
Update Layout Manager header file
allenyangcc Jul 31, 2022
8f67081
Update Layout Manager cpp file
allenyangcc Jul 31, 2022
840ed75
Add Layout Manager To GUI Cmake
datacrystals Jul 31, 2022
ce0fff0
Add Layout Manager to GUI.h
datacrystals Jul 31, 2022
5a89e5e
Add Layout Manager to GUI.h
datacrystals Jul 31, 2022
f83246d
Add Layout Manager to GUI.h
datacrystals Jul 31, 2022
c966247
Add Layout Manager to GUI.h
datacrystals Jul 31, 2022
6692832
Add Layout Manager to GUI.h
datacrystals Jul 31, 2022
a18ee20
Add Layout Manager to GUI.h
datacrystals Jul 31, 2022
07b9962
Add Layout Manager to GUI.h
datacrystals Jul 31, 2022
16e1cb3
Add Layout Manager to GUI.h
datacrystals Jul 31, 2022
0d91eb9
Add Layout Manager to GUI.h
datacrystals Jul 31, 2022
6417a31
Add Layout Manager to GUI.h
datacrystals Jul 31, 2022
123fc10
Add Layout Manager to GUI.h
datacrystals Jul 31, 2022
e81cbdd
Add Layout Manager to GUI.h
datacrystals Jul 31, 2022
8dd0487
Add Layout Manager to GUI.h
datacrystals Jul 31, 2022
51955ce
Add Layout Manager to GUI.h
datacrystals Jul 31, 2022
2e8e8d5
Update Layout Manager
datacrystals Jul 31, 2022
21f3016
Update Layout Manager
datacrystals Jul 31, 2022
b4586f7
Update Layout Manager
datacrystals Jul 31, 2022
62cbf99
Update Layout Manager
datacrystals Jul 31, 2022
cd4418f
Update Layout Manager
datacrystals Jul 31, 2022
cd39c4b
Update Layout Manager
datacrystals Jul 31, 2022
0b5e319
Update Layout Manager
datacrystals Jul 31, 2022
b50d197
Update CMAKE Configuration
datacrystals Aug 7, 2022
174dd56
Updated function to support WindowNames and WindowStatus
allenyangcc Sep 2, 2022
0a2139f
Fix Comment Warnings
datacrystals Sep 2, 2022
ad85c0e
Remove Unused Variable
datacrystals Sep 2, 2022
1b868c0
Merge branch 'master' into 100-add-layout-menu-to-create-preset-edito…
datacrystals Sep 2, 2022
19186d8
Fix Menu Code
datacrystals Sep 2, 2022
208020a
Add Error Handling
datacrystals Sep 2, 2022
3dfc93d
Add Default Layout YAML
datacrystals Sep 2, 2022
275a046
Call LoadLayouts
datacrystals Sep 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/Core/Editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ target_link_libraries(VisualEditor
ERS_Editor_UserProfileManager
ERS_Editor_3DCursor
ERS_Editor_WindowManager
ERS_Editor_LayoutManager

ERS_SceneManager

Expand Down
6 changes: 5 additions & 1 deletion Source/Core/Editor/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ GUISystem::GUISystem(ERS_STRUCT_SystemUtils* SystemUtils, GLFWwindow* Window, Cu
WindowManager_ = std::make_unique<ERS_CLASS_WindowManager>(SystemUtils_);
WindowManager_->GenerateWindowStruct(ProjectUtils_, HIDUtils_, VisualRenderer_, ThemeManager_.get(), FontManager_.get(), Cursors3D_, SceneManager_);


LayoutManager_ = std::make_unique<ERS_CLASS_LayoutManager>(SystemUtils, WindowManager_.get());


// Initialize Windows
SystemUtils_->Logger_->Log("Initializing Editor Menus", 5);
Menu_File_ = std::make_unique<GUI_Menu_File>(SystemUtils_, SceneManager_, ProjectUtils_, WindowManager_->GetWindowsStruct());
Menu_Window_ = std::make_unique<GUI_Menu_Window>(SystemUtils_, WindowManager_->GetWindowsStruct(), VisualRenderer_);
Menu_Debug_ = std::make_unique<GUI_Menu_Debug>(SystemUtils_, WindowManager_->GetWindowsStruct(), WindowManager_.get());
Menu_Settings_ = std::make_unique<GUI_Menu_Settings>(SystemUtils_, HIDUtils_, WindowManager_->GetWindowsStruct());
Menu_Settings_ = std::make_unique<GUI_Menu_Settings>(SystemUtils_, HIDUtils_, WindowManager_->GetWindowsStruct(), LayoutManager_.get());

// Disable Dragging Except By Title Bar
ImGuiIO& IO = ImGui::GetIO();
Expand Down Expand Up @@ -107,6 +110,7 @@ void GUISystem::UpdateGUI() {
ImGui::EndMainMenuBar();
}


// Updates all the windows, draws their content if enabled
WindowManager_->UpdateAllWindows();

Expand Down
3 changes: 3 additions & 0 deletions Source/Core/Editor/GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <ERS_Editor_UserProfileManager.h>
#include <ERS_Editor_3DCursor.h>
#include <ERS_Editor_WindowManager.h>
#include <ERS_Editor_LayoutManager.h>

#include <ERS_SceneManager.h>

Expand Down Expand Up @@ -63,7 +64,9 @@ class GUISystem {

std::unique_ptr<ERS_CLASS_FontManager> FontManager_; /**<Pointer To FontManager Instance*/
std::unique_ptr<ERS_CLASS_UserProfileManager> UserProfileManager_; /**<Pointer To User Profile Manager Instance*/
std::unique_ptr<ERS_CLASS_LayoutManager> LayoutManager_; /**<Instance of the layout manager class*/
std::unique_ptr<ERS_CLASS_WindowManager> WindowManager_; /**<Class owning all gui windows*/


public:

Expand Down
1 change: 1 addition & 0 deletions Source/Core/Editor/Menus/GUI_Menu_Settings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ target_link_libraries(Menu_Settings
ERS_STRUCT_ProjectUtils

ERS_Editor_WindowManager
ERS_Editor_LayoutManager

GUI_Window_ControllerSettings

Expand Down
49 changes: 48 additions & 1 deletion Source/Core/Editor/Menus/GUI_Menu_Settings/GUI_Menu_Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#include <GUI_Menu_Settings.h>


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);

Expand All @@ -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<std::string> 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_);
Expand All @@ -46,6 +91,8 @@ void GUI_Menu_Settings::Draw() {
}

ImGui::Separator();

// Controller Settings
if (ImGui::BeginMenu("Game Controllers")) {

// Refresh
Expand Down
12 changes: 6 additions & 6 deletions Source/Core/Editor/Menus/GUI_Menu_Settings/GUI_Menu_Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <ERS_STRUCT_ProjectUtils.h>
#include <ERS_STRUCT_Windows.h>

#include <ERS_Editor_LayoutManager.h>

#include <GUI_Window_ControllerSettings.h>

Expand All @@ -33,11 +34,10 @@ class GUI_Menu_Settings {

private:

ERS_STRUCT_SystemUtils* SystemUtils_ = nullptr; /**<SystemUtils Instance, Used To Get Systems From Other Classes*/
ERS_STRUCT_HumanInputDeviceUtils* HIDUtils_ = nullptr; /**<HID Utils Pointer*/
ERS_STRUCT_Windows* Windows_ = nullptr; /**<Struct Containing the system's windows*/


ERS_STRUCT_SystemUtils* SystemUtils_ = nullptr; /**<SystemUtils Instance, Used To Get Systems From Other Classes*/
ERS_STRUCT_HumanInputDeviceUtils* HIDUtils_ = nullptr; /**<HID Utils Pointer*/
ERS_STRUCT_Windows* Windows_ = nullptr; /**<Struct Containing the system's windows*/
ERS_CLASS_LayoutManager* LayoutManager_; /**<Pointer to layout manager*/

public:

Expand All @@ -47,7 +47,7 @@ class GUI_Menu_Settings {
*
* @param SystemUtils
*/
GUI_Menu_Settings(ERS_STRUCT_SystemUtils* SystemUtils, ERS_STRUCT_HumanInputDeviceUtils* HIDUtils, ERS_STRUCT_Windows* Windows);
GUI_Menu_Settings(ERS_STRUCT_SystemUtils* SystemUtils, ERS_STRUCT_HumanInputDeviceUtils* HIDUtils, ERS_STRUCT_Windows* Windows, ERS_CLASS_LayoutManager* LayoutManager);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ target_link_libraries(ERS_Editor_LayoutManager

# Link Internal Libs
target_link_libraries(ERS_Editor_LayoutManager
ERS_STRUCT_SystemUtils

ERS_Editor_WindowManager
ERS_CLASS_LoggingSystem
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
//======================================================================//

#include <ERS_Editor_LayoutManager.h>
#include <filesystem>
#include <imgui.h>
#include <fstream>

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() {
Expand All @@ -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;
Expand All @@ -47,6 +49,18 @@ void ERS_CLASS_LayoutManager::LoadLayouts() {
IniStr = LayoutNode["ImGuiIni"].as<std::string>();
Layout.IniString = IniStr;

// Load the Window names and status
std::vector<std::string> WindowNames = WindowManager_->GetWindowNames();

for (auto i : WindowNames) {
if (LayoutNode[i].as<std::string>() == "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);
Expand Down Expand Up @@ -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<std::string> 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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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<std::string> 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);
}
Loading