diff --git a/src/core/core.cpp b/src/core/core.cpp index d977b54..66629e6 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -68,7 +68,7 @@ namespace lunarium mpInstance->mpWindow->GetPosition(&mpInstance->mState.Display.WindowStartPosition.X, &mpInstance->mState.Display.WindowStartPosition.Y); - mpInstance->mState.SaveToFile(); + //mpInstance->mState.SaveToFile(); // Run Mode shuts down first mpInstance->mpRunMode->Shutdown(); diff --git a/src/run_modes/editor/CMakeLists.txt b/src/run_modes/editor/CMakeLists.txt index 16f628e..5cee27a 100644 --- a/src/run_modes/editor/CMakeLists.txt +++ b/src/run_modes/editor/CMakeLists.txt @@ -2,6 +2,7 @@ # Source Files set(EDITOR_SRC "editor.cpp" +"panel_manager.cpp" "project/project.cpp" "panels/iPanel.cpp" "panels/mainPanel.cpp" diff --git a/src/run_modes/editor/editor.cpp b/src/run_modes/editor/editor.cpp index cef19e9..9597a26 100644 --- a/src/run_modes/editor/editor.cpp +++ b/src/run_modes/editor/editor.cpp @@ -8,18 +8,14 @@ #include "editor.h" -#include "panels/mainPanel.h" +#include "panel_manager.h" #include #include #include #include -// Panels -#include "panels/about.h" + #include "panels/assetBrowser.h" -#include "panels/worldTree.h" -#include "panels/worldView.h" -#include "panels/propertiesView.h" // Tools #include "tools/map_editor/map_editor.h" @@ -30,7 +26,7 @@ namespace editor { Editor::Editor() - : mLogCat(-1), mpMainPanel(nullptr), mpFileBrowser(nullptr), mpPath(nullptr), mDoNewProject(false), mDoOpenProject(false), + : mLogCat(-1), mpFileBrowser(nullptr), mpPath(nullptr), mDoNewProject(false), mDoOpenProject(false), mDoSaveProject(false), mDoSaveAs(false), mpMapEditor(nullptr) { } @@ -38,35 +34,27 @@ namespace editor OpRes Editor::Initialize() { mLogCat = Logger::RegisterCategory("EDITOR"); - mpMainPanel = &MainPanel::GetInstance(); - mpMainPanel->SetEditor(this); // Initialize internal data DataManager::Initialize(); - CreatePanels(); + PanelManager::GetInstance().Initialize(this); return OpRes::OK(); } void Editor::Shutdown() { - DestoryPanels(); DataManager::Shutdown(); - MainPanel::FreeInstance(); + PanelManager::GetInstance().Shutdown(); + PanelManager::FreeInstance(); } void Editor::OnTick(double delta) { // Panels - for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++) - { - if (iter->second->IsOpen()) - { - iter->second->Update(delta); - } - } + PanelManager::GetInstance().OnTick(delta); // Tools if (mpMapEditor) @@ -79,15 +67,7 @@ namespace editor void Editor::OnRender(lunarium::IGraphics* g) { - mpMainPanel->DoFrame(); - - for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++) - { - if (iter->second->IsOpen()) - { - iter->second->DoFrame(); - } - } + PanelManager::GetInstance().OnRender(g); if (mpMapEditor) { @@ -129,25 +109,7 @@ namespace editor //////////////////////////////////////////////////////////// // HELPER METHODS //////////////////////////////////////////////////////////// - void Editor::CreatePanels() - { - mPanels[PanelType::PT_ABOUT] = new AboutPanel; - mPanels[PanelType::PT_ASSET_BROWSER] = new AssetBrowser(""); - mPanels[PanelType::PT_WORLD_TREE] = new WorldTree(); - mPanels[PanelType::PT_WORLD_VIEW] = new WorldView(); - mPanels[PanelType::PT_PROPERTIES_VIEW] = new PropertiesView(); - } - void Editor::DestoryPanels() - { - delete mPanels[PanelType::PT_ABOUT]; - delete mPanels[PanelType::PT_ASSET_BROWSER]; - delete mPanels[PanelType::PT_WORLD_TREE]; - delete mPanels[PanelType::PT_WORLD_VIEW]; - delete mPanels[PanelType::PT_PROPERTIES_VIEW]; - - mPanels.clear(); - } void Editor::DestroyTools() { @@ -190,7 +152,7 @@ namespace editor { Logger::Log(mLogCat, LogLevel::ERROR, "Could not create a new project: %s", result.Description); } - ((AssetBrowser*)mPanels[PanelType::PT_ASSET_BROWSER])->SetAssetDirectory(*mpPath / std::filesystem::path("contents/assets")); + ((AssetBrowser*)PanelManager::GetInstance().GetPanel(PanelType::PT_ASSET_BROWSER))->SetAssetDirectory(*mpPath / std::filesystem::path("contents/assets")); } else { @@ -235,7 +197,7 @@ namespace editor { Logger::Log(mLogCat, LogLevel::ERROR, "Could not open project: %s -- reason: %s", mpPath->string().c_str(), result.Description); } - ((AssetBrowser*)mPanels[PanelType::PT_ASSET_BROWSER])->SetAssetDirectory(mpPath->parent_path() / std::filesystem::path("contents/assets")); + ((AssetBrowser*)PanelManager::GetInstance().GetPanel(PanelType::PT_ASSET_BROWSER))->SetAssetDirectory(mpPath->parent_path() / std::filesystem::path("contents/assets")); } else { @@ -297,7 +259,7 @@ namespace editor void Editor::ShowAboutPanel() { - mPanels[PanelType::PT_ABOUT]->SetOpen(true); + PanelManager::GetInstance().OpenPanel(PanelType::PT_ABOUT); } diff --git a/src/run_modes/editor/editor.h b/src/run_modes/editor/editor.h index d3d9b13..ec2e503 100644 --- a/src/run_modes/editor/editor.h +++ b/src/run_modes/editor/editor.h @@ -30,7 +30,6 @@ namespace lunarium }; class MapEditor; - class MainPanel; class Editor : public iRunMode { public: @@ -60,8 +59,6 @@ namespace lunarium private: // Data uint32_t mLogCat; - MainPanel* mpMainPanel; - std::map mPanels; Project mProject; diff --git a/src/run_modes/editor/panel_manager.cpp b/src/run_modes/editor/panel_manager.cpp new file mode 100644 index 0000000..efc2162 --- /dev/null +++ b/src/run_modes/editor/panel_manager.cpp @@ -0,0 +1,162 @@ +/****************************************************************************** +* File - panel_manager.cpp +* Author - Joey Pollack +* Date - 2022/02/07 (y/m/d) +* Mod Date - 2022/02/07 (y/m/d) +* Description - Manage the editor panels +******************************************************************************/ + +#include "panel_manager.h" +#include "editor.h" +#include + +// Panels +#include "panels/about.h" +#include "panels/assetBrowser.h" +#include "panels/worldTree.h" +#include "panels/worldView.h" +#include "panels/propertiesView.h" + +namespace lunarium { namespace editor +{ + PanelManager* PanelManager::mpInstance = nullptr; + PanelManager& PanelManager::GetInstance() + { + if (!mpInstance) + { + mpInstance = new PanelManager(); + } + + return *mpInstance; + } + + void PanelManager::FreeInstance() + { + delete mpInstance; + mpInstance = nullptr; + } + + + PanelManager::PanelManager() + : mpEditor(nullptr), mpMainPanel(nullptr) + { + + } + + OpRes PanelManager::Initialize(Editor* editor) + { + mpEditor = editor; + + + mpMainPanel = &MainPanel::GetInstance(); + mpMainPanel->SetEditor(mpEditor); + + CreatePanels(); + + return OpRes::OK(); + } + + void PanelManager::Shutdown() + { + DestoryPanels(); + MainPanel::FreeInstance(); + } + + void PanelManager::OpenPanel(PanelType type) + { + Panel* p = GetPanel(type); + if (!p || p->IsOpen()) + { + return; + } + + p->SetOpen(true); + } + + void PanelManager::ClosePanel(PanelType type) + { + Panel* p = GetPanel(type); + if (!p || !p->IsOpen()) + { + return; + } + + p->SetOpen(false); + } + + bool PanelManager::IsOpen(PanelType type) + { + Panel* p = GetPanel(type); + if (!p) + { + return false; + } + + return p->IsOpen(); + } + + Panel* PanelManager::GetPanel(PanelType type) + { + auto iter = mPanels.find(type); + if (iter != mPanels.end()) + { + return iter->second; + } + + Logger::Log(mpEditor->GetLogCat(), LogLevel::WARNING, "Requested panel not found: %d", type); + return nullptr; + } + + const MainPanel::DockSpaces& PanelManager::GetDockSpaces() const + { + return mpMainPanel->GetDockSpaces(); + } + + void PanelManager::OnTick(double delta) + { + for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++) + { + if (iter->second->IsOpen()) + { + iter->second->Update(delta); + } + } + } + + void PanelManager::OnRender(lunarium::IGraphics* g) + { + mpMainPanel->DoFrame(); + + for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++) + { + if (iter->second->IsOpen()) + { + iter->second->DoFrame(); + } + } + } + + //////////////////////////////////////////////////////////// + // HELPER METHODS + //////////////////////////////////////////////////////////// + + void PanelManager::CreatePanels() + { + mPanels[PanelType::PT_ABOUT] = new AboutPanel; + mPanels[PanelType::PT_ASSET_BROWSER] = new AssetBrowser(""); + mPanels[PanelType::PT_WORLD_TREE] = new WorldTree(); + mPanels[PanelType::PT_WORLD_VIEW] = new WorldView(); + mPanels[PanelType::PT_PROPERTIES_VIEW] = new PropertiesView(); + } + + void PanelManager::DestoryPanels() + { + delete mPanels[PanelType::PT_ABOUT]; + delete mPanels[PanelType::PT_ASSET_BROWSER]; + delete mPanels[PanelType::PT_WORLD_TREE]; + delete mPanels[PanelType::PT_WORLD_VIEW]; + delete mPanels[PanelType::PT_PROPERTIES_VIEW]; + + mPanels.clear(); + } +}} \ No newline at end of file diff --git a/src/run_modes/editor/panel_manager.h b/src/run_modes/editor/panel_manager.h new file mode 100644 index 0000000..9b6a7dd --- /dev/null +++ b/src/run_modes/editor/panel_manager.h @@ -0,0 +1,56 @@ +/****************************************************************************** +* File - panel_manager.h +* Author - Joey Pollack +* Date - 2022/02/07 (y/m/d) +* Mod Date - 2022/02/07 (y/m/d) +* Description - Manage the editor panels +******************************************************************************/ + +#ifndef PANEL_MANAGER_H_ +#define PANEL_MANAGER_H_ + +#include +#include "panels/mainPanel.h" +#include "panels/iPanel.h" +#include + +namespace lunarium{ + class IGraphics; +namespace editor +{ + class Editor; + class PanelManager + { + + public: + static PanelManager& GetInstance(); + static void FreeInstance(); + OpRes Initialize(Editor* editor); + void Shutdown(); + + void OpenPanel(PanelType type); + void ClosePanel(PanelType type); + bool IsOpen(PanelType type); + Panel* GetPanel(PanelType type); + + const MainPanel::DockSpaces& GetDockSpaces() const; + + void OnTick(double delta); + void OnRender(lunarium::IGraphics* g); + + private: + Editor* mpEditor; + MainPanel* mpMainPanel; + std::map mPanels; + + private: + static PanelManager* mpInstance; + PanelManager(); + + void CreatePanels(); + void DestoryPanels(); + + }; +}} + +#endif // PANEL_MANAGER_H_ \ No newline at end of file diff --git a/src/run_modes/editor/panels/about.cpp b/src/run_modes/editor/panels/about.cpp index abf07ab..01be194 100644 --- a/src/run_modes/editor/panels/about.cpp +++ b/src/run_modes/editor/panels/about.cpp @@ -9,6 +9,7 @@ #include "about.h" #include #include +#include namespace lunarium { diff --git a/src/run_modes/editor/panels/assetBrowser.cpp b/src/run_modes/editor/panels/assetBrowser.cpp index bd40428..4d820f6 100644 --- a/src/run_modes/editor/panels/assetBrowser.cpp +++ b/src/run_modes/editor/panels/assetBrowser.cpp @@ -8,6 +8,7 @@ #include "assetBrowser.h" #include +#include namespace lunarium { diff --git a/src/run_modes/editor/panels/iPanel.cpp b/src/run_modes/editor/panels/iPanel.cpp index cb2fdb5..f2a534b 100644 --- a/src/run_modes/editor/panels/iPanel.cpp +++ b/src/run_modes/editor/panels/iPanel.cpp @@ -9,12 +9,13 @@ #include "iPanel.h" #include +#include namespace lunarium { namespace editor { - Panel::Panel(PanelType type, bool isOpen) + Panel::Panel(PanelType type,bool isOpen) : mType(type), mIsOpen(isOpen) { diff --git a/src/run_modes/editor/panels/iPanel.h b/src/run_modes/editor/panels/iPanel.h index 49cc872..9af0c6a 100644 --- a/src/run_modes/editor/panels/iPanel.h +++ b/src/run_modes/editor/panels/iPanel.h @@ -13,6 +13,8 @@ namespace lunarium { namespace editor { + class Editor; + enum PanelType { PT_MAIN, @@ -41,6 +43,7 @@ namespace editor protected: PanelType mType; bool mIsOpen; + // Editor* mpEditor; int mX; int mY; diff --git a/src/run_modes/editor/panels/mainPanel.cpp b/src/run_modes/editor/panels/mainPanel.cpp index 1f39492..aaa8ca5 100644 --- a/src/run_modes/editor/panels/mainPanel.cpp +++ b/src/run_modes/editor/panels/mainPanel.cpp @@ -11,6 +11,7 @@ #include "../editor.h" #include #include +#include // To use the DockWindowXXX methods #include namespace lunarium @@ -46,6 +47,11 @@ namespace editor mpEditor = e; } + const MainPanel::DockSpaces& MainPanel::GetDockSpaces() const + { + return mDockSpaces; + } + bool MainPanel::DoFrame() { if (!mIsOpen) @@ -70,7 +76,8 @@ namespace editor return false; } - ImGui::DockSpaceOverViewport(); + MakeDockSpaces(); + ImGui::PopStyleVar(); ImGui::End(); @@ -100,6 +107,12 @@ namespace editor return true; } + void MainPanel::MakeDockSpaces() + { + mDockSpaces.Main = ImGui::DockSpace(ImGui::GetID("Lunarium Editor")); + + } + void MainPanel::DoMainMenu() { ImGui::BeginMainMenuBar(); diff --git a/src/run_modes/editor/panels/mainPanel.h b/src/run_modes/editor/panels/mainPanel.h index 4eb0504..7718fd6 100644 --- a/src/run_modes/editor/panels/mainPanel.h +++ b/src/run_modes/editor/panels/mainPanel.h @@ -18,12 +18,24 @@ namespace editor class Editor; class MainPanel : public Panel { + public: + struct DockSpaces + { + unsigned int Main; + unsigned int Left; + unsigned int Right; + unsigned int Center; + unsigned int Top; + unsigned int Bottom; + }; + public: MainPanel(); static MainPanel& GetInstance(); static void FreeInstance(); void SetEditor(Editor* e); + const DockSpaces& GetDockSpaces() const; // Returns false if the window is closed bool DoFrame(); @@ -35,9 +47,11 @@ namespace editor private: Editor* mpEditor; + DockSpaces mDockSpaces; private: // HELPERS void DoMainMenu(); + void MakeDockSpaces(); }; } } diff --git a/src/run_modes/editor/panels/propertiesView.cpp b/src/run_modes/editor/panels/propertiesView.cpp index d8f3a15..d625237 100644 --- a/src/run_modes/editor/panels/propertiesView.cpp +++ b/src/run_modes/editor/panels/propertiesView.cpp @@ -9,6 +9,7 @@ #include "propertiesView.h" #include +#include namespace lunarium { namespace editor { diff --git a/src/run_modes/editor/panels/worldTree.cpp b/src/run_modes/editor/panels/worldTree.cpp index 0d442a1..df09492 100644 --- a/src/run_modes/editor/panels/worldTree.cpp +++ b/src/run_modes/editor/panels/worldTree.cpp @@ -9,6 +9,7 @@ #include "worldTree.h" #include #include +#include namespace lunarium { diff --git a/src/run_modes/editor/panels/worldView.cpp b/src/run_modes/editor/panels/worldView.cpp index 847b605..5fce5f2 100644 --- a/src/run_modes/editor/panels/worldView.cpp +++ b/src/run_modes/editor/panels/worldView.cpp @@ -9,6 +9,8 @@ #include "worldView.h" #include #include +#include +#include "../panel_manager.h" namespace lunarium { @@ -26,6 +28,7 @@ namespace editor return false; //ImGui::SetNextWindowPosition() + ImGui::SetNextWindowDockID(PanelManager::GetInstance().GetDockSpaces().Center, ImGuiCond_Appearing); if (!ImGui::Begin("World View", &mIsOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar)) { ImGui::End(); diff --git a/src/run_modes/editor/panels/worldView.h b/src/run_modes/editor/panels/worldView.h index acfc561..e2cd678 100644 --- a/src/run_modes/editor/panels/worldView.h +++ b/src/run_modes/editor/panels/worldView.h @@ -17,6 +17,7 @@ namespace lunarium class World; namespace editor { + class Editor; class WorldView : public Panel { public: @@ -28,6 +29,7 @@ namespace editor private: World* mpWorld; + Editor* mpEditor; }; }} // lunarium::editor