|
|
|
@ -27,7 +27,7 @@ namespace editor
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AssetBrowser::AssetBrowser(std::filesystem::path dir, Editor* pEditor)
|
|
|
|
AssetBrowser::AssetBrowser(std::filesystem::path dir, Editor* pEditor)
|
|
|
|
: Panel("Asset Browser", PanelDockZone::DDZ_BOTTOM, true, (ImGuiWindowFlags)ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
|
|
|
|
: Panel("Asset Browser", PanelDockZone::DDZ_BOTTOM, true, (ImGuiWindowFlags)ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
|
|
|
|
mAssetDirectory(dir), mpEditor(pEditor), mSyncTree(false)
|
|
|
|
mAssetDirectory(dir), mpEditor(pEditor), mSyncTree(false), mpHoveredAsset(nullptr), mbMenusOpen(false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DefinePopups();
|
|
|
|
DefinePopups();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -229,6 +229,9 @@ namespace editor
|
|
|
|
|
|
|
|
|
|
|
|
for (auto iter = assets.begin(); iter != assets.end(); iter++)
|
|
|
|
for (auto iter = assets.begin(); iter != assets.end(); iter++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((*iter)->GetIsTrashed())
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if (ImGui::Selectable((*iter)->GetFileLocation().stem().string().c_str()))
|
|
|
|
if (ImGui::Selectable((*iter)->GetFileLocation().stem().string().c_str()))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Show properties if this is new selection (meaning wasn't selected last frame)
|
|
|
|
// Show properties if this is new selection (meaning wasn't selected last frame)
|
|
|
|
@ -252,10 +255,11 @@ namespace editor
|
|
|
|
mpEditor->OnAssetOpen((*iter));
|
|
|
|
mpEditor->OnAssetOpen((*iter));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Right))
|
|
|
|
if (ImGui::IsItemHovered() && ImGui::IsItemClicked(ImGuiMouseButton_Right))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: CONTEXT MENU FOR ITEMS - Test Removing/Trashing
|
|
|
|
// Change context menu to apply to the hovered asset
|
|
|
|
|
|
|
|
mpHoveredAsset = (*iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -271,53 +275,82 @@ namespace editor
|
|
|
|
// CONTEXT MENUS
|
|
|
|
// CONTEXT MENUS
|
|
|
|
void AssetBrowser::DoContentContextMenu()
|
|
|
|
void AssetBrowser::DoContentContextMenu()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (ImGui::BeginPopupContextWindow(0, 1, false))
|
|
|
|
if (ImGui::BeginPopupContextWindow(0, ImGuiPopupFlags_MouseButtonRight))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (ImGui::Button("New Folder"))
|
|
|
|
if (mpHoveredAsset)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//mNewFolder = true;
|
|
|
|
mbMenusOpen = true;
|
|
|
|
OpenPopup(PopUp::NEW_FOLDER).LogIfFailed(Editor::LogCat);
|
|
|
|
DoHoveredContextMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DoEmptySpaceContextMenu();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Buttons for creating/importing new assets
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (mbMenusOpen)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mbMenusOpen = false;
|
|
|
|
|
|
|
|
mpHoveredAsset = nullptr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AssetBrowser::DoHoveredContextMenu()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ImGui::Button("Trash Asset"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mpEditor->OnAssetTrash(mpHoveredAsset);
|
|
|
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
|
|
|
mpHoveredAsset = nullptr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AssetBrowser::DoEmptySpaceContextMenu()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ImGui::Button("New Folder"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// mNewFolder = true;
|
|
|
|
|
|
|
|
OpenPopup(PopUp::NEW_FOLDER).LogIfFailed(Editor::LogCat);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ImGui::BeginMenu("New Asset"))
|
|
|
|
if (ImGui::BeginMenu("New Asset"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ImGui::MenuItem("New World"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (ImGui::MenuItem("New World"))
|
|
|
|
OpenPopup(PopUp::NEW_WORLD).LogIfFailed(Editor::LogCat);
|
|
|
|
{
|
|
|
|
}
|
|
|
|
OpenPopup(PopUp::NEW_WORLD).LogIfFailed(Editor::LogCat);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ImGui::MenuItem("New Script"))
|
|
|
|
if (ImGui::MenuItem("New Script"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OpenPopup(PopUp::NEW_SCRIPT).LogIfFailed(Editor::LogCat);
|
|
|
|
OpenPopup(PopUp::NEW_SCRIPT).LogIfFailed(Editor::LogCat);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ImGui::BeginMenu("Import Asset"))
|
|
|
|
if (ImGui::BeginMenu("Import Asset"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ImGui::MenuItem("Image"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (ImGui::MenuItem("Image"))
|
|
|
|
std::filesystem::path outPath;
|
|
|
|
{
|
|
|
|
|
|
|
|
std::filesystem::path outPath;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// prepare filters for the dialog
|
|
|
|
// prepare filters for the dialog
|
|
|
|
FileSystem::FilterItem filterItem[3] = {{"Image file", "png"}, {"Image File", "jpg"}, {"Image File", "jpeg"}};
|
|
|
|
FileSystem::FilterItem filterItem[3] = {{"Image file", "png"}, {"Image File", "jpg"}, {"Image File", "jpeg"}};
|
|
|
|
|
|
|
|
|
|
|
|
// show the dialog
|
|
|
|
// show the dialog
|
|
|
|
FileSystem::DialogResult result = FileSystem::OpenFileDialog(outPath, filterItem, 3);
|
|
|
|
FileSystem::DialogResult result = FileSystem::OpenFileDialog(outPath, filterItem, 3);
|
|
|
|
if (result == FileSystem::DialogResult::OK)
|
|
|
|
if (result == FileSystem::DialogResult::OK)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Logger::Info(Editor::LogCat, "Importing asset: %s", outPath.string().c_str());
|
|
|
|
Logger::Info(Editor::LogCat, "Importing asset: %s", outPath.string().c_str());
|
|
|
|
|
|
|
|
|
|
|
|
LUUID id = 0;
|
|
|
|
LUUID id = 0;
|
|
|
|
ContentManager::GetInstance().ImportFile(outPath, mSelectedDir / outPath.filename(),
|
|
|
|
ContentManager::GetInstance().ImportFile(outPath, mSelectedDir / outPath.filename(),
|
|
|
|
AssetType::EATYPE_IMAGE, id).LogIfFailed(Editor::LogCat);
|
|
|
|
AssetType::EATYPE_IMAGE, id)
|
|
|
|
}
|
|
|
|
.LogIfFailed(Editor::LogCat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
// TODO: Buttons for creating/importing new assets
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -344,66 +377,75 @@ namespace editor
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// New Folder
|
|
|
|
// New Folder
|
|
|
|
AddPopup(PopUp::NEW_FOLDER, "New Folder Name", [](Panel *p)
|
|
|
|
AddPopup(PopUp::NEW_FOLDER, "New Folder Name", [](Panel *p)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool stay_open = true;
|
|
|
|
|
|
|
|
AssetBrowser* ab = (AssetBrowser*)p;
|
|
|
|
|
|
|
|
char name_buf[64] = "New Folder";
|
|
|
|
|
|
|
|
ImGui::TextUnformatted("Folder Name: ");
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
if (ImGui::InputText("##Folder Name", name_buf, 64, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool stay_open = true;
|
|
|
|
std::filesystem::create_directory(ab->mSelectedDir / name_buf);
|
|
|
|
AssetBrowser* ab = (AssetBrowser*)p;
|
|
|
|
stay_open = false;
|
|
|
|
char name_buf[64] = "New Folder";
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
ImGui::TextUnformatted("Folder Name: ");
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
if (ImGui::InputText("##Folder Name", name_buf, 64, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::filesystem::create_directory(ab->mSelectedDir / name_buf);
|
|
|
|
|
|
|
|
stay_open = false;
|
|
|
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
|
|
|
|
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
stay_open = false;
|
|
|
|
stay_open = false;
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return stay_open;
|
|
|
|
return stay_open;
|
|
|
|
}).LogIfFailed(Editor::LogCat);
|
|
|
|
}).LogIfFailed(Editor::LogCat);
|
|
|
|
|
|
|
|
|
|
|
|
// New World
|
|
|
|
// New World
|
|
|
|
AddPopup(PopUp::NEW_WORLD, "New World Name", [](Panel *p)
|
|
|
|
AddPopup(PopUp::NEW_WORLD, "New World Name", [](Panel *p)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool stay_open = true;
|
|
|
|
|
|
|
|
AssetBrowser* ab = (AssetBrowser*)p;
|
|
|
|
|
|
|
|
char name_buf[64] = "New World";
|
|
|
|
|
|
|
|
ImGui::TextUnformatted("World Name: ");
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
if (ImGui::InputText("##World Name", name_buf, 64, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool stay_open = true;
|
|
|
|
auto assets_dir = ab->mpEditor->GetProject()->MakeRelativeToAssets(ab->mSelectedDir);
|
|
|
|
AssetBrowser* ab = (AssetBrowser*)p;
|
|
|
|
EditorAsset* pAsset = new editor::World(assets_dir / name_buf);
|
|
|
|
char name_buf[64] = "New World";
|
|
|
|
LUUID id;
|
|
|
|
ImGui::TextUnformatted("World Name: ");
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
ContentManager::GetInstance().AddGeneratedAsset(pAsset, id).LogIfFailed(Editor::LogCat);
|
|
|
|
if (ImGui::InputText("##World Name", name_buf, 64, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue))
|
|
|
|
stay_open = false;
|
|
|
|
{
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
auto assets_dir = ab->mpEditor->GetProject()->MakeRelativeToAssets(ab->mSelectedDir);
|
|
|
|
}
|
|
|
|
EditorAsset* pAsset = new editor::World(assets_dir / name_buf);
|
|
|
|
|
|
|
|
LUUID id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ContentManager::GetInstance().AddGeneratedAsset(pAsset, id).LogIfFailed(Editor::LogCat);
|
|
|
|
|
|
|
|
stay_open = false;
|
|
|
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
|
|
|
|
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
stay_open = false;
|
|
|
|
stay_open = false;
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return stay_open;
|
|
|
|
return stay_open;
|
|
|
|
}).LogIfFailed(Editor::LogCat);
|
|
|
|
}).LogIfFailed(Editor::LogCat);
|
|
|
|
|
|
|
|
|
|
|
|
// New script asset
|
|
|
|
// New script asset
|
|
|
|
AddPopup(PopUp::NEW_SCRIPT, "New Script Name", [](Panel *p)
|
|
|
|
AddPopup(PopUp::NEW_SCRIPT, "New Script Name", [](Panel *p)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool stay_open = true;
|
|
|
|
|
|
|
|
AssetBrowser* ab = (AssetBrowser*)p;
|
|
|
|
|
|
|
|
char name_buf[64] = "New Script";
|
|
|
|
|
|
|
|
ImGui::TextUnformatted("Script Name: ");
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
if (ImGui::InputText("##Script Name", name_buf, 64, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool stay_open = true;
|
|
|
|
auto assets_dir = ab->mpEditor->GetProject()->MakeRelativeToAssets(ab->mSelectedDir);
|
|
|
|
AssetBrowser* ab = (AssetBrowser*)p;
|
|
|
|
std::string sname_buf = name_buf;
|
|
|
|
char name_buf[64] = "New Script";
|
|
|
|
if (sname_buf.find(' ')!= std::string::npos)
|
|
|
|
ImGui::TextUnformatted("Script Name: ");
|
|
|
|
{
|
|
|
|
ImGui::SameLine();
|
|
|
|
// This does not show up
|
|
|
|
if (ImGui::InputText("##Script Name", name_buf, 64, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue))
|
|
|
|
ImGui::BeginTooltip();
|
|
|
|
|
|
|
|
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Script names can not contain spaces!");
|
|
|
|
|
|
|
|
ImGui::EndTooltip();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto assets_dir = ab->mpEditor->GetProject()->MakeRelativeToAssets(ab->mSelectedDir);
|
|
|
|
|
|
|
|
std::string sname_buf = name_buf;
|
|
|
|
|
|
|
|
sname_buf.append(".wren");
|
|
|
|
sname_buf.append(".wren");
|
|
|
|
std::filesystem::path location = assets_dir / sname_buf;
|
|
|
|
std::filesystem::path location = assets_dir / sname_buf;
|
|
|
|
EditorAsset* pAsset = new editor::Script(location, ab->mpEditor->GetProject()->GetAssetDirectory());
|
|
|
|
EditorAsset* pAsset = new editor::Script(location, ab->mpEditor->GetProject()->GetAssetDirectory());
|
|
|
|
@ -413,14 +455,21 @@ namespace editor
|
|
|
|
stay_open = false;
|
|
|
|
stay_open = false;
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
if (ImGui::Button("X"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
stay_open = false;
|
|
|
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
|
|
|
|
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
stay_open = false;
|
|
|
|
stay_open = false;
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return stay_open;
|
|
|
|
return stay_open;
|
|
|
|
}).LogIfFailed(Editor::LogCat);
|
|
|
|
}).LogIfFailed(Editor::LogCat);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|