diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 8f628365e9..5163037947 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -1253,6 +1253,12 @@ 38B8E2E219E671D2002D7CE7 /* UILayoutComponent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 38B8E2DF19E671D2002D7CE7 /* UILayoutComponent.cpp */; }; 38B8E2E319E671D2002D7CE7 /* UILayoutComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = 38B8E2E019E671D2002D7CE7 /* UILayoutComponent.h */; }; 38B8E2E419E671D2002D7CE7 /* UILayoutComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = 38B8E2E019E671D2002D7CE7 /* UILayoutComponent.h */; }; + 38F5263E1A48363B000DB7F7 /* ArmatureNodeReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 38F5263B1A48363B000DB7F7 /* ArmatureNodeReader.cpp */; }; + 38F5263F1A48363B000DB7F7 /* ArmatureNodeReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 38F5263B1A48363B000DB7F7 /* ArmatureNodeReader.cpp */; }; + 38F526401A48363B000DB7F7 /* ArmatureNodeReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 38F5263C1A48363B000DB7F7 /* ArmatureNodeReader.h */; }; + 38F526411A48363B000DB7F7 /* ArmatureNodeReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 38F5263C1A48363B000DB7F7 /* ArmatureNodeReader.h */; }; + 38F526421A48363B000DB7F7 /* CSArmatureNode_generated.h in Headers */ = {isa = PBXBuildFile; fileRef = 38F5263D1A48363B000DB7F7 /* CSArmatureNode_generated.h */; }; + 38F526431A48363B000DB7F7 /* CSArmatureNode_generated.h in Headers */ = {isa = PBXBuildFile; fileRef = 38F5263D1A48363B000DB7F7 /* CSArmatureNode_generated.h */; }; 3E2BDADE19C030ED0055CDCD /* AudioEngine.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E2BDADD19C030ED0055CDCD /* AudioEngine.h */; }; 3E2BDAEC19C0436F0055CDCD /* AudioEngine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E2BDAEB19C0436F0055CDCD /* AudioEngine.cpp */; }; 3E2F27A619CFBFE100E7C490 /* AudioEngine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E2BDAEB19C0436F0055CDCD /* AudioEngine.cpp */; }; @@ -2443,6 +2449,9 @@ 38B8E2D419E66581002D7CE7 /* CSLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSLoader.h; sourceTree = ""; }; 38B8E2DF19E671D2002D7CE7 /* UILayoutComponent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UILayoutComponent.cpp; sourceTree = ""; }; 38B8E2E019E671D2002D7CE7 /* UILayoutComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UILayoutComponent.h; sourceTree = ""; }; + 38F5263B1A48363B000DB7F7 /* ArmatureNodeReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArmatureNodeReader.cpp; sourceTree = ""; }; + 38F5263C1A48363B000DB7F7 /* ArmatureNodeReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArmatureNodeReader.h; sourceTree = ""; }; + 38F5263D1A48363B000DB7F7 /* CSArmatureNode_generated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSArmatureNode_generated.h; sourceTree = ""; }; 3E2BDADD19C030ED0055CDCD /* AudioEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioEngine.h; sourceTree = ""; }; 3E2BDAEB19C0436F0055CDCD /* AudioEngine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioEngine.cpp; sourceTree = ""; }; 3E6176551960F89B00DE83F5 /* CCController-iOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = "CCController-iOS.mm"; path = "../base/CCController-iOS.mm"; sourceTree = ""; }; @@ -4362,6 +4371,16 @@ path = SpriteReader; sourceTree = ""; }; + 38F5263A1A48363B000DB7F7 /* ArmatureNodeReader */ = { + isa = PBXGroup; + children = ( + 38F5263B1A48363B000DB7F7 /* ArmatureNodeReader.cpp */, + 38F5263C1A48363B000DB7F7 /* ArmatureNodeReader.h */, + 38F5263D1A48363B000DB7F7 /* CSArmatureNode_generated.h */, + ); + path = ArmatureNodeReader; + sourceTree = ""; + }; 46A15FD01807A56F005B8026 /* audio */ = { isa = PBXGroup; children = ( @@ -4963,6 +4982,7 @@ 50FCEB6818C72017004AD434 /* WidgetReader */ = { isa = PBXGroup; children = ( + 38F5263A1A48363B000DB7F7 /* ArmatureNodeReader */, 382384251A2590F9002C4610 /* NodeReader */, 3823843A1A259140002C4610 /* SingleNodeReader */, 382384411A25915C002C4610 /* SpriteReader */, @@ -5209,6 +5229,7 @@ 15AE180A19AAD2F700C27E9E /* CCAABB.h in Headers */, 46A170E71807CECA005B8026 /* CCPhysicsBody.h in Headers */, 15AE1A5A19AAD40300C27E9E /* b2StackAllocator.h in Headers */, + 38F526401A48363B000DB7F7 /* ArmatureNodeReader.h in Headers */, B29A7E3119EE1B7700872B35 /* SkinnedMeshAttachment.h in Headers */, 15AE1B6F19AADA9900C27E9E /* GUIDefine.h in Headers */, 15AE1A8119AAD40300C27E9E /* b2FrictionJoint.h in Headers */, @@ -5337,6 +5358,7 @@ 15AE1B6C19AADA9900C27E9E /* UIWidget.h in Headers */, 15AE180E19AAD2F700C27E9E /* CCAnimate3D.h in Headers */, 1A5701B3180BCB590088DEC7 /* CCFontFNT.h in Headers */, + 38F526421A48363B000DB7F7 /* CSArmatureNode_generated.h in Headers */, 15AE1BD919AAE01E00C27E9E /* CCControlStepper.h in Headers */, 15AE192119AAD35000C27E9E /* CocoStudio.h in Headers */, 15AE18A119AAD33D00C27E9E /* CCNodeLoaderListener.h in Headers */, @@ -5961,6 +5983,7 @@ 15AE1AA819AAD40300C27E9E /* b2Island.h in Headers */, 15B3708B19EE414C00ABE682 /* Manifest.h in Headers */, 1A570213180BCBF40088DEC7 /* CCProgressTimer.h in Headers */, + 38F526431A48363B000DB7F7 /* CSArmatureNode_generated.h in Headers */, B37510821823ACA100B3BA6A /* CCPhysicsJointInfo_chipmunk.h in Headers */, 1A570217180BCBF40088DEC7 /* CCRenderTexture.h in Headers */, 15AE1ABB19AAD40300C27E9E /* b2EdgeAndPolygonContact.h in Headers */, @@ -5992,6 +6015,7 @@ 15AE1A3B19AAD3D500C27E9E /* b2BroadPhase.h in Headers */, 15AE195619AAD35100C27E9E /* CCDisplayManager.h in Headers */, 15AE1B8719AADA9A00C27E9E /* UIButton.h in Headers */, + 38F526411A48363B000DB7F7 /* ArmatureNodeReader.h in Headers */, 50ABBE441925AB6F00A911A9 /* CCDirector.h in Headers */, 5034CA4A191D591100CE6051 /* ccShader_Label_df.frag in Headers */, 15AE1B7519AADA9A00C27E9E /* UILoadingBar.h in Headers */, @@ -6534,6 +6558,7 @@ 382383F01A258FA7002C4610 /* flatc.cpp in Sources */, 1A57028A180BCC900088DEC7 /* CCSpriteFrameCache.cpp in Sources */, 15AE18E619AAD35000C27E9E /* CCActionFrameEasing.cpp in Sources */, + 38F5263E1A48363B000DB7F7 /* ArmatureNodeReader.cpp in Sources */, B29A7DC919EE1B7700872B35 /* SlotData.c in Sources */, 15AE190F19AAD35000C27E9E /* CCInputDelegate.cpp in Sources */, 15AE181A19AAD2F700C27E9E /* CCBundle3D.cpp in Sources */, @@ -7017,6 +7042,7 @@ 15AE19B619AAD39700C27E9E /* TextBMFontReader.cpp in Sources */, 15AE1BFD19AAE01E00C27E9E /* CCInvocation.cpp in Sources */, B24AA98A195A675C007B4522 /* CCFastTMXTiledMap.cpp in Sources */, + 38F5263F1A48363B000DB7F7 /* ArmatureNodeReader.cpp in Sources */, 15AE18CE19AAD33D00C27E9E /* CCNodeLoader.cpp in Sources */, 38ACD1FD1A27111900C3093D /* WidgetCallBackHandlerProtocol.cpp in Sources */, 29394CF719B01DBA00D2DE1A /* UIWebViewImpl-ios.mm in Sources */, diff --git a/cocos/2d/libcocos2d.vcxproj b/cocos/2d/libcocos2d.vcxproj index 9a76bceed7..794eb88d50 100644 --- a/cocos/2d/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d.vcxproj @@ -363,6 +363,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + @@ -767,6 +768,8 @@ 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 b3c9d5794c..815ac9e9a4 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} + @@ -1304,6 +1307,9 @@ base\allocator + + cocostudio\reader\WidgetReader\ArmatureNodeReader + @@ -2550,6 +2556,12 @@ base\allocator + + cocostudio\reader\WidgetReader\ArmatureNodeReader + + + cocostudio\reader\WidgetReader\ArmatureNodeReader + diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems index cc461f644f..3d2ab32d4d 100644 --- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems +++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems @@ -231,6 +231,8 @@ + + @@ -634,6 +636,7 @@ + diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters index af92c8d5bd..abd28a29b8 100644 --- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters +++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters @@ -1261,6 +1261,12 @@ base + + cocostudio\reader\WidgetReader\ArmatureNodeReader + + + cocostudio\reader\WidgetReader\ArmatureNodeReader + @@ -2336,6 +2342,9 @@ base + + cocostudio\reader\WidgetReader\ArmatureNodeReader + @@ -2566,6 +2575,9 @@ {a6638f35-5c81-4835-9897-0f9efb0be02b} + + {1151b6b3-739f-4cff-add0-6b772fa7d226} + diff --git a/cocos/2d/libcocos2d_wp8.vcxproj b/cocos/2d/libcocos2d_wp8.vcxproj index a7b7d5a732..9ff4ef101c 100644 --- a/cocos/2d/libcocos2d_wp8.vcxproj +++ b/cocos/2d/libcocos2d_wp8.vcxproj @@ -377,6 +377,8 @@ + + @@ -853,6 +855,7 @@ + diff --git a/cocos/2d/libcocos2d_wp8.vcxproj.filters b/cocos/2d/libcocos2d_wp8.vcxproj.filters index af6ee16546..4222bbc3d3 100644 --- a/cocos/2d/libcocos2d_wp8.vcxproj.filters +++ b/cocos/2d/libcocos2d_wp8.vcxproj.filters @@ -242,6 +242,9 @@ {02d389d5-8f57-4bd6-b12a-95af86c5b356} + + {939d9d3e-06b3-494e-affd-070c2c1cbe1d} + @@ -1311,6 +1314,9 @@ base + + cocostudio\reader\WidgetReader\ArmatureNodeReader + @@ -2544,6 +2550,12 @@ base + + cocostudio\reader\WidgetReader\ArmatureNodeReader + + + cocostudio\reader\WidgetReader\ArmatureNodeReader + diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp index 95b423fba8..fd359dcc5a 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp @@ -57,6 +57,7 @@ #include "cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.h" #include "cocostudio/WidgetReader/PageViewReader/PageViewReader.h" #include "cocostudio/WidgetReader/ListViewReader/ListViewReader.h" +#include "cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h" #include "flatbuffers/flatbuffers.h" #include "flatbuffers/util.h" @@ -200,6 +201,8 @@ CSLoader::CSLoader() CREATE_CLASS_NODE_READER_INFO(PageViewReader); CREATE_CLASS_NODE_READER_INFO(ListViewReader); + CREATE_CLASS_NODE_READER_INFO(ArmatureNodeReader); + } void CSLoader::purge() @@ -789,12 +792,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); + } } } } @@ -1125,12 +1139,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/Android.mk b/cocos/editor-support/cocostudio/Android.mk index 76c658543a..fe9aee5840 100644 --- a/cocos/editor-support/cocostudio/Android.mk +++ b/cocos/editor-support/cocostudio/Android.mk @@ -68,8 +68,8 @@ ActionTimeline/CCTimeLine.cpp \ ActionTimeline/CCActionTimeline.cpp \ ActionTimeline/CSLoader.cpp \ FlatBuffersSerialize.cpp \ -WidgetCallBackHandlerProtocol.cpp - +WidgetCallBackHandlerProtocol.cpp \ +WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. diff --git a/cocos/editor-support/cocostudio/CMakeLists.txt b/cocos/editor-support/cocostudio/CMakeLists.txt index 0e7fe8710a..d0fe57d34d 100644 --- a/cocos/editor-support/cocostudio/CMakeLists.txt +++ b/cocos/editor-support/cocostudio/CMakeLists.txt @@ -69,6 +69,7 @@ set(COCOS_CS_SRC editor-support/cocostudio/ActionTimeline/CCTimeLine.cpp editor-support/cocostudio/ActionTimeline/CSLoader.cpp editor-support/cocostudio/FlatBuffersSerialize.cpp + editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp ) include_directories( editor-support ) diff --git a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp index 615973aee7..8397e5668c 100644 --- a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp +++ b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp @@ -1187,9 +1187,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) @@ -1219,7 +1239,9 @@ Offset FlatBuffersSerialize::createProjectNodeOptionsForSimu return CreateProjectNodeOptions(*_builder, nodeOptions, - _builder->CreateString(filename)); + _builder->CreateString(filename), + isloop, + isAutoPlay); } } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp new file mode 100644 index 0000000000..2494264820 --- /dev/null +++ b/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/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/WidgetReader/ArmatureNodeReader/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/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h b/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h new file mode 100644 index 0000000000..941680c4f5 --- /dev/null +++ b/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h @@ -0,0 +1,65 @@ +/**************************************************************************** +Copyright (c) 2014 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#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/WidgetReader/ArmatureNodeReader/CSArmatureNode_generated.h b/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/CSArmatureNode_generated.h new file mode 100644 index 0000000000..8122ddf54e --- /dev/null +++ b/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/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/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 c6142aede4..ddf3f8a4be 100644 --- a/tests/cpp-tests/Classes/AppDelegate.cpp +++ b/tests/cpp-tests/Classes/AppDelegate.cpp @@ -123,6 +123,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 { @@ -163,6 +164,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..2093b6e67a 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,27 @@ void TestLoadFromBinary::dataLoaded( float percent ) m_armatureIndex = 0; } } + + + +//TestArmatureNode + +void TestArmatureNode::onEnter() +{ + ArmatureTestLayer::onEnter(); + + auto node = CSLoader::createNode("TestArmatureNode.csb"); + addChild(node); + node->setPositionX(Director::getInstance()->getVisibleSize().width * .25f); +} + + +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 84e5fd6000..3a3364d79f 160000 --- a/tests/cpp-tests/Resources/ccs-res +++ b/tests/cpp-tests/Resources/ccs-res @@ -1 +1 @@ -Subproject commit 84e5fd6000d7439082f6a8b507f520a52c50ad4e +Subproject commit 3a3364d79fe4c8fa6487b65edf7a2104a496903e