Merge pull request #13801 from chengstory/OptimizateDoLayout

Move "ui::Helper::DoLayout"  to "CreateNode"。
This commit is contained in:
pandamicro 2015-09-15 13:37:00 +08:00
commit dbe3e062bc
3 changed files with 52 additions and 4 deletions

View File

@ -265,7 +265,7 @@ Node* CSLoader::createNode(const std::string& filename)
CCLOG("suffix = %s", suffix.c_str()); CCLOG("suffix = %s", suffix.c_str());
CSLoader* load = CSLoader::getInstance(); CSLoader* load = CSLoader::getInstance();
if (suffix == "csb") if (suffix == "csb")
{ {
return load->createNodeWithFlatBuffersFile(filename); return load->createNodeWithFlatBuffersFile(filename);
@ -274,7 +274,7 @@ Node* CSLoader::createNode(const std::string& filename)
{ {
return load->createNodeFromJson(filename); return load->createNodeFromJson(filename);
} }
return nullptr; return nullptr;
} }
@ -286,7 +286,7 @@ Node* CSLoader::createNode(const std::string &filename, const ccNodeLoadCallback
CCLOG("suffix = %s", suffix.c_str()); CCLOG("suffix = %s", suffix.c_str());
CSLoader* load = CSLoader::getInstance(); CSLoader* load = CSLoader::getInstance();
if (suffix == "csb") if (suffix == "csb")
{ {
return load->createNodeWithFlatBuffersFile(filename, callback); return load->createNodeWithFlatBuffersFile(filename, callback);
@ -295,6 +295,30 @@ Node* CSLoader::createNode(const std::string &filename, const ccNodeLoadCallback
return nullptr; 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 CSLoader::getExtentionName(const std::string& name)
{ {
std::string result = ""; 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 red = (GLubyte)DICTOOL->getIntValue_json(json, RED, 255);
GLubyte green = (GLubyte)DICTOOL->getIntValue_json(json, GREEN, 255); GLubyte green = (GLubyte)DICTOOL->getIntValue_json(json, GREEN, 255);
GLubyte blue = (GLubyte)DICTOOL->getIntValue_json(json, BLUE, 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 tag = DICTOOL->getIntValue_json(json, TAG);
int actionTag = DICTOOL->getIntValue_json(json, ACTION_TAG); int actionTag = DICTOOL->getIntValue_json(json, ACTION_TAG);
bool visible = DICTOOL->getBooleanValue_json(json, VISIBLE); bool visible = DICTOOL->getBooleanValue_json(json, VISIBLE);

View File

@ -81,6 +81,8 @@ public:
static cocos2d::Node* createNode(const std::string& filename, const ccNodeLoadCallback& callback); 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);
static cocos2d::Node* createNode(const Data data, const ccNodeLoadCallback &callback); 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 std::string& filename);
static cocostudio::timeline::ActionTimeline* createTimeline(const Data data, const std::string& filename); static cocostudio::timeline::ActionTimeline* createTimeline(const Data data, const std::string& filename);

View File

@ -193,6 +193,28 @@ ccs.load = function(file, path){
return object; 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 //Forward compatible interface
ccs.actionTimelineCache = { ccs.actionTimelineCache = {