diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp index 869947a38e..60efaaabfb 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp @@ -265,7 +265,7 @@ Node* CSLoader::createNode(const std::string& filename) CCLOG("suffix = %s", suffix.c_str()); CSLoader* load = CSLoader::getInstance(); - + if (suffix == "csb") { return load->createNodeWithFlatBuffersFile(filename); @@ -274,7 +274,7 @@ Node* CSLoader::createNode(const std::string& filename) { return load->createNodeFromJson(filename); } - + return nullptr; } @@ -286,7 +286,7 @@ Node* CSLoader::createNode(const std::string &filename, const ccNodeLoadCallback CCLOG("suffix = %s", suffix.c_str()); CSLoader* load = CSLoader::getInstance(); - + if (suffix == "csb") { return load->createNodeWithFlatBuffersFile(filename, callback); @@ -295,6 +295,30 @@ Node* CSLoader::createNode(const std::string &filename, const ccNodeLoadCallback return nullptr; } +Node* CSLoader::createNodeWithVisibleSize(const std::string& filename) +{ + auto node = createNode(filename); + if (node != nullptr) + { + Size frameSize = Director::getInstance()->getVisibleSize(); + node->setContentSize(frameSize); + ui::Helper::doLayout(node); + } + return node; +} + +Node* CSLoader::createNodeWithVisibleSize(const std::string &filename, const ccNodeLoadCallback &callback) +{ + auto node = createNode(filename, callback); + if (node != nullptr) + { + Size frameSize = Director::getInstance()->getVisibleSize(); + node->setContentSize(frameSize); + ui::Helper::doLayout(node); + } + return node; +} + std::string CSLoader::getExtentionName(const std::string& name) { std::string result = ""; @@ -551,7 +575,7 @@ void CSLoader::initNode(Node* node, const rapidjson::Value& json) GLubyte red = (GLubyte)DICTOOL->getIntValue_json(json, RED, 255); GLubyte green = (GLubyte)DICTOOL->getIntValue_json(json, GREEN, 255); GLubyte blue = (GLubyte)DICTOOL->getIntValue_json(json, BLUE, 255); - int zorder = DICTOOL->getIntValue_json(json, ZORDER); + int zorder = DICTOOL->getIntValue_json(json, ZORDER); int tag = DICTOOL->getIntValue_json(json, TAG); int actionTag = DICTOOL->getIntValue_json(json, ACTION_TAG); bool visible = DICTOOL->getBooleanValue_json(json, VISIBLE); diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h index 76817ca6c7..bb2cfe516b 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.h @@ -81,6 +81,8 @@ public: static cocos2d::Node* createNode(const std::string& filename, const ccNodeLoadCallback& callback); static cocos2d::Node* createNode(const Data data); static cocos2d::Node* createNode(const Data data, const ccNodeLoadCallback &callback); + static cocos2d::Node* createNodeWithVisibleSize(const std::string& filename); + static cocos2d::Node* createNodeWithVisibleSize(const std::string& filename, const ccNodeLoadCallback& callback); static cocostudio::timeline::ActionTimeline* createTimeline(const std::string& filename); static cocostudio::timeline::ActionTimeline* createTimeline(const Data data, const std::string& filename); diff --git a/cocos/scripting/js-bindings/script/studio/jsb_studio_load.js b/cocos/scripting/js-bindings/script/studio/jsb_studio_load.js index 1b8ae731d8..74914a54d7 100644 --- a/cocos/scripting/js-bindings/script/studio/jsb_studio_load.js +++ b/cocos/scripting/js-bindings/script/studio/jsb_studio_load.js @@ -193,6 +193,28 @@ ccs.load = function(file, path){ return object; }; +/** + * Analysis of studio JSON file and layout ui widgets by visible size. + * The incoming file name, parse out the corresponding object + * Temporary support file list: + * ui 1.* + * node 1.* - 2.* + * action 1.* - 2.* + * scene 0.* - 1.* + * @param {String} file + * @param {String} [path=] Resource path + * @returns {{node: cc.Node, action: cc.Action}} + */ +ccs.loadWithVisibleSize = function(file, path){ + var object = ccs.load(file, path); + var size = cc.director.getVisibleSize(); + if(object.node && size){ + object.node.setContentSize(size.width, size.height); + ccui.helper.doLayout(object.node); + } + return object; +}; + //Forward compatible interface ccs.actionTimelineCache = {