Asset Browser now has references to the actual EditorAsset objects and can detect single click selection and double click open actions

gui_api_redesign
Joey Pollack 4 years ago
parent 9dede57b96
commit c3df5775d0

@ -41,6 +41,7 @@ Editor:
Scene Hierarchy (Tree View):
Asset Viewer:
✔ Get references to the EditorAsset objects instead of the raw file locations @done(22-06-01 18:48)
☐ Put files into a table with columns for the file Properties
Tools:

@ -11,7 +11,13 @@
namespace lunarium
{
Asset::Asset(AssetType type)
: mType(type)
: mType(type), mUUID(0)
{
}
Asset::Asset(LUUID uuid, AssetType type)
: mType(type), mUUID(uuid)
{
}
@ -26,4 +32,9 @@ namespace lunarium
return mType;
}
LUUID Asset::GetUUID() const
{
return mUUID;
}
}

@ -9,6 +9,8 @@
#ifndef ASSET_H_
#define ASSET_H_
#include <core/common_defs.h>
namespace lunarium
{
enum AssetType
@ -23,11 +25,15 @@ namespace lunarium
{
public:
Asset(AssetType type = AssetType::ASSET_TYPE_UNKNOWN);
Asset(LUUID uuid, AssetType type = AssetType::ASSET_TYPE_UNKNOWN);
virtual ~Asset() = 0;
AssetType GetType() const;
LUUID GetUUID() const;
private:
AssetType mType;
LUUID mUUID;
};
}

@ -13,6 +13,7 @@ namespace lunarium
void Script::SetScript(const char* script)
{
mScript = script;
mScriptErrors.clear();
}
const char* Script::GetScript() const

@ -17,7 +17,7 @@ namespace lunarium { namespace editor
{
ImGui::Text("Tag:");
ImGui::SameLine();
ImGui::InputText("##Tag", comp.Info.data(), comp.Info.capacity())
ImGui::InputText("##Tag", comp.Info.data(), comp.Info.capacity());
}
void CompGui::RenderTransformComp(TransformComponent& comp)

@ -217,6 +217,19 @@ namespace lunarium { namespace editor
}
}
void ContentManager::GetAllAssetsInDirectory(std::vector<EditorAsset*>& container, std::filesystem::path dir)
{
container.clear();
for (auto iter = mAssets.begin(); iter != mAssets.end(); iter++)
{
auto temp = iter->second->GetFileLocation().remove_filename();
if (temp == dir)
{
container.push_back(iter->second);
}
}
}
EditorAsset* ContentManager::GetAsset(uint64_t id)
{
auto iter = mAssets.find(id);

@ -38,8 +38,10 @@ namespace lunarium { namespace editor
void GetAllAssetIDs(std::vector<uint64_t>& container) const;
void GetAllAssetsByType(std::vector<EditorAsset*>& container, AssetType type) const;
void GetAllAssetsInDirectory(std::vector<EditorAsset*>& container, std::filesystem::path dir); // dir should be relative to the asset dir
EditorAsset* GetAsset(uint64_t id);
/// Add an asset that was generated by the editor (like tile maps or scripts)
[[nodiscard]] OpRes AddGeneratedAsset(EditorAsset* asset, uint64_t& id);

@ -68,17 +68,11 @@ namespace editor
return res;
}
mPanelManager.AddPanel(new AssetBrowser(""), mPanels.AssetBrowser).LogIfFailed(LogCat);
mPanelManager.AddPanel(new AssetBrowser("", this), mPanels.AssetBrowser).LogIfFailed(LogCat);
mPanelManager.AddPanel(new WorldTree(), mPanels.WorldTree).LogIfFailed(LogCat);
mPanelManager.AddPanel(new WorldView(), mPanels.WorldView).LogIfFailed(LogCat);
mPanelManager.AddPanel(new PropertiesView(), mPanels.PropertiesView).LogIfFailed(LogCat);
// TEST ENTITY
mTestWorld = new lunarium::World;
mTestEntity = mTestWorld->CreateEntity();
mTestWorld->GetEntity(mTestEntity)->AddComponent<TagComponent>();
((PropertiesView*)mPanelManager.GetPanel(mPanels.PropertiesView))->SetSelection(mTestWorld->GetEntity(mTestEntity));
return OpRes::OK();
}

@ -52,6 +52,8 @@ namespace lunarium { namespace editor
unsigned int GetNextWindowID();
bool IsToolOpen(ToolType type) const;
void ChangeWorld(lunarium::World* pWorld);
std::filesystem::path GetAssetBrowserLocation();
Project* GetProject();
@ -61,7 +63,7 @@ namespace lunarium { namespace editor
private: // Data
PanelManager mPanelManager;
lunarium::World* mTestWorld;
lunarium::World* mWorld;
Project mProject;
// Tools
@ -89,7 +91,6 @@ namespace lunarium { namespace editor
bool mDoSaveAs;
// TEST DATA
LUUID mTestEntity;
private: // HELPERS

@ -9,14 +9,17 @@
#include "asset_browser.h"
#include <dearimgui/imgui.h>
#include <editor/editor.h>
#include <editor/contents/content_manager.h>
#include <editor/contents/editor_asset.h>
#include <utils/logger.h>
namespace lunarium
{
namespace editor
{
AssetBrowser::AssetBrowser(std::filesystem::path dir)
AssetBrowser::AssetBrowser(std::filesystem::path dir, Editor* pEditor)
: Panel("Asset Browser", gui::PanelDockZone::DDZ_BOTTOM, true),
mAssetDirectory(dir), mTreeRoot(nullptr), mSelectedNode(nullptr)
mAssetDirectory(dir), mTreeRoot(nullptr), mSelectedNode(nullptr), mpEditor(pEditor)
{
mTreeRoot = ReloadAssets(mAssetDirectory);
mSelectedNode = mTreeRoot;
@ -72,15 +75,44 @@ namespace editor
// Display each file in a row
for(auto const& dir_entry: std::filesystem::directory_iterator{mSelectedDir})
// for(auto const& dir_entry: std::filesystem::directory_iterator{mSelectedDir})
// {
// if (!std::filesystem::is_directory(dir_entry))
// {
// // TODO: Turn into a table with file properties as columns
// ImGui::TextWrapped(dir_entry.path().filename().string().c_str());
// }
// }
std::filesystem::path selected_final = mpEditor->GetProject()->MakeRelativeToAssets(mSelectedDir);
std::vector<EditorAsset*> assets;
ContentManager::GetInstance().GetAllAssetsInDirectory(assets, selected_final);
for (auto iter = assets.begin(); iter != assets.end(); iter++)
{
if (!std::filesystem::is_directory(dir_entry))
if (ImGui::Selectable((*iter)->GetFileLocation().stem().string().c_str()))
{
// TODO: Turn into a table with file properties as columns
ImGui::TextWrapped(dir_entry.path().filename().string().c_str());
// TODO: Show properties if this is new selection (meaning wasn't selected last frame)
Logger::Info(Editor::LogCat, "Asset selected. Properties shold show in the PropertiesView Panel");
}
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
// TODO: Open relevant editor
Logger::Info(Editor::LogCat, "Asset double clicked on. Relevant editor should open!");
}
}
if (ImGui::BeginPopupContextWindow(0, 1, false))
{
if (ImGui::Button("Click Me!"))
{
Logger::Info(Editor::LogCat, "Context menu button clicked!");
}
ImGui::EndPopup();
}
}
}
ImGui::EndChild();

@ -10,6 +10,7 @@
#define ASSET_BROWSER_H_
#include <gui/panel.h>
#include <editor/editor.h>
#include <filesystem>
#include <vector>
@ -21,7 +22,7 @@ namespace editor
class AssetBrowser : public gui::Panel
{
public:
AssetBrowser(std::filesystem::path dir);
AssetBrowser(std::filesystem::path dir, Editor* pEditor);
void SetAssetDirectory(std::filesystem::path dir);
@ -42,6 +43,7 @@ namespace editor
std::filesystem::path mSelectedDir;
Node* mTreeRoot;
Node* mSelectedNode;
Editor* mpEditor;
private:
Node* ReloadAssets(std::filesystem::path dir);

@ -17,7 +17,7 @@
namespace lunarium { namespace editor
{
PropertiesView::PropertiesView()
: Panel("Properties", gui::PanelDockZone::DDZ_RIGHT, true)
: Panel("Properties", gui::PanelDockZone::DDZ_RIGHT, true), mpSelectedAsset(nullptr), mpSelectedEntity(nullptr)
{
}

@ -49,6 +49,12 @@ namespace editor
ImGui::TreePop();
}
if (ImGui::BeginPopupContextWindow(0, ImGuiPopupFlags_MouseButtonRight))
{
ImGui::EndPopup();
}
ImGui::End();
return true;
}

@ -55,16 +55,6 @@ namespace lunarium
}
// void World::AddGameObject(GameObject* pObj)
// {
// }
// bool World::RemoveGameObject(GameObject* pObj)
// {
// }
void World::SetWorldScript(Script* pScript)
{
@ -85,6 +75,12 @@ namespace lunarium
{
//Logger::Error(LogCategory::GAME_SYSTEM, "World::CreateEntity not implemented!");
Entity* new_ent = new Entity(*this);
if (mEntities.find(new_ent->GetUUID()) != mEntities.end())
{
Logger::Warn(LogCategory::GAME_SYSTEM, "UUID collision when creating new entity! UUID: %d", new_ent->GetUUID());
}
mEntities[new_ent->GetUUID()] = new_ent;
return new_ent->GetUUID();
}
@ -92,6 +88,10 @@ namespace lunarium
Entity* World::GetEntity(LUUID id)
{
if (mEntities.find(id) == mEntities.end())
{
Logger::Warn(LogCategory::GAME_SYSTEM, "Entity with id: %d not found.", id);
}
return mEntities[id];
}

@ -1,3 +1,10 @@
[Window][Asset Browser]
Pos=0,546
Size=1280,174
Collapsed=0
DockId=0x00000003,0
ClassId=0x00000001
[Window][World Tree]
Pos=0,24
Size=204,520
@ -12,13 +19,6 @@ Collapsed=0
DockId=0x00000008,0
ClassId=0x00000001
[Window][Asset Browser]
Pos=0,546
Size=1280,174
Collapsed=0
DockId=0x00000003,0
ClassId=0x00000001
[Window][Properties]
Pos=1024,24
Size=256,520
@ -36,44 +36,55 @@ Pos=60,60
Size=400,400
Collapsed=0
[Window][File Browser]
ViewportPos=526,598
ViewportId=0x2389D759
Size=600,400
Collapsed=0
[Window][Map Editor]
ViewportPos=416,108
ViewportPos=622,126
ViewportId=0xDAA48CA2
Size=1290,772
Size=1056,762
Collapsed=0
[Window][Map Canvas]
ViewportPos=416,108
ViewportPos=622,126
ViewportId=0xDAA48CA2
Pos=8,56
Size=943,708
Size=830,698
Collapsed=0
DockId=0x0000000E,0
ClassId=0x000000C3
ClassId=0x00000045
[Window][Tile Set View]
ViewportPos=416,108
ViewportPos=622,126
ViewportId=0xDAA48CA2
Pos=953,56
Size=329,708
Pos=840,56
Size=208,698
Collapsed=0
DockId=0x0000000C,0
ClassId=0x000000C3
ClassId=0x00000045
[Window][File Browser]
Pos=150,80
Size=600,400
[Window][DockSpaceViewport_11111111]
Size=1280,720
Collapsed=0
[Window][Dear ImGui Demo]
ViewportPos=172,128
ViewportId=0xE927CF2F
Size=550,680
Collapsed=0
[Docking][Data]
DockSpace ID=0x27CF68A1 Pos=424,164 Size=1274,708 Split=Y
DockNode ID=0x00000009 Parent=0x27CF68A1 SizeRef=1280,538 Split=X
DockNode ID=0x0000000B Parent=0x00000009 SizeRef=943,538 Split=X
DockNode ID=0x0000000D Parent=0x0000000B SizeRef=204,538
DockNode ID=0x0000000E Parent=0x0000000B SizeRef=816,538 CentralNode=1 Selected=0xB3CA1100
DockNode ID=0x0000000C Parent=0x00000009 SizeRef=329,538 Selected=0xB093288C
DockNode ID=0x0000000A Parent=0x27CF68A1 SizeRef=1280,180
DockSpace ID=0x2F8DD699 Window=0xBEB76114 Pos=244,144 Size=1280,696 Split=Y
DockSpace ID=0x27CF68A1 Pos=630,182 Size=1040,698 Split=Y
DockNode ID=0x00000009 Parent=0x27CF68A1 SizeRef=1056,570 Split=X
DockNode ID=0x0000000B Parent=0x00000009 SizeRef=843,570 Split=X
DockNode ID=0x0000000D Parent=0x0000000B SizeRef=168,570
DockNode ID=0x0000000E Parent=0x0000000B SizeRef=673,570 CentralNode=1 Selected=0xB3CA1100
DockNode ID=0x0000000C Parent=0x00000009 SizeRef=211,570 Selected=0xB093288C
DockNode ID=0x0000000A Parent=0x27CF68A1 SizeRef=1056,190
DockSpace ID=0x2F8DD699 Window=0xBEB76114 Pos=476,90 Size=1280,696 Split=Y
DockNode ID=0x00000001 Parent=0x2F8DD699 SizeRef=1280,538 Split=X
DockNode ID=0x00000005 Parent=0x00000001 SizeRef=1022,538 Split=X
DockNode ID=0x00000007 Parent=0x00000005 SizeRef=204,538 Selected=0xFD1747F8

Loading…
Cancel
Save