diff --git a/cocos/editor-support/cocostudio/CCActionManagerEx.cpp b/cocos/editor-support/cocostudio/CCActionManagerEx.cpp index f36a9d3030..d359a12043 100644 --- a/cocos/editor-support/cocostudio/CCActionManagerEx.cpp +++ b/cocos/editor-support/cocostudio/CCActionManagerEx.cpp @@ -33,10 +33,10 @@ static ActionManagerEx* sharedActionManager = nullptr; ActionManagerEx* ActionManagerEx::getInstance() { - if (!sharedActionManager) { - sharedActionManager = new (std::nothrow) ActionManagerEx(); - } - return sharedActionManager; + if (!sharedActionManager) { + sharedActionManager = new (std::nothrow) ActionManagerEx(); + } + return sharedActionManager; } void ActionManagerEx::destroyInstance() @@ -55,30 +55,31 @@ ActionManagerEx::ActionManagerEx() ActionManagerEx::~ActionManagerEx() { - _actionDic.clear(); + _actionDic.clear(); } -void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::Value &dic, Ref* root) +void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::Value &dic, Ref* root, int version) { - std::string path = jsonName; - ssize_t pos = path.find_last_of("/"); - std::string fileName = path.substr(pos+1,path.length()); - cocos2d::Vector actionList; - int actionCount = DICTOOL->getArrayCount_json(dic, "actionlist"); - for (int i=0; iautorelease(); - const rapidjson::Value &actionDic = DICTOOL->getDictionaryFromArray_json(dic, "actionlist", i); - action->initWithDictionary(actionDic,root); - actionList.pushBack(action); - } - _actionDic[fileName] = actionList; + std::string path = jsonName; + this->_studioVersionNumber = version; + ssize_t pos = path.find_last_of("/"); + std::string fileName = path.substr(pos+1,path.length()); + cocos2d::Vector actionList; + int actionCount = DICTOOL->getArrayCount_json(dic, "actionlist"); + for (int i=0; iautorelease(); + const rapidjson::Value &actionDic = DICTOOL->getDictionaryFromArray_json(dic, "actionlist", i); + action->initWithDictionary(actionDic,root); + actionList.pushBack(action); + } + _actionDic[fileName] = actionList; } void ActionManagerEx::initWithBinary(const char* file, cocos2d::Ref *root, CocoLoader* cocoLoader, - stExpCocoNode* pCocoNode) + stExpCocoNode* pCocoNode) { std::string path = file; ssize_t pos = path.find_last_of("/"); @@ -113,54 +114,54 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V ActionObject* ActionManagerEx::getActionByName(const char* jsonName,const char* actionName) { - std::string path = jsonName; - ssize_t pos = path.find_last_of("/"); - std::string fileName = path.substr(pos+1,path.length()); - auto iterator = _actionDic.find(fileName); - if (iterator == _actionDic.end()) - { - return nullptr; - } - auto actionList = iterator->second; - for (int i = 0; i < actionList.size(); i++) - { - ActionObject* action = actionList.at(i); - if (strcmp(actionName, action->getName()) == 0) - { - return action; - } - } - return nullptr; + std::string path = jsonName; + ssize_t pos = path.find_last_of("/"); + std::string fileName = path.substr(pos+1,path.length()); + auto iterator = _actionDic.find(fileName); + if (iterator == _actionDic.end()) + { + return nullptr; + } + auto actionList = iterator->second; + for (int i = 0; i < actionList.size(); i++) + { + ActionObject* action = actionList.at(i); + if (strcmp(actionName, action->getName()) == 0) + { + return action; + } + } + return nullptr; } ActionObject* ActionManagerEx::playActionByName(const char* jsonName,const char* actionName) { - ActionObject* action = getActionByName(jsonName,actionName); - if (action) - { - action->play(); - } - return action; + ActionObject* action = getActionByName(jsonName,actionName); + if (action) + { + action->play(); + } + return action; } ActionObject* ActionManagerEx::playActionByName(const char* jsonName,const char* actionName, CallFunc* func) { - ActionObject* action = getActionByName(jsonName,actionName); - if (action) - { - action->play(func); - } - return action; + ActionObject* action = getActionByName(jsonName,actionName); + if (action) + { + action->play(func); + } + return action; } ActionObject* ActionManagerEx::stopActionByName(const char* jsonName,const char* actionName) { - ActionObject* action = getActionByName(jsonName,actionName); - if (action) - { - action->stop(); - } - return action; + ActionObject* action = getActionByName(jsonName,actionName); + if (action) + { + action->stop(); + } + return action; } void ActionManagerEx::releaseActions() @@ -182,4 +183,9 @@ void ActionManagerEx::releaseActions() _actionDic.clear(); } +int ActionManagerEx::getStudioVersionNumber() const +{ + return this->_studioVersionNumber; +} + } diff --git a/cocos/editor-support/cocostudio/CCActionManagerEx.h b/cocos/editor-support/cocostudio/CCActionManagerEx.h index eec3ba75cd..01b9cd17b3 100644 --- a/cocos/editor-support/cocostudio/CCActionManagerEx.h +++ b/cocos/editor-support/cocostudio/CCActionManagerEx.h @@ -110,7 +110,7 @@ public: ActionObject* stopActionByName(const char* jsonName,const char* actionName); /*init properties with json dictionary*/ - void initWithDictionary(const char* jsonName,const rapidjson::Value &dic, Ref* root); + void initWithDictionary(const char* jsonName,const rapidjson::Value &dic, Ref* root, int version = 1600); void initWithBinary(const char* file, Ref* root, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode); /** @@ -119,8 +119,11 @@ public: */ void releaseActions(); + int getStudioVersionNumber() const; + protected: std::unordered_map> _actionDic; + int _studioVersionNumber; }; } diff --git a/cocos/editor-support/cocostudio/CCActionNode.cpp b/cocos/editor-support/cocostudio/CCActionNode.cpp index 9000018a65..0970a9db1e 100644 --- a/cocos/editor-support/cocostudio/CCActionNode.cpp +++ b/cocos/editor-support/cocostudio/CCActionNode.cpp @@ -29,6 +29,8 @@ THE SOFTWARE. #include "ui/UILayout.h" #include "editor-support/cocostudio/CocoLoader.h" #include "base/ccUtils.h" +#include "editor-support/cocostudio/CCActionManagerEx.h" + using namespace cocos2d; using namespace ui; @@ -107,7 +109,7 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root) { float positionX = DICTOOL->getFloatValue_json(actionFrameDic, "positionx"); float positionY = DICTOOL->getFloatValue_json(actionFrameDic, "positiony"); - if (positionOffset && (nullptr != node->getParent())) + if (positionOffset && (nullptr != node->getParent()) && ActionManagerEx::getInstance()->getStudioVersionNumber() < 1600) { Vec2 AnchorPointIn = node->getParent()->getAnchorPointInPoints(); positionX += AnchorPointIn.x; @@ -136,7 +138,7 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root) actionFrame->setScaleY(scaleY); auto cActionArray = _frameArray.at((int)kKeyframeScale); cActionArray->pushBack(actionFrame); - actionFrame->release(); + actionFrame->release(); } bool existRotation = DICTOOL->checkObjectExist_json(actionFrameDic,"rotation"); @@ -637,7 +639,7 @@ void ActionNode::easingToFrame(float duration,float delayTime,ActionFrame* srcFr if (cAction == nullptr || cNode == nullptr) { return; - } + } cAction->startWithTarget(cNode); cAction->update(delayTime); } diff --git a/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp b/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp index 8ce870784f..572bfe310b 100644 --- a/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp +++ b/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp @@ -251,7 +251,12 @@ static bool js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx(JSContext *c js_proxy_t *proxy = jsb_get_js_proxy(obj); cocostudio::ActionManagerEx* cobj = (cocostudio::ActionManagerEx *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx : Invalid Native Object"); - if (argc == 3) { + + int version = 0; + if (argc == 4) { + ok &= jsval_to_int(cx, args.get(3), &version); + } + if (argc >= 3) { const char* arg0; const char* arg1; cocos2d::Ref* arg2; @@ -271,7 +276,7 @@ static bool js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx(JSContext *c JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx : Error processing arguments"); - cobj->initWithDictionary(arg0, arg1Jsondoc, arg2); + cobj->initWithDictionary(arg0, arg1Jsondoc, arg2, version); args.rval().setUndefined(); return true; } diff --git a/cocos/scripting/js-bindings/script/studio/jsb_studio_boot.js b/cocos/scripting/js-bindings/script/studio/jsb_studio_boot.js index e64312fc7e..88f4b6aa41 100644 --- a/cocos/scripting/js-bindings/script/studio/jsb_studio_boot.js +++ b/cocos/scripting/js-bindings/script/studio/jsb_studio_boot.js @@ -40,8 +40,8 @@ ccs.actionManager = ccs.ActionManager.getInstance(); ccs.ActionManager.prototype.clear = function() { this.releaseActions(); }; -ccs.ActionManager.prototype.initWithDictionary = function(file, dic, node) { - ccs.actionManager.initWithDictionaryEx(file, JSON.stringify(dic), node); +ccs.ActionManager.prototype.initWithDictionary = function(file, dic, node, version) { + ccs.actionManager.initWithDictionaryEx(file, JSON.stringify(dic), node, version); } /** @@ -70,4 +70,4 @@ ccs.Component.extend = ccs.Component.extend || cc.Component.extend; ccs.SkinNode = cc.Node; ccs.BoneNode.extend = cc.Class.extend; -ccs.SkeletonNode.extend = cc.Class.extend; \ No newline at end of file +ccs.SkeletonNode.extend = cc.Class.extend; diff --git a/cocos/scripting/js-bindings/script/studio/parsers/uiParser-1.x.js b/cocos/scripting/js-bindings/script/studio/parsers/uiParser-1.x.js index 4f88976592..c11d51c67c 100644 --- a/cocos/scripting/js-bindings/script/studio/parsers/uiParser-1.x.js +++ b/cocos/scripting/js-bindings/script/studio/parsers/uiParser-1.x.js @@ -39,7 +39,9 @@ deferred: function(json, resourcePath, node, file){ if(node){ - ccs.actionManager.initWithDictionary(file, json["animation"], node); + var version = json["Version"] || json["version"]; + var versionNum = ccs.uiReader.getVersionInteger(version); + ccs.actionManager.initWithDictionary(file, json["animation"], node, versionNum); node.setContentSize(cc.size(json["designWidth"], json["designHeight"])); } } @@ -702,4 +704,4 @@ load.registerParser("ccui", "*", parser); -})(ccs._load, ccs._parser); \ No newline at end of file +})(ccs._load, ccs._parser);