Skip to content

Commit 33d340d

Browse files
committed
#157 Add the export empty .GUI
1 parent d98276b commit 33d340d

File tree

14 files changed

+98
-2
lines changed

14 files changed

+98
-2
lines changed

Projects/Editor/Source/AssetManager/CAssetImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ namespace Skylicht
173173

174174
void CAssetImporter::importAll()
175175
{
176-
if (m_fileIterator == m_fileIteratorEnd)
176+
if (*m_fileIterator == NULL || m_fileIterator == m_fileIteratorEnd)
177177
return;
178178

179179
while (m_fileIterator != m_fileIteratorEnd)

Projects/Editor/Source/Editor/CEditor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,10 @@ namespace Skylicht
11041104
{
11051105
assetCreater->createEmptySprite();
11061106
}
1107+
else if (label == L"GUI")
1108+
{
1109+
assetCreater->createEmptyGUI();
1110+
}
11071111
}
11081112

11091113
void CEditor::OnCommandWindowOpen(GUI::CBase* item)

Projects/Editor/Source/Editor/SpaceController/CAssetCreateController.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This file is part of the "Skylicht Engine".
2626

2727
#include "CAssetCreateController.h"
2828
#include "CAssetPropertyController.h"
29+
#include "CSceneController.h"
2930

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

3738
#include "Scene/CSceneExporter.h"
3839
#include "ResourceSettings/SpriteExportSettings.h"
40+
#include "Graphics2D/CGUIExporter.h"
3941

4042
namespace Skylicht
4143
{
@@ -134,6 +136,29 @@ namespace Skylicht
134136
importAndSelect(fullPath.c_str());
135137
}
136138

139+
void CAssetCreateController::createEmptyGUI()
140+
{
141+
CSpaceAssets* spaceAssets = (CSpaceAssets*)CEditor::getInstance()->getWorkspaceByName(L"Assets");
142+
143+
CAssetManager* assetMgr = CAssetManager::getInstance();
144+
145+
std::string currentFolder = assetMgr->getAssetFolder();
146+
if (spaceAssets != NULL)
147+
currentFolder = spaceAssets->getListController()->getCurrentFolder();
148+
149+
std::string fullPath = assetMgr->genereateAssetPath("/GUI%02d.gui", currentFolder.c_str());
150+
151+
CZone* zone = CSceneController::getInstance()->getScene()->getZone(0);
152+
CGameObject* canvas = zone->createEmptyObject();
153+
CCanvas* nullCanvas = canvas->addComponent<CCanvas>();
154+
155+
CGUIExporter::save(fullPath.c_str(), nullCanvas);
156+
157+
importAndSelect(fullPath.c_str());
158+
159+
canvas->remove();
160+
}
161+
137162
void CAssetCreateController::importAndSelect(const char* path)
138163
{
139164
CAssetImporter importer;

Projects/Editor/Source/Editor/SpaceController/CAssetCreateController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ namespace Skylicht
4444

4545
void createEmptySprite();
4646

47+
void createEmptyGUI();
48+
4749
protected:
4850

4951
void importAndSelect(const char* path);

Projects/Skylicht/Engine/Source/Graphics2D/CGUIExporter.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,44 @@ namespace Skylicht
2929
{
3030
bool CGUIExporter::save(const char* file, CCanvas* canvas)
3131
{
32-
return false;
32+
io::IXMLWriter* writeFile = getIrrlichtDevice()->getFileSystem()->createXMLWriter(file);
33+
if (writeFile == NULL)
34+
return false;
35+
36+
writeFile->writeComment(L"File generated by function CGUIExporter::save");
37+
writeFile->writeLineBreak();
38+
39+
CGUIElement* root = canvas->getRootElement();
40+
CObjectSerializable* object = root->createSerializable();
41+
42+
if (root->getChilds().size())
43+
{
44+
CObjectSerializable* childs = new CObjectSerializable("Childs");
45+
object->addProperty(childs);
46+
object->autoRelease(childs);
47+
addChild(root, childs);
48+
}
49+
50+
object->save(writeFile);
51+
52+
writeFile->drop();
53+
return true;
54+
}
55+
56+
void CGUIExporter::addChild(CGUIElement* parent, CObjectSerializable* parents)
57+
{
58+
std::vector<CGUIElement*>& childs = parent->getChilds();
59+
for (CGUIElement* element : childs)
60+
{
61+
CObjectSerializable* object = element->createSerializable();
62+
63+
if (element->getChilds().size() > 0)
64+
{
65+
CObjectSerializable* childs = new CObjectSerializable("Childs");
66+
object->addProperty(childs);
67+
object->autoRelease(childs);
68+
addChild(element, childs);
69+
}
70+
}
3371
}
3472
}

Projects/Skylicht/Engine/Source/Graphics2D/CGUIExporter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,9 @@ namespace Skylicht
3232
{
3333
public:
3434
static bool save(const char* file, CCanvas* canvas);
35+
36+
private:
37+
38+
static void addChild(CGUIElement* parent, CObjectSerializable* parents);
3539
};
3640
}

Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIElement.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,11 @@ namespace Skylicht
144144
{
145145

146146
}
147+
148+
CObjectSerializable* CGUIElement::createSerializable()
149+
{
150+
CObjectSerializable* object = new CObjectSerializable(getTypeName().c_str());
151+
object->autoRelease(new CBoolProperty(object, "visible", m_visible));
152+
return object;
153+
}
147154
}

Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIElement.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ namespace Skylicht
265265
return m_visible;
266266
}
267267

268+
DECLARE_GETTYPENAME(CGUIElement);
269+
270+
virtual CObjectSerializable* createSerializable();
271+
268272
protected:
269273

270274
bool removeChild(CGUIElement* child);

Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIImage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,7 @@ namespace Skylicht
7171
{
7272
return m_pivot;
7373
}
74+
75+
DECLARE_GETTYPENAME(CGUIImage);
7476
};
7577
}

Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIMask.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,7 @@ namespace Skylicht
4646
void beginMaskTest(CCamera* camera);
4747

4848
void endMaskTest();
49+
50+
DECLARE_GETTYPENAME(CGUIMask);
4951
};
5052
}

Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIRect.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,7 @@ namespace Skylicht
4141
virtual ~CGUIRect();
4242

4343
virtual void render(CCamera *camera);
44+
45+
DECLARE_GETTYPENAME(CGUIRect);
4446
};
4547
}

Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIRoundedRect.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,7 @@ namespace Skylicht
5454
m_radius = r;
5555
init();
5656
}
57+
58+
DECLARE_GETTYPENAME(CGUIRoundedRect);
5759
};
5860
}

Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUISprite.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,7 @@ namespace Skylicht
5959
void setAlignCenterModule();
6060

6161
void setOffsetModule(float x, float y);
62+
63+
DECLARE_GETTYPENAME(CGUISprite);
6264
};
6365
}

Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIText.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,7 @@ namespace Skylicht
143143
{
144144
m_centerRotate = b;
145145
}
146+
147+
DECLARE_GETTYPENAME(CGUIText);
146148
};
147149
}

0 commit comments

Comments
 (0)