From 6aef59c7e304da477a9ec4164ff5951bb5a06604 Mon Sep 17 00:00:00 2001 From: Joeyrp Date: Thu, 24 Feb 2022 15:11:34 -0500 Subject: [PATCH] editor assets refactored to fit the new project content system design --- .gitignore | 5 + src/internal_libs/assets/definitions.h | 6 +- src/run_modes/editor/CMakeLists.txt | 6 +- src/run_modes/editor/editor.h | 13 +-- src/run_modes/editor/panels/worldTree.cpp | 4 +- src/run_modes/editor/panels/worldTree.h | 9 +- .../project/contents/content_manager.cpp | 91 +++++++++++++++++++ .../editor/project/contents/content_manager.h | 55 +++++++++++ .../editor/project/contents/definitions.h | 22 +++++ .../editor/project/contents/editor_asset.cpp | 35 +++++++ .../editor/project/contents/editor_asset.h | 40 ++++++++ .../contents}/tile_map.cpp | 0 .../contents}/tile_map.h | 0 .../contents}/tile_set.cpp | 12 +-- .../contents}/tile_set.h | 8 +- src/run_modes/editor/project/project.cpp | 13 ++- src/run_modes/editor/project/project.h | 18 ++-- .../editor/tools/map_editor/map_editor.cpp | 11 ++- .../editor/tools/map_editor/map_editor.h | 2 + .../tools/map_editor/panels/map_canvas.h | 2 +- .../tools/map_editor/panels/tile_set_view.cpp | 52 +++++++---- .../tools/map_editor/panels/tile_set_view.h | 2 +- src/run_modes/game/world/world.cpp | 4 +- src/run_modes/game/world/world.h | 18 ++-- 24 files changed, 355 insertions(+), 73 deletions(-) create mode 100644 src/run_modes/editor/project/contents/content_manager.cpp create mode 100644 src/run_modes/editor/project/contents/content_manager.h create mode 100644 src/run_modes/editor/project/contents/definitions.h create mode 100644 src/run_modes/editor/project/contents/editor_asset.cpp create mode 100644 src/run_modes/editor/project/contents/editor_asset.h rename src/run_modes/editor/{tools/map_editor => project/contents}/tile_map.cpp (100%) rename src/run_modes/editor/{tools/map_editor => project/contents}/tile_map.h (100%) rename src/run_modes/editor/{tools/map_editor => project/contents}/tile_set.cpp (88%) rename src/run_modes/editor/{tools/map_editor => project/contents}/tile_set.h (82%) diff --git a/.gitignore b/.gitignore index 878e1fd..95ec471 100644 --- a/.gitignore +++ b/.gitignore @@ -36,9 +36,14 @@ *.out *.app +# line counter +.VSCodeCounter + # other *.log *.zip +*.png +*.jpg test_data/test_save.xml ######################## CMAKE IGNORES diff --git a/src/internal_libs/assets/definitions.h b/src/internal_libs/assets/definitions.h index c8cb65a..2f77a0d 100644 --- a/src/internal_libs/assets/definitions.h +++ b/src/internal_libs/assets/definitions.h @@ -6,8 +6,8 @@ * Description - Common graphics definitions ******************************************************************************/ -#ifndef DEFINITIONS_H_ -#define DEFINITIONS_H_ +#ifndef ASSETS_DEFINITIONS_H_ +#define ASSETS_DEFINITIONS_H_ namespace lunarium { @@ -20,4 +20,4 @@ namespace lunarium }; } -#endif // DEFINITIONS_H_ \ No newline at end of file +#endif // ASSETS_DEFINITIONS_H_ \ No newline at end of file diff --git a/src/run_modes/editor/CMakeLists.txt b/src/run_modes/editor/CMakeLists.txt index 87ca19c..3a93313 100644 --- a/src/run_modes/editor/CMakeLists.txt +++ b/src/run_modes/editor/CMakeLists.txt @@ -9,9 +9,11 @@ set(EDITOR_SRC "panels/worldTree.cpp" "panels/worldView.cpp" "panels/propertiesView.cpp" +"project/contents/content_manager.cpp" +"project/contents/editor_asset.cpp" +"project/contents/tile_map.cpp" +"project/contents/tile_set.cpp" "tools/map_editor/map_editor.cpp" -"tools/map_editor/tile_map.cpp" -"tools/map_editor/tile_set.cpp" "tools/map_editor/panels/map_canvas.cpp" "tools/map_editor/panels/tile_set_view.cpp" ) diff --git a/src/run_modes/editor/editor.h b/src/run_modes/editor/editor.h index 91ea60b..2eca385 100644 --- a/src/run_modes/editor/editor.h +++ b/src/run_modes/editor/editor.h @@ -20,12 +20,13 @@ #include #include -namespace lunarium +namespace lunarium { class FileBrowser; - namespace editor - { +} +namespace lunarium { namespace editor +{ enum ToolType { TT_MAIN_EDITOR, @@ -41,7 +42,7 @@ namespace lunarium public: Editor(); - OpRes Initialize(); + [[nodiscard]] OpRes Initialize(); void Shutdown(); void OnTick(double delta); void OnRender(lunarium::IGraphics* g); @@ -88,7 +89,7 @@ namespace lunarium void HandleOpenPanel(const char* name, gui::PanelType type); }; - } -} + +}} #endif // EDITOR_H_ \ No newline at end of file diff --git a/src/run_modes/editor/panels/worldTree.cpp b/src/run_modes/editor/panels/worldTree.cpp index 16aadc1..f2e73d0 100644 --- a/src/run_modes/editor/panels/worldTree.cpp +++ b/src/run_modes/editor/panels/worldTree.cpp @@ -21,12 +21,12 @@ namespace editor } - void WorldTree::SetWorld(World* pWorld) + void WorldTree::SetWorld(lunarium::game::World* pWorld) { mpWorld = pWorld; } - World* WorldTree::GetWorld() + lunarium::game::World* WorldTree::GetWorld() { return mpWorld; } diff --git a/src/run_modes/editor/panels/worldTree.h b/src/run_modes/editor/panels/worldTree.h index 03f86ce..6d837a0 100644 --- a/src/run_modes/editor/panels/worldTree.h +++ b/src/run_modes/editor/panels/worldTree.h @@ -13,7 +13,8 @@ namespace lunarium { - class World; + namespace game { class World; } + namespace editor { class WorldTree : public gui::Panel @@ -21,13 +22,13 @@ namespace editor public: WorldTree(); - void SetWorld(World* pWorld); - World* GetWorld(); + void SetWorld(lunarium::game::World* pWorld); + lunarium::game::World* GetWorld(); bool DoFrame(); private: - World* mpWorld; + lunarium::game::World* mpWorld; }; } } diff --git a/src/run_modes/editor/project/contents/content_manager.cpp b/src/run_modes/editor/project/contents/content_manager.cpp new file mode 100644 index 0000000..f01d596 --- /dev/null +++ b/src/run_modes/editor/project/contents/content_manager.cpp @@ -0,0 +1,91 @@ +/****************************************************************************** +* File - content_manager.cpp +* Author - Joey Pollack +* Date - 2022/02/22 (y/m/d) +* Mod Date - 2022/02/22 (y/m/d) +* Description - Keeps track of all resource files in the project. +* Reads/Writes meta-data to the contents_meta.xml file. +* Also manages the physical location of each asset file. +******************************************************************************/ + +#include "content_manager.h" +#include "../project.h" +#include + +namespace lunarium { namespace editor +{ + ContentManager* ContentManager::mpInstance = nullptr; + + ContentManager::ContentManager() + : mpProject(nullptr) + { + + } + + ContentManager& ContentManager::GetInstance() + { + if (!mpInstance) + { + mpInstance = new ContentManager(); + } + + return *mpInstance; + } + + void ContentManager::FreeInstance() + { + if (mpInstance) + { + delete mpInstance; + mpInstance = nullptr; + } + } + + OpRes ContentManager::Load(Project* project) + { + mpProject = project; + std::filesystem::path root = mpProject->GetRootDirectory(); + mContentFile = root / "contents/content_meta.xml"; + + if (!std::filesystem::exists(mContentFile)) + { + pugi::xml_document doc; + pugi::xml_node proj_node = doc.append_child("Contents"); + if (!doc.save_file(mContentFile.string().c_str())) + { + return OpRes::Fail("ContentManager could not save file: %s", mContentFile.string().c_str()); + } + + return OpRes::OK(); + } + + return OpRes::Fail("ContentManager::Load not implemented"); + } + + OpRes ContentManager::Save() + { + return OpRes::Fail("ContentManager::Save not implemented"); + } + + void ContentManager::Unload() + { + mpProject = nullptr; + mAssets.clear(); + mContentFile = ""; + } + + OpRes ContentManager::ImportFile(std::filesystem::path file, AssetType type) + { + return OpRes::Fail("ContentManager::ImportFile not implemented"); + } + + void ContentManager::MoveAsset(EditorAsset* asset, std::filesystem::path to) + { + + } + + void ContentManager::RenameAsset(EditorAsset* asset, std::string name) + { + + } +}} \ No newline at end of file diff --git a/src/run_modes/editor/project/contents/content_manager.h b/src/run_modes/editor/project/contents/content_manager.h new file mode 100644 index 0000000..edfd9e3 --- /dev/null +++ b/src/run_modes/editor/project/contents/content_manager.h @@ -0,0 +1,55 @@ +/****************************************************************************** +* File - content_manager.h +* Author - Joey Pollack +* Date - 2022/02/22 (y/m/d) +* Mod Date - 2022/02/22 (y/m/d) +* Description - Keeps track of all resource files in the project. +* Reads/Writes meta-data to the contents_meta.xml file. +* Also manages the physical location of each asset file. +******************************************************************************/ + +#ifndef CONTENT_MANAGER_H_ +#define CONTENT_MANAGER_H_ + +#include "definitions.h" +#include +#include +#include +#include + +namespace lunarium { namespace editor +{ + + class Project; + class EditorAsset; + + class ContentManager + { + public: + + static ContentManager& GetInstance(); + static void FreeInstance(); + + [[nodiscard]] OpRes Load(Project* project); + [[nodiscard]] OpRes Save(); + void Unload(); + + [[nodiscard]] OpRes ImportFile(std::filesystem::path file, AssetType type); + void MoveAsset(EditorAsset* asset, std::filesystem::path to); + void RenameAsset(EditorAsset* asset, std::string name); + + private: + static ContentManager* mpInstance; + Project* mpProject; + std::filesystem::path mContentFile; + std::map mAssets; + + private: + ContentManager(); + ContentManager(ContentManager&) = delete; + ContentManager& operator=(const ContentManager&) = delete; + + }; +}} + +#endif // CONTENT_MANAGER_H_ \ No newline at end of file diff --git a/src/run_modes/editor/project/contents/definitions.h b/src/run_modes/editor/project/contents/definitions.h new file mode 100644 index 0000000..db9341f --- /dev/null +++ b/src/run_modes/editor/project/contents/definitions.h @@ -0,0 +1,22 @@ +/****************************************************************************** +* File - definitions.h +* Author - Joey Pollack +* Date - 2022/02/24 (y/m/d) +* Mod Date - 2022/02/24 (y/m/d) +* Description - file for common defintions for the editor content system +******************************************************************************/ + +#ifndef EDITOR_ASSETS_DEFINITIONS_H_ +#define EDITOR_ASSETS_DEFINITIONS_H_ + +namespace lunarium { namespace editor +{ + enum AssetType + { + EATYPE_IMAGE, + EATYPE_TILE_SET, + EATYPE_TILE_MAP, + }; +}} + +#endif // EDITOR_ASSETS_DEFINITIONS_H_ \ No newline at end of file diff --git a/src/run_modes/editor/project/contents/editor_asset.cpp b/src/run_modes/editor/project/contents/editor_asset.cpp new file mode 100644 index 0000000..fb5c08f --- /dev/null +++ b/src/run_modes/editor/project/contents/editor_asset.cpp @@ -0,0 +1,35 @@ +/****************************************************************************** +* File - editor_asset.h +* Author - Joey Pollack +* Date - 2022/02/22 (y/m/d) +* Mod Date - 2022/02/22 (y/m/d) +* Description - Editor assets base class +******************************************************************************/ + +#include "editor_asset.h" + +namespace lunarium { namespace editor { + + EditorAsset::EditorAsset(AssetType type) + : mType(type) + { + + } + + + AssetType EditorAsset::GetType() + { + return mType; + } + + uint64_t EditorAsset::GetID() + { + return mID; + } + + std::filesystem::path EditorAsset::GetFileLocation() + { + return mLocation; + } + +}} \ No newline at end of file diff --git a/src/run_modes/editor/project/contents/editor_asset.h b/src/run_modes/editor/project/contents/editor_asset.h new file mode 100644 index 0000000..eccc80f --- /dev/null +++ b/src/run_modes/editor/project/contents/editor_asset.h @@ -0,0 +1,40 @@ +/****************************************************************************** +* File - editor_asset.h +* Author - Joey Pollack +* Date - 2022/02/22 (y/m/d) +* Mod Date - 2022/02/22 (y/m/d) +* Description - Editor assets base class +******************************************************************************/ + +#ifndef EDITOR_ASSETS_H_ +#define EDITOR_ASSETS_H_ + +#include "definitions.h" +#include "content_manager.h" +#include +#include + +namespace lunarium { namespace editor +{ + + class EditorAsset + { + public: + EditorAsset(AssetType type); + + AssetType GetType(); + uint64_t GetID(); + std::filesystem::path GetFileLocation(); + + private: + friend class ContentManager; + + AssetType mType; + uint64_t mID; + std::filesystem::path mLocation; + + protected: + }; +}} + +#endif // EDITOR_ASSETS_H_ \ No newline at end of file diff --git a/src/run_modes/editor/tools/map_editor/tile_map.cpp b/src/run_modes/editor/project/contents/tile_map.cpp similarity index 100% rename from src/run_modes/editor/tools/map_editor/tile_map.cpp rename to src/run_modes/editor/project/contents/tile_map.cpp diff --git a/src/run_modes/editor/tools/map_editor/tile_map.h b/src/run_modes/editor/project/contents/tile_map.h similarity index 100% rename from src/run_modes/editor/tools/map_editor/tile_map.h rename to src/run_modes/editor/project/contents/tile_map.h diff --git a/src/run_modes/editor/tools/map_editor/tile_set.cpp b/src/run_modes/editor/project/contents/tile_set.cpp similarity index 88% rename from src/run_modes/editor/tools/map_editor/tile_set.cpp rename to src/run_modes/editor/project/contents/tile_set.cpp index 7d48105..49e2886 100644 --- a/src/run_modes/editor/tools/map_editor/tile_set.cpp +++ b/src/run_modes/editor/project/contents/tile_set.cpp @@ -15,16 +15,11 @@ namespace lunarium { namespace editor { TileSet::TileSet() - : mSetImage(nullptr), mTileSize({ 0, 0}) + : EditorAsset(AssetType::EATYPE_TILE_SET), mSetImage(nullptr), mTileSize({ 0, 0}) { } - void TileSet::SetFileLocation(std::filesystem::path path) - { - mFileLocation = path; - } - void TileSet::SetImage(Image* image) { mSetImage = image; @@ -37,11 +32,6 @@ namespace lunarium { namespace editor mNumTiles.Height = mSetImage->GetHeight() / mTileSize.Height; } - std::filesystem::path TileSet::GetFileLocation() - { - return mFileLocation; - } - Image* TileSet::GetImage() { return mSetImage; diff --git a/src/run_modes/editor/tools/map_editor/tile_set.h b/src/run_modes/editor/project/contents/tile_set.h similarity index 82% rename from src/run_modes/editor/tools/map_editor/tile_set.h rename to src/run_modes/editor/project/contents/tile_set.h index d2835bd..3f03edc 100644 --- a/src/run_modes/editor/tools/map_editor/tile_set.h +++ b/src/run_modes/editor/project/contents/tile_set.h @@ -9,6 +9,7 @@ #ifndef TILE_SET_H_ #define TILE_SET_H_ +#include "editor_asset.h" #include #include @@ -16,16 +17,14 @@ namespace lunarium { class Image; class IGraphics; } namespace lunarium { namespace editor { - class TileSet + class TileSet : public EditorAsset { public: TileSet(); - - void SetFileLocation(std::filesystem::path path); + void SetImage(Image* image); void SetTileSize(Sizei size); - std::filesystem::path GetFileLocation(); Image* GetImage(); Sizei GetTileSize(); Rectangle GetTileRect(Vec2i index); @@ -33,7 +32,6 @@ namespace lunarium { namespace editor void Render(lunarium::IGraphics* g); private: - std::filesystem::path mFileLocation; Image* mSetImage; Sizei mTileSize; // in pixels, must be a square power of 2 Sizei mNumTiles; diff --git a/src/run_modes/editor/project/project.cpp b/src/run_modes/editor/project/project.cpp index 3c621ee..ef647a3 100644 --- a/src/run_modes/editor/project/project.cpp +++ b/src/run_modes/editor/project/project.cpp @@ -7,10 +7,11 @@ ******************************************************************************/ #include "project.h" - +#include +#include "contents/content_manager.h" #include -namespace lunarium +namespace lunarium { namespace editor { Project::Project() : mIsLoaded(false) @@ -49,6 +50,12 @@ namespace lunarium std::filesystem::create_directory(mLocation / std::filesystem::path("contents")); std::filesystem::create_directory(mLocation / std::filesystem::path("contents/assets")); + mpContentManager = &ContentManager::GetInstance(); + if (Failed(mpContentManager->Load(this).LogIfFailed(Editor::LogCat))) + { + return OpRes::Fail("Could not load project in content manager"); + } + mIsLoaded = true; return OpRes::OK(); } @@ -94,4 +101,4 @@ namespace lunarium { return mLocation; } -} \ No newline at end of file +}} \ No newline at end of file diff --git a/src/run_modes/editor/project/project.h b/src/run_modes/editor/project/project.h index 4347410..fb1dd65 100644 --- a/src/run_modes/editor/project/project.h +++ b/src/run_modes/editor/project/project.h @@ -15,19 +15,21 @@ #include #include -namespace lunarium +namespace lunarium { namespace editor { - class Scene; + class ContentManager; + class World; + class Project { public: Project(); /// location should NOT include the project file - OpRes GenerateProject(std::string name, std::filesystem::path location); + [[nodiscard]] OpRes GenerateProject(std::string name, std::filesystem::path location); /// location should be the full path including the project file - OpRes LoadProject(std::filesystem::path location); + [[nodiscard]] OpRes LoadProject(std::filesystem::path location); void UnloadCurrentProject(); void SaveProject(); @@ -40,8 +42,12 @@ namespace lunarium std::string mName; std::filesystem::path mLocation; - std::vector mScenes; + ContentManager* mpContentManager; + std::vector mWorlds; + + private: + void LoadContent(); }; -} +}} #endif // PROJECT_H_ \ No newline at end of file diff --git a/src/run_modes/editor/tools/map_editor/map_editor.cpp b/src/run_modes/editor/tools/map_editor/map_editor.cpp index 0a5f388..4947a94 100644 --- a/src/run_modes/editor/tools/map_editor/map_editor.cpp +++ b/src/run_modes/editor/tools/map_editor/map_editor.cpp @@ -14,8 +14,8 @@ #include #include #include -#include "tile_set.h" -#include "tile_map.h" +#include +#include // Panels #include "panels/map_canvas.h" @@ -150,6 +150,11 @@ namespace lunarium { namespace editor return mMapLoaded; } + const std::map* MapEditor::GetTileSets() const + { + return &mTileSets; + } + //////////////////////////////////////////////////////////// // HELPERS //////////////////////////////////////////////////////////// @@ -229,7 +234,7 @@ namespace lunarium { namespace editor Core::Graphics().RegisterImage(*i); TileSet* ts = new TileSet(); - ts->SetFileLocation(*path); + // ts->SetFileLocation(*path); ts->SetImage(i); ts->SetTileSize({16, 16}); // NOTE: Hardcoding the tile size for testing diff --git a/src/run_modes/editor/tools/map_editor/map_editor.h b/src/run_modes/editor/tools/map_editor/map_editor.h index fc3b2fa..db2a26d 100644 --- a/src/run_modes/editor/tools/map_editor/map_editor.h +++ b/src/run_modes/editor/tools/map_editor/map_editor.h @@ -46,6 +46,8 @@ namespace editor void SaveMap(); bool IsMapLoaded() const; + const std::map* GetTileSets() const; + private: bool mIsOpen; diff --git a/src/run_modes/editor/tools/map_editor/panels/map_canvas.h b/src/run_modes/editor/tools/map_editor/panels/map_canvas.h index 2a4d9a1..2d924f7 100644 --- a/src/run_modes/editor/tools/map_editor/panels/map_canvas.h +++ b/src/run_modes/editor/tools/map_editor/panels/map_canvas.h @@ -10,7 +10,7 @@ #define MAP_CANVAS_H_ #include -#include "../tile_map.h" +#include #include #include diff --git a/src/run_modes/editor/tools/map_editor/panels/tile_set_view.cpp b/src/run_modes/editor/tools/map_editor/panels/tile_set_view.cpp index e8d48b6..dad9e1b 100644 --- a/src/run_modes/editor/tools/map_editor/panels/tile_set_view.cpp +++ b/src/run_modes/editor/tools/map_editor/panels/tile_set_view.cpp @@ -8,7 +8,7 @@ #include "tile_set_view.h" #include "../map_editor.h" -#include "../tile_set.h" +#include #include #include #include @@ -21,7 +21,7 @@ namespace lunarium { namespace editor { TileSetView::TileSetView(MapEditor* editor) : Panel(gui::PanelType::PT_TILE_SET_VIEW, "Tile Set View", gui::PanelDockZone::DDZ_RIGHT, true), - mpEditor(editor), mpTileSet(nullptr), mpViewImage(nullptr), mFrameBuffer(-1), + mpEditor(editor), mpSelectedTileSet(nullptr), mpViewImage(nullptr), mFrameBuffer(-1), mViewOffset({0, 0}), mViewZoom(1.0f), mMouseDown(false) { @@ -47,7 +47,7 @@ namespace lunarium { namespace editor // Check that it's within the window bool is_in_window = x >= 0.0f && x < mWorkAreaSize.X && y >= 0.0f && y < mWorkAreaSize.Y; - if (is_in_window && mpTileSet) + if (is_in_window && mpSelectedTileSet) { // Adjust for scrolling x += mScrollOffset.X; @@ -56,8 +56,8 @@ namespace lunarium { namespace editor //Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Mouse Pos scrolled (%f, %f)", x, y); // Find selected tile - mSelectedTile.X = x / mpTileSet->GetTileSize().Width; - mSelectedTile.Y = y / mpTileSet->GetTileSize().Height; + mSelectedTile.X = x / mpSelectedTileSet->GetTileSize().Width; + mSelectedTile.Y = y / mpSelectedTileSet->GetTileSize().Height; //Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Updating Tile Selection: tile (%d, %d)", mSelectedTile.X, mSelectedTile.Y); @@ -73,11 +73,11 @@ namespace lunarium { namespace editor if (mInvalidate) { - if (mpTileSet) + if (mpSelectedTileSet) { if (mFrameBuffer == -1) { - mFrameBuffer = Core::Graphics().CreateRenderTexture(mpTileSet->GetImage()->GetWidth(), mpTileSet->GetImage()->GetHeight(), 4); + mFrameBuffer = Core::Graphics().CreateRenderTexture(mpSelectedTileSet->GetImage()->GetWidth(), mpSelectedTileSet->GetImage()->GetHeight(), 4); } //Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Invalidating tile set window"); @@ -86,12 +86,12 @@ namespace lunarium { namespace editor Core::Graphics().SetClearColor(Color::Transparent()); Core::GetInstance().BeginRenderToTexture(mFrameBuffer).LogIfFailed(Editor::LogCat); - mpTileSet->Render(&Core::Graphics()); + mpSelectedTileSet->Render(&Core::Graphics()); // Draw selected tile highlight if (mSelectedTile.X >= 0 && mSelectedTile.Y >= 0) { - Rectangle selection = mpTileSet->GetTileRect(mSelectedTile); + Rectangle selection = mpSelectedTileSet->GetTileRect(mSelectedTile); Core::Graphics().DrawBox(selection, Color::Red(), 1.5f); } @@ -126,12 +126,31 @@ namespace lunarium { namespace editor float child_height = ImGui::GetFrameHeight() * 2; ImGui::BeginChild(ImGui::GetID(GetName()), ImVec2(ImGui::GetWindowSize().x, child_height), true); - ImGui::TextUnformatted("THIS IS SOME PLACEHOLDER TEXT -- ADD TOOLS HERE FOR SELECTING TILE SETS"); - ImGui::EndChild(); + // ImGui::TextUnformatted("THIS IS SOME PLACEHOLDER TEXT -- ADD TOOLS HERE FOR SELECTING TILE SETS"); + std::string name = ""; + if (mpSelectedTileSet) + { + name = mpSelectedTileSet->GetFileLocation().filename().string(); + } + if (ImGui::BeginCombo("Tile Sets", name.c_str())) + { + auto tile_sets = mpEditor->GetTileSets(); + for (auto iter = tile_sets->begin(); iter != tile_sets->end(); iter++) + { + bool selected = false; + if (ImGui::Selectable(iter->second->GetFileLocation().filename().string().c_str(), &selected)) + { + ImGui::SetItemDefaultFocus(); + mpSelectedTileSet = iter->second; + Invalidate(); + } + } + + ImGui::EndCombo(); + } + - ImVec2 test = ImGui::GetWindowSize(); - test.y -= child_height; - //ImGui::BeginChild(ImGui::GetID(GetName()), ImVec2(ImGui::GetWindowSize().x, test.y)); + ImGui::EndChild(); mWorkAreaPos = { ImGui::GetWindowPos().x, ImGui::GetWindowPos().y }; mWorkAreaSize = { ImGui::GetWindowSize().x, ImGui::GetWindowSize().y }; @@ -151,20 +170,19 @@ namespace lunarium { namespace editor ImVec2(mpViewImage->GetWidth(), mpViewImage->GetHeight()), ImVec2(0, 1), ImVec2(1, 0)); // the last 2 params are flipping the image on the y } - //ImGui::EndChild(); ImGui::End(); return mIsOpen; } void TileSetView::SetTileSet(TileSet* set) { - mpTileSet = set; + mpSelectedTileSet = set; Invalidate(true); } TileSet* TileSetView::GetTileSet() { - return mpTileSet; + return mpSelectedTileSet; } diff --git a/src/run_modes/editor/tools/map_editor/panels/tile_set_view.h b/src/run_modes/editor/tools/map_editor/panels/tile_set_view.h index 491e70c..01b4e03 100644 --- a/src/run_modes/editor/tools/map_editor/panels/tile_set_view.h +++ b/src/run_modes/editor/tools/map_editor/panels/tile_set_view.h @@ -36,7 +36,7 @@ namespace lunarium { namespace editor private: MapEditor* mpEditor; - TileSet* mpTileSet; + TileSet* mpSelectedTileSet; int mFrameBuffer; bool mInvalidate; Image* mpViewImage; diff --git a/src/run_modes/game/world/world.cpp b/src/run_modes/game/world/world.cpp index 61207fd..ccf3902 100644 --- a/src/run_modes/game/world/world.cpp +++ b/src/run_modes/game/world/world.cpp @@ -16,7 +16,7 @@ #include #include -namespace lunarium +namespace lunarium { namespace game { World::World(Camera* pCam, Sizei region_size, Sizei world_size) : mpCamera(pCam), mRegionSize(region_size), mpWorldScript(nullptr), mRegions(region_size), mWorldSize(world_size) @@ -108,4 +108,4 @@ namespace lunarium return mpWorldScript; } -} \ No newline at end of file +}} \ No newline at end of file diff --git a/src/run_modes/game/world/world.h b/src/run_modes/game/world/world.h index 1379bc2..5a208bb 100644 --- a/src/run_modes/game/world/world.h +++ b/src/run_modes/game/world/world.h @@ -21,20 +21,24 @@ namespace lunarium { class Graphics; + class Image; + class Script; +} + +namespace lunarium { namespace game +{ class Camera; class GameObject; - class Script; - class Image; class World { public: struct Region { - Script* mRegionScript; + lunarium::Script* mRegionScript; Vec2i mCoords; std::vector mObjects; - std::vector mLayers; + std::vector mLayers; }; public: // INTERFACE @@ -58,13 +62,13 @@ namespace lunarium bool RemoveRegion(Vec2i at); void SetWorldScript(Script* pScript); - Script* GetWorldScript(); + lunarium::Script* GetWorldScript(); private: Camera* mpCamera; std::vector mWorldObjects; - Script* mpWorldScript; + lunarium::Script* mpWorldScript; Sizei mRegionSize; // in pixels Sizei mWorldSize; // num regions ex. 10x10 Grid mRegions; @@ -72,6 +76,6 @@ namespace lunarium }; -} +}} #endif // WORLD_H_ \ No newline at end of file