Panel and PanelManager refactored. Panel IDs are now handed out when added to the PanelManager. The IDs are no longer tied to the gui subsystem through enum values.

Gui_Panel_Refactor
Joey Pollack 4 years ago
parent 03b7e7ccf1
commit 8e07cec621

@ -126,7 +126,7 @@ add_subdirectory(src/run_modes/tester)
add_subdirectory(src/run_modes/editor) add_subdirectory(src/run_modes/editor)
# add run mode editor # add run mode editor
add_subdirectory(src/run_modes/game) add_subdirectory(src/run_modes/player)
target_include_directories(${PROJECT_NAME} target_include_directories(${PROJECT_NAME}
PUBLIC "${PROJECT_BINARY_DIR}" PUBLIC "${PROJECT_BINARY_DIR}"

@ -136,13 +136,7 @@ namespace lunarium
// Init the Debug log window // Init the Debug log window
OpRes result; OpRes result;
mPanels[gui::PanelType::PT_CORE_CONSOLE] = new CoreConsole; mPanelIDs.CoreConsole = AddPanel(new CoreConsole);
// result = LogGui::GetInstance().Initialize();
// if (Failed(result))
// {
// Logger::Log(LogCategory::CORE, LogLevel::WARNING,
// "Could not initialized the debug log window: %s", result.Description);
// }
Logger::Log(LogCategory::CORE, LogLevel::INFO, "Running Lunarium version %s", Version::GetVersion().ToString().c_str()); Logger::Log(LogCategory::CORE, LogLevel::INFO, "Running Lunarium version %s", Version::GetVersion().ToString().c_str());
@ -248,12 +242,7 @@ namespace lunarium
return; return;
#else #else
mpRunMode = new editor::Editor; mpRunMode = new editor::Editor;
FreePanel(mPanelIDs.CoreConsole); // Editor uses it's own console
delete mPanels[gui::PanelType::PT_CORE_CONSOLE];
mPanels[gui::PanelType::PT_CORE_CONSOLE] = nullptr;
// Editor has it's own console
// LogGui::GetInstance().SetStickToWindow(false);
// LuaConsole::GetInstance().SetStickToWindow(false);
#endif #endif
} }
@ -300,7 +289,7 @@ namespace lunarium
glfwSetWindowTitle(mpWindow->GetWindow(), title.c_str()); glfwSetWindowTitle(mpWindow->GetWindow(), title.c_str());
// Get pointers to gui panels // Get pointers to gui panels
CoreConsole* con = (CoreConsole*)mPanels[gui::PanelType::PT_CORE_CONSOLE]; CoreConsole* con = (CoreConsole*)mPanels[mPanelIDs.CoreConsole];
// Poll input // Poll input
Window::PollEvents(); Window::PollEvents();
@ -424,4 +413,20 @@ namespace lunarium
return *mpInstance->mpInput; return *mpInstance->mpInput;
} }
////////////////////////////////////////////////////////////
// HELPERS
////////////////////////////////////////////////////////////
uint32_t Core::AddPanel(gui::Panel* p)
{
mPanels.push_back(p);
return mPanels.size() - 1;
}
void Core::FreePanel(uint32_t id)
{
delete mPanels[id];
mPanels[id] = nullptr;
}
} }

@ -59,7 +59,11 @@ namespace lunarium
bool mbShowGuiDemo; bool mbShowGuiDemo;
// Panels // Panels
std::map<gui::PanelType, gui::Panel*> mPanels; struct
{
uint32_t CoreConsole;
} mPanelIDs;
std::vector<gui::Panel*> mPanels;
// Log Files // Log Files
std::ofstream mMasterLogFile; std::ofstream mMasterLogFile;
@ -78,6 +82,10 @@ namespace lunarium
static IGraphics& Graphics(); static IGraphics& Graphics();
static InputManager& Input(); static InputManager& Input();
private: // HELPERS
uint32_t AddPanel(gui::Panel* p);
void FreePanel(uint32_t id);
private: // HIDDEN METHODS private: // HIDDEN METHODS
Core(); Core();

@ -15,7 +15,7 @@
namespace lunarium namespace lunarium
{ {
CoreConsole::CoreConsole() CoreConsole::CoreConsole()
: Console(gui::PanelType::PT_CORE_CONSOLE, "Core Console"), mDockIsInit(false) : Console("Core Console"), mDockIsInit(false)
{ {
} }

@ -45,8 +45,8 @@ namespace lunarium
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// CONSOLE // CONSOLE
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Console::Console(PanelType type, const char* name) Console::Console(const char* name)
: Panel(type, name, gui::PanelDockZone::DDZ_NONE, false), : Panel(name, gui::PanelDockZone::DDZ_NONE, false),
mbNewCommand(false), mRecalledCommand(-1), mIsFocused(false), mListener(nullptr), mbNewCommand(false), mRecalledCommand(-1), mIsFocused(false), mListener(nullptr),
mbOglDebug(false), mbInfoVerbose(false), mpListener(nullptr) mbOglDebug(false), mbInfoVerbose(false), mpListener(nullptr)
{ {

@ -34,7 +34,7 @@ namespace lunarium
class Console : public Panel class Console : public Panel
{ {
public: public:
Console(PanelType type, const char* name); Console(const char* name);
virtual ~Console(); virtual ~Console();
virtual void Update(float dt); virtual void Update(float dt);
virtual bool DoFrame(); virtual bool DoFrame();

@ -14,8 +14,8 @@ namespace lunarium
{ {
namespace gui namespace gui
{ {
Panel::Panel(PanelType type, std::string name, PanelDockZone dock_zone, bool isOpen) Panel::Panel(std::string name, PanelDockZone dock_zone, bool isOpen)
: mType(type), mIsOpen(isOpen), mPanelName(name), mDockZone(dock_zone) : mIsOpen(isOpen), mPanelName(name), mDockZone(dock_zone)
{ {
} }
@ -25,11 +25,6 @@ namespace gui
} }
PanelType Panel::GetType() const
{
return mType;
}
const char* Panel::GetName() const const char* Panel::GetName() const
{ {
return mPanelName.c_str(); return mPanelName.c_str();

@ -22,9 +22,8 @@ namespace gui
class Panel class Panel
{ {
public: public:
Panel(PanelType type, std::string name, PanelDockZone dock_zone, bool isOpen = false); Panel(std::string name, PanelDockZone dock_zone, bool isOpen = false);
virtual ~Panel(); virtual ~Panel();
PanelType GetType() const;
const char* GetName() const; const char* GetName() const;
virtual void Update(float dt); virtual void Update(float dt);
@ -36,11 +35,9 @@ namespace gui
PanelDockZone GetDockZone() const; PanelDockZone GetDockZone() const;
protected: protected:
PanelType mType;
std::string mPanelName; std::string mPanelName;
bool mIsOpen; bool mIsOpen;
PanelDockZone mDockZone; PanelDockZone mDockZone;
// Editor* mpEditor;
int mX; int mX;
int mY; int mY;

@ -11,30 +11,6 @@
namespace lunarium { namespace gui namespace lunarium { namespace gui
{ {
enum PanelType
{
// core
PT_CORE_CONSOLE,
// editor
PT_MAIN,
PT_ABOUT,
PT_WORLD_TREE,
PT_WORLD_VIEW,
PT_ASSET_BROWSER,
PT_PROPERTIES_VIEW,
PT_EDITOR_CONSOLE,
// Map Editor
PT_MAP_CANVAS,
PT_TILE_SET_VIEW,
PT_TILE_PROPERTIES,
PT_MAP_PROPERTIES,
PT_MAP_PREVIEW,
PT_UNKNOWN,
};
enum PanelDockZone enum PanelDockZone
{ {
DDZ_LEFT, DDZ_LEFT,

@ -60,10 +60,10 @@ namespace editor
return res; return res;
} }
mPanelManager.AddPanel(new AssetBrowser("")).LogIfFailed(LogCat); mPanelManager.AddPanel(new AssetBrowser(""), mPanels.AssetBrowser).LogIfFailed(LogCat);
mPanelManager.AddPanel(new WorldTree()).LogIfFailed(LogCat); mPanelManager.AddPanel(new WorldTree(), mPanels.WorldTree).LogIfFailed(LogCat);
mPanelManager.AddPanel(new WorldView()).LogIfFailed(LogCat); mPanelManager.AddPanel(new WorldView(), mPanels.WorldView).LogIfFailed(LogCat);
mPanelManager.AddPanel(new PropertiesView()).LogIfFailed(LogCat); mPanelManager.AddPanel(new PropertiesView(), mPanels.PropertiesView).LogIfFailed(LogCat);
return OpRes::OK(); return OpRes::OK();
} }
@ -150,7 +150,7 @@ namespace editor
std::filesystem::path Editor::GetAssetBrowserLocation() std::filesystem::path Editor::GetAssetBrowserLocation()
{ {
return mProject.GetAssetDirectory() / ((AssetBrowser*)mPanelManager.GetPanel(gui::PanelType::PT_ASSET_BROWSER))->GetSelectedDirectory(); return mProject.GetAssetDirectory() / ((AssetBrowser*)mPanelManager.GetPanel(mPanels.AssetBrowser))->GetSelectedDirectory();
} }
Project* Editor::GetProject() Project* Editor::GetProject()
@ -207,7 +207,7 @@ namespace editor
{ {
Logger::Log(LogCat, LogLevel::ERROR, "Could not create a new project: %s", result.Description); Logger::Log(LogCat, LogLevel::ERROR, "Could not create a new project: %s", result.Description);
} }
((AssetBrowser*)mPanelManager.GetPanel(PanelType::PT_ASSET_BROWSER))->SetAssetDirectory(*mpPath / std::filesystem::path("contents/assets")); ((AssetBrowser*)mPanelManager.GetPanel(mPanels.AssetBrowser))->SetAssetDirectory(*mpPath / std::filesystem::path("contents/assets"));
mDoNewProject = false; mDoNewProject = false;
} }
else if (mFileBrowser.GetResult() == FileBrowser::Result::CANCEL) else if (mFileBrowser.GetResult() == FileBrowser::Result::CANCEL)
@ -231,7 +231,7 @@ namespace editor
mDoOpenProject = false; mDoOpenProject = false;
return; return;
} }
((AssetBrowser*)mPanelManager.GetPanel(PanelType::PT_ASSET_BROWSER))->SetAssetDirectory(mpPath->parent_path() / std::filesystem::path("contents/assets")); ((AssetBrowser*)mPanelManager.GetPanel(mPanels.AssetBrowser))->SetAssetDirectory(mpPath->parent_path() / std::filesystem::path("contents/assets"));
mDoOpenProject = false; mDoOpenProject = false;
} }
else if (mFileBrowser.GetResult() == FileBrowser::Result::CANCEL) else if (mFileBrowser.GetResult() == FileBrowser::Result::CANCEL)
@ -389,10 +389,10 @@ namespace editor
} }
ImGui::Separator(); ImGui::Separator();
HandleOpenPanel("Asset Browser", gui::PanelType::PT_ASSET_BROWSER); HandleOpenPanel("Asset Browser", mPanels.AssetBrowser);
HandleOpenPanel("World Tree", gui::PanelType::PT_WORLD_TREE); HandleOpenPanel("World Tree", mPanels.WorldTree);
HandleOpenPanel("World View", gui::PanelType::PT_WORLD_VIEW); HandleOpenPanel("World View", mPanels.WorldView);
HandleOpenPanel("Properties", gui::PanelType::PT_PROPERTIES_VIEW); HandleOpenPanel("Properties", mPanels.PropertiesView);
ImGui::EndMenu(); ImGui::EndMenu();
} }
@ -427,11 +427,11 @@ namespace editor
} }
void Editor::HandleOpenPanel(const char* name, gui::PanelType type) void Editor::HandleOpenPanel(const char* name, uint32_t id)
{ {
if (ImGui::MenuItem(name)) if (ImGui::MenuItem(name))
{ {
mPanelManager.OpenPanel(type); mPanelManager.OpenPanel(id);
} }
} }

@ -70,6 +70,16 @@ namespace lunarium { namespace editor
FileBrowser mFileBrowser; FileBrowser mFileBrowser;
const std::filesystem::path* mpPath; const std::filesystem::path* mpPath;
// Panels
struct
{
uint32_t AssetBrowser;
uint32_t WorldTree;
uint32_t WorldView;
uint32_t PropertiesView;
} mPanels;
// Non-Docking panels // Non-Docking panels
AboutPanel mAboutPanel; AboutPanel mAboutPanel;
@ -89,7 +99,7 @@ namespace lunarium { namespace editor
void DestroyTools(); void DestroyTools();
void HandleMenuEvents(); void HandleMenuEvents();
void HandleOpenPanel(const char* name, gui::PanelType type); void HandleOpenPanel(const char* name, uint32_t id);
}; };

@ -52,60 +52,52 @@ namespace lunarium { namespace editor
} }
OpRes PanelManager::AddPanel(gui::Panel* panel) OpRes PanelManager::AddPanel(gui::Panel* panel, uint32_t& id)
{ {
if (mPanels.find(panel->GetType()) != mPanels.end()) if (mPanelsByName.find(panel->GetName()) != mPanelsByName.end())
{ {
return OpRes::Fail("Cannot add panel - panel already exists. Panel Name: %s", panel->GetName()); return OpRes::Fail("Cannot add panel - panel already exists. Panel Name: %s", panel->GetName());
} }
mPanels[panel->GetType()] = panel; mPanelsByName[panel->GetName()] = panel;
mPanels.push_back(panel);
id = mPanels.size() - 1;
return OpRes::OK(); return OpRes::OK();
} }
void PanelManager::OpenPanel(PanelType type) void PanelManager::OpenPanel(uint32_t id)
{
Panel* p = GetPanel(type);
if (!p || p->IsOpen())
{ {
if (mPanels.size() >= id || id < 0)
return; return;
}
p->SetOpen(true); mPanels[id]->SetOpen(true);
} }
void PanelManager::ClosePanel(PanelType type) void PanelManager::ClosePanel(uint32_t id)
{
Panel* p = GetPanel(type);
if (!p || !p->IsOpen())
{ {
if (mPanels.size() >= id || id < 0)
return; return;
}
p->SetOpen(false); mPanels[id]->SetOpen(false);
} }
bool PanelManager::IsOpen(PanelType type) bool PanelManager::IsOpen(uint32_t id)
{
Panel* p = GetPanel(type);
if (!p)
{ {
if (mPanels.size() >= id || id < 0)
return false; return false;
}
return p->IsOpen(); return mPanels[id]->IsOpen();
} }
Panel* PanelManager::GetPanel(PanelType type) Panel* PanelManager::GetPanel(uint32_t id)
{ {
auto iter = mPanels.find(type); if (id >= 0 && id < mPanels.size())
if (iter != mPanels.end())
{ {
return iter->second; return mPanels[id];
} }
Logger::Log(mpEditor->GetLogCat(), LogLevel::WARNING, "Requested panel not found: %d", type); Logger::Log(mpEditor->GetLogCat(), LogLevel::WARNING, "Requested panel not found: %d", id);
return nullptr; return nullptr;
} }
@ -134,55 +126,21 @@ namespace lunarium { namespace editor
{ {
for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++) for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++)
{ {
if (iter->second->IsOpen()) if ((*iter)->IsOpen())
{ {
iter->second->Update(delta); (*iter)->Update(delta);
} }
} }
} }
// void PanelManager::OnRender(lunarium::IGraphics* g)
// {
// // mpMainPanel->DoFrame();
// //ImGuiViewport* Viewport = ImGui::GetMainViewport();
// ImGuiViewport* Viewport = ImGui::GetWindowViewport();
// 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(mName.c_str(), nullptr, WindowFlags);
// ImGui::PopStyleVar(3);
// MakeDockSpaces();
// ImGui::End();
// for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++)
// {
// if (iter->second->IsOpen())
// {
// ImGui::SetNextWindowClass(&mWindowClass);
// iter->second->DoFrame();
// }
// }
// }
void PanelManager::RenderPanels() void PanelManager::RenderPanels()
{ {
for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++) for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++)
{ {
if (iter->second->IsOpen()) if ((*iter)->IsOpen())
{ {
ImGui::SetNextWindowClass(&mWindowClass); ImGui::SetNextWindowClass(&mWindowClass);
iter->second->DoFrame(); (*iter)->DoFrame();
} }
} }
} }
@ -194,7 +152,7 @@ namespace lunarium { namespace editor
{ {
for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++) for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++)
{ {
delete iter->second; delete (*iter);
} }
mPanels.clear(); mPanels.clear();
@ -232,7 +190,7 @@ namespace lunarium { namespace editor
// Dock Panels // Dock Panels
for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++) for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++)
{ {
PanelDockZone dz = iter->second->GetDockZone(); PanelDockZone dz = (*iter)->GetDockZone();
if (dz != PanelDockZone::DDZ_NONE) if (dz != PanelDockZone::DDZ_NONE)
{ {
// If the panel expects the bottom node to be split but it isn't // If the panel expects the bottom node to be split but it isn't
@ -251,7 +209,7 @@ namespace lunarium { namespace editor
dz = PanelDockZone::DDZ_BOT_LEFT; dz = PanelDockZone::DDZ_BOT_LEFT;
} }
ImGui::DockBuilderDockWindow(iter->second->GetName(), mDockZoneIDs[dz]); ImGui::DockBuilderDockWindow((*iter)->GetName(), mDockZoneIDs[dz]);
} }
} }
} }

@ -13,6 +13,7 @@
#include <gui/dearimgui/imgui.h> #include <gui/dearimgui/imgui.h>
#include <gui/panel.h> #include <gui/panel.h>
#include <map> #include <map>
#include <vector>
struct ImGuiWindowClass; struct ImGuiWindowClass;
@ -30,11 +31,11 @@ namespace editor
void Shutdown(); void Shutdown();
// Panel interface // Panel interface
OpRes AddPanel(gui::Panel* panel); [[nodiscard]] OpRes AddPanel(gui::Panel* panel, uint32_t& id);
void OpenPanel(gui::PanelType type); void OpenPanel(uint32_t id);
void ClosePanel(gui::PanelType type); void ClosePanel(uint32_t id);
bool IsOpen(gui::PanelType type); bool IsOpen(uint32_t id);
gui::Panel* GetPanel(gui::PanelType type); gui::Panel* GetPanel(uint32_t id);
const ImGuiWindowClass* GetWindowClass() const; const ImGuiWindowClass* GetWindowClass() const;
// Docking // Docking
@ -49,9 +50,10 @@ namespace editor
private: private:
Editor* mpEditor; Editor* mpEditor;
std::string mName; std::string mName;
bool mSplitBottom; // If ture the bottom dock node will also be split into left/right bool mSplitBottom; // If true the bottom dock node will also be split into left/right
bool mResetDockSpace; bool mResetDockSpace;
std::map<gui::PanelType, gui::Panel*> mPanels; std::vector<gui::Panel*> mPanels;
std::map<const char*, gui::Panel*> mPanelsByName;
unsigned int mDockSpaceID; unsigned int mDockSpaceID;
ImGuiWindowClass mWindowClass; ImGuiWindowClass mWindowClass;
std::map<gui::PanelDockZone, unsigned int> mDockZoneIDs; std::map<gui::PanelDockZone, unsigned int> mDockZoneIDs;

@ -16,7 +16,7 @@ namespace lunarium
namespace editor namespace editor
{ {
AboutPanel::AboutPanel() AboutPanel::AboutPanel()
: Panel(gui::PanelType::PT_ABOUT, "About", gui::PanelDockZone::DDZ_NONE) : Panel("About", gui::PanelDockZone::DDZ_NONE)
{ {
} }

@ -15,7 +15,7 @@ namespace lunarium
namespace editor namespace editor
{ {
AssetBrowser::AssetBrowser(std::filesystem::path dir) AssetBrowser::AssetBrowser(std::filesystem::path dir)
: Panel(gui::PanelType::PT_ASSET_BROWSER, "Asset Browser", gui::PanelDockZone::DDZ_BOTTOM, true), : Panel("Asset Browser", gui::PanelDockZone::DDZ_BOTTOM, true),
mAssetDirectory(dir), mTreeRoot(nullptr), mSelectedNode(nullptr) mAssetDirectory(dir), mTreeRoot(nullptr), mSelectedNode(nullptr)
{ {
mTreeRoot = ReloadAssets(mAssetDirectory); mTreeRoot = ReloadAssets(mAssetDirectory);

@ -14,7 +14,7 @@
namespace lunarium { namespace editor namespace lunarium { namespace editor
{ {
PropertiesView::PropertiesView() PropertiesView::PropertiesView()
: Panel(gui::PanelType::PT_PROPERTIES_VIEW, "Properties", gui::PanelDockZone::DDZ_RIGHT, true) : Panel("Properties", gui::PanelDockZone::DDZ_RIGHT, true)
{ {
} }

@ -7,7 +7,7 @@
******************************************************************************/ ******************************************************************************/
#include "worldTree.h" #include "worldTree.h"
#include <game/world/world.h> #include <player/world/world.h>
#include <gui/dearimgui/imgui.h> #include <gui/dearimgui/imgui.h>
#include <editor/editor.h> #include <editor/editor.h>
@ -16,7 +16,7 @@ namespace lunarium
namespace editor namespace editor
{ {
WorldTree::WorldTree() WorldTree::WorldTree()
: Panel(gui::PanelType::PT_WORLD_TREE, "World Tree", gui::PanelDockZone::DDZ_LEFT, true), mpWorld(nullptr) : Panel("World Tree", gui::PanelDockZone::DDZ_LEFT, true), mpWorld(nullptr)
{ {
} }

@ -8,7 +8,7 @@
#include "worldView.h" #include "worldView.h"
#include <utils/logger.h> #include <utils/logger.h>
#include <game/world/world.h> #include <player/world/world.h>
#include <gui/dearimgui/imgui.h> #include <gui/dearimgui/imgui.h>
#include <editor/editor.h> #include <editor/editor.h>
#include "../panel_manager.h" #include "../panel_manager.h"
@ -18,7 +18,7 @@ namespace lunarium
namespace editor namespace editor
{ {
WorldView::WorldView() WorldView::WorldView()
: Panel(gui::PanelType::PT_WORLD_VIEW, "World View", gui::PanelDockZone::DDZ_CENTER ,true), mpWorld(nullptr) : Panel("World View", gui::PanelDockZone::DDZ_CENTER ,true), mpWorld(nullptr)
{ {
} }

@ -47,8 +47,8 @@ namespace lunarium { namespace editor
return OpRes::Fail("Could not initialize the panel manager!"); return OpRes::Fail("Could not initialize the panel manager!");
} }
mPanelManager.AddPanel(new MapCanvas(this)).LogIfFailed(mpEditor->GetLogCat()); mPanelManager.AddPanel(new MapCanvas(this), mPanels.MapCanvas).LogIfFailed(mpEditor->GetLogCat());
mPanelManager.AddPanel(new TileSetView(this)).LogIfFailed(mpEditor->GetLogCat()); mPanelManager.AddPanel(new TileSetView(this), mPanels.TileSetView).LogIfFailed(mpEditor->GetLogCat());
Open(); Open();
@ -156,17 +156,17 @@ namespace lunarium { namespace editor
mpMap->ClearMap(); mpMap->ClearMap();
// Add all tilesets that match the Map's tile size // Add all tilesets that match the Map's tile size
((TileSetView*)mPanelManager.GetPanel(gui::PanelType::PT_TILE_SET_VIEW))->ClearTileSets(); ((TileSetView*)mPanelManager.GetPanel(mPanels.TileSetView))->ClearTileSets();
for (auto iter = mTileSets.begin(); iter != mTileSets.end(); iter++) for (auto iter = mTileSets.begin(); iter != mTileSets.end(); iter++)
{ {
if (iter->second->GetTileSize() == mpMap->GetTileSize()) if (iter->second->GetTileSize() == mpMap->GetTileSize())
{ {
mpMap->AddTileSet(iter->second->GetTileSetID(), iter->second); mpMap->AddTileSet(iter->second->GetTileSetID(), iter->second);
((TileSetView*)mPanelManager.GetPanel(gui::PanelType::PT_TILE_SET_VIEW))->AddTileSet(iter->second); ((TileSetView*)mPanelManager.GetPanel(mPanels.TileSetView))->AddTileSet(iter->second);
} }
} }
((MapCanvas*)mPanelManager.GetPanel(gui::PanelType::PT_MAP_CANVAS))->SetTileMap(mpMap); ((MapCanvas*)mPanelManager.GetPanel(mPanels.MapCanvas))->SetTileMap(mpMap);
} }
OpRes MapEditor::LoadMap(std::string map) OpRes MapEditor::LoadMap(std::string map)
@ -282,7 +282,7 @@ namespace lunarium { namespace editor
if (mpMap && mpMap->GetTileSize() == ts->GetTileSize()) if (mpMap && mpMap->GetTileSize() == ts->GetTileSize())
{ {
mpMap->AddTileSet(ts->GetTileSetID(), ts); mpMap->AddTileSet(ts->GetTileSetID(), ts);
((TileSetView*)mPanelManager.GetPanel(gui::PanelType::PT_TILE_SET_VIEW))->AddTileSet(ts); ((TileSetView*)mPanelManager.GetPanel(mPanels.TileSetView))->AddTileSet(ts);
} }
mImportTileSet = false; mImportTileSet = false;
@ -300,6 +300,6 @@ namespace lunarium { namespace editor
void MapEditor::ChangeSelectedTile(TileRef tile) void MapEditor::ChangeSelectedTile(TileRef tile)
{ {
((MapCanvas*)mPanelManager.GetPanel(gui::PanelType::PT_MAP_CANVAS))->SetSelectedTile(tile); ((MapCanvas*)mPanelManager.GetPanel(mPanels.MapCanvas))->SetSelectedTile(tile);
} }
}} }}

@ -60,6 +60,11 @@ namespace editor
Editor* mpEditor; Editor* mpEditor;
PanelManager mPanelManager; PanelManager mPanelManager;
struct
{
uint32_t MapCanvas;
uint32_t TileSetView;
} mPanels;
FileBrowser mFileBrowser; FileBrowser mFileBrowser;

@ -21,7 +21,7 @@
namespace lunarium { namespace editor namespace lunarium { namespace editor
{ {
MapCanvas::MapCanvas(MapEditor* editor) MapCanvas::MapCanvas(MapEditor* editor)
: Panel(gui::PanelType::PT_MAP_CANVAS, "Map Canvas", gui::PanelDockZone::DDZ_CENTER, true), : Panel("Map Canvas", gui::PanelDockZone::DDZ_CENTER, true),
mpMapEditor(editor), mpCanvasImage(nullptr), mMap(nullptr), mSelectedTile({-1, -1}), mFrameBuffer(-1), mMapSizeChanged(false), mpMapEditor(editor), mpCanvasImage(nullptr), mMap(nullptr), mSelectedTile({-1, -1}), mFrameBuffer(-1), mMapSizeChanged(false),
mZoomFactor(1.0f), mScrollDragged(false) mZoomFactor(1.0f), mScrollDragged(false)
{ {

@ -20,7 +20,7 @@
namespace lunarium { namespace editor namespace lunarium { namespace editor
{ {
TileSetView::TileSetView(MapEditor* editor) TileSetView::TileSetView(MapEditor* editor)
: Panel(gui::PanelType::PT_TILE_SET_VIEW, "Tile Set View", gui::PanelDockZone::DDZ_RIGHT, true), : Panel("Tile Set View", gui::PanelDockZone::DDZ_RIGHT, true),
mpEditor(editor), mpSelectedTileSet(nullptr), mpViewImage(nullptr), mFrameBuffer(-1), mpEditor(editor), mpSelectedTileSet(nullptr), mpViewImage(nullptr), mFrameBuffer(-1),
mViewOffset({0, 0}), mViewZoom(1.0f), mMouseDown(false) mViewOffset({0, 0}), mViewZoom(1.0f), mMouseDown(false)
{ {

Loading…
Cancel
Save