From ed030afcea4d90007363c37d6ee807f1986ced41 Mon Sep 17 00:00:00 2001 From: Joeyrp Date: Tue, 8 Feb 2022 15:45:26 -0500 Subject: [PATCH] Refactored MainPanel into the PanelManager instead (they both were basically doing the same job) Menu and status bar code refactored into Editor (This could become quite large may need another class to handle the menus) Build script now accepts the g option to delete the imgui.ini file on build for testing. --- scripts/build.bat | 15 ++- src/main.cpp | 2 +- src/run_modes/editor/CMakeLists.txt | 1 - src/run_modes/editor/editor.cpp | 122 ++++++++++++++++------ src/run_modes/editor/editor.h | 14 +-- src/run_modes/editor/panel_manager.cpp | 77 +++++++++++--- src/run_modes/editor/panel_manager.h | 20 +++- src/run_modes/editor/panels/mainPanel.cpp | 2 +- 8 files changed, 188 insertions(+), 65 deletions(-) diff --git a/scripts/build.bat b/scripts/build.bat index d243510..7c5c5a7 100644 --- a/scripts/build.bat +++ b/scripts/build.bat @@ -7,8 +7,16 @@ IF not exist build/ ( goto END ) +set "DELGUI=" +set "RELEASE=" -IF "%~1" == "r" ( +If "%~1" == "r" set "RELEASE=1" +If "%~2" == "r" set "RELEASE=1" + +If "%~1" == "g" set "DELGUI=1" +If "%~2" == "g" set "DELGUI=1" + +IF defined RELEASE ( cmake --build build/ --target ALL_BUILD --config Release xcopy /y test_data\engine_state.xml build\Release\ ) ELSE ( @@ -16,4 +24,9 @@ cmake --build build/ --target ALL_BUILD --config Debug xcopy /y test_data\engine_state.xml build\Debug\ ) +IF defined DELGUI ( +del /s /q build\Debug\imgui.ini +del /s /q build\Release\imgui.ini +) + :END \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 4a77bcf..0468baf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,7 +35,7 @@ int main(int argc, char** argv) return 1; } - std::cout << "\nEngine core successfully initialized!\n"; + //std::cout << "\nEngine core successfully initialized!\n"; core.RunGameLoop(); diff --git a/src/run_modes/editor/CMakeLists.txt b/src/run_modes/editor/CMakeLists.txt index 5cee27a..0b770f0 100644 --- a/src/run_modes/editor/CMakeLists.txt +++ b/src/run_modes/editor/CMakeLists.txt @@ -5,7 +5,6 @@ set(EDITOR_SRC "panel_manager.cpp" "project/project.cpp" "panels/iPanel.cpp" -"panels/mainPanel.cpp" "panels/about.cpp" "panels/assetBrowser.cpp" "panels/worldTree.cpp" diff --git a/src/run_modes/editor/editor.cpp b/src/run_modes/editor/editor.cpp index 9597a26..fa095b1 100644 --- a/src/run_modes/editor/editor.cpp +++ b/src/run_modes/editor/editor.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "panels/assetBrowser.h" @@ -67,6 +68,8 @@ namespace editor void Editor::OnRender(lunarium::IGraphics* g) { + DoMainMenu(); + DoStatusBar(); PanelManager::GetInstance().OnRender(g); if (mpMapEditor) @@ -227,51 +230,108 @@ namespace editor } - - //////////////////////////////////////////////////////////// - // MENU BAR EVENTS + // MENU BAR //////////////////////////////////////////////////////////// - void Editor::NewProject() + void Editor::DoMainMenu() { - mDoNewProject = true; - } + ImGui::BeginMainMenuBar(); + + // File + if (ImGui::BeginMenu("File")) + { + if (ImGui::MenuItem("New Project")) + { + mDoNewProject = true; + } - void Editor::OpenProject() - { - mDoOpenProject = true; - } + if (ImGui::MenuItem("Open Project")) + { + mDoOpenProject = true; + } - void Editor::SaveProject() - { - mDoSaveProject = true; - } + if (ImGui::MenuItem("Save Project")) + { + mDoSaveProject = true; + } - void Editor::SaveAs() - { - mDoSaveAs = true; - } + if (ImGui::MenuItem("Save Project As")) + { + mDoSaveAs = true; + } - void Editor::Exit() - { - Core::GetInstance().SignalShutdown(); - } + ImGui::Separator(); - void Editor::ShowAboutPanel() - { - PanelManager::GetInstance().OpenPanel(PanelType::PT_ABOUT); + if (ImGui::MenuItem("Exit")) + { + Core::GetInstance().SignalShutdown(); + } + ImGui::EndMenu(); + } + + if (ImGui::BeginMenu("Windows")) + { + if (ImGui::MenuItem("Reset Window Docking")) + { + PanelManager::GetInstance().ResetDocking(); + } + ImGui::EndMenu(); + } + + // Tools + if (ImGui::BeginMenu("Tools")) + { + if (ImGui::MenuItem("Map Editor")) + { + if (!mpMapEditor) + { + mpMapEditor = new MapEditor; + mpMapEditor->Initialize(this); + } + + mpMapEditor->Open(); + } + ImGui::EndMenu(); + } + + if (ImGui::BeginMenu("Help")) + { + if (ImGui::MenuItem("About")) + { + PanelManager::GetInstance().OpenPanel(PanelType::PT_ABOUT); + } + + ImGui::EndMenu(); + } + + ImGui::EndMainMenuBar(); } - - void Editor::OpenMapEditor() + void Editor::DoStatusBar() { - if (!mpMapEditor) + const ImGuiViewport* viewport = ImGui::GetMainViewport(); + ImGui::SetNextWindowViewport(viewport->ID); + float height = viewport->WorkSize.y * 0.05f; + float ypos = (viewport->WorkPos.y + viewport->WorkSize.y) - height; + ImGui::SetNextWindowSize(ImVec2(viewport->WorkSize.x, height), ImGuiCond_Always); + ImGui::SetNextWindowPos(ImVec2(viewport->WorkPos.x, ypos), ImGuiCond_Always); + ImGui::Begin("status bar", nullptr, ImGuiWindowFlags_NoCollapse + | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize + | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoDocking ); + + if (ImGui::BeginTable("status", 3, ImGuiTableFlags_BordersInnerV)) { - mpMapEditor = new MapEditor; - mpMapEditor->Initialize(this); + ImGui::AlignTextToFramePadding(); + ImGui::TableNextColumn(); + ImGui::Text("Lunarium"); + ImGui::TableNextColumn(); + ImGui::Text("Testing"); + ImGui::TableNextColumn(); + ImGui::Text("Status Bar"); + ImGui::EndTable(); } - mpMapEditor->Open(); + ImGui::End(); } } diff --git a/src/run_modes/editor/editor.h b/src/run_modes/editor/editor.h index ec2e503..0cb6257 100644 --- a/src/run_modes/editor/editor.h +++ b/src/run_modes/editor/editor.h @@ -43,16 +43,6 @@ namespace lunarium uint32_t GetLogCat() const; bool IsToolOpen(ToolType type) const; - // Menu Bar Events - void NewProject(); - void OpenProject(); - void SaveProject(); - void SaveAs(); - void Exit(); - void OpenMapEditor(); - - void ShowAboutPanel(); - private: Editor(const Editor&) = delete; const Editor& operator=(const Editor&) = delete; @@ -77,8 +67,8 @@ namespace lunarium private: // HELPERS - void CreatePanels(); - void DestoryPanels(); + void DoMainMenu(); + void DoStatusBar(); void DestroyTools(); void HandleMenuEvents(); }; diff --git a/src/run_modes/editor/panel_manager.cpp b/src/run_modes/editor/panel_manager.cpp index 1ed4f1d..51e797e 100644 --- a/src/run_modes/editor/panel_manager.cpp +++ b/src/run_modes/editor/panel_manager.cpp @@ -9,6 +9,9 @@ #include "panel_manager.h" #include "editor.h" #include +#include +#include // To use the DockWindowXXX methods +#include // Panels #include "panels/about.h" @@ -38,7 +41,7 @@ namespace lunarium { namespace editor PanelManager::PanelManager() - : mpEditor(nullptr), mpMainPanel(nullptr) + : mpEditor(nullptr), mResetDockSpace(false) { } @@ -48,9 +51,14 @@ namespace lunarium { namespace editor mpEditor = editor; - mpMainPanel = &MainPanel::GetInstance(); - mpMainPanel->SetEditor(mpEditor); - mpMainPanel->ResetDockSpace(); + //mpMainPanel = &MainPanel::GetInstance(); + // mpMainPanel->SetEditor(mpEditor); + //mpMainPanel->ResetDockSpace(); + + if (!std::filesystem::exists("imgui.ini")) + { + mResetDockSpace = true; + } CreatePanels(); @@ -60,7 +68,7 @@ namespace lunarium { namespace editor void PanelManager::Shutdown() { DestoryPanels(); - MainPanel::FreeInstance(); + //MainPanel::FreeInstance(); } void PanelManager::OpenPanel(PanelType type) @@ -108,20 +116,14 @@ namespace lunarium { namespace editor return nullptr; } - const MainPanel::DockSpaces& PanelManager::GetDockSpaces() const + const PanelManager::DockSpaces& PanelManager::GetDockSpaces() const { - return mpMainPanel->GetDockSpaces(); + return mDockSpaces; } void PanelManager::ResetDocking() { - for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++) - { - if (iter->second->IsOpen()) - { - iter->second->ForceDock(); - } - } + mResetDockSpace = true; } void PanelManager::OnTick(double delta) @@ -137,7 +139,26 @@ namespace lunarium { namespace editor void PanelManager::OnRender(lunarium::IGraphics* g) { - mpMainPanel->DoFrame(); + // mpMainPanel->DoFrame(); + + ImGuiViewport* Viewport = ImGui::GetMainViewport(); + ImGui::SetNextWindowPos( Viewport->WorkPos ); + ImGui::SetNextWindowSize( Viewport->WorkSize ); + ImGui::SetNextWindowViewport( Viewport->ID ); + ImGuiWindowFlags WindowFlags = 0; + WindowFlags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDocking; + WindowFlags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus; + + ImGui::PushStyleVar( ImGuiStyleVar_WindowRounding, 0.0f ); + ImGui::PushStyleVar( ImGuiStyleVar_WindowBorderSize, 0.0f ); + ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 0.0f, 0.0f ) ); + + ImGui::Begin("Lunarium Editor", nullptr, WindowFlags); + ImGui::PopStyleVar(3); + + MakeDockSpaces(); + + ImGui::End(); for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++) { @@ -171,4 +192,30 @@ namespace lunarium { namespace editor mPanels.clear(); } + + void PanelManager::MakeDockSpaces() + { + ImGuiViewport* Viewport = ImGui::GetMainViewport(); + mDockSpaces.Main = ImGui::DockSpace(ImGui::GetID("Lunarium Editor Dockspace")); + if (!ImGui::DockBuilderGetNode(mDockSpaces.Main) || mResetDockSpace) + { + Logger::Log(mpEditor->GetLogCat(), LogLevel::INFO, "Resetting Dockspaces"); + + mResetDockSpace = false; + ImGui::DockBuilderRemoveNode(mDockSpaces.Main); + ImGui::DockBuilderAddNode(mDockSpaces.Main, ImGuiDockNodeFlags_DockSpace); + ImGui::DockBuilderSetNodeSize(mDockSpaces.Main, Viewport->Size); + //ImGui::DockBuilderSetNodePos(mDockSpaces.Main, Viewport->WorkPos); + + ImGui::DockBuilderSplitNode(mDockSpaces.Main, ImGuiDir_Left, 0.25f, &mDockSpaces.Left, &mDockSpaces.Center); + ImGui::DockBuilderSplitNode(mDockSpaces.Center, ImGuiDir_Right, 0.25f, &mDockSpaces.Right, &mDockSpaces.Center); + ImGui::DockBuilderSplitNode(mDockSpaces.Center, ImGuiDir_Down, 0.25f, &mDockSpaces.Bottom, &mDockSpaces.Center); + ImGui::DockBuilderFinish(mDockSpaces.Main); + + // Dock Panels + ImGui::DockBuilderDockWindow("World View", mDockSpaces.Center); + + } + + } }} \ No newline at end of file diff --git a/src/run_modes/editor/panel_manager.h b/src/run_modes/editor/panel_manager.h index 0960849..032af99 100644 --- a/src/run_modes/editor/panel_manager.h +++ b/src/run_modes/editor/panel_manager.h @@ -10,7 +10,7 @@ #define PANEL_MANAGER_H_ #include -#include "panels/mainPanel.h" +//#include "panels/mainPanel.h" #include "panels/iPanel.h" #include @@ -21,6 +21,16 @@ namespace editor class Editor; class PanelManager { + public: + struct DockSpaces + { + unsigned int Main; + unsigned int Left; + unsigned int Right; + unsigned int Center; + // unsigned int Top; + unsigned int Bottom; + }; public: static PanelManager& GetInstance(); @@ -33,7 +43,7 @@ namespace editor bool IsOpen(PanelType type); Panel* GetPanel(PanelType type); - const MainPanel::DockSpaces& GetDockSpaces() const; + const DockSpaces& GetDockSpaces() const; void ResetDocking(); void OnTick(double delta); @@ -41,7 +51,9 @@ namespace editor private: Editor* mpEditor; - MainPanel* mpMainPanel; + // MainPanel* mpMainPanel; + DockSpaces mDockSpaces; + bool mResetDockSpace; std::map mPanels; private: @@ -51,6 +63,8 @@ namespace editor void CreatePanels(); void DestoryPanels(); + void MakeDockSpaces(); + }; }} diff --git a/src/run_modes/editor/panels/mainPanel.cpp b/src/run_modes/editor/panels/mainPanel.cpp index a6750c3..e31c87a 100644 --- a/src/run_modes/editor/panels/mainPanel.cpp +++ b/src/run_modes/editor/panels/mainPanel.cpp @@ -139,7 +139,7 @@ namespace editor ImGui::DockBuilderRemoveNode(mDockSpaces.Main); ImGui::DockBuilderAddNode(mDockSpaces.Main, ImGuiDockNodeFlags_DockSpace); ImGui::DockBuilderSetNodeSize(mDockSpaces.Main, Viewport->Size); - ImGui::DockBuilderSetNodePos(mDockSpaces.Main, Viewport->WorkPos); + //ImGui::DockBuilderSetNodePos(mDockSpaces.Main, Viewport->WorkPos); ImGui::DockBuilderSplitNode(mDockSpaces.Main, ImGuiDir_Left, 0.25f, &mDockSpaces.Left, &mDockSpaces.Center); ImGui::DockBuilderSplitNode(mDockSpaces.Center, ImGuiDir_Right, 0.25f, &mDockSpaces.Right, &mDockSpaces.Center);