Panel management code moved from Editor class into the PanelManager class

WorldView panel does not currently show up because the dockspace is not fully set up yet.
Gui_Panel_Refactor
Joeyrp 4 years ago
parent 8444e45fb0
commit 6a6c6d42ab

@ -68,7 +68,7 @@ namespace lunarium
mpInstance->mpWindow->GetPosition(&mpInstance->mState.Display.WindowStartPosition.X, mpInstance->mpWindow->GetPosition(&mpInstance->mState.Display.WindowStartPosition.X,
&mpInstance->mState.Display.WindowStartPosition.Y); &mpInstance->mState.Display.WindowStartPosition.Y);
mpInstance->mState.SaveToFile(); //mpInstance->mState.SaveToFile();
// Run Mode shuts down first // Run Mode shuts down first
mpInstance->mpRunMode->Shutdown(); mpInstance->mpRunMode->Shutdown();

@ -2,6 +2,7 @@
# Source Files # Source Files
set(EDITOR_SRC set(EDITOR_SRC
"editor.cpp" "editor.cpp"
"panel_manager.cpp"
"project/project.cpp" "project/project.cpp"
"panels/iPanel.cpp" "panels/iPanel.cpp"
"panels/mainPanel.cpp" "panels/mainPanel.cpp"

@ -8,18 +8,14 @@
#include "editor.h" #include "editor.h"
#include "panels/mainPanel.h" #include "panel_manager.h"
#include <core/core.h> #include <core/core.h>
#include <utils/logger.h> #include <utils/logger.h>
#include <gui/fileBrowser.h> #include <gui/fileBrowser.h>
#include <internal_data/dataManager.h> #include <internal_data/dataManager.h>
// Panels
#include "panels/about.h"
#include "panels/assetBrowser.h" #include "panels/assetBrowser.h"
#include "panels/worldTree.h"
#include "panels/worldView.h"
#include "panels/propertiesView.h"
// Tools // Tools
#include "tools/map_editor/map_editor.h" #include "tools/map_editor/map_editor.h"
@ -30,7 +26,7 @@ namespace editor
{ {
Editor::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) mDoSaveProject(false), mDoSaveAs(false), mpMapEditor(nullptr)
{ {
} }
@ -38,35 +34,27 @@ namespace editor
OpRes Editor::Initialize() OpRes Editor::Initialize()
{ {
mLogCat = Logger::RegisterCategory("EDITOR"); mLogCat = Logger::RegisterCategory("EDITOR");
mpMainPanel = &MainPanel::GetInstance();
mpMainPanel->SetEditor(this);
// Initialize internal data // Initialize internal data
DataManager::Initialize(); DataManager::Initialize();
CreatePanels(); PanelManager::GetInstance().Initialize(this);
return OpRes::OK(); return OpRes::OK();
} }
void Editor::Shutdown() void Editor::Shutdown()
{ {
DestoryPanels();
DataManager::Shutdown(); DataManager::Shutdown();
MainPanel::FreeInstance(); PanelManager::GetInstance().Shutdown();
PanelManager::FreeInstance();
} }
void Editor::OnTick(double delta) void Editor::OnTick(double delta)
{ {
// Panels // Panels
for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++) PanelManager::GetInstance().OnTick(delta);
{
if (iter->second->IsOpen())
{
iter->second->Update(delta);
}
}
// Tools // Tools
if (mpMapEditor) if (mpMapEditor)
@ -79,15 +67,7 @@ namespace editor
void Editor::OnRender(lunarium::IGraphics* g) void Editor::OnRender(lunarium::IGraphics* g)
{ {
mpMainPanel->DoFrame(); PanelManager::GetInstance().OnRender(g);
for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++)
{
if (iter->second->IsOpen())
{
iter->second->DoFrame();
}
}
if (mpMapEditor) if (mpMapEditor)
{ {
@ -129,25 +109,7 @@ namespace editor
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// HELPER METHODS // 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() void Editor::DestroyTools()
{ {
@ -190,7 +152,7 @@ namespace editor
{ {
Logger::Log(mLogCat, LogLevel::ERROR, "Could not create a new project: %s", result.Description); 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 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); 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 else
{ {
@ -297,7 +259,7 @@ namespace editor
void Editor::ShowAboutPanel() void Editor::ShowAboutPanel()
{ {
mPanels[PanelType::PT_ABOUT]->SetOpen(true); PanelManager::GetInstance().OpenPanel(PanelType::PT_ABOUT);
} }

@ -30,7 +30,6 @@ namespace lunarium
}; };
class MapEditor; class MapEditor;
class MainPanel;
class Editor : public iRunMode class Editor : public iRunMode
{ {
public: public:
@ -60,8 +59,6 @@ namespace lunarium
private: // Data private: // Data
uint32_t mLogCat; uint32_t mLogCat;
MainPanel* mpMainPanel;
std::map<PanelType, Panel*> mPanels;
Project mProject; Project mProject;

@ -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 <utils/logger.h>
// 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();
}
}}

@ -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 <utils/opRes.h>
#include "panels/mainPanel.h"
#include "panels/iPanel.h"
#include <map>
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<PanelType, Panel*> mPanels;
private:
static PanelManager* mpInstance;
PanelManager();
void CreatePanels();
void DestoryPanels();
};
}}
#endif // PANEL_MANAGER_H_

@ -9,6 +9,7 @@
#include "about.h" #include "about.h"
#include <dearimgui/imgui.h> #include <dearimgui/imgui.h>
#include <core/version.h> #include <core/version.h>
#include <editor/editor.h>
namespace lunarium namespace lunarium
{ {

@ -8,6 +8,7 @@
#include "assetBrowser.h" #include "assetBrowser.h"
#include <dearimgui/imgui.h> #include <dearimgui/imgui.h>
#include <editor/editor.h>
namespace lunarium namespace lunarium
{ {

@ -9,12 +9,13 @@
#include "iPanel.h" #include "iPanel.h"
#include <dearimgui/imgui.h> #include <dearimgui/imgui.h>
#include <editor/editor.h>
namespace lunarium namespace lunarium
{ {
namespace editor namespace editor
{ {
Panel::Panel(PanelType type, bool isOpen) Panel::Panel(PanelType type,bool isOpen)
: mType(type), mIsOpen(isOpen) : mType(type), mIsOpen(isOpen)
{ {

@ -13,6 +13,8 @@ namespace lunarium
{ {
namespace editor namespace editor
{ {
class Editor;
enum PanelType enum PanelType
{ {
PT_MAIN, PT_MAIN,
@ -41,6 +43,7 @@ namespace editor
protected: protected:
PanelType mType; PanelType mType;
bool mIsOpen; bool mIsOpen;
// Editor* mpEditor;
int mX; int mX;
int mY; int mY;

@ -11,6 +11,7 @@
#include "../editor.h" #include "../editor.h"
#include <core/core.h> #include <core/core.h>
#include <dearimgui/imgui.h> #include <dearimgui/imgui.h>
#include <dearimgui/imgui_internal.h> // To use the DockWindowXXX methods
#include <utils/logger.h> #include <utils/logger.h>
namespace lunarium namespace lunarium
@ -46,6 +47,11 @@ namespace editor
mpEditor = e; mpEditor = e;
} }
const MainPanel::DockSpaces& MainPanel::GetDockSpaces() const
{
return mDockSpaces;
}
bool MainPanel::DoFrame() bool MainPanel::DoFrame()
{ {
if (!mIsOpen) if (!mIsOpen)
@ -70,7 +76,8 @@ namespace editor
return false; return false;
} }
ImGui::DockSpaceOverViewport(); MakeDockSpaces();
ImGui::PopStyleVar(); ImGui::PopStyleVar();
ImGui::End(); ImGui::End();
@ -100,6 +107,12 @@ namespace editor
return true; return true;
} }
void MainPanel::MakeDockSpaces()
{
mDockSpaces.Main = ImGui::DockSpace(ImGui::GetID("Lunarium Editor"));
}
void MainPanel::DoMainMenu() void MainPanel::DoMainMenu()
{ {
ImGui::BeginMainMenuBar(); ImGui::BeginMainMenuBar();

@ -18,12 +18,24 @@ namespace editor
class Editor; class Editor;
class MainPanel : public Panel 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: public:
MainPanel(); MainPanel();
static MainPanel& GetInstance(); static MainPanel& GetInstance();
static void FreeInstance(); static void FreeInstance();
void SetEditor(Editor* e); void SetEditor(Editor* e);
const DockSpaces& GetDockSpaces() const;
// Returns false if the window is closed // Returns false if the window is closed
bool DoFrame(); bool DoFrame();
@ -35,9 +47,11 @@ namespace editor
private: private:
Editor* mpEditor; Editor* mpEditor;
DockSpaces mDockSpaces;
private: // HELPERS private: // HELPERS
void DoMainMenu(); void DoMainMenu();
void MakeDockSpaces();
}; };
} }
} }

@ -9,6 +9,7 @@
#include "propertiesView.h" #include "propertiesView.h"
#include <dearimgui/imgui.h> #include <dearimgui/imgui.h>
#include <editor/editor.h>
namespace lunarium { namespace editor namespace lunarium { namespace editor
{ {

@ -9,6 +9,7 @@
#include "worldTree.h" #include "worldTree.h"
#include <game/world/world.h> #include <game/world/world.h>
#include <dearimgui/imgui.h> #include <dearimgui/imgui.h>
#include <editor/editor.h>
namespace lunarium namespace lunarium
{ {

@ -9,6 +9,8 @@
#include "worldView.h" #include "worldView.h"
#include <game/world/world.h> #include <game/world/world.h>
#include <dearimgui/imgui.h> #include <dearimgui/imgui.h>
#include <editor/editor.h>
#include "../panel_manager.h"
namespace lunarium namespace lunarium
{ {
@ -26,6 +28,7 @@ namespace editor
return false; return false;
//ImGui::SetNextWindowPosition() //ImGui::SetNextWindowPosition()
ImGui::SetNextWindowDockID(PanelManager::GetInstance().GetDockSpaces().Center, ImGuiCond_Appearing);
if (!ImGui::Begin("World View", &mIsOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar)) if (!ImGui::Begin("World View", &mIsOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar))
{ {
ImGui::End(); ImGui::End();

@ -17,6 +17,7 @@ namespace lunarium
class World; class World;
namespace editor namespace editor
{ {
class Editor;
class WorldView : public Panel class WorldView : public Panel
{ {
public: public:
@ -28,6 +29,7 @@ namespace editor
private: private:
World* mpWorld; World* mpWorld;
Editor* mpEditor;
}; };
}} // lunarium::editor }} // lunarium::editor

Loading…
Cancel
Save