diff --git a/cocos/2d/libcocos2d.vcxproj b/cocos/2d/libcocos2d.vcxproj index 8e828b70d7..b4703e3a77 100644 --- a/cocos/2d/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d.vcxproj @@ -325,6 +325,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + @@ -724,6 +725,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + @@ -758,6 +760,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + diff --git a/cocos/2d/libcocos2d.vcxproj.filters b/cocos/2d/libcocos2d.vcxproj.filters index f47532b1d9..6f875a692a 100644 --- a/cocos/2d/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d.vcxproj.filters @@ -241,6 +241,9 @@ {92ff4e66-3943-47da-a439-c8f182bb871a} + + {e1848cce-b225-42c4-bb6e-6430b6da123b} + @@ -1301,6 +1304,9 @@ base\allocator + + cocostudio\reader\WidgetReader\ArmatureNode + @@ -2544,6 +2550,12 @@ base\allocator + + cocostudio\reader\WidgetReader\ArmatureNode + + + cocostudio\reader\WidgetReader\ArmatureNode + diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp index 99da4ab027..00a7e9e0f7 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp @@ -786,12 +786,23 @@ Node* CSLoader::nodeWithFlatBuffers(const flatbuffers::NodeTree *nodetree) { node = createNodeWithFlatBuffersFile(filePath); reader->setPropsWithFlatBuffers(node, options->data()); - + + bool isloop = projectNodeOptions->isLoop(); + bool isautoplay = projectNodeOptions->isAutoPlay(); + cocostudio::timeline::ActionTimeline* action = cocostudio::timeline::ActionTimelineCache::getInstance()->createActionWithFlatBuffersFile(filePath); - if(action) + if (action) { node->runAction(action); action->gotoFrameAndPlay(0); + if (isautoplay) + { + action->gotoFrameAndPlay(0, isloop); + } + else + { + action->gotoFrameAndPause(0); + } } } } @@ -1112,12 +1123,22 @@ Node* CSLoader::nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree *nod { node = createNodeWithFlatBuffersForSimulator(filePath); reader->setPropsWithFlatBuffers(node, options->data()); - - cocostudio::timeline::ActionTimeline* action = cocostudio::timeline::ActionTimelineCache::getInstance()->createActionWithFlatBuffersForSimulator(filePath); + + bool isloop = projectNodeOptions->isLoop(); + bool isautoplay = projectNodeOptions->isAutoPlay(); + cocostudio::timeline::ActionTimeline* action = cocostudio::timeline::ActionTimelineCache::getInstance()->createActionWithFlatBuffersFile(filePath); if (action) { node->runAction(action); action->gotoFrameAndPlay(0); + if (isautoplay) + { + action->gotoFrameAndPlay(0, isloop); + } + else + { + action->gotoFrameAndPause(0); + } } } } diff --git a/cocos/editor-support/cocostudio/ArmatureNodeReader.cpp b/cocos/editor-support/cocostudio/ArmatureNodeReader.cpp new file mode 100644 index 0000000000..76667450ac --- /dev/null +++ b/cocos/editor-support/cocostudio/ArmatureNodeReader.cpp @@ -0,0 +1,160 @@ +#include "tinyxml2/tinyxml2.h" +#include "flatbuffers/flatbuffers.h" +#include "cocostudio/WidgetReader/NodeReader/NodeReader.h" +#include "cocostudio/CSParseBinary_generated.h" +#include "CSArmatureNode_generated.h" +#include "cocostudio/ArmatureNodeReader.h" +#include "cocostudio/CCArmature.h" + + +USING_NS_CC; +using namespace cocostudio; +using namespace flatbuffers; + +IMPLEMENT_CLASS_NODE_READER_INFO(ArmatureNodeReader) + +ArmatureNodeReader::ArmatureNodeReader() +{ + +} + +ArmatureNodeReader::~ArmatureNodeReader() +{ + +} + +static ArmatureNodeReader* _instanceArmatureNodeReader = nullptr; + +ArmatureNodeReader* ArmatureNodeReader::getInstance() +{ + if (_instanceArmatureNodeReader == nullptr) + { + _instanceArmatureNodeReader = new (std::nothrow) ArmatureNodeReader(); + } + return _instanceArmatureNodeReader; +} + +Offset ArmatureNodeReader::createOptionsWithFlatBuffers(const tinyxml2::XMLElement *objectData, + flatbuffers::FlatBufferBuilder *builder) +{ + + auto temp = NodeReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder); + auto nodeOptions = *(Offset*)(&temp); + + bool isloop = false; + bool isAutoPlay = false; + std::string currentAnimationName = ""; + + int type = 0; + std::string path = ""; + + const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute(); + while (attribute) + { + std::string attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "IsLoop") + { + isloop = (value == "True") ? true : false; + } + else if (attriname == "IsAutoPlay") + { + isAutoPlay = (value == "True") ? true : false; + } + else if (attriname == "CurrentAnimationName") + { + currentAnimationName = value; + } + + attribute = attribute->Next(); + } + + const tinyxml2::XMLElement* child = objectData->FirstChildElement(); + while (child) + { + std::string attriname = child->Name(); + if (attriname == "FileData") + { + attribute = child->FirstAttribute(); + + while (attribute) + { + attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "Type") + { + type = 0; + } + else if (attriname == "Path") + { + path = value; + } + + attribute = attribute->Next(); + } + } + + child = child->NextSiblingElement(); + } + + auto options = CreateCSArmatureNodeOption(*builder, + nodeOptions, + CreateResourceItemData(*builder, + type, + builder->CreateString(path)), + isloop, + isAutoPlay, + builder->CreateString(currentAnimationName)); + + return *(Offset
*)(&options); +} + +void ArmatureNodeReader::setPropsWithFlatBuffers(cocos2d::Node *node, + const flatbuffers::Table *nodeOptions) +{ + + auto* custom = static_cast(node); + auto options = (flatbuffers::CSArmatureNodeOption*)nodeOptions; + auto reader = ArmatureNodeReader::getInstance(); + + std::string filepath(options->fileData()->path()->c_str()); + ArmatureDataManager::getInstance()->addArmatureFileInfo(FileUtils::getInstance()->fullPathForFilename(filepath)); + custom->init(getArmatureName(filepath)); + if (options->isAutoPlay()) + custom->getAnimation()->play(options->currentAnimationName()->c_str(), -1, options->isLoop()); + else + custom->getAnimation()->setIsPlaying(false); +} + +cocos2d::Node* ArmatureNodeReader::createNodeWithFlatBuffers(const flatbuffers::Table *nodeOptions) +{ + auto node = CCArmature::create(); + + // self + auto options = (flatbuffers::CSArmatureNodeOption*)nodeOptions; + setPropsWithFlatBuffers(node, (Table*)options); + + // super node + auto NodeReader = NodeReader::getInstance(); + NodeReader->setPropsWithFlatBuffers(node, (Table*)options->nodeOptions()); + + return node; +} + + + +std::string ArmatureNodeReader::getArmatureName(const std::string& exporJsonPath) +{ + //FileUtils.getFileData(exporJsonPath, "r", size) // need read armature name in exportJsonPath + int end = exporJsonPath.find_last_of("."); + int start = exporJsonPath.find_last_of("\\") + 1; + int start1 = exporJsonPath.find_last_of("/") + 1; + if (start < start1) + start = start1; + + if (start == -1) + start = 0; + return exporJsonPath.substr(start, end - start); +} \ No newline at end of file diff --git a/cocos/editor-support/cocostudio/ArmatureNodeReader.h b/cocos/editor-support/cocostudio/ArmatureNodeReader.h new file mode 100644 index 0000000000..667cf0779d --- /dev/null +++ b/cocos/editor-support/cocostudio/ArmatureNodeReader.h @@ -0,0 +1,43 @@ + + +#ifndef __ARMATURENODEREADER_H_ +#define __ARMATURENODEREADER_H_ + +#include "cocos2d.h" +#include "cocostudio/FlatBuffersSerialize.h" +#include "cocostudio/WidgetReader/NodeReaderProtocol.h" +#include "cocostudio/WidgetReader/NodeReaderDefine.h" + + +/**************************************** +* reader of CSArmatureNode +* @param register reader before use it: +CSLoader* instance = CSLoader::getInstance(); +instance->registReaderObject("ArmatureNodeReader", (ObjectFactory::Instance)CustomSpriteReader::getInstance); +*@param Reader's name must be CLASSNAME#Reader, CLASSNAME is the dataobject's prefix: CLASSNAME#ObjectData +* +* +*****************************************/ +class ArmatureNodeReader : public cocos2d::Ref, public cocostudio::NodeReaderProtocol +{ + DECLARE_CLASS_NODE_READER_INFO + +public: + + ArmatureNodeReader(); + ~ArmatureNodeReader(); + + static ArmatureNodeReader* getInstance(); + static void purge(); + + flatbuffers::Offset createOptionsWithFlatBuffers(const tinyxml2::XMLElement* objectData, + flatbuffers::FlatBufferBuilder* builder); + void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* textBMFontOptions); + + //CSArmatureNode + cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* nodeOptions) override; +private: + std::string getArmatureName(const std::string& exporJsonPath); +}; + +#endif /* defined(__ARMATURENODEREADER_H_) */ diff --git a/cocos/editor-support/cocostudio/CSArmatureNode_generated.h b/cocos/editor-support/cocostudio/CSArmatureNode_generated.h new file mode 100644 index 0000000000..8122ddf54e --- /dev/null +++ b/cocos/editor-support/cocostudio/CSArmatureNode_generated.h @@ -0,0 +1,108 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +#ifndef FLATBUFFERS_GENERATED_CSARMATURENODE_FLATBUFFERS_H_ +#define FLATBUFFERS_GENERATED_CSARMATURENODE_FLATBUFFERS_H_ + +#include "flatbuffers/flatbuffers.h" + + +namespace flatbuffers { + +struct CSArmatureNodeOption; +struct ResourceItemData; + + +struct CSArmatureNodeOption : private flatbuffers::Table { + const WidgetOptions *nodeOptions() const { return GetPointer(4); } + const ResourceItemData *fileData() const { return GetPointer(6); } + uint8_t isLoop() const { return GetField(8, 1); } + uint8_t isAutoPlay() const { return GetField(10, 1); } + const flatbuffers::String *currentAnimationName() const { return GetPointer(12); } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyField(verifier, 4 /* nodeOptions */) && + verifier.VerifyTable(nodeOptions()) && + VerifyField(verifier, 6 /* fileData */) && + verifier.VerifyTable(fileData()) && + VerifyField(verifier, 8 /* isLoop */) && + VerifyField(verifier, 10 /* isAutoPlay */) && + VerifyField(verifier, 12 /* currentAnimationName */) && + verifier.Verify(currentAnimationName()) && + verifier.EndTable(); + } +}; + +struct CSArmatureNodeOptionBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_nodeOptions(flatbuffers::Offset nodeOptions) { fbb_.AddOffset(4, nodeOptions); } + void add_fileData(flatbuffers::Offset fileData) { fbb_.AddOffset(6, fileData); } + void add_isLoop(uint8_t isLoop) { fbb_.AddElement(8, isLoop, 1); } + void add_isAutoPlay(uint8_t isAutoPlay) { fbb_.AddElement(10, isAutoPlay, 1); } + void add_currentAnimationName(flatbuffers::Offset currentAnimationName) { fbb_.AddOffset(12, currentAnimationName); } + CSArmatureNodeOptionBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } + CSArmatureNodeOptionBuilder &operator=(const CSArmatureNodeOptionBuilder &); + flatbuffers::Offset Finish() { + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 5)); + return o; + } +}; + +inline flatbuffers::Offset CreateCSArmatureNodeOption(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset nodeOptions = 0, + flatbuffers::Offset fileData = 0, + uint8_t isLoop = 1, + uint8_t isAutoPlay = 1, + flatbuffers::Offset currentAnimationName = 0) { + CSArmatureNodeOptionBuilder builder_(_fbb); + builder_.add_currentAnimationName(currentAnimationName); + builder_.add_fileData(fileData); + builder_.add_nodeOptions(nodeOptions); + builder_.add_isAutoPlay(isAutoPlay); + builder_.add_isLoop(isLoop); + return builder_.Finish(); +} + +struct ResourceItemData : private flatbuffers::Table { + int32_t type() const { return GetField(4, 0); } + const flatbuffers::String *path() const { return GetPointer(6); } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyField(verifier, 4 /* type */) && + VerifyField(verifier, 6 /* path */) && + verifier.Verify(path()) && + verifier.EndTable(); + } +}; + +struct ResourceItemDataBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_type(int32_t type) { fbb_.AddElement(4, type, 0); } + void add_path(flatbuffers::Offset path) { fbb_.AddOffset(6, path); } + ResourceItemDataBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } + ResourceItemDataBuilder &operator=(const ResourceItemDataBuilder &); + flatbuffers::Offset Finish() { + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 2)); + return o; + } +}; + +inline flatbuffers::Offset CreateResourceItemData(flatbuffers::FlatBufferBuilder &_fbb, + int32_t type = 0, + flatbuffers::Offset path = 0) { + ResourceItemDataBuilder builder_(_fbb); + builder_.add_path(path); + builder_.add_type(type); + return builder_.Finish(); +} + +inline const CSArmatureNodeOption *GetCSArmatureNodeOption(const void *buf) { return flatbuffers::GetRoot(buf); } + +inline bool VerifyCSArmatureNodeOptionBuffer(flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer(); } + +inline void FinishCSArmatureNodeOptionBuffer(flatbuffers::FlatBufferBuilder &fbb, flatbuffers::Offset root) { fbb.Finish(root); } + +} // namespace flatbuffers + +#endif // FLATBUFFERS_GENERATED_CSARMATURENODE_FLATBUFFERS_H_ 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..230f933ae4 100644 --- a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp +++ b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp @@ -1169,9 +1169,29 @@ Offset FlatBuffersSerialize::createProjectNodeOptionsForSimu { auto temp = NodeReader::getInstance()->createOptionsWithFlatBuffers(objectData, _builder); auto nodeOptions = *(Offset*)(&temp); - + std::string filename = ""; - + + + bool isloop = true; + bool isAutoPlay = true; + const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute(); + while (attribute) + { + std::string attriname = attribute->Name(); + std::string value = attribute->Value(); + if (attriname == "IsLoop") + { + isloop = (value == "True") ? true : false; + + } + else if (attriname == "IsAutoPlay") + { + isAutoPlay = (value == "True") ? true : false; + } + attribute = attribute->Next(); + } + // FileData const tinyxml2::XMLElement* child = objectData->FirstChildElement(); while (child) @@ -1201,7 +1221,9 @@ Offset FlatBuffersSerialize::createProjectNodeOptionsForSimu return CreateProjectNodeOptions(*_builder, nodeOptions, - _builder->CreateString(filename)); + _builder->CreateString(filename), + isloop, + isAutoPlay); } } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp index 3b733b434e..23ff6f16b5 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp @@ -69,7 +69,27 @@ namespace cocostudio auto nodeOptions = *(Offset*)(&temp); std::string filename = ""; - + bool isloop = true; + bool isAutoPlay = true; + + const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute(); + while (attribute) + { + std::string attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "IsLoop") + { + isloop = (value == "True") ? true : false; + } + else if (attriname == "IsAutoPlay") + { + isAutoPlay = (value == "True") ? true : false; + } + + attribute = attribute->Next(); + } + // FileData const tinyxml2::XMLElement* child = objectData->FirstChildElement(); while (child) @@ -101,49 +121,9 @@ namespace cocostudio auto options = CreateProjectNodeOptions(*builder, nodeOptions, - builder->CreateString(filename)); - - return *(Offset
*)(&options); - } - - Offset
ProjectNodeReader::createOptionsWithFlatBuffersForSimulator(const tinyxml2::XMLElement *objectData, - flatbuffers::FlatBufferBuilder *builder) - { - auto temp = NodeReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder); - auto nodeOptions = *(Offset*)(&temp); - - std::string filename = ""; - - // FileData - const tinyxml2::XMLElement* child = objectData->FirstChildElement(); - while (child) - { - std::string name = child->Name(); - - if (name == "FileData") - { - const tinyxml2::XMLAttribute* attribute = child->FirstAttribute(); - - while (attribute) - { - name = attribute->Name(); - std::string value = attribute->Value(); - - if (name == "Path") - { - filename = value; - } - - attribute = attribute->Next(); - } - } - - child = child->NextSiblingElement(); - } - - auto options = CreateProjectNodeOptions(*builder, - nodeOptions, - builder->CreateString(filename)); + builder->CreateString(filename), + isloop, + isAutoPlay); return *(Offset
*)(&options); } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.h b/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.h index e32b6ab2d5..48b2fccd43 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.h @@ -44,8 +44,7 @@ namespace cocostudio flatbuffers::Offset createOptionsWithFlatBuffers(const tinyxml2::XMLElement* objectData, flatbuffers::FlatBufferBuilder* builder); - flatbuffers::Offset createOptionsWithFlatBuffersForSimulator(const tinyxml2::XMLElement* objectData, - flatbuffers::FlatBufferBuilder* builder); + void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* projectNodeOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* nodeOptions) { return nullptr; }; }; diff --git a/tests/cpp-tests/Classes/AppDelegate.cpp b/tests/cpp-tests/Classes/AppDelegate.cpp index 66a9bbbd6e..2a07f89f61 100644 --- a/tests/cpp-tests/Classes/AppDelegate.cpp +++ b/tests/cpp-tests/Classes/AppDelegate.cpp @@ -122,6 +122,7 @@ bool AppDelegate::applicationDidFinishLaunching() searchPaths.push_back("ccs-res/hd/cocosui/CustomTest/CustomWidgetCallbackBindTest"); searchPaths.push_back("hd/ActionTimeline"); + searchPaths.push_back("ccs-res/hd/armature"); } else { @@ -161,6 +162,8 @@ bool AppDelegate::applicationDidFinishLaunching() searchPaths.push_back("ccs-res/cocosui/CustomTest/CustomWidgetCallbackBindTest"); searchPaths.push_back("ActionTimeline"); + searchPaths.push_back("ccs-res/armature"); + } fileUtils->setSearchPaths(searchPaths); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index 08e53d316e..012e4500c4 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -78,6 +78,9 @@ Layer *CreateLayer(int index) case TEST_DIRECT_FROM_BINARY: pLayer = new (std::nothrow) TestLoadFromBinary(); break; + case TEST_ARMATURE_NODE: + pLayer = new (std::nothrow) TestArmatureNode(); + break; default: break; } @@ -1601,3 +1604,26 @@ void TestLoadFromBinary::dataLoaded( float percent ) m_armatureIndex = 0; } } + + + +//TestArmatureNode + +void TestArmatureNode::onEnter() +{ + ArmatureTestLayer::onEnter(); + + auto node = CSLoader::createNode("TestArmatureNode.csb"); + addChild(node); +} + + +std::string TestArmatureNode::title() const +{ + return "Test Armature Node"; +} +std::string TestArmatureNode::subtitle() const +{ + return "Csb file loaded"; +} + diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index a5e1a3f49a..82d273ebee 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -46,6 +46,7 @@ enum { TEST_EASING, TEST_CHANGE_ANIMATION_INTERNAL, TEST_DIRECT_FROM_BINARY, + TEST_ARMATURE_NODE, TEST_LAYER_COUNT }; @@ -412,4 +413,12 @@ private: int m_armatureIndex; // index of sync loaded armature, default -1 is none }; +class TestArmatureNode : public ArmatureTestLayer +{ +public: + virtual void onEnter(); + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + #endif // __HELLOWORLD_SCENE_H__ diff --git a/tests/cpp-tests/Resources/ccs-res b/tests/cpp-tests/Resources/ccs-res index 1d8bede8e9..3ff088ff83 160000 --- a/tests/cpp-tests/Resources/ccs-res +++ b/tests/cpp-tests/Resources/ccs-res @@ -1 +1 @@ -Subproject commit 1d8bede8e900625bc47972c4a925763e43f70ba2 +Subproject commit 3ff088ff83f49ccf1ecc30c58e880031aa3339ed