From f88b23f52bf7871bab5836d3d6c0fd72dc6670c8 Mon Sep 17 00:00:00 2001 From: zhangcheng Date: Mon, 14 Sep 2015 13:07:15 +0800 Subject: [PATCH 1/5] Move "ui::Helper::DoLayout" to "CreateNode". --- .../cocostudio/ActionTimeline/CSLoader.cpp | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp index 869947a38e..1924c8beca 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp @@ -265,17 +265,24 @@ Node* CSLoader::createNode(const std::string& filename) CCLOG("suffix = %s", suffix.c_str()); CSLoader* load = CSLoader::getInstance(); - + Node *node = nullptr; if (suffix == "csb") { - return load->createNodeWithFlatBuffersFile(filename); + node = load->createNodeWithFlatBuffersFile(filename); } else if (suffix == "json" || suffix == "ExportJson") { - return load->createNodeFromJson(filename); + node = load->createNodeFromJson(filename); } - - return nullptr; + + if (node != nullptr) + { + Size frameSize = Director::getInstance()->getVisibleSize(); + node->setContentSize(frameSize); + ui::Helper::doLayout(node); + } + + return node; } Node* CSLoader::createNode(const std::string &filename, const ccNodeLoadCallback &callback) @@ -286,13 +293,20 @@ Node* CSLoader::createNode(const std::string &filename, const ccNodeLoadCallback CCLOG("suffix = %s", suffix.c_str()); CSLoader* load = CSLoader::getInstance(); - + Node *node = nullptr; if (suffix == "csb") { - return load->createNodeWithFlatBuffersFile(filename, callback); + node = load->createNodeWithFlatBuffersFile(filename, callback); } - return nullptr; + 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) @@ -551,7 +565,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); From 224f392a9c12556671946d677a0584e069dc7dc7 Mon Sep 17 00:00:00 2001 From: zhangcheng Date: Mon, 14 Sep 2015 16:51:58 +0800 Subject: [PATCH 2/5] Add createNodeWithVisibleSize to CSLoader. --- .../cocostudio/ActionTimeline/CSLoader.cpp | 36 ++++++++++++------- .../cocostudio/ActionTimeline/CSLoader.h | 2 ++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp index 1924c8beca..60efaaabfb 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp @@ -265,24 +265,17 @@ Node* CSLoader::createNode(const std::string& filename) CCLOG("suffix = %s", suffix.c_str()); CSLoader* load = CSLoader::getInstance(); - Node *node = nullptr; + if (suffix == "csb") { - node = load->createNodeWithFlatBuffersFile(filename); + return load->createNodeWithFlatBuffersFile(filename); } else if (suffix == "json" || suffix == "ExportJson") { - node = load->createNodeFromJson(filename); + return load->createNodeFromJson(filename); } - if (node != nullptr) - { - Size frameSize = Director::getInstance()->getVisibleSize(); - node->setContentSize(frameSize); - ui::Helper::doLayout(node); - } - - return node; + return nullptr; } Node* CSLoader::createNode(const std::string &filename, const ccNodeLoadCallback &callback) @@ -293,19 +286,36 @@ Node* CSLoader::createNode(const std::string &filename, const ccNodeLoadCallback CCLOG("suffix = %s", suffix.c_str()); CSLoader* load = CSLoader::getInstance(); - Node *node = nullptr; + if (suffix == "csb") { - node = load->createNodeWithFlatBuffersFile(filename, callback); + return load->createNodeWithFlatBuffersFile(filename, callback); } + 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; } 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); From 83f5f85f562dc0f70e958ed7f6ca32e72f2259a7 Mon Sep 17 00:00:00 2001 From: zhangcheng Date: Tue, 15 Sep 2015 11:16:02 +0800 Subject: [PATCH 3/5] add loadWithVisibleSize js function. --- .../script/studio/jsb_studio_load.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) 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..ead25a5e6c 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,36 @@ 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 = { + node: null, + action: null + }; + + object.node = ccs._load(file, null, path); + var size = cc.director.getVisibleSize(); + if(object.node && size){ + object.node.setContentSize(size.width, size.height); + ccui.helper.doLayout(object.node); + } + object.action = ccs._load(file, "action", path); + if(object.action && object.action.tag === -1 && object.node) + object.action.tag = object.node.tag; + return object; +}; + //Forward compatible interface ccs.actionTimelineCache = { From fa7f97b26e7bc97b01103d674d8b4cee6bc4052e Mon Sep 17 00:00:00 2001 From: zhangcheng Date: Tue, 15 Sep 2015 11:35:43 +0800 Subject: [PATCH 4/5] Adjustment spaces. --- .../js-bindings/script/studio/jsb_studio_load.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 ead25a5e6c..4554d9362d 100644 --- a/cocos/scripting/js-bindings/script/studio/jsb_studio_load.js +++ b/cocos/scripting/js-bindings/script/studio/jsb_studio_load.js @@ -212,11 +212,11 @@ ccs.loadWithVisibleSize = function(file, path){ }; object.node = ccs._load(file, null, path); - var size = cc.director.getVisibleSize(); - if(object.node && size){ - object.node.setContentSize(size.width, size.height); - ccui.helper.doLayout(object.node); - } + var size = cc.director.getVisibleSize(); + if(object.node && size){ + object.node.setContentSize(size.width, size.height); + ccui.helper.doLayout(object.node); + } object.action = ccs._load(file, "action", path); if(object.action && object.action.tag === -1 && object.node) object.action.tag = object.node.tag; From fb104189d4ff8f6a27470bdc6326f9246bf72c34 Mon Sep 17 00:00:00 2001 From: zhangcheng Date: Tue, 15 Sep 2015 13:04:45 +0800 Subject: [PATCH 5/5] Multiplexing ccs.load. --- .../js-bindings/script/studio/jsb_studio_load.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) 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 4554d9362d..74914a54d7 100644 --- a/cocos/scripting/js-bindings/script/studio/jsb_studio_load.js +++ b/cocos/scripting/js-bindings/script/studio/jsb_studio_load.js @@ -206,20 +206,12 @@ ccs.load = function(file, path){ * @returns {{node: cc.Node, action: cc.Action}} */ ccs.loadWithVisibleSize = function(file, path){ - var object = { - node: null, - action: null - }; - - object.node = ccs._load(file, null, 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); } - object.action = ccs._load(file, "action", path); - if(object.action && object.action.tag === -1 && object.node) - object.action.tag = object.node.tag; return object; };