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
parent
8444e45fb0
commit
6a6c6d42ab
@ -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_
|
||||||
Loading…
Reference in New Issue