|
|
|
|
@ -1,12 +1,13 @@
|
|
|
|
|
/******************************************************************************
|
|
|
|
|
* File - worldTree.cpp
|
|
|
|
|
* Author - Joey Pollack
|
|
|
|
|
* Date - 2021/11/04 (y/m/d)
|
|
|
|
|
* Mod Date - 2021/11/04 (y/m/d)
|
|
|
|
|
* Description - The tree view listing all objects in the world
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
* File - worldTree.cpp
|
|
|
|
|
* Author - Joey Pollack
|
|
|
|
|
* Date - 2021/11/04 (y/m/d)
|
|
|
|
|
* Mod Date - 2021/11/04 (y/m/d)
|
|
|
|
|
* Description - The tree view listing all objects in the world
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "world_tree.h"
|
|
|
|
|
#include <editor/editor.h>
|
|
|
|
|
#include <core/core.h>
|
|
|
|
|
#include <world/world.h>
|
|
|
|
|
#include <world/entity.h>
|
|
|
|
|
@ -17,109 +18,135 @@
|
|
|
|
|
|
|
|
|
|
namespace lunarium
|
|
|
|
|
{
|
|
|
|
|
namespace editor
|
|
|
|
|
{
|
|
|
|
|
WorldTree::WorldTree()
|
|
|
|
|
: Panel("World Tree", PanelDockZone::DDZ_LEFT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
|
|
|
|
|
mpWorld(new lunarium::World), mDoNewEntity(false)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WorldTree::SetWorld(lunarium::World* pWorld)
|
|
|
|
|
{
|
|
|
|
|
mpWorld = pWorld;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lunarium::World* WorldTree::GetWorld()
|
|
|
|
|
{
|
|
|
|
|
return mpWorld;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WorldTree::DoFrame()
|
|
|
|
|
namespace editor
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::TreeNode("World Root") && mpWorld)
|
|
|
|
|
WorldTree::WorldTree(Editor *editor)
|
|
|
|
|
: Panel("World Tree", PanelDockZone::DDZ_LEFT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
|
|
|
|
|
mpEditor(editor),
|
|
|
|
|
// TODO: Temp world created here
|
|
|
|
|
mpWorld(new lunarium::World),
|
|
|
|
|
mDoNewEntity(false), mpSelectedEntity(nullptr)
|
|
|
|
|
{
|
|
|
|
|
// List all world entities
|
|
|
|
|
// This will fail if we end up implementing child entities
|
|
|
|
|
// In that case this needs to become recursive
|
|
|
|
|
int idx = 0;
|
|
|
|
|
for (auto iter = mpWorld->EntitiesBegin(); !mpWorld->EntitiesIsEnd(iter); iter++, idx++)
|
|
|
|
|
{
|
|
|
|
|
std::string name = "Entity";
|
|
|
|
|
name += std::to_string(idx);
|
|
|
|
|
if ((*iter)->HasComponent<TagComponent>())
|
|
|
|
|
AddPopup(PopUp::NEW_ENTITY, "New Entity", [](Panel *p)
|
|
|
|
|
{
|
|
|
|
|
name = (*iter)->GetComponent<TagComponent>().Info;
|
|
|
|
|
}
|
|
|
|
|
WorldTree* pWT = (WorldTree*)p;
|
|
|
|
|
char name_buf[64] = "NewEntity";
|
|
|
|
|
ImGui::TextUnformatted("Entity Name: ");
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::InputText("##Entity Name", name_buf, 64, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue))
|
|
|
|
|
{
|
|
|
|
|
LUUID id = pWT->mpWorld->CreateEntity();
|
|
|
|
|
pWT->mpWorld->GetEntity(id)->AddComponent<TagComponent>();
|
|
|
|
|
TagComponent& tc = pWT->mpWorld->GetEntity(id)->GetComponent<TagComponent>();
|
|
|
|
|
tc.Info = name_buf;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ImGui::TreeNode(name.c_str()))
|
|
|
|
|
{
|
|
|
|
|
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::TreePop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::TreePop();
|
|
|
|
|
void WorldTree::SetWorld(lunarium::World *pWorld)
|
|
|
|
|
{
|
|
|
|
|
mpWorld = pWorld;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DoContextMenu();
|
|
|
|
|
HandlePopupEvents();
|
|
|
|
|
}
|
|
|
|
|
lunarium::World *WorldTree::GetWorld()
|
|
|
|
|
{
|
|
|
|
|
return mpWorld;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WorldTree::DoContextMenu()
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::BeginPopupContextWindow(0, ImGuiPopupFlags_MouseButtonRight))
|
|
|
|
|
void WorldTree::DoFrame()
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::Button("Create New Entity"))
|
|
|
|
|
Entity *pSelection = nullptr;
|
|
|
|
|
if (ImGui::TreeNode("World Root") && mpWorld)
|
|
|
|
|
{
|
|
|
|
|
if (!mpWorld)
|
|
|
|
|
{
|
|
|
|
|
Logger::Warn(Editor::LogCat, "Can not create new entity - World pointer is null");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
// List all world entities
|
|
|
|
|
// This will fail if we end up implementing child entities
|
|
|
|
|
// In that case this needs to become recursive
|
|
|
|
|
int idx = 0;
|
|
|
|
|
for (auto iter = mpWorld->EntitiesBegin(); !mpWorld->EntitiesIsEnd(iter); iter++, idx++)
|
|
|
|
|
{
|
|
|
|
|
mDoNewEntity = true;
|
|
|
|
|
std::string name = "Entity";
|
|
|
|
|
name += std::to_string(idx);
|
|
|
|
|
if ((*iter)->HasComponent<TagComponent>())
|
|
|
|
|
{
|
|
|
|
|
name = (*iter)->GetComponent<TagComponent>().Info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((*iter)->HasChildren())
|
|
|
|
|
{
|
|
|
|
|
// TODO: Recurse through children
|
|
|
|
|
if (ImGui::TreeNode(name.c_str()))
|
|
|
|
|
{
|
|
|
|
|
ImGui::TreePop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bool is_selected = false;
|
|
|
|
|
if ((*iter) == mpSelectedEntity)
|
|
|
|
|
{
|
|
|
|
|
is_selected = true;
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::Selectable(name.c_str(), &is_selected))
|
|
|
|
|
{
|
|
|
|
|
mpSelectedEntity = (*iter);
|
|
|
|
|
if (is_selected)
|
|
|
|
|
{
|
|
|
|
|
mpEditor->OnEntitySelect(mpSelectedEntity);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mpEditor->OnEntitySelect(nullptr);
|
|
|
|
|
mpSelectedEntity = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WorldTree::HandlePopupEvents()
|
|
|
|
|
{
|
|
|
|
|
if (mDoNewEntity)
|
|
|
|
|
{
|
|
|
|
|
PopupNewEntity();
|
|
|
|
|
ImGui::OpenPopup("New Entity");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::TreePop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WorldTree::PopupNewEntity()
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::BeginPopupContextItem("New Entity"))
|
|
|
|
|
{
|
|
|
|
|
char name_buf[64] = "NewEntity";
|
|
|
|
|
ImGui::TextUnformatted("Entity Name: ");
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::InputText("##Entity Name", name_buf, 64, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue))
|
|
|
|
|
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && ImGui::IsWindowHovered())
|
|
|
|
|
{
|
|
|
|
|
LUUID id = mpWorld->CreateEntity();
|
|
|
|
|
mpWorld->GetEntity(id)->AddComponent<TagComponent>();
|
|
|
|
|
TagComponent& tc = mpWorld->GetEntity(id)->GetComponent<TagComponent>();
|
|
|
|
|
tc.Info = name_buf;
|
|
|
|
|
mDoNewEntity = false;
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
mpSelectedEntity = nullptr;
|
|
|
|
|
mpEditor->OnEntitySelect(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
|
|
|
|
|
// TODO: Find a way to change this so that OnEntitySelect is not called every frame
|
|
|
|
|
// if (pSelection != mpSelectedEntity)
|
|
|
|
|
// {
|
|
|
|
|
// mpSelectedEntity = pSelection;
|
|
|
|
|
// mpEditor->OnEntitySelect(mpSelectedEntity);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
DoContextMenu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WorldTree::DoContextMenu()
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::BeginPopupContextWindow(0, ImGuiPopupFlags_MouseButtonRight))
|
|
|
|
|
{
|
|
|
|
|
mDoNewEntity = false;
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
if (ImGui::Button("Create New Entity"))
|
|
|
|
|
{
|
|
|
|
|
if (!mpWorld)
|
|
|
|
|
{
|
|
|
|
|
Logger::Warn(Editor::LogCat, "Can not create new entity - World pointer is null");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OpenPopup(PopUp::NEW_ENTITY);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|