Editor entity create and delete.
This commit is contained in:
@@ -45,7 +45,7 @@ public:
|
|||||||
void SetEntityCreateCallback(OnEntityCreate_t f) { m_OnEntityCreate = f; }
|
void SetEntityCreateCallback(OnEntityCreate_t f) { m_OnEntityCreate = f; }
|
||||||
// Called when the user means to delete an entity.
|
// Called when the user means to delete an entity.
|
||||||
typedef std::function<void(EntityWrapper)> OnEntityDelete_t;
|
typedef std::function<void(EntityWrapper)> OnEntityDelete_t;
|
||||||
void SetEntityCreateCallback(OnEntityDelete_t f) { m_OnEntityDelete = f; }
|
void SetEntityDeleteCallback(OnEntityDelete_t f) { m_OnEntityDelete = f; }
|
||||||
// Called when the user means to attach a new component to an entity.
|
// Called when the user means to attach a new component to an entity.
|
||||||
typedef std::function<void(EntityWrapper, const std::string&)> OnComponentAttach_t;
|
typedef std::function<void(EntityWrapper, const std::string&)> OnComponentAttach_t;
|
||||||
void SetComponentAttachCallback(OnComponentAttach_t f) { m_OnComponentAttach = f; }
|
void SetComponentAttachCallback(OnComponentAttach_t f) { m_OnComponentAttach = f; }
|
||||||
@@ -80,6 +80,8 @@ private:
|
|||||||
// Entity file handling methods
|
// Entity file handling methods
|
||||||
void entityImport(World* world);
|
void entityImport(World* world);
|
||||||
void entitySave(EntityWrapper entity);
|
void entitySave(EntityWrapper entity);
|
||||||
|
void entityCreate(World* world, EntityWrapper parent);
|
||||||
|
void entityDelete(EntityWrapper entity);
|
||||||
|
|
||||||
// UI drawing methods
|
// UI drawing methods
|
||||||
void drawMenu();
|
void drawMenu();
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ private:
|
|||||||
// GUI callbacks
|
// GUI callbacks
|
||||||
void OnEntitySelected(EntityWrapper entity);
|
void OnEntitySelected(EntityWrapper entity);
|
||||||
void OnEntitySave(EntityWrapper entity, boost::filesystem::path filePath);
|
void OnEntitySave(EntityWrapper entity, boost::filesystem::path filePath);
|
||||||
|
EntityWrapper OnEntityCreate(EntityWrapper parent);
|
||||||
|
void OnEntityDelete(EntityWrapper entity);
|
||||||
void OnComponentAttach(EntityWrapper entity, const std::string& componentType);
|
void OnComponentAttach(EntityWrapper entity, const std::string& componentType);
|
||||||
void OnComponentDelete(EntityWrapper entity, const std::string& componentType);
|
void OnComponentDelete(EntityWrapper entity, const std::string& componentType);
|
||||||
};
|
};
|
||||||
@@ -29,10 +29,7 @@ void EditorGUI::drawEntities(World* world)
|
|||||||
|
|
||||||
float buttonWidth = (ImGui::GetContentRegionAvailWidth() - 10.f) / 3.f ;
|
float buttonWidth = (ImGui::GetContentRegionAvailWidth() - 10.f) / 3.f ;
|
||||||
if (ImGui::Button("Create", ImVec2(buttonWidth, 0))) {
|
if (ImGui::Button("Create", ImVec2(buttonWidth, 0))) {
|
||||||
if (m_OnEntityCreate != nullptr) {
|
entityCreate(world, m_CurrentSelection);
|
||||||
EntityWrapper newEntity = m_OnEntityCreate(EntityWrapper(world, EntityID_Invalid));
|
|
||||||
SelectEntity(newEntity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ImGui::SameLine(0.f, 5.f);
|
ImGui::SameLine(0.f, 5.f);
|
||||||
if (ImGui::Button("Import", ImVec2(buttonWidth, 0))) {
|
if (ImGui::Button("Import", ImVec2(buttonWidth, 0))) {
|
||||||
@@ -115,16 +112,12 @@ bool EditorGUI::drawEntityNode(EntityWrapper entity)
|
|||||||
if (ImGui::BeginPopupContextItem("entity context menu")) {
|
if (ImGui::BeginPopupContextItem("entity context menu")) {
|
||||||
if (ImGui::Button("Save")) {
|
if (ImGui::Button("Save")) {
|
||||||
entitySave(entity);
|
entitySave(entity);
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("Delete")) {
|
if (ImGui::Button("Delete")) {
|
||||||
if (m_OnEntityDelete != nullptr) {
|
entityDelete(entity);
|
||||||
m_OnEntityDelete(entity);
|
ImGui::CloseCurrentPopup();
|
||||||
ImGui::CloseCurrentPopup();
|
|
||||||
}
|
|
||||||
if (!m_CurrentSelection.Valid()) {
|
|
||||||
SelectEntity(EntityWrapper::Invalid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
drawModals();
|
drawModals();
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
@@ -456,3 +449,26 @@ void EditorGUI::entitySave(EntityWrapper entity)
|
|||||||
ImGui::OpenPopup("Save failed");
|
ImGui::OpenPopup("Save failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorGUI::entityCreate(World* world, EntityWrapper parent)
|
||||||
|
{
|
||||||
|
if (m_OnEntityCreate != nullptr) {
|
||||||
|
// Create the new entity in the world we're drawing for
|
||||||
|
if (parent.World == nullptr) {
|
||||||
|
parent.World = world;
|
||||||
|
}
|
||||||
|
EntityWrapper newEntity = m_OnEntityCreate(parent);
|
||||||
|
SelectEntity(newEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorGUI::entityDelete(EntityWrapper entity)
|
||||||
|
{
|
||||||
|
if (m_OnEntityDelete != nullptr) {
|
||||||
|
m_OnEntityDelete(entity);
|
||||||
|
m_EntityFiles.erase(entity);
|
||||||
|
}
|
||||||
|
if (!m_CurrentSelection.Valid()) {
|
||||||
|
SelectEntity(EntityWrapper::Invalid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ EditorSystem::EditorSystem(EventBroker* eventBroker, IRenderer* renderer, Render
|
|||||||
m_EditorGUI->SetEntitySelectedCallback(std::bind(&EditorSystem::OnEntitySelected, this, std::placeholders::_1));
|
m_EditorGUI->SetEntitySelectedCallback(std::bind(&EditorSystem::OnEntitySelected, this, std::placeholders::_1));
|
||||||
m_EditorGUI->SetEntityImportCallback(std::bind(&EditorSystem::importEntity, this, std::placeholders::_1, std::placeholders::_2));
|
m_EditorGUI->SetEntityImportCallback(std::bind(&EditorSystem::importEntity, this, std::placeholders::_1, std::placeholders::_2));
|
||||||
m_EditorGUI->SetEntitySaveCallback(std::bind(&EditorSystem::OnEntitySave, this, std::placeholders::_1, std::placeholders::_2));
|
m_EditorGUI->SetEntitySaveCallback(std::bind(&EditorSystem::OnEntitySave, this, std::placeholders::_1, std::placeholders::_2));
|
||||||
|
m_EditorGUI->SetEntityCreateCallback(std::bind(&EditorSystem::OnEntityCreate, this, std::placeholders::_1));
|
||||||
|
m_EditorGUI->SetEntityDeleteCallback(std::bind(&EditorSystem::OnEntityDelete, this, std::placeholders::_1));
|
||||||
m_EditorGUI->SetComponentAttachCallback(std::bind(&EditorSystem::OnComponentAttach, this, std::placeholders::_1, std::placeholders::_2));
|
m_EditorGUI->SetComponentAttachCallback(std::bind(&EditorSystem::OnComponentAttach, this, std::placeholders::_1, std::placeholders::_2));
|
||||||
m_EditorGUI->SetComponentDeleteCallback(std::bind(&EditorSystem::OnComponentDelete, this, std::placeholders::_1, std::placeholders::_2));
|
m_EditorGUI->SetComponentDeleteCallback(std::bind(&EditorSystem::OnComponentDelete, this, std::placeholders::_1, std::placeholders::_2));
|
||||||
|
|
||||||
@@ -65,6 +67,18 @@ void EditorSystem::OnEntitySave(EntityWrapper entity, boost::filesystem::path fi
|
|||||||
writer.WriteEntity(entity.World, entity.ID);
|
writer.WriteEntity(entity.World, entity.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EntityWrapper EditorSystem::OnEntityCreate(EntityWrapper parent)
|
||||||
|
{
|
||||||
|
EntityID entity = parent.World->CreateEntity(parent.ID);
|
||||||
|
parent.World->AttachComponent(entity, "Transform");
|
||||||
|
return EntityWrapper(parent.World, entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorSystem::OnEntityDelete(EntityWrapper entity)
|
||||||
|
{
|
||||||
|
entity.World->DeleteEntity(entity.ID);
|
||||||
|
}
|
||||||
|
|
||||||
void EditorSystem::OnComponentAttach(EntityWrapper entity, const std::string& componentType)
|
void EditorSystem::OnComponentAttach(EntityWrapper entity, const std::string& componentType)
|
||||||
{
|
{
|
||||||
entity.World->AttachComponent(entity.ID, componentType);
|
entity.World->AttachComponent(entity.ID, componentType);
|
||||||
|
|||||||
@@ -160,7 +160,8 @@ void Renderer::InitializeRenderPasses()
|
|||||||
//Temp func
|
//Temp func
|
||||||
void Renderer::FillDepth(RenderScene& scene)
|
void Renderer::FillDepth(RenderScene& scene)
|
||||||
{
|
{
|
||||||
for (auto job : scene.ForwardJobs) {
|
// HACK: FIX ME TOBIAS
|
||||||
|
/*for (auto job : scene.ForwardJobs) {
|
||||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||||
if(! modelJob) {
|
if(! modelJob) {
|
||||||
return;
|
return;
|
||||||
@@ -171,5 +172,5 @@ void Renderer::FillDepth(RenderScene& scene)
|
|||||||
glm::vec3 worldpos = glm::vec3(scene.Camera->ViewMatrix() * glm::vec4(abspos, 1));
|
glm::vec3 worldpos = glm::vec3(scene.Camera->ViewMatrix() * glm::vec4(abspos, 1));
|
||||||
modelJob->Depth = worldpos.z;
|
modelJob->Depth = worldpos.z;
|
||||||
}
|
}
|
||||||
scene.ForwardJobs.sort(Renderer::DepthSort);
|
scene.ForwardJobs.sort(Renderer::DepthSort);*/
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user