diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp index 99da4ab027..527c14e1ac 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp @@ -762,6 +762,9 @@ Node* CSLoader::nodeWithFlatBuffersFile(const std::string &fileName) SpriteFrameCache::getInstance()->addSpriteFramesWithFile(textures->Get(i)->c_str()); } + auto v = csparsebinary->version(); + if (v) _csdVersion = v->c_str(); + Node* node = nodeWithFlatBuffers(csparsebinary->nodeTree()); return node; @@ -1083,6 +1086,10 @@ Node* CSLoader::createNodeWithFlatBuffersForSimulator(const std::string& filenam } auto nodeTree = csparsebinary->nodeTree(); + + auto v = csparsebinary->version(); + if (v) _csdVersion = v->c_str(); + Node* node = nodeWithFlatBuffersForSimulator(nodeTree); _rootNode = nullptr; @@ -1189,6 +1196,7 @@ Node* CSLoader::nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree *nod node->addChild(child); } } + Helper::doLayout(node); } // _loadingNodeParentHierarchy.pop_back(); diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h index d80d792ef5..38cadc9cef 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h @@ -100,7 +100,8 @@ public: cocos2d::Node* createNodeWithFlatBuffersForSimulator(const std::string& filename); cocos2d::Node* nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree* nodetree); - + std::string getCsdVersion() { return _csdVersion; } + protected: cocos2d::Node* loadNode(const rapidjson::Value& json); @@ -147,6 +148,7 @@ protected: Node* _rootNode; // std::vector _loadingNodeParentHierarchy; + std::string _csdVersion; }; NS_CC_END diff --git a/cocos/editor-support/cocostudio/CSParseBinary_generated.h b/cocos/editor-support/cocostudio/CSParseBinary_generated.h index d4360f64a0..d4ebff7371 100644 --- a/cocos/editor-support/cocostudio/CSParseBinary_generated.h +++ b/cocos/editor-support/cocostudio/CSParseBinary_generated.h @@ -12,6 +12,7 @@ struct CSParseBinary; struct NodeTree; struct Options; struct WidgetOptions; +struct LayoutComponentTable; struct SingleNodeOptions; struct SpriteOptions; struct ParticleSystemOptions; @@ -176,6 +177,7 @@ struct CSParseBinary : private flatbuffers::Table { const flatbuffers::Vector> *texturePngs() const { return GetPointer> *>(6); } const NodeTree *nodeTree() const { return GetPointer(8); } const NodeAction *action() const { return GetPointer(10); } + const flatbuffers::String *version() const { return GetPointer(12); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* textures */) && @@ -188,6 +190,8 @@ struct CSParseBinary : private flatbuffers::Table { verifier.VerifyTable(nodeTree()) && VerifyField(verifier, 10 /* action */) && verifier.VerifyTable(action()) && + VerifyField(verifier, 12 /* version */) && + verifier.Verify(version()) && verifier.EndTable(); } }; @@ -199,10 +203,11 @@ struct CSParseBinaryBuilder { void add_texturePngs(flatbuffers::Offset>> texturePngs) { fbb_.AddOffset(6, texturePngs); } void add_nodeTree(flatbuffers::Offset nodeTree) { fbb_.AddOffset(8, nodeTree); } void add_action(flatbuffers::Offset action) { fbb_.AddOffset(10, action); } + void add_version(flatbuffers::Offset version) { fbb_.AddOffset(12, version); } CSParseBinaryBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } CSParseBinaryBuilder &operator=(const CSParseBinaryBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 4)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 5)); return o; } }; @@ -211,8 +216,10 @@ inline flatbuffers::Offset CreateCSParseBinary(flatbuffers::FlatB flatbuffers::Offset>> textures = 0, flatbuffers::Offset>> texturePngs = 0, flatbuffers::Offset nodeTree = 0, - flatbuffers::Offset action = 0) { + flatbuffers::Offset action = 0, + flatbuffers::Offset version = 0) { CSParseBinaryBuilder builder_(_fbb); + builder_.add_version(version); builder_.add_action(action); builder_.add_nodeTree(nodeTree); builder_.add_texturePngs(texturePngs); @@ -318,6 +325,7 @@ struct WidgetOptions : private flatbuffers::Table { const flatbuffers::String *customProperty() const { return GetPointer(38); } const flatbuffers::String *callBackType() const { return GetPointer(40); } const flatbuffers::String *callBackName() const { return GetPointer(42); } + const LayoutComponentTable *layoutComponent() const { return GetPointer(44); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* name */) && @@ -345,6 +353,8 @@ struct WidgetOptions : private flatbuffers::Table { verifier.Verify(callBackType()) && VerifyField(verifier, 42 /* callBackName */) && verifier.Verify(callBackName()) && + VerifyField(verifier, 44 /* layoutComponent */) && + verifier.VerifyTable(layoutComponent()) && verifier.EndTable(); } }; @@ -372,10 +382,11 @@ struct WidgetOptionsBuilder { void add_customProperty(flatbuffers::Offset customProperty) { fbb_.AddOffset(38, customProperty); } void add_callBackType(flatbuffers::Offset callBackType) { fbb_.AddOffset(40, callBackType); } void add_callBackName(flatbuffers::Offset callBackName) { fbb_.AddOffset(42, callBackName); } + void add_layoutComponent(flatbuffers::Offset layoutComponent) { fbb_.AddOffset(44, layoutComponent); } WidgetOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } WidgetOptionsBuilder &operator=(const WidgetOptionsBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 20)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 21)); return o; } }; @@ -400,8 +411,10 @@ inline flatbuffers::Offset CreateWidgetOptions(flatbuffers::FlatB flatbuffers::Offset frameEvent = 0, flatbuffers::Offset customProperty = 0, flatbuffers::Offset callBackType = 0, - flatbuffers::Offset callBackName = 0) { + flatbuffers::Offset callBackName = 0, + flatbuffers::Offset layoutComponent = 0) { WidgetOptionsBuilder builder_(_fbb); + builder_.add_layoutComponent(layoutComponent); builder_.add_callBackName(callBackName); builder_.add_callBackType(callBackType); builder_.add_customProperty(customProperty); @@ -425,6 +438,111 @@ inline flatbuffers::Offset CreateWidgetOptions(flatbuffers::FlatB return builder_.Finish(); } +struct LayoutComponentTable : private flatbuffers::Table { + uint8_t positionXPercentEnabled() const { return GetField(4, 0); } + uint8_t positionYPercentEnabled() const { return GetField(6, 0); } + float positionXPercent() const { return GetField(8, 0); } + float positionYPercent() const { return GetField(10, 0); } + uint8_t sizeXPercentEnable() const { return GetField(12, 0); } + uint8_t sizeYPercentEnable() const { return GetField(14, 0); } + float sizeXPercent() const { return GetField(16, 0); } + float sizeYPercent() const { return GetField(18, 0); } + uint8_t stretchHorizontalEnabled() const { return GetField(20, 0); } + uint8_t stretchVerticalEnabled() const { return GetField(22, 0); } + const flatbuffers::String *horizontalEdge() const { return GetPointer(24); } + const flatbuffers::String *verticalEdge() const { return GetPointer(26); } + float leftMargin() const { return GetField(28, 0); } + float rightMargin() const { return GetField(30, 0); } + float topMargin() const { return GetField(32, 0); } + float bottomMargin() const { return GetField(34, 0); } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyField(verifier, 4 /* positionXPercentEnabled */) && + VerifyField(verifier, 6 /* positionYPercentEnabled */) && + VerifyField(verifier, 8 /* positionXPercent */) && + VerifyField(verifier, 10 /* positionYPercent */) && + VerifyField(verifier, 12 /* sizeXPercentEnable */) && + VerifyField(verifier, 14 /* sizeYPercentEnable */) && + VerifyField(verifier, 16 /* sizeXPercent */) && + VerifyField(verifier, 18 /* sizeYPercent */) && + VerifyField(verifier, 20 /* stretchHorizontalEnabled */) && + VerifyField(verifier, 22 /* stretchVerticalEnabled */) && + VerifyField(verifier, 24 /* horizontalEdge */) && + verifier.Verify(horizontalEdge()) && + VerifyField(verifier, 26 /* verticalEdge */) && + verifier.Verify(verticalEdge()) && + VerifyField(verifier, 28 /* leftMargin */) && + VerifyField(verifier, 30 /* rightMargin */) && + VerifyField(verifier, 32 /* topMargin */) && + VerifyField(verifier, 34 /* bottomMargin */) && + verifier.EndTable(); + } +}; + +struct LayoutComponentTableBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_positionXPercentEnabled(uint8_t positionXPercentEnabled) { fbb_.AddElement(4, positionXPercentEnabled, 0); } + void add_positionYPercentEnabled(uint8_t positionYPercentEnabled) { fbb_.AddElement(6, positionYPercentEnabled, 0); } + void add_positionXPercent(float positionXPercent) { fbb_.AddElement(8, positionXPercent, 0); } + void add_positionYPercent(float positionYPercent) { fbb_.AddElement(10, positionYPercent, 0); } + void add_sizeXPercentEnable(uint8_t sizeXPercentEnable) { fbb_.AddElement(12, sizeXPercentEnable, 0); } + void add_sizeYPercentEnable(uint8_t sizeYPercentEnable) { fbb_.AddElement(14, sizeYPercentEnable, 0); } + void add_sizeXPercent(float sizeXPercent) { fbb_.AddElement(16, sizeXPercent, 0); } + void add_sizeYPercent(float sizeYPercent) { fbb_.AddElement(18, sizeYPercent, 0); } + void add_stretchHorizontalEnabled(uint8_t stretchHorizontalEnabled) { fbb_.AddElement(20, stretchHorizontalEnabled, 0); } + void add_stretchVerticalEnabled(uint8_t stretchVerticalEnabled) { fbb_.AddElement(22, stretchVerticalEnabled, 0); } + void add_horizontalEdge(flatbuffers::Offset horizontalEdge) { fbb_.AddOffset(24, horizontalEdge); } + void add_verticalEdge(flatbuffers::Offset verticalEdge) { fbb_.AddOffset(26, verticalEdge); } + void add_leftMargin(float leftMargin) { fbb_.AddElement(28, leftMargin, 0); } + void add_rightMargin(float rightMargin) { fbb_.AddElement(30, rightMargin, 0); } + void add_topMargin(float topMargin) { fbb_.AddElement(32, topMargin, 0); } + void add_bottomMargin(float bottomMargin) { fbb_.AddElement(34, bottomMargin, 0); } + LayoutComponentTableBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } + LayoutComponentTableBuilder &operator=(const LayoutComponentTableBuilder &); + flatbuffers::Offset Finish() { + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 16)); + return o; + } +}; + +inline flatbuffers::Offset CreateLayoutComponentTable(flatbuffers::FlatBufferBuilder &_fbb, + uint8_t positionXPercentEnabled = 0, + uint8_t positionYPercentEnabled = 0, + float positionXPercent = 0, + float positionYPercent = 0, + uint8_t sizeXPercentEnable = 0, + uint8_t sizeYPercentEnable = 0, + float sizeXPercent = 0, + float sizeYPercent = 0, + uint8_t stretchHorizontalEnabled = 0, + uint8_t stretchVerticalEnabled = 0, + flatbuffers::Offset horizontalEdge = 0, + flatbuffers::Offset verticalEdge = 0, + float leftMargin = 0, + float rightMargin = 0, + float topMargin = 0, + float bottomMargin = 0) { + LayoutComponentTableBuilder builder_(_fbb); + builder_.add_bottomMargin(bottomMargin); + builder_.add_topMargin(topMargin); + builder_.add_rightMargin(rightMargin); + builder_.add_leftMargin(leftMargin); + builder_.add_verticalEdge(verticalEdge); + builder_.add_horizontalEdge(horizontalEdge); + builder_.add_sizeYPercent(sizeYPercent); + builder_.add_sizeXPercent(sizeXPercent); + builder_.add_positionYPercent(positionYPercent); + builder_.add_positionXPercent(positionXPercent); + builder_.add_stretchVerticalEnabled(stretchVerticalEnabled); + builder_.add_stretchHorizontalEnabled(stretchHorizontalEnabled); + builder_.add_sizeYPercentEnable(sizeYPercentEnable); + builder_.add_sizeXPercentEnable(sizeXPercentEnable); + builder_.add_positionYPercentEnabled(positionYPercentEnabled); + builder_.add_positionXPercentEnabled(positionXPercentEnabled); + return builder_.Finish(); +} + struct SingleNodeOptions : private flatbuffers::Table { const WidgetOptions *nodeOptions() const { return GetPointer(4); } bool Verify(flatbuffers::Verifier &verifier) const { @@ -1557,12 +1675,16 @@ inline flatbuffers::Offset CreateListViewOptions(flatbuffers::F struct ProjectNodeOptions : private flatbuffers::Table { const WidgetOptions *nodeOptions() const { return GetPointer(4); } const flatbuffers::String *fileName() const { return GetPointer(6); } + uint8_t isLoop() const { return GetField(8, 1); } + uint8_t isAutoPlay() const { return GetField(10, 1); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* nodeOptions */) && verifier.VerifyTable(nodeOptions()) && VerifyField(verifier, 6 /* fileName */) && verifier.Verify(fileName()) && + VerifyField(verifier, 8 /* isLoop */) && + VerifyField(verifier, 10 /* isAutoPlay */) && verifier.EndTable(); } }; @@ -1572,20 +1694,26 @@ struct ProjectNodeOptionsBuilder { flatbuffers::uoffset_t start_; void add_nodeOptions(flatbuffers::Offset nodeOptions) { fbb_.AddOffset(4, nodeOptions); } void add_fileName(flatbuffers::Offset fileName) { fbb_.AddOffset(6, fileName); } + void add_isLoop(uint8_t isLoop) { fbb_.AddElement(8, isLoop, 1); } + void add_isAutoPlay(uint8_t isAutoPlay) { fbb_.AddElement(10, isAutoPlay, 1); } ProjectNodeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } ProjectNodeOptionsBuilder &operator=(const ProjectNodeOptionsBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 2)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 4)); return o; } }; inline flatbuffers::Offset CreateProjectNodeOptions(flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset nodeOptions = 0, - flatbuffers::Offset fileName = 0) { + flatbuffers::Offset fileName = 0, + uint8_t isLoop = 1, + uint8_t isAutoPlay = 1) { ProjectNodeOptionsBuilder builder_(_fbb); builder_.add_fileName(fileName); builder_.add_nodeOptions(nodeOptions); + builder_.add_isAutoPlay(isAutoPlay); + builder_.add_isLoop(isLoop); return builder_.Finish(); } diff --git a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp index d3c135a831..615973aee7 100644 --- a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp +++ b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp @@ -167,7 +167,15 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithXMLFile(const std::str while (element) { // CCLOG("entity name = %s", element->Name()); - + if (strcmp("PropertyGroup", element->Name()) == 0) + { + const tinyxml2::XMLAttribute* attribute = element->FirstAttribute(); + while (attribute && strcmp("Version", attribute->Name()) != 0) + attribute = attribute->Next(); + if (attribute) + _csdVersion = attribute->Value(); + } + if (strcmp("Content", element->Name()) == 0) { const tinyxml2::XMLAttribute* attribute = element->FirstAttribute(); @@ -248,10 +256,11 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithXMLFile(const std::str auto csparsebinary = CreateCSParseBinary(*_builder, _builder->CreateVector(_textures), - _builder->CreateVector(_texturePngs), + _builder->CreateVector(_texturePngs), nodeTree, - aciton); - _builder->Finish(csparsebinary); + aciton, + _builder->CreateString(_csdVersion)); + _builder->Finish(csparsebinary); _textures.clear(); _texturePngs.clear(); @@ -988,7 +997,15 @@ FlatBufferBuilder* FlatBuffersSerialize::createFlatBuffersWithXMLFileForSimulato while (element) { // CCLOG("entity name = %s", element->Name()); - + if (strcmp("PropertyGroup", element->Name()) == 0) + { + const tinyxml2::XMLAttribute* attribute = element->FirstAttribute(); + while (attribute && strcmp("Version", attribute->Name()) != 0) + attribute = attribute->Next(); + if (attribute) + _csdVersion = attribute->Value(); + } + if (strcmp("Content", element->Name()) == 0) { const tinyxml2::XMLAttribute* attribute = element->FirstAttribute(); @@ -1046,10 +1063,11 @@ FlatBufferBuilder* FlatBuffersSerialize::createFlatBuffersWithXMLFileForSimulato } auto csparsebinary = CreateCSParseBinary(*_builder, - _builder->CreateVector(_textures), - _builder->CreateVector(_texturePngs), + _builder->CreateVector(_textures), + _builder->CreateVector(_texturePngs), nodeTree, - aciton); + aciton, + _builder->CreateString(_csdVersion)); _builder->Finish(csparsebinary); _textures.clear(); diff --git a/cocos/editor-support/cocostudio/FlatBuffersSerialize.h b/cocos/editor-support/cocostudio/FlatBuffersSerialize.h index f514a8f38f..bdaea811ea 100644 --- a/cocos/editor-support/cocostudio/FlatBuffersSerialize.h +++ b/cocos/editor-support/cocostudio/FlatBuffersSerialize.h @@ -128,6 +128,7 @@ public: std::string classType); flatbuffers::Offset createProjectNodeOptionsForSimulator(const tinyxml2::XMLElement* objectData); /**/ + std::string getCsdVersion() { return _csdVersion; } public: std::vector> _textures; @@ -137,7 +138,7 @@ public: private: flatbuffers::FlatBufferBuilder* _builder; flatbuffers::Offset* _csparsebinary; - + std::string _csdVersion; }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp index e4136795a5..3064733e99 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -796,6 +796,11 @@ namespace cocostudio Size scale9Size(options->scale9Size()->width(), options->scale9Size()->height()); button->setContentSize(scale9Size); } + else + { + Size contentSize(options->widgetOptions()->size()->width(), options->widgetOptions()->size()->height()); + button->setContentSize(contentSize); + } } Node* ButtonReader::createNodeWithFlatBuffers(const flatbuffers::Table *buttonOptions) diff --git a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp index 1fbd8da0ac..ac5b11a127 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp @@ -375,7 +375,11 @@ namespace cocostudio Rect capInsets(f_capInset->x(), f_capInset->y(), f_capInset->width(), f_capInset->height()); imageView->setCapInsets(capInsets); } - + else + { + Size contentSize(options->widgetOptions()->size()->width(), options->widgetOptions()->size()->height()); + imageView->setContentSize(contentSize); + } } Node* ImageViewReader::createNodeWithFlatBuffers(const flatbuffers::Table *imageViewOptions) diff --git a/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp index 38d46b4a88..2270cc66bb 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp @@ -29,7 +29,7 @@ #include "tinyxml2.h" #include "flatbuffers/flatbuffers.h" - +#include "ui/UILayoutComponent.h" USING_NS_CC; using namespace flatbuffers; @@ -87,6 +87,23 @@ namespace cocostudio bool touchEnabled = false; std::string frameEvent = ""; std::string customProperty = ""; + + bool positionXPercentEnabled = false; + bool positionYPercentEnabled = false; + float positionXPercent = 0; + float positionYPercent = 0; + bool sizeXPercentEnable = false; + bool sizeYPercentEnable = false; + float sizeXPercent = 0; + float sizeYPercent = 0; + bool stretchHorizontalEnabled = false; + bool stretchVerticalEnabled = false; + std::string horizontalEdge; + std::string verticalEdge; + float leftMargin = 0; + float rightMargin = 0; + float topMargin = 0; + float bottomMargin = 0; // attributes const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute(); @@ -151,6 +168,54 @@ namespace cocostudio { frameEvent = value; } + else if (attriname == "PositionPrecentXEnabled") + { + positionXPercentEnabled = value == "True"; + } + else if (attriname == "PositionPrecentYEnabled") + { + positionYPercentEnabled = value == "True"; + } + else if (attriname == "PercentWidthEnable") + { + sizeXPercentEnable = value == "True"; + } + else if (attriname == "PercentHeightEnbale") + { + sizeYPercentEnable = value == "True"; + } + else if (attriname == "StretchWidthEnable") + { + stretchHorizontalEnabled = value == "True"; + } + else if (attriname == "StretchHeightEnable") + { + stretchVerticalEnabled = value == "True"; + } + else if (attriname == "HorizontalEage") + { + horizontalEdge = value; + } + else if (attriname == "VerticalEage") + { + verticalEdge = value; + } + else if (attriname == "LeftMargin") + { + leftMargin = atof(value.c_str()); + } + else if (attriname == "RightMargin") + { + rightMargin = atof(value.c_str()); + } + else if (attriname == "TopMargin") + { + topMargin = atof(value.c_str()); + } + else if (attriname == "ButtomMargin") + { + bottomMargin = atof(value.c_str()); + } attribute = attribute->Next(); } @@ -276,7 +341,48 @@ namespace cocostudio attribute = attribute->Next(); } } - + else if (attriname == "PrePosition") + { + attribute = child->FirstAttribute(); + + while (attribute) + { + attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "X") + { + positionXPercent = atof(value.c_str()); + } + else if (attriname == "Y") + { + positionYPercent = atof(value.c_str()); + } + + attribute = attribute->Next(); + } + } + else if (attriname == "PreSize") + { + attribute = child->FirstAttribute(); + + while (attribute) + { + attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "X") + { + sizeXPercent = atof(value.c_str()); + } + else if (attriname == "Y") + { + sizeYPercent = atof(value.c_str()); + } + + attribute = attribute->Next(); + } + } child = child->NextSiblingElement(); } @@ -286,7 +392,23 @@ namespace cocostudio AnchorPoint f_anchortpoint(anchorPoint.x, anchorPoint.y); Color f_color(color.a, color.r, color.g, color.b); FlatSize f_size(size.x, size.y); - + auto f_layoutComponent = CreateLayoutComponentTable(*builder, + positionXPercentEnabled, + positionYPercentEnabled, + positionXPercent, + positionYPercent, + sizeXPercentEnable, + sizeYPercentEnable, + sizeXPercent, + sizeYPercent, + stretchHorizontalEnabled, + stretchVerticalEnabled, + builder->CreateString(horizontalEdge), + builder->CreateString(verticalEdge), + leftMargin, + rightMargin, + topMargin, + bottomMargin); auto options = CreateWidgetOptions(*builder, builder->CreateString(name), @@ -306,8 +428,10 @@ namespace cocostudio ignoreSize, touchEnabled, builder->CreateString(frameEvent), - builder->CreateString(customProperty) - ); + builder->CreateString(customProperty), + 0, + 0, + f_layoutComponent); return *(Offset*)(&options); } @@ -368,8 +492,80 @@ namespace cocostudio node->setCascadeColorEnabled(true); node->setCascadeOpacityEnabled(true); + + setLayoutComponentPropsWithFlatBuffers(node, nodeOptions); } - + + void NodeReader::setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions) + { + auto layoutComponentTable = ((WidgetOptions*)nodeOptions)->layoutComponent(); + if (!layoutComponentTable) return; + + bool positionXPercentEnabled = layoutComponentTable->positionXPercentEnabled(); + bool positionYPercentEnabled = layoutComponentTable->positionYPercentEnabled(); + float positionXPercent = layoutComponentTable->positionXPercent(); + float positionYPercent = layoutComponentTable->positionYPercent(); + bool sizeXPercentEnable = layoutComponentTable->sizeXPercentEnable(); + bool sizeYPercentEnable = layoutComponentTable->sizeYPercentEnable(); + float sizeXPercent = layoutComponentTable->sizeXPercent(); + float sizeYPercent = layoutComponentTable->sizeYPercent(); + bool stretchHorizontalEnabled = layoutComponentTable->stretchHorizontalEnabled(); + bool stretchVerticalEnabled = layoutComponentTable->stretchVerticalEnabled(); + std::string horizontalEdge = layoutComponentTable->horizontalEdge()->c_str(); + std::string verticalEdge = layoutComponentTable->verticalEdge()->c_str(); + float leftMargin = layoutComponentTable->leftMargin(); + float rightMargin = layoutComponentTable->rightMargin(); + float topMargin = layoutComponentTable->topMargin(); + float bottomMargin = layoutComponentTable->bottomMargin(); + + auto layoutComponent = ui::LayoutComponent::create(); + node->addComponent(layoutComponent); + + layoutComponent->setPositionPercentXEnabled(positionXPercentEnabled); + layoutComponent->setPositionPercentYEnabled(positionYPercentEnabled); + layoutComponent->setPositionPercentX(positionXPercent); + layoutComponent->setPositionPercentY(positionYPercent); + layoutComponent->setPercentWidthEnabled(sizeXPercentEnable); + layoutComponent->setPercentHeightEnabled(sizeYPercentEnable); + layoutComponent->setPercentWidth(sizeXPercent); + layoutComponent->setPercentHeight(sizeYPercent); + layoutComponent->setStretchWidthEnabled(stretchHorizontalEnabled); + layoutComponent->setStretchHeightEnabled(stretchVerticalEnabled); + ui::LayoutComponent::HorizontalEage horizontalEdgeType = ui::LayoutComponent::HorizontalEage::None; + if (horizontalEdge == "LeftEage") + { + horizontalEdgeType = ui::LayoutComponent::HorizontalEage::Left; + } + else if (horizontalEdge == "RightEage") + { + horizontalEdgeType = ui::LayoutComponent::HorizontalEage::Right; + } + else if (horizontalEdge == "BothEage") + { + horizontalEdgeType = ui::LayoutComponent::HorizontalEage::Center; + } + layoutComponent->setHorizontalEage(horizontalEdgeType); + ui::LayoutComponent::VerticalEage verticalEdgeType = ui::LayoutComponent::VerticalEage::None; + if (verticalEdge == "TopEage") + { + verticalEdgeType = ui::LayoutComponent::VerticalEage::Top; + } + else if (verticalEdge == "ButtomEage") + { + verticalEdgeType = ui::LayoutComponent::VerticalEage::Bottom; + } + else if (verticalEdge == "BothEage") + { + verticalEdgeType = ui::LayoutComponent::VerticalEage::Center; + } + layoutComponent->setVerticalEage(verticalEdgeType); + + layoutComponent->setTopMargin(topMargin); + layoutComponent->setButtomMargin(bottomMargin); + layoutComponent->setLeftMargin(leftMargin); + layoutComponent->setRightMargin(rightMargin); + } + Node* NodeReader::createNodeWithFlatBuffers(const flatbuffers::Table *nodeOptions) { Node* node = Node::create(); diff --git a/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.h b/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.h index 57fb46f660..84049e6d73 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.h @@ -46,6 +46,7 @@ namespace cocostudio flatbuffers::Offset createOptionsWithFlatBuffers(const tinyxml2::XMLElement* objectData, flatbuffers::FlatBufferBuilder* builder); void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions); + void setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* nodeOptions); }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp index 5e382580c3..4e4d8397ae 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp @@ -9,6 +9,8 @@ #include "tinyxml2.h" #include "flatbuffers/flatbuffers.h" +#include "ui/UILayoutComponent.h" +#include "../ActionTimeline/CSLoader.h" USING_NS_CC; using namespace ui; @@ -384,6 +386,23 @@ namespace cocostudio std::string customProperty = ""; std::string callbackType = ""; std::string callbackName = ""; + + bool positionXPercentEnabled = false; + bool positionYPercentEnabled = false; + float positionXPercent = 0; + float positionYPercent = 0; + bool sizeXPercentEnable = false; + bool sizeYPercentEnable = false; + float sizeXPercent = 0; + float sizeYPercent = 0; + bool stretchHorizontalEnabled = false; + bool stretchVerticalEnabled = false; + std::string horizontalEdge; + std::string verticalEdge; + float leftMargin = 0; + float rightMargin = 0; + float topMargin = 0; + float bottomMargin = 0; // attributes const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute(); @@ -456,7 +475,55 @@ namespace cocostudio { callbackName = value; } - + else if (attriname == "PositionPrecentXEnabled") + { + positionXPercentEnabled = value == "True"; + } + else if (attriname == "PositionPrecentYEnabled") + { + positionYPercentEnabled = value == "True"; + } + else if (attriname == "PercentWidthEnable") + { + sizeXPercentEnable = value == "True"; + } + else if (attriname == "PercentHeightEnbale") + { + sizeYPercentEnable = value == "True"; + } + else if (attriname == "StretchWidthEnable") + { + stretchHorizontalEnabled = value == "True"; + } + else if (attriname == "StretchHeightEnable") + { + stretchVerticalEnabled = value == "True"; + } + else if (attriname == "HorizontalEage") + { + horizontalEdge = value; + } + else if (attriname == "VerticalEage") + { + verticalEdge = value; + } + else if (attriname == "LeftMargin") + { + leftMargin = atof(value.c_str()); + } + else if (attriname == "RightMargin") + { + rightMargin = atof(value.c_str()); + } + else if (attriname == "TopMargin") + { + topMargin = atof(value.c_str()); + } + else if (attriname == "ButtomMargin") + { + bottomMargin = atof(value.c_str()); + } + attribute = attribute->Next(); } @@ -581,6 +648,48 @@ namespace cocostudio attribute = attribute->Next(); } } + else if (attriname == "PrePosition") + { + attribute = child->FirstAttribute(); + + while (attribute) + { + attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "X") + { + positionXPercent = atof(value.c_str()); + } + else if (attriname == "Y") + { + positionYPercent = atof(value.c_str()); + } + + attribute = attribute->Next(); + } + } + else if (attriname == "PreSize") + { + attribute = child->FirstAttribute(); + + while (attribute) + { + attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "X") + { + sizeXPercent = atof(value.c_str()); + } + else if (attriname == "Y") + { + sizeYPercent = atof(value.c_str()); + } + + attribute = attribute->Next(); + } + } child = child->NextSiblingElement(); } @@ -591,6 +700,23 @@ namespace cocostudio AnchorPoint f_anchortpoint(anchorPoint.x, anchorPoint.y); Color f_color(color.a, color.r, color.g, color.b); FlatSize f_size(size.x, size.y); + auto f_layoutComponent = CreateLayoutComponentTable(*builder, + positionXPercentEnabled, + positionYPercentEnabled, + positionXPercent, + positionYPercent, + sizeXPercentEnable, + sizeYPercentEnable, + sizeXPercent, + sizeYPercent, + stretchHorizontalEnabled, + stretchVerticalEnabled, + builder->CreateString(horizontalEdge), + builder->CreateString(verticalEdge), + leftMargin, + rightMargin, + topMargin, + bottomMargin); auto options = CreateWidgetOptions(*builder, builder->CreateString(name), @@ -612,8 +738,8 @@ namespace cocostudio builder->CreateString(frameEvent), builder->CreateString(customProperty), builder->CreateString(callbackType), - builder->CreateString(callbackName) - ); + builder->CreateString(callbackName), + f_layoutComponent); return *(Offset
*)(&options); } @@ -629,7 +755,33 @@ namespace cocostudio widget->setAnchorPoint(Vec2::ZERO); widget->setUnifySizeEnabled(true); - + std::string versionString = CSLoader::getInstance()->getCsdVersion(); + + //assume versionString is like "2.0.6.0" + if (versionString.length() > 0) + { + int p1, p2, p3, v1, v2, v3; + p1 = p2 = p3 = v1 = v2 = v3 = 0; + p1 = versionString.find('.'); + if (p1 > 0) + { + p2 = versionString.find('.', p1 + 1); + v1 = atoi(versionString.substr(0, p1).c_str()); + } + if (p2 > p1) + { + p3 = versionString.find('.', p2 + 1); + v2 = atoi(versionString.substr(p1 + 1, p2 - p1 - 1).c_str()); + } + if (p3 > p2) + { + v3 = atoi(versionString.substr(p2 + 1, p3 - p2 - 1).c_str()); + } + + if (!(v1 <= 2 && v2 == 0 && v3 <= 6)) + widget->setUnifySizeEnabled(false); + } + bool ignoreSize = options->ignoreSize(); widget->ignoreContentAdaptWithSize(ignoreSize); @@ -691,6 +843,77 @@ namespace cocostudio std::string callbackName = options->callBackName()->c_str(); widget->setCallbackName(callbackName); + setLayoutComponentPropsWithFlatBuffers(widget, widgetOptions); + } + + void WidgetReader::setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions) + { + auto layoutComponentTable = ((WidgetOptions*)nodeOptions)->layoutComponent(); + if (!layoutComponentTable) return; + + bool positionXPercentEnabled = layoutComponentTable->positionXPercentEnabled(); + bool positionYPercentEnabled = layoutComponentTable->positionYPercentEnabled(); + float positionXPercent = layoutComponentTable->positionXPercent(); + float positionYPercent = layoutComponentTable->positionYPercent(); + bool sizeXPercentEnable = layoutComponentTable->sizeXPercentEnable(); + bool sizeYPercentEnable = layoutComponentTable->sizeYPercentEnable(); + float sizeXPercent = layoutComponentTable->sizeXPercent(); + float sizeYPercent = layoutComponentTable->sizeYPercent(); + bool stretchHorizontalEnabled = layoutComponentTable->stretchHorizontalEnabled(); + bool stretchVerticalEnabled = layoutComponentTable->stretchVerticalEnabled(); + std::string horizontalEdge = layoutComponentTable->horizontalEdge()->c_str(); + std::string verticalEdge = layoutComponentTable->verticalEdge()->c_str(); + float leftMargin = layoutComponentTable->leftMargin(); + float rightMargin = layoutComponentTable->rightMargin(); + float topMargin = layoutComponentTable->topMargin(); + float bottomMargin = layoutComponentTable->bottomMargin(); + + auto layoutComponent = ui::LayoutComponent::create(); + node->addComponent(layoutComponent); + + layoutComponent->setPositionPercentXEnabled(positionXPercentEnabled); + layoutComponent->setPositionPercentYEnabled(positionYPercentEnabled); + layoutComponent->setPositionPercentX(positionXPercent); + layoutComponent->setPositionPercentY(positionYPercent); + layoutComponent->setPercentWidthEnabled(sizeXPercentEnable); + layoutComponent->setPercentHeightEnabled(sizeYPercentEnable); + layoutComponent->setPercentWidth(sizeXPercent); + layoutComponent->setPercentHeight(sizeYPercent); + layoutComponent->setStretchWidthEnabled(stretchHorizontalEnabled); + layoutComponent->setStretchHeightEnabled(stretchVerticalEnabled); + ui::LayoutComponent::HorizontalEage horizontalEdgeType = ui::LayoutComponent::HorizontalEage::None; + if (horizontalEdge == "LeftEage") + { + horizontalEdgeType = ui::LayoutComponent::HorizontalEage::Left; + } + else if (horizontalEdge == "RightEage") + { + horizontalEdgeType = ui::LayoutComponent::HorizontalEage::Right; + } + else if (horizontalEdge == "BothEage") + { + horizontalEdgeType = ui::LayoutComponent::HorizontalEage::Center; + } + layoutComponent->setHorizontalEage(horizontalEdgeType); + ui::LayoutComponent::VerticalEage verticalEdgeType = ui::LayoutComponent::VerticalEage::None; + if (verticalEdge == "TopEage") + { + verticalEdgeType = ui::LayoutComponent::VerticalEage::Top; + } + else if (verticalEdge == "ButtomEage") + { + verticalEdgeType = ui::LayoutComponent::VerticalEage::Bottom; + } + else if (verticalEdge == "BothEage") + { + verticalEdgeType = ui::LayoutComponent::VerticalEage::Center; + } + layoutComponent->setVerticalEage(verticalEdgeType); + + layoutComponent->setTopMargin(topMargin); + layoutComponent->setButtomMargin(bottomMargin); + layoutComponent->setLeftMargin(leftMargin); + layoutComponent->setRightMargin(rightMargin); } Node* WidgetReader::createNodeWithFlatBuffers(const flatbuffers::Table *widgetOptions) diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h index 19276f3ea2..6e0a456753 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h @@ -60,6 +60,7 @@ namespace cocostudio flatbuffers::Offset createOptionsWithFlatBuffers(const tinyxml2::XMLElement* objectData, flatbuffers::FlatBufferBuilder* builder); void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* widgetOptions); + void setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* widgetOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* widgetOptions); /**/