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->mState.Display.WindowStartPosition.Y);
mpInstance->mState.SaveToFile();
//mpInstance->mState.SaveToFile();
// Run Mode shuts down first
mpInstance->mpRunMode->Shutdown();

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

@ -8,18 +8,14 @@
#include "editor.h"
#include "panels/mainPanel.h"
#include "panel_manager.h"
#include <core/core.h>
#include <utils/logger.h>
#include <gui/fileBrowser.h>
#include <internal_data/dataManager.h>
// 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);
}

@ -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<PanelType, Panel*> mPanels;
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 <dearimgui/imgui.h>
#include <core/version.h>
#include <editor/editor.h>
namespace lunarium
{

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

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

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

@ -11,6 +11,7 @@
#include "../editor.h"
#include <core/core.h>
#include <dearimgui/imgui.h>
#include <dearimgui/imgui_internal.h> // To use the DockWindowXXX methods
#include <utils/logger.h>
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();

@ -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();
};
}
}

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

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

@ -9,6 +9,8 @@
#include "worldView.h"
#include <game/world/world.h>
#include <dearimgui/imgui.h>
#include <editor/editor.h>
#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();

@ -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

Loading…
Cancel
Save