|
|
|
|
@ -16,145 +16,154 @@
|
|
|
|
|
#include <editor/editor.h>
|
|
|
|
|
#include <utils/logger.h>
|
|
|
|
|
|
|
|
|
|
namespace lunarium
|
|
|
|
|
namespace lunarium { namespace editor
|
|
|
|
|
{
|
|
|
|
|
namespace editor
|
|
|
|
|
WorldTree::WorldTree(Editor *editor)
|
|
|
|
|
: Panel("World Tree", PanelDockZone::DDZ_LEFT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
|
|
|
|
|
mpEditor(editor),
|
|
|
|
|
// TODO: Temp world created here
|
|
|
|
|
mpWorld(nullptr),
|
|
|
|
|
mpSelectedEntity(nullptr), mNewChild(false), mParentEnt(nullptr)
|
|
|
|
|
{
|
|
|
|
|
WorldTree::WorldTree(Editor *editor)
|
|
|
|
|
: Panel("World Tree", PanelDockZone::DDZ_LEFT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
|
|
|
|
|
mpEditor(editor),
|
|
|
|
|
// TODO: Temp world created here
|
|
|
|
|
mpWorld(nullptr),
|
|
|
|
|
mpSelectedEntity(nullptr)
|
|
|
|
|
{
|
|
|
|
|
AddPopup(PopUp::NEW_ENTITY, "New Entity", [](Panel *p)
|
|
|
|
|
AddPopup(PopUp::NEW_ENTITY, "New Entity", [](Panel *p)
|
|
|
|
|
{
|
|
|
|
|
WorldTree* pWT = (WorldTree*)p;
|
|
|
|
|
if (!pWT->mpWorld)
|
|
|
|
|
{
|
|
|
|
|
WorldTree* pWT = (WorldTree*)p;
|
|
|
|
|
if (!pWT->mpWorld)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
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)->SetName(name_buf);
|
|
|
|
|
|
|
|
|
|
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
|
|
|
|
|
if (pWT->mNewChild)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
pWT->mParentEnt->AddChild(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}).LogIfFailed(Editor::LogCat);
|
|
|
|
|
}
|
|
|
|
|
pWT->mNewChild = false;
|
|
|
|
|
pWT->mParentEnt = nullptr;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WorldTree::SetWorld(lunarium::World *pWorld)
|
|
|
|
|
{
|
|
|
|
|
mpWorld = pWorld;
|
|
|
|
|
mpSelectedEntity = nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
|
|
|
|
|
{
|
|
|
|
|
pWT->mNewChild = false;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}).LogIfFailed(Editor::LogCat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WorldTree::SetWorld(lunarium::World *pWorld)
|
|
|
|
|
{
|
|
|
|
|
mpWorld = pWorld;
|
|
|
|
|
mpSelectedEntity = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lunarium::World *WorldTree::GetWorld()
|
|
|
|
|
lunarium::World *WorldTree::GetWorld()
|
|
|
|
|
{
|
|
|
|
|
return mpWorld;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WorldTree::DoFrame()
|
|
|
|
|
{
|
|
|
|
|
Entity *pSelection = nullptr;
|
|
|
|
|
if (!mpWorld)
|
|
|
|
|
{
|
|
|
|
|
return mpWorld;
|
|
|
|
|
|
|
|
|
|
ImGui::Text("No World Loaded");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WorldTree::DoFrame()
|
|
|
|
|
ImGui::SetNextItemOpen(true);
|
|
|
|
|
|
|
|
|
|
if (ImGui::TreeNode("World Root"))
|
|
|
|
|
{
|
|
|
|
|
Entity *pSelection = nullptr;
|
|
|
|
|
if (!mpWorld)
|
|
|
|
|
// 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++)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ImGui::Text("No World Loaded");
|
|
|
|
|
return;
|
|
|
|
|
if (!(*iter)->HasComponent<ParentEntityComponent>())
|
|
|
|
|
{
|
|
|
|
|
ShowEntity((*iter));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::SetNextItemOpen(true);
|
|
|
|
|
ImGui::TreePop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ImGui::TreeNode("World Root"))
|
|
|
|
|
{
|
|
|
|
|
// 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>())
|
|
|
|
|
{
|
|
|
|
|
name = (*iter)->GetComponent<TagComponent>().Info;
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && ImGui::IsWindowHovered())
|
|
|
|
|
{
|
|
|
|
|
mpSelectedEntity = nullptr;
|
|
|
|
|
mpEditor->OnEntitySelect(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
DoContextMenu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::TreePop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && ImGui::IsWindowHovered())
|
|
|
|
|
void WorldTree::ShowEntity(Entity* pEnt)
|
|
|
|
|
{
|
|
|
|
|
bool was_clicked = false;
|
|
|
|
|
bool was_right_clicked = false;
|
|
|
|
|
if (ImGui::TreeNode(pEnt->GetName().c_str()))
|
|
|
|
|
{
|
|
|
|
|
was_clicked = ImGui::IsItemClicked(ImGuiMouseButton_Left);
|
|
|
|
|
was_right_clicked = ImGui::IsItemClicked(ImGuiMouseButton_Right);
|
|
|
|
|
|
|
|
|
|
const std::vector<LUUID>& children = pEnt->GetChildren();
|
|
|
|
|
for (auto iter = children.begin(); iter != children.end(); iter++)
|
|
|
|
|
{
|
|
|
|
|
mpSelectedEntity = nullptr;
|
|
|
|
|
mpEditor->OnEntitySelect(nullptr);
|
|
|
|
|
Entity* pe = mpWorld->GetEntity((*iter));
|
|
|
|
|
ShowEntity(pe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DoContextMenu();
|
|
|
|
|
ImGui::TreePop();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
was_clicked = ImGui::IsItemClicked(ImGuiMouseButton_Left);
|
|
|
|
|
was_right_clicked = ImGui::IsItemClicked(ImGuiMouseButton_Right);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (was_clicked)
|
|
|
|
|
{
|
|
|
|
|
mpSelectedEntity = pEnt;
|
|
|
|
|
mpEditor->OnEntitySelect(pEnt);
|
|
|
|
|
}
|
|
|
|
|
if (was_right_clicked)
|
|
|
|
|
{
|
|
|
|
|
mNewChild = true;
|
|
|
|
|
mParentEnt = pEnt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WorldTree::DoContextMenu()
|
|
|
|
|
void WorldTree::DoContextMenu()
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::BeginPopupContextWindow(0, ImGuiPopupFlags_MouseButtonRight))
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::BeginPopupContextWindow(0, ImGuiPopupFlags_MouseButtonRight))
|
|
|
|
|
if (ImGui::Button("Create New Entity"))
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::Button("Create New Entity"))
|
|
|
|
|
if (!mpWorld)
|
|
|
|
|
{
|
|
|
|
|
if (!mpWorld)
|
|
|
|
|
{
|
|
|
|
|
Logger::Warn(Editor::LogCat, "Can not create new entity - World pointer is null");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OpenPopup(PopUp::NEW_ENTITY).LogIfFailed(Editor::LogCat);
|
|
|
|
|
}
|
|
|
|
|
Logger::Warn(Editor::LogCat, "Can not create new entity - World pointer is null");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OpenPopup(PopUp::NEW_ENTITY).LogIfFailed(Editor::LogCat);
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}}
|