Skip to content

Commit

Permalink
#123 Implement menu create Component Object on Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed May 26, 2022
1 parent 5d47db0 commit 16b9dfb
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 8 deletions.
20 changes: 14 additions & 6 deletions Projects/Editor/Source/Editor/CEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,24 +365,29 @@ namespace Skylicht
submenu->addSeparator();
temp = submenu;

/*
GUI::CMenuItem* object = submenu->addItem(L"Object");
submenu = object->getMenu();
submenu->OnCommand = BIND_LISTENER(&CEditor::OnCommandGameObject, this);

/*
submenu->addItem(L"Cube");
submenu->addItem(L"Sphere");
submenu->addItem(L"Capsule");
submenu->addItem(L"Cylinder");
submenu->addItem(L"Plane");
submenu->addSeparator();
submenu->addItem(L"Mesh");
submenu->addSeparator();
submenu->addItem(L"Terrain");
submenu->addSeparator();
*/

submenu->addItem(L"Skydome");
submenu->addItem(L"Skybox");
submenu->addItem(L"Sky");
submenu->addSeparator();

submenu->addItem(L"Mesh");
/*
submenu->addSeparator();
submenu->addItem(L"Terrain");
submenu = temp;
GUI::CMenuItem* effect = submenu->addItem(L"Effect");
Expand All @@ -392,6 +397,7 @@ namespace Skylicht
submenu->addItem(L"Particle System");
submenu->addItem(L"Line");
submenu->addItem(L"Trail");
*/

submenu = temp;
GUI::CMenuItem* lighting = submenu->addItem(L"Lighting");
Expand All @@ -403,11 +409,13 @@ namespace Skylicht
submenu->addItem(L"Spot Light");
submenu->addSeparator();
submenu->addItem(L"Reflection Probe");
submenu->addItem(L"Light Probe");
submenu->addItem(L"Light Probes");

/*
submenu = temp;
submenu->addSeparator();
submenu->addItem(L"Camera");
submenu->addSeparator();
submenu->addItem(L"Trigger");
*/
Expand Down
4 changes: 2 additions & 2 deletions Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ namespace Skylicht

// lighting
CGameObject* lightObj = zone->createEmptyObject();
lightObj->setName(L"DirectionLight");
lightObj->setName(L"Direction Light");

CTransformEuler* lightTransform = lightObj->getTransformEuler();
lightTransform->setPosition(core::vector3df(2.0f, 2.0f, 2.0f));
Expand All @@ -414,7 +414,7 @@ namespace Skylicht

// sky & sun
CGameObject* skySunObj = zone->createEmptyObject();
skySunObj->setName(L"Sky & Sun");
skySunObj->setName(L"Sky");
skySunObj->addComponent<CSkySun>();

// lightprobres
Expand Down
89 changes: 89 additions & 0 deletions Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,62 @@ namespace Skylicht
return;

if (objectType == L"Zone")
{
createZone();
}
if (objectType == L"Empty Object")
{
createEmptyObject(NULL);
}
else if (objectType == L"Container Object")
{
createContainerObject(NULL);
}
else if (objectType == L"Skydome")
{
std::vector<std::string> components = { "CSkyDome" };
createComponentObject("Skydome", components, NULL);
}
else if (objectType == L"Skybox")
{
std::vector<std::string> components = { "CSkyBox" };
createComponentObject("Skybox", components, NULL);
}
else if (objectType == L"Sky")
{
std::vector<std::string> components = { "CSkySun" };
createComponentObject("Sky", components, NULL);
}
else if (objectType == L"Mesh")
{
std::vector<std::string> components = { "CRenderMesh", "CIndirectLighting" };
createComponentObject("Mesh", components, NULL);
}
else if (objectType == L"Direction Light")
{
std::vector<std::string> components = { "CDirectionalLight" };
createComponentObject("Direction Light", components, NULL);
}
else if (objectType == L"Point Light")
{
std::vector<std::string> components = { "CPointLight" };
createComponentObject("Point Light", components, NULL);
}
else if (objectType == L"Spot Light")
{

}
else if (objectType == L"Reflection Probe")
{
std::vector<std::string> components = { "CReflectionProbe" };
createComponentObject("Reflection Probe", components, NULL);
}
else if (objectType == L"Light Probes")
{
std::vector<std::string> components = { "CLightProbes" };
createComponentObject("Light Probes", components, NULL);
}

}

void CSceneController::onContextMenu(CHierachyNode* node)
Expand Down Expand Up @@ -646,6 +697,44 @@ namespace Skylicht
return newObject;
}

CGameObject* CSceneController::createComponentObject(const char* name, std::vector<std::string>& components, CContainerObject* parent, bool saveHistory)
{
CContainerObject* p = parent == NULL ? m_zone : parent;
if (p == NULL)
return NULL;

CGameObject* newObject = p->createEmptyObject();

std::string generateName = p->generateObjectName(name);
newObject->setName(generateName.c_str());

p->getZone()->updateAddRemoveObject();
p->getZone()->updateIndexSearchObject();

// add components
for (std::string& comp : components)
newObject->addComponentByTypeName(comp.c_str());

CHierachyNode* parentNode = m_hierachyNode->getNodeByTag(p);
if (parentNode != NULL)
{
CHierachyNode* node = parentNode->addChild();
node->setName(newObject->getName());
node->setIcon(GUI::ESystemIcon::Res3D);
node->setTagData(newObject, CHierachyNode::GameObject);

setNodeEvent(node);

if (m_spaceHierarchy != NULL)
m_spaceHierarchy->addToTreeNode(node);
}

if (saveHistory)
m_history->saveCreateHistory(newObject);

return newObject;
}

void CSceneController::createResourceComponent(const std::string& path, CGameObject* gameObject)
{
std::string shortPath = CAssetManager::getInstance()->getShortPath(path.c_str());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ namespace Skylicht

CGameObject* createContainerObject(CContainerObject* parent, bool saveHistory = true);

CGameObject* createComponentObject(const char* name, std::vector<std::string>& components, CContainerObject* parent, bool saveHistory = true);

void createResourceComponent(const std::string& path, CGameObject* gameObject);

CHierachyNode* buildHierarchyData(CGameObject* object, CHierachyNode* parentNode);
Expand Down

0 comments on commit 16b9dfb

Please sign in to comment.