Skip to content
This repository has been archived by the owner on Nov 12, 2023. It is now read-only.

Commit

Permalink
The SceneHierarchy widget should be good to go regarding duplication …
Browse files Browse the repository at this point in the history
…of folders
  • Loading branch information
Madman10K committed Feb 19, 2022
1 parent 48788e6 commit 9b86d72
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 19 deletions.
3 changes: 1 addition & 2 deletions Engine/GameFramework/GameplayClasses/Level/Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,9 @@ void UVK::Level::openInternal(UVK::String location, bool first)
if (global.bEditor)
{
Actor temp = Actor();
std::string tempStr;
int tmpInt = 1;
bool tmpBool = true;
SceneHierarchy::display(temp, tempStr, tmpInt, tmpBool, global.instance->editor->currentLevelFolders, true);
SceneHierarchy::display(temp, tmpInt, tmpBool, global.instance->editor->currentLevelFolders, true);
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Engine/Renderer/EditorUI/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void UVK::Editor::displayEditor(FVector4& colour, GLFrameBuffer& fb, Camera& cam
if (bools.bShowDetailsPanel)
bools.bEditorUsingTextbox = DetailsPanel::display(selectedEntity, lvl, bools.bShowDetailsPanel, moduleManager, bools.bDestroyEntity) ? true : bools.bEditorUsingTextbox;
if (bools.bShowSceneHierarchy)
bools.bEditorUsingTextbox = SceneHierarchy::display(selectedEntity, strings.entAppend, entNum, bools.bShowSceneHierarchy, currentLevelFolders) ? true : bools.bEditorUsingTextbox;
bools.bEditorUsingTextbox = SceneHierarchy::display(selectedEntity, entNum, bools.bShowSceneHierarchy, currentLevelFolders) ? true : bools.bEditorUsingTextbox;
if (bools.bShowViewport)
{
style.WindowPadding = ImVec2(0.0f, 0.0f);
Expand Down
1 change: 0 additions & 1 deletion Engine/Renderer/EditorUI/EditorUtils/Structs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ namespace UVK
std::string location;
std::string name;
std::string fileOutLocation;
std::string entAppend;
std::string terminalCommand;
UVK::String colTheme{};
std::string engineVersion;
Expand Down
2 changes: 2 additions & 0 deletions Engine/Renderer/EditorUI/Widgets/Windows/DetailsPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ bool DetailsPanel::display(UVK::Actor& ent, UVK::Level* lvl, bool& bShow, const
if (a.id == 330 && a.name.find("Editor") == std::string::npos)
a.id += 1;

ImGui::TextWrapped("UUID: %lu", a.uuid.data());

ImGui::TextWrapped("Development Name");
ImGui::SameLine();
if (ImGui::InputText("##Development Name##devname", &a.devName) || ImGui::IsItemActive())
Expand Down
4 changes: 2 additions & 2 deletions Engine/Renderer/EditorUI/Widgets/Windows/Filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ bool Filesystem::display(std_filesystem::path& pt, UVK::Texture* textures, UVK::
}
catch (std_filesystem::filesystem_error&){}
}
else if (payload = ImGui::AcceptDragDropPayload("ENGINE_FS_WIDGET_ALL"))
else if ((payload = ImGui::AcceptDragDropPayload("ENGINE_FS_WIDGET_ALL")))
{
try
{
Expand Down Expand Up @@ -260,7 +260,7 @@ bool Filesystem::display(std_filesystem::path& pt, UVK::Texture* textures, UVK::
}
catch (std_filesystem::filesystem_error&){}
}
else if (payload = ImGui::AcceptDragDropPayload("ENGINE_FS_WIDGET_ALL"))
else if ((payload = ImGui::AcceptDragDropPayload("ENGINE_FS_WIDGET_ALL")))
{
try
{
Expand Down
92 changes: 81 additions & 11 deletions Engine/Renderer/EditorUI/Widgets/Windows/SceneHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,28 @@
#include <State/StateTracker.hpp>
#include <cpp/imgui_stdlib.h>

UVK::Actor SceneHierarchy::duplicateEntity(UVK::Actor& currentPopupEntity, const bool& bDrawHighlighted, const bool& nopop)
void SceneHierarchy::duplicateFolder(std::vector<UVK::EditorFolder>& folders, UVK::EditorFolder* folder, const bool& bDrawHighlighted, const bool& nopop)
{
if (folder != nullptr && folder->bValid)
{
static size_t i = 0;

auto size = folder->contents.size();
folders.push_back({
.name = "New" + folder->name + std::to_string(i),
.bValid = true,
});

for (size_t j = 0; j < size; j++)
duplicateEntity(folder->contents[j], bDrawHighlighted, nopop, &folders.back());
i++;
}
}

UVK::Actor SceneHierarchy::duplicateEntity(UVK::Actor& currentPopupEntity, const bool& bDrawHighlighted, const bool& nopop, UVK::EditorFolder* folder)
{
if (!currentPopupEntity.valid() || !currentPopupEntity.has<UVK::CoreComponent>())
return currentPopupEntity;
auto& coreComponent = currentPopupEntity.get<UVK::CoreComponent>();
UVK::Actor actor(coreComponent.name, coreComponent.id, coreComponent.devName);
auto& a = actor.add<UVK::CoreComponent>();
Expand All @@ -28,6 +48,11 @@ UVK::Actor SceneHierarchy::duplicateEntity(UVK::Actor& currentPopupEntity, const
}
}
});


if (folder != nullptr && folder->bValid)
folder->contents.push_back(actor);

//if (currentPopupEntity.has<UVK::AudioComponent>())
// actor.add<UVK::AudioComponent>() = currentPopupEntity.get<UVK::AudioComponent>();

Expand Down Expand Up @@ -136,7 +161,7 @@ UVK::Actor SceneHierarchy::addEntity(int& entNum)
return UVK::Actor(a);
}

bool SceneHierarchy::display(UVK::Actor& selectedEntity, std::string& entAppend, int& entNum, bool& bShow, std::vector<UVK::EditorFolder>& folders, const bool& bReset)
bool SceneHierarchy::display(UVK::Actor& selectedEntity, int& entNum, bool& bShow, std::vector<UVK::EditorFolder>& folders, const bool& bReset)
{
static std::vector<UVK::EditorFolder*> selectedFolders;
static UVK::EditorFolder* selectedFolder = nullptr;
Expand Down Expand Up @@ -211,16 +236,14 @@ bool SceneHierarchy::display(UVK::Actor& selectedEntity, std::string& entAppend,
if (ImGui::MenuItem("+ 2x Duplicate"))
{
for (auto& a : selectedEntities)
{
if (a.valid())
{
duplicateEntity(a, false);
}
}
duplicateEntity(a, false, true);
if (selectedEntity.valid())
{
duplicateEntity(selectedEntity, false);
}
duplicateEntity(selectedEntity, false, true);
for (auto& a : selectedFolders)
duplicateFolder(folders, a, false, true);
duplicateFolder(folders, selectedFolder, false, true);

return bReturn;
}
ImGui::EndMenuBar();
Expand Down Expand Up @@ -304,6 +327,14 @@ bool SceneHierarchy::display(UVK::Actor& selectedEntity, std::string& entAppend,
auto ent = addEntity(entNum);
if (selectedFolders.empty() && selectedFolder != nullptr)
selectedFolder->contents.emplace_back(ent);
if (bDrawHighlighted)
{
ImGui::PopStyleColor();
ImGui::PopStyleColor();
}
else
ImGui::PopStyleColor();
return bReturn;
}
if (ImGui::MenuItem("+ New Folder"))
{
Expand All @@ -314,12 +345,28 @@ bool SceneHierarchy::display(UVK::Actor& selectedEntity, std::string& entAppend,

UVK::EditorFolder fld = {"NewFolder" + std::to_string(j), true, {}};
folders.emplace_back(fld);
if (bDrawHighlighted)
{
ImGui::PopStyleColor();
ImGui::PopStyleColor();
}
else
ImGui::PopStyleColor();
return bReturn;
}
ImGui::Separator();
if (ImGui::MenuItem("- Delete Entity"))
{
bDeleteWarning = true;
bCalledFromPopup = true;
if (bDrawHighlighted)
{
ImGui::PopStyleColor();
ImGui::PopStyleColor();
}
else
ImGui::PopStyleColor();
return bReturn;
}
if (ImGui::MenuItem("* Remove From Folder"))
{
Expand All @@ -343,10 +390,25 @@ bool SceneHierarchy::display(UVK::Actor& selectedEntity, std::string& entAppend,
}
}
}
if (bDrawHighlighted)
{
ImGui::PopStyleColor();
ImGui::PopStyleColor();
}
else
ImGui::PopStyleColor();
return bReturn;
}
if (ImGui::MenuItem("+ 2x Duplicate"))
{
duplicateEntity(currentPopupEntity, bDrawHighlighted, false);
if (bDrawHighlighted)
{
ImGui::PopStyleColor();
ImGui::PopStyleColor();
}
else
ImGui::PopStyleColor();
return bReturn;
}
ImGui::EndPopup();
Expand Down Expand Up @@ -401,7 +463,7 @@ skip:; // Semicolon needed to remove compiler error
if (selectedEntity.valid())
a.contents.emplace_back(selectedEntity);
}
else if (payload = ImGui::AcceptDragDropPayload("ENGINE_SH_WIDGET_ENTITY2"))
else if ((payload = ImGui::AcceptDragDropPayload("ENGINE_SH_WIDGET_ENTITY2")))
{
for (auto& f : selectedEntities)
{
Expand Down Expand Up @@ -590,6 +652,7 @@ skip:; // Semicolon needed to remove compiler error
auto ent = addEntity(entNum);
if (selectedFolders.empty() && selectedFolder != nullptr)
selectedFolder->contents.emplace_back(ent);
return bReturn;
}
if (ImGui::MenuItem("+ New Folder"))
{
Expand All @@ -600,13 +663,20 @@ skip:; // Semicolon needed to remove compiler error

UVK::EditorFolder fld = {"NewFolder" + std::to_string(j), true, {}};
folders.emplace_back(fld);
return bReturn;
}
if (ImGui::MenuItem("+ 2x Duplicate"))
{
duplicateFolder(folders, currentPopupFolder, false, true);
return bReturn;
}
ImGui::Separator();
if (ImGui::MenuItem("- Delete Folder"))
{
bDeleteWarning = true;
bCalledFromPopup = true;
currentPopupEntity.data() = entt::null;
return bReturn;
}
ImGui::Text("Folder Name: ");
ImGui::SameLine();
Expand Down
6 changes: 4 additions & 2 deletions Engine/Renderer/EditorUI/Widgets/Windows/SceneHierarchy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ namespace SceneHierarchy
{
UVK::Actor addEntity(int& entNum);
void destroyEntity(UVK::Actor& selectedEntity);
bool display(UVK::Actor& selectedEntity, std::string& entAppend, int& entNum, bool& bShow, std::vector<UVK::EditorFolder>& folders, const bool& bReset = false);
UVK::Actor duplicateEntity(UVK::Actor& currentPopupEntity, const bool& bDrawHighlighted, const bool& nopop = true);
bool display(UVK::Actor& selectedEntity, int& entNum, bool& bShow, std::vector<UVK::EditorFolder>& folders, const bool& bReset = false);

UVK::Actor duplicateEntity(UVK::Actor& currentPopupEntity, const bool& bDrawHighlighted, const bool& nopop = true, UVK::EditorFolder* folder = nullptr);
void duplicateFolder(std::vector<UVK::EditorFolder>& folders, UVK::EditorFolder* folder, const bool& bDrawHighlighted, const bool& nopop = true);
}
#endif

0 comments on commit 9b86d72

Please sign in to comment.