Skip to content

Commit

Permalink
#157 Add the export empty .GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Oct 11, 2022
1 parent d98276b commit 33d340d
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Projects/Editor/Source/AssetManager/CAssetImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ namespace Skylicht

void CAssetImporter::importAll()
{
if (m_fileIterator == m_fileIteratorEnd)
if (*m_fileIterator == NULL || m_fileIterator == m_fileIteratorEnd)
return;

while (m_fileIterator != m_fileIteratorEnd)
Expand Down
4 changes: 4 additions & 0 deletions Projects/Editor/Source/Editor/CEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,10 @@ namespace Skylicht
{
assetCreater->createEmptySprite();
}
else if (label == L"GUI")
{
assetCreater->createEmptyGUI();
}
}

void CEditor::OnCommandWindowOpen(GUI::CBase* item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This file is part of the "Skylicht Engine".

#include "CAssetCreateController.h"
#include "CAssetPropertyController.h"
#include "CSceneController.h"

#include "Reactive/CObserver.h"
#include "AssetManager/CAssetManager.h"
Expand All @@ -36,6 +37,7 @@ This file is part of the "Skylicht Engine".

#include "Scene/CSceneExporter.h"
#include "ResourceSettings/SpriteExportSettings.h"
#include "Graphics2D/CGUIExporter.h"

namespace Skylicht
{
Expand Down Expand Up @@ -134,6 +136,29 @@ namespace Skylicht
importAndSelect(fullPath.c_str());
}

void CAssetCreateController::createEmptyGUI()
{
CSpaceAssets* spaceAssets = (CSpaceAssets*)CEditor::getInstance()->getWorkspaceByName(L"Assets");

CAssetManager* assetMgr = CAssetManager::getInstance();

std::string currentFolder = assetMgr->getAssetFolder();
if (spaceAssets != NULL)
currentFolder = spaceAssets->getListController()->getCurrentFolder();

std::string fullPath = assetMgr->genereateAssetPath("/GUI%02d.gui", currentFolder.c_str());

CZone* zone = CSceneController::getInstance()->getScene()->getZone(0);
CGameObject* canvas = zone->createEmptyObject();
CCanvas* nullCanvas = canvas->addComponent<CCanvas>();

CGUIExporter::save(fullPath.c_str(), nullCanvas);

importAndSelect(fullPath.c_str());

canvas->remove();
}

void CAssetCreateController::importAndSelect(const char* path)
{
CAssetImporter importer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace Skylicht

void createEmptySprite();

void createEmptyGUI();

protected:

void importAndSelect(const char* path);
Expand Down
40 changes: 39 additions & 1 deletion Projects/Skylicht/Engine/Source/Graphics2D/CGUIExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,44 @@ namespace Skylicht
{
bool CGUIExporter::save(const char* file, CCanvas* canvas)
{
return false;
io::IXMLWriter* writeFile = getIrrlichtDevice()->getFileSystem()->createXMLWriter(file);
if (writeFile == NULL)
return false;

writeFile->writeComment(L"File generated by function CGUIExporter::save");
writeFile->writeLineBreak();

CGUIElement* root = canvas->getRootElement();
CObjectSerializable* object = root->createSerializable();

if (root->getChilds().size())
{
CObjectSerializable* childs = new CObjectSerializable("Childs");
object->addProperty(childs);
object->autoRelease(childs);
addChild(root, childs);
}

object->save(writeFile);

writeFile->drop();
return true;
}

void CGUIExporter::addChild(CGUIElement* parent, CObjectSerializable* parents)
{
std::vector<CGUIElement*>& childs = parent->getChilds();
for (CGUIElement* element : childs)
{
CObjectSerializable* object = element->createSerializable();

if (element->getChilds().size() > 0)
{
CObjectSerializable* childs = new CObjectSerializable("Childs");
object->addProperty(childs);
object->autoRelease(childs);
addChild(element, childs);
}
}
}
}
4 changes: 4 additions & 0 deletions Projects/Skylicht/Engine/Source/Graphics2D/CGUIExporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ namespace Skylicht
{
public:
static bool save(const char* file, CCanvas* canvas);

private:

static void addChild(CGUIElement* parent, CObjectSerializable* parents);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,11 @@ namespace Skylicht
{

}

CObjectSerializable* CGUIElement::createSerializable()
{
CObjectSerializable* object = new CObjectSerializable(getTypeName().c_str());
object->autoRelease(new CBoolProperty(object, "visible", m_visible));
return object;
}
}
4 changes: 4 additions & 0 deletions Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ namespace Skylicht
return m_visible;
}

DECLARE_GETTYPENAME(CGUIElement);

virtual CObjectSerializable* createSerializable();

protected:

bool removeChild(CGUIElement* child);
Expand Down
2 changes: 2 additions & 0 deletions Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,7 @@ namespace Skylicht
{
return m_pivot;
}

DECLARE_GETTYPENAME(CGUIImage);
};
}
2 changes: 2 additions & 0 deletions Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIMask.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ namespace Skylicht
void beginMaskTest(CCamera* camera);

void endMaskTest();

DECLARE_GETTYPENAME(CGUIMask);
};
}
2 changes: 2 additions & 0 deletions Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIRect.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ namespace Skylicht
virtual ~CGUIRect();

virtual void render(CCamera *camera);

DECLARE_GETTYPENAME(CGUIRect);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@ namespace Skylicht
m_radius = r;
init();
}

DECLARE_GETTYPENAME(CGUIRoundedRect);
};
}
2 changes: 2 additions & 0 deletions Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUISprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ namespace Skylicht
void setAlignCenterModule();

void setOffsetModule(float x, float y);

DECLARE_GETTYPENAME(CGUISprite);
};
}
2 changes: 2 additions & 0 deletions Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIText.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,7 @@ namespace Skylicht
{
m_centerRotate = b;
}

DECLARE_GETTYPENAME(CGUIText);
};
}

0 comments on commit 33d340d

Please sign in to comment.