Merge pull request #44 from WenhaiLin/master

Bug fix and stability improvements
This commit is contained in:
Wenhai Lin
2016-04-25 16:20:47 +08:00
21 changed files with 263 additions and 343 deletions
+5
View File
@@ -885,6 +885,11 @@ void Node::addChildHelper(Node* child, int localZOrder, int tag, const std::stri
if (child == nullptr) {
return;
}
if (child->_parent != nullptr)
{
log("child already added. It can't be added again");
return;
}
if (_children.empty())
{
this->childrenAlloc();
+2 -2
View File
@@ -531,7 +531,7 @@ Image* RenderTexture::newImage(bool fliimage)
glBindFramebuffer(GL_FRAMEBUFFER, _FBO);
// TODO: move this to configuration, so we don't check it every time
/* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers.
/* Certain Qualcomm Adreno GPU's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers.
*/
if (Configuration::getInstance()->checkForGLExtension("GL_QCOM"))
{
@@ -613,7 +613,7 @@ void RenderTexture::onBegin()
glBindFramebuffer(GL_FRAMEBUFFER, _FBO);
// TODO: move this to configuration, so we don't check it every time
/* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers.
/* Certain Qualcomm Adreno GPU's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers.
*/
if (Configuration::getInstance()->checkForGLExtension("GL_QCOM"))
{
+5 -4
View File
@@ -82,6 +82,7 @@ NS_CC_BEGIN
extern const char* cocos2dVersion();
Director* Director::DirectorInstance = nullptr;
bool Director::PurgeDirectorInNextLoop = false;
const char *Director::EVENT_PROJECTION_CHANGED = "director_projection_changed";
const char *Director::EVENT_AFTER_DRAW = "director_after_draw";
@@ -131,7 +132,7 @@ bool Director::init()
_paused = false;
// purge ?
_purgeDirectorInNextLoop = false;
PurgeDirectorInNextLoop = false;
// restart ?
_restartDirectorInNextLoop = false;
@@ -900,7 +901,7 @@ void Director::popToSceneStackLevel(int level)
void Director::end()
{
_purgeDirectorInNextLoop = true;
PurgeDirectorInNextLoop = true;
}
void Director::restart()
@@ -1321,10 +1322,10 @@ void DisplayLinkDirector::startAnimation()
void DisplayLinkDirector::mainLoop()
{
if (_purgeDirectorInNextLoop)
if (PurgeDirectorInNextLoop)
{
_purgeDirectorInNextLoop = false;
purgeDirector();
PurgeDirectorInNextLoop = false;
}
else if (_restartDirectorInNextLoop)
{
+2 -2
View File
@@ -490,13 +490,13 @@ public:
*/
const std::thread::id& getCocos2dThreadId() const { return _cocos2d_thread_id; }
bool isPurgeDirectorInNextLoop() const { return _purgeDirectorInNextLoop; }
static bool isPurgeDirectorInNextLoop() { return PurgeDirectorInNextLoop; }
void purgeDirector();
protected:
void reset();
bool _purgeDirectorInNextLoop; // this flag will be set to true in end()
static bool PurgeDirectorInNextLoop; // this flag will be set to true in end()
void restartDirector();
bool _restartDirectorInNextLoop; // this flag will be set to true in restart()
@@ -181,17 +181,15 @@ public:
}
std::vector<cocos2d::Vec2> _calculateVertices(cocos2d::SpriteFrame* spriteFrame, const cocos2d::Size& contentSize, float insetLeft, float insetRight, float insetTop, float insetBottom) {
float leftWidth, centerWidth, rightWidth;
float topHeight, centerHeight, bottomHeight;
float leftWidth, rightWidth;
float topHeight, bottomHeight;
auto rect = spriteFrame->getRect();
leftWidth = insetLeft;
rightWidth = insetRight;
centerWidth = rect.size.width - leftWidth - rightWidth;
topHeight = insetTop;
bottomHeight = insetBottom;
centerHeight = rect.size.height - topHeight - bottomHeight;
auto preferSize = contentSize;
auto sizableWidth = preferSize.width - leftWidth - rightWidth;
+13 -18
View File
@@ -50,8 +50,7 @@ void HttpClient::networkThread()
{
increaseThreadCount();
while (true) @autoreleasepool {
while (true) {
HttpRequest *request;
// step 1: send http request if the requestQueue isn't empty
@@ -68,22 +67,20 @@ void HttpClient::networkThread()
break;
}
// Create a HttpResponse object, the default setting is http access failed
HttpResponse *response = new (std::nothrow) HttpResponse(request);
processResponse(response, _responseMessage);
// add response packet into queue
_responseQueueMutex.lock();
_responseQueue.pushBack(response);
_responseQueueMutex.unlock();
_schedulerMutex.lock();
if (Director::DirectorInstance)
if (Director::DirectorInstance && !Director::isPurgeDirectorInNextLoop())
{
// Create a HttpResponse object, the default setting is http access failed
HttpResponse *response = new (std::nothrow) HttpResponse(request);
processResponse(response, _responseMessage);
// add response packet into queue
_responseQueueMutex.lock();
_responseQueue.pushBack(response);
_responseQueueMutex.unlock();
Director::DirectorInstance->getScheduler()->performFunctionInCocosThread(CC_CALLBACK_0(HttpClient::dispatchResponseCallbacks, this));
}
_schedulerMutex.unlock();
}
// cleanup: if worker thread received quit signal, clean up un-completed request queue
@@ -106,8 +103,7 @@ void HttpClient::networkThreadAlone(HttpRequest* request, HttpResponse* response
char responseMessage[RESPONSE_BUFFER_SIZE] = { 0 };
processResponse(response, responseMessage);
_schedulerMutex.lock();
if (Director::DirectorInstance)
if (Director::DirectorInstance && !Director::isPurgeDirectorInNextLoop())
{
Director::DirectorInstance->getScheduler()->performFunctionInCocosThread([this, response, request]{
const ccHttpRequestCallback& callback = request->getCallback();
@@ -127,7 +123,6 @@ void HttpClient::networkThreadAlone(HttpRequest* request, HttpResponse* response
request->release();
});
}
_schedulerMutex.unlock();
decreaseThreadCountAndMayDeleteThis();
}
@@ -755,7 +755,7 @@ bool js_creator_Scale9SpriteV2_constructor(JSContext *cx, uint32_t argc, jsval *
JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent));
args.rval().set(OBJECT_TO_JSVAL(obj));
// link the native object with the javascript object
js_proxy_t* p = jsb_new_proxy(cobj, obj);
jsb_new_proxy(cobj, obj);
if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok)
ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args);
return true;
@@ -5064,7 +5064,7 @@ void js_register_cocos2dx_EventKeyboard(JSContext *cx, JS::HandleObject global)
bool js_console_log(JSContext *cx, uint32_t argc, jsval *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if (argc == 1) {
if (argc >= 1) {
std::string msg;
bool ok = jsval_to_std_string(cx, args.get(0), &msg);
if (!ok) {
@@ -5077,7 +5077,6 @@ bool js_console_log(JSContext *cx, uint32_t argc, jsval *vp)
return true;
}
JS_ReportError(cx, "js_console_log : wrong number of arguments");
return false;
}
@@ -1966,198 +1966,117 @@ bool jsval_to_FontDefinition( JSContext *cx, JS::HandleValue vp, FontDefinition
JSB_PRECONDITION( jsobj, "Not a valid JS object");
// defaul values
const char * defautlFontName = "Arial";
const int defaultFontSize = 32;
TextHAlignment defaultTextAlignment = TextHAlignment::LEFT;
TextVAlignment defaultTextVAlignment = TextVAlignment::TOP;
// by default shadow and stroke are off
out->_shadow._shadowEnabled = false;
out->_stroke._strokeEnabled = false;
// white text by default
out->_fontFillColor = Color3B::WHITE;
out->_fontName = "Arial";
out->_fontSize = 32;
out->_alignment = TextHAlignment::LEFT;
out->_vertAlignment = TextVAlignment::TOP;
// font name
JS::RootedValue jsr(cx);
JS_GetProperty(cx, jsobj, "fontName", &jsr);
JS::ToString(cx, jsr);
JSStringWrapper wrapper(jsr);
const char* fontName = wrapper.get();
if (fontName && strlen(fontName) > 0)
{
out->_fontName = fontName;
}
else
{
out->_fontName = defautlFontName;
}
JS::RootedValue jsFontName(cx);
if (JS_GetProperty(cx, jsobj, "fontName", &jsFontName) && !jsFontName.isNullOrUndefined())
jsval_to_std_string(cx, jsFontName, &(out->_fontName));
// font size
bool hasProperty, hasSecondProp;
JS_HasProperty(cx, jsobj, "fontSize", &hasProperty);
if ( hasProperty )
JS::RootedValue jsFontSize(cx);
if (JS_GetProperty(cx, jsobj, "fontSize", &jsFontSize) && !jsFontSize.isNullOrUndefined())
{
JS_GetProperty(cx, jsobj, "fontSize", &jsr);
double fontSize = 0.0;
JS::ToNumber(cx, jsr, &fontSize);
out->_fontSize = fontSize;
}
else
{
out->_fontSize = defaultFontSize;
JS::ToNumber(cx, jsFontSize, &fontSize);
out->_fontSize = fontSize;
}
// font alignment horizontal
JS_HasProperty(cx, jsobj, "textAlign", &hasProperty);
if ( hasProperty )
JS::RootedValue jsTextAlign(cx);
if (JS_GetProperty(cx, jsobj, "textAlign", &jsTextAlign) && !jsTextAlign.isNullOrUndefined())
{
JS_GetProperty(cx, jsobj, "textAlign", &jsr);
double fontAlign = 0.0;
JS::ToNumber(cx, jsr, &fontAlign);
out->_alignment = (TextHAlignment)(int)fontAlign;
}
else
{
out->_alignment = defaultTextAlignment;
double textAlign = 0.0;
JS::ToNumber(cx, jsTextAlign, &textAlign);
out->_alignment = (TextHAlignment)(int)textAlign;
}
// font alignment vertical
JS_HasProperty(cx, jsobj, "verticalAlign", &hasProperty);
if ( hasProperty )
JS::RootedValue jsVerticalAlign(cx);
if (JS_GetProperty(cx, jsobj, "verticalAlign", &jsVerticalAlign) && !jsVerticalAlign.isNullOrUndefined())
{
JS_GetProperty(cx, jsobj, "verticalAlign", &jsr);
double fontAlign = 0.0;
JS::ToNumber(cx, jsr, &fontAlign);
out->_vertAlignment = (TextVAlignment)(int)fontAlign;
}
else
{
out->_vertAlignment = defaultTextVAlignment;
double verticalAlign = 0.0;
JS::ToNumber(cx, jsVerticalAlign, &verticalAlign);
out->_vertAlignment = (TextVAlignment)(int)verticalAlign;
}
// font fill color
JS_HasProperty(cx, jsobj, "fillStyle", &hasProperty);
if ( hasProperty )
JS::RootedValue jsFillColor(cx);
if (JS_GetProperty(cx, jsobj, "fillStyle", &jsFillColor) && !jsFillColor.isNullOrUndefined())
{
JS_GetProperty(cx, jsobj, "fillStyle", &jsr);
JS::RootedObject jsobjColor(cx);
JS::RootedValue jsvalColor(cx, jsr);
if (!JS_ValueToObject(cx, jsvalColor, &jsobjColor))
return false;
out->_fontFillColor = getColorFromJSObject(cx, jsobjColor);
jsval_to_cccolor3b(cx, jsFillColor, &(out->_fontFillColor));
}
// font rendering box dimensions
JS_HasProperty(cx, jsobj, "boundingWidth", &hasProperty);
JS_HasProperty(cx, jsobj, "boundingHeight", &hasSecondProp);
if ( hasProperty && hasSecondProp )
JS::RootedValue jsWidth(cx);
if (JS_GetProperty(cx, jsobj, "boundingWidth", &jsWidth) && !jsWidth.isNullOrUndefined())
{
JS_GetProperty(cx, jsobj, "boundingWidth", &jsr);
double boundingW = 0.0;
JS::ToNumber(cx, jsr, &boundingW);
JS_GetProperty(cx, jsobj, "boundingHeight", &jsr);
double boundingH = 0.0;
JS::ToNumber(cx, jsr, &boundingH);
Size dimension;
dimension.width = boundingW;
dimension.height = boundingH;
out->_dimensions = dimension;
double boundingWidth = 0.0;
JS::ToNumber(cx, jsWidth, &boundingWidth);
out->_dimensions.width = boundingWidth;
}
JS::RootedValue jsHeight(cx);
if (JS_GetProperty(cx, jsobj, "boundingHeight", &jsHeight) && !jsHeight.isNullOrUndefined())
{
double boundingHeight = 0.0;
JS::ToNumber(cx, jsHeight, &boundingHeight);
out->_dimensions.height = boundingHeight;
}
// shadow
JS_HasProperty(cx, jsobj, "shadowEnabled", &hasProperty);
if ( hasProperty )
JS::RootedValue jsShadowEnabled(cx);
if (JS_GetProperty(cx, jsobj, "shadowEnabled", &jsShadowEnabled) && !jsShadowEnabled.isNullOrUndefined())
{
JS_GetProperty(cx, jsobj, "shadowEnabled", &jsr);
out->_shadow._shadowEnabled = ToBoolean(jsr);
if ( out->_shadow._shadowEnabled )
out->_shadow._shadowEnabled = ToBoolean(jsShadowEnabled);
if (out->_shadow._shadowEnabled)
{
// default shadow values
out->_shadow._shadowOffset = Size(5, 5);
out->_shadow._shadowBlur = 1;
out->_shadow._shadowOpacity = 1;
// shado offset
JS_HasProperty(cx, jsobj, "shadowOffsetX", &hasProperty);
JS_HasProperty(cx, jsobj, "shadowOffsetY", &hasSecondProp);
if ( hasProperty && hasSecondProp )
JS::RootedValue jsOffsetX(cx);
if (JS_GetProperty(cx, jsobj, "shadowOffsetX", &jsOffsetX) && !jsOffsetX.isNullOrUndefined())
{
JS_GetProperty(cx, jsobj, "shadowOffsetX", &jsr);
double offx = 0.0;
JS::ToNumber(cx, jsr, &offx);
JS_GetProperty(cx, jsobj, "shadowOffsetY", &jsr);
double offy = 0.0;
JS::ToNumber(cx, jsr, &offy);
Size offset;
offset.width = offx;
offset.height = offy;
out->_shadow._shadowOffset = offset;
double shadowOffsetX = 0.0;
JS::ToNumber(cx, jsOffsetX, &shadowOffsetX);
out->_shadow._shadowOffset.width = shadowOffsetX;
}
// shadow blur
JS_HasProperty(cx, jsobj, "shadowBlur", &hasProperty);
if ( hasProperty )
JS::RootedValue jsOffsetY(cx);
if (JS_GetProperty(cx, jsobj, "shadowOffsetY", &jsOffsetY) && !jsOffsetY.isNullOrUndefined())
{
JS_GetProperty(cx, jsobj, "shadowBlur", &jsr);
double shadowBlur = 0.0;
JS::ToNumber(cx, jsr, &shadowBlur);
out->_shadow._shadowBlur = shadowBlur;
double shadowOffsetY = 0.0;
JS::ToNumber(cx, jsOffsetY, &shadowOffsetY);
out->_shadow._shadowOffset.height = shadowOffsetY;
}
// shadow intensity
JS_HasProperty(cx, jsobj, "shadowOpacity", &hasProperty);
if ( hasProperty )
JS::RootedValue jsOpacity(cx);
if (JS_GetProperty(cx, jsobj, "shadowOpacity", &jsOpacity) && !jsOpacity.isNullOrUndefined())
{
JS_GetProperty(cx, jsobj, "shadowOpacity", &jsr);
double shadowOpacity = 0.0;
JS::ToNumber(cx, jsr, &shadowOpacity);
JS::ToNumber(cx, jsOpacity, &shadowOpacity);
out->_shadow._shadowOpacity = shadowOpacity;
}
}
}
// stroke
JS_HasProperty(cx, jsobj, "strokeEnabled", &hasProperty);
if ( hasProperty )
JS::RootedValue jsStrokeEnabled(cx);
if (JS_GetProperty(cx, jsobj, "shadowEnabled", &jsStrokeEnabled) && !jsStrokeEnabled.isNullOrUndefined())
{
JS_GetProperty(cx, jsobj, "strokeEnabled", &jsr);
out->_stroke._strokeEnabled = ToBoolean(jsr);
if ( out->_stroke._strokeEnabled )
out->_stroke._strokeEnabled = ToBoolean(jsStrokeEnabled);
if (out->_stroke._strokeEnabled)
{
// default stroke values
out->_stroke._strokeSize = 1;
out->_stroke._strokeColor = Color3B::BLUE;
// stroke color
JS_HasProperty(cx, jsobj, "strokeStyle", &hasProperty);
if ( hasProperty )
JS::RootedValue jsStrokeColor(cx);
if (JS_GetProperty(cx, jsobj, "strokeStyle", &jsStrokeColor) && !jsStrokeColor.isNullOrUndefined())
{
JS_GetProperty(cx, jsobj, "strokeStyle", &jsr);
JS::RootedObject jsobjStrokeColor(cx);
if (!JS_ValueToObject( cx, jsr, &jsobjStrokeColor ) )
return false;
out->_stroke._strokeColor = getColorFromJSObject(cx, jsobjStrokeColor);
jsval_to_cccolor3b(cx, jsStrokeColor, &(out->_stroke._strokeColor));
}
// stroke size
JS_HasProperty(cx, jsobj, "lineWidth", &hasProperty);
if ( hasProperty )
JS::RootedValue jsLineWidth(cx);
if (JS_GetProperty(cx, jsobj, "lineWidth", &jsLineWidth) && !jsLineWidth.isNullOrUndefined())
{
JS_GetProperty(cx, jsobj, "lineWidth", &jsr);
double strokeSize = 0.0;
JS::ToNumber(cx, jsr, &strokeSize);
out->_stroke._strokeSize = strokeSize;
double lineWidth = 0.0;
JS::ToNumber(cx, jsLineWidth, &lineWidth);
out->_stroke._strokeSize = lineWidth;
}
}
}
@@ -129,14 +129,10 @@ ccui.TextField.prototype._ctor = function(placeholder, fontName, fontSize){
ccui.RichElementText.prototype._ctor = function(tag, color, opacity, text, fontName, fontSize, flags, url)
{
if(fontName == undefined)
fontName = "Helvetica";
if(text == undefined)
text = "";
if (flags == undefined)
flags = 0;
if (url == undefined)
url = "";
fontName = fontName || '';
text = text || '';
flags = flags || 0;
url = url || '';
fontSize !== undefined && this.init(tag, color, opacity, text, fontName, fontSize, flags, url);
};
@@ -153,7 +149,8 @@ if (ccui.WebView)
{
ccui.WebView.prototype._ctor = function(url){
this.init();
url !== undefined && this.loadURL(url);
if(url)
this.loadURL(url);
};
}
@@ -161,7 +158,8 @@ if (ccui.VideoPlayer)
{
ccui.VideoPlayer.prototype._ctor = function(url){
this.init();
url !== undefined && this.setURL(url);
if(url)
this.setURL(url);
};
}
@@ -500,6 +500,19 @@ if (ccui.VideoPlayer)
this["VideoPlayer_"+event] = callback;
};
}
ccui.Text.prototype._setString = ccui.Text.prototype.setString;
ccui.Text.prototype.setString = function(text)
{
var textType = typeof text;
if(textType === 'string')
this._setString(text);
else if(textType === 'number')
this._setString('' + text);
else
cc.log('ccui.Text.setString error: text is not string,is ' + (typeof text));
};
/*
* UIWidget temporary solution to addChild
* addNode and addChild function should be merged in ccui.Widget
@@ -1306,7 +1306,7 @@ cc._initSys = function(config, CONFIG_KEY){
str += "os : " + self.os + "\r\n";
str += "platform : " + self.platform + "\r\n";
cc.log(str);
}
};
platform = locSys.platform;
locSys.isMobile = ( platform === locSys.ANDROID ||
@@ -1410,9 +1410,9 @@ cc._initDebugSetting = function (mode) {
//+++++++++++++++++++++++++something about CCGame begin+++++++++++++++++++++++++++
/**
* @type {Object}
* @name cc.game
* An object to boot the game.
* @class
* @name cc.game
*/
cc.game = {
DEBUG_MODE_NONE : 0,
@@ -1446,7 +1446,7 @@ cc.game = {
_prepareCalled : false,//whether the prepare function has been called
_prepared : false,//whether the engine has prepared
_paused : true,//whether the game is paused
_paused : false,//whether the game is paused
_intervalId : null,//interval target of main
@@ -1962,9 +1962,30 @@ cc.TMXLayer.prototype.getPositonAt = function(x, y){
return this._getPositionAt(pos);
};
// Predefined font definition
cc.FontDefinition = function () {
this.fontName = "Arial";
this.fontSize = 32;
this.textAlign = cc.TEXT_ALIGNMENT_CENTER;
this.verticalAlign = cc.VERTICAL_TEXT_ALIGNMENT_TOP;
this.fillStyle = cc.color(255, 255, 255, 255);
this.boundingWidth = 0;
this.boundingHeight = 0;
this.strokeEnabled = false;
this.strokeStyle = cc.color(255, 255, 255, 255);
this.lineWidth = 1;
this.shadowEnabled = false;
this.shadowOffsetX = 0;
this.shadowOffsetY = 0;
this.shadowBlur = 0;
this.shadowOpacity = 1.0;
};
//LabelTTF
cc.LabelTTF.prototype.initWithString = function(text, fontName, fontSize, dimensions, hAlignment, vAlignment) {
var fontDef = new cc.FontDefinition();
var fontDef = {};
if(typeof fontName === 'string') fontDef.fontName = fontName;
if(typeof fontSize === 'number') fontDef.fontSize = fontSize;
if(dimensions) {
@@ -2955,6 +2976,15 @@ cc.GLProgram.prototype.setUniformLocationWithMatrix4fv = function(){
this.setUniformLocationWithMatrixfvUnion.apply(this, tempArray);
}
cc.Node.prototype._setPositionX = cc.Node.prototype.setPositionX;
cc.Node.prototype.setPositionX = function(posX)
{
if (typeof posX === 'number') {
this._setPositionX(posX);
}
else
cc.log('cc.Node.setPositionX error:value is not number');
};
//
// Script Component
@@ -235,32 +235,33 @@ _p._ctor = function(normalImage, selectedImage, three, four, five) {
callback = null,
target = null;
if (normalImage === undefined) {
if (!normalImage) {
//undefined || null || ''
cc.MenuItemImage.prototype.init.call(this);
}
else {
if (four === undefined) {
callback = three;
}
else if (five === undefined) {
if (typeof three === 'function') {
callback = three;
target = four;
}
else {
disabledImage = three;
callback = four;
var imageIndex = 0;
var imageArray = new Array();
for (var i = 0; i < arguments.length && i < 5; ++i) {
if(typeof arguments[i] === 'function')
callback = arguments[i];
else if (typeof arguments[i] === 'object')
target = arguments[i];
else if (typeof arguments[i] === 'string')
{
imageArray[imageIndex] = arguments[i];
imageIndex += 1;
}
}
else if (five) {
disabledImage = three;
callback = four;
target = five;
}
callback = callback ? callback.bind(target) : null;
if(!callback)
callback = null;
else if(callback && target)
callback = callback.bind(target);
var normalSprite = new cc.Sprite(normalImage);
var selectedSprite = new cc.Sprite(selectedImage);
var disabledSprite = disabledImage ? new cc.Sprite(disabledImage) : new cc.Sprite(normalImage);
var selectedSprite = imageArray[1] ? new cc.Sprite(imageArray[1]) : new cc.Sprite(normalImage);
var disabledSprite = imageArray[2] ? new cc.Sprite(imageArray[2]) : new cc.Sprite(normalImage);
this.initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, callback);
}
};
@@ -149,7 +149,8 @@
frame.setAnchorPoint(cc.p(anchorx, anchory));
return frame;
}
},{
},
{
name: "AnchorPoint",
handle: function(options){
var frame = new ccs.AnchorPointFrame();
@@ -158,7 +159,8 @@
frame.setAnchorPoint(cc.p(anchorx, anchory));
return frame;
}
},{
},
{
name: "InnerAction",
handle: function(options){
var frame = new ccs.InnerActionFrame();
@@ -197,7 +199,7 @@
var frame, texture, plist, path, spriteFrame;
frame = new ccs.TextureFrame();
texture = options["TextureFile"];
if(texture != null) {
if(texture) {
plist = texture["Plist"];
path = texture["Path"];
spriteFrame = cc.spriteFrameCache.getSpriteFrame(path);
@@ -42,8 +42,12 @@
*/
widgetFromJsonFile: function(file){
var json = cc.loader.getRes(cc.path.join(cc.loader.resPath, file));
if(json)
if(json) {
this._fileDesignSizes[file] = cc.size(json["designWidth"]||0, json["designHeight"]||0);
}
else {
return null;
}
var version = json["Version"] || json["version"];
var versionNum = ccs.uiReader.getVersionInteger(version);
@@ -167,7 +167,7 @@
var filePath = options["fileName"];
var node;
if (filePath && "" !== filePath){
if (filePath){
node = this.createNode(filePath);
}else{
node = new ccs.Node();
@@ -219,9 +219,9 @@
var path = options["resourcePath"];
var tmx = null;
if (tmxFile && "" !== tmxFile){
if (tmxFile){
tmx = new cc.TMXTiledMap(tmxFile);
}else if (tmxString && "" !== tmxString && path && "" !== path){
}else if (tmxString && path){
tmx = new cc.TMXTiledMap(tmxString, path);
}
return tmx;
@@ -42,8 +42,9 @@
getNodeJson: function(json){
var content = json["Content"];
if(content["ObjectData"])
return content["ObjectData"];
var ObjectData = content["ObjectData"];
if(ObjectData !== undefined && ObjectData !== null)
return ObjectData;
return content["Content"]["ObjectData"];
},
@@ -57,7 +58,7 @@
var getParam = function(value, dValue){
if(value === undefined)
if(value === undefined || value === null)
return dValue;
else
return value;
@@ -84,28 +85,26 @@
}
var rotationSkewX = json["RotationSkewX"];
if (cc.isValidValue(rotationSkewX))
if (rotationSkewX)
node.setRotationX(rotationSkewX);
var rotationSkewY = json["RotationSkewY"];
if (cc.isValidValue(rotationSkewY))
if (rotationSkewY)
node.setRotationY(rotationSkewY);
var anchor = json["AnchorPoint"];
if(anchor){
if(anchor["ScaleX"] == null)
anchor["ScaleX"] = 0;
if(anchor["ScaleY"] == null)
anchor["ScaleY"] = 0;
if(anchor["ScaleX"] != 0.5 || anchor["ScaleY"] != 0.5)
node.setAnchorPoint(cc.p(anchor["ScaleX"] || 0, anchor["ScaleY"] || 0));
var anchorX = anchor["ScaleX"] || 0;
var anchorY = anchor["ScaleY"] || 0;
node.setAnchorPoint(cc.p(anchorX, anchorY));
}
if (cc.isValidValue(json["ZOrder"]))
if (json["ZOrder"])
node.setLocalZOrder(json["ZOrder"]);
var visible = getParam(json["VisibleForFrame"], true);
node.setVisible(visible);
var visible = json["VisibleForFrame"];
if(cc.isValidValue(visible))
node.setVisible(visible);
var size = json["Size"];
if(size)
@@ -119,7 +118,7 @@
var actionTag = json["ActionTag"] || 0;
var extensionData = new ccs.ComExtensionData();
var customProperty = json["UserData"];
if(customProperty !== undefined)
if(customProperty !== undefined && customProperty !== null)
extensionData.setCustomProperty(customProperty);
extensionData.setActionTag(actionTag);
if (node.getComponent("ComExtensionData"))
@@ -282,7 +281,6 @@
if (rotationSkewY)
widget.setRotationY(rotationSkewY);
//var rotation = json["Rotation"];
var flipX = json["FlipX"];
if (flipX)
@@ -293,16 +291,14 @@
widget.setFlippedY(true);
var zOrder = json["zOrder"];
if (cc.isValidValue(zOrder))
if (zOrder)
widget.setLocalZOrder(zOrder);
//var visible = json["Visible"];
var visible = getParam(json["VisibleForFrame"], true);
widget.setVisible(visible);
var alpha = json["Alpha"];
if (cc.isValidValue(alpha))
if (cc.isValidValue(alpha) && alpha !== 255)
widget.setOpacity(alpha);
widget.setTag(json["Tag"] || 0);
@@ -310,8 +306,6 @@
var touchEnabled = json["TouchEnable"] || false;
widget.setTouchEnabled(touchEnabled);
// -- var frameEvent = json["FrameEvent"];
var callBackType = json["CallBackType"];
if (cc.isValidValue(callBackType))
widget.setCallbackType(callBackType);
@@ -361,13 +355,12 @@
};
var setLayoutComponent = function(widget, json){
var layoutComponent = ccui.LayoutComponent.bindLayoutComponent(widget);
if(!layoutComponent)
return;
var positionXPercentEnabled = json["PositionPercentXEnable"] || json["PositionPercentXEnabled"] || false;
var positionYPercentEnabled = json["PositionPercentYEnable"] || json["PositionPercentYEnabled"] || false;
var positionXPercentEnabled = json["PositionPercentXEnable"]|| false;
var positionYPercentEnabled = json["PositionPercentYEnable"] || false;
var positionXPercent = 0,
positionYPercent = 0,
PrePosition = json["PrePosition"];
@@ -375,19 +368,19 @@
positionXPercent = PrePosition["X"] || 0;
positionYPercent = PrePosition["Y"] || 0;
}
var sizeXPercentEnable = json["PercentWidthEnable"] || json["PercentWidthEnabled"] || false;
var sizeYPercentEnable = json["PercentHeightEnable"]|| json["PercentHeightEnabled"] || false;
var sizeXPercentEnable = json["PercentWidthEnable"] || false;
var sizeYPercentEnable = json["PercentHeightEnable"] || false;
var sizeXPercent = 0,
sizeYPercent = 0,
PreSize = json["PreSize"];
if (PrePosition) {
if (PreSize) {
sizeXPercent = PreSize["X"] || 0;
sizeYPercent = PreSize["Y"] || 0;
}
var stretchHorizontalEnabled = json["StretchWidthEnable"] || false;
var stretchVerticalEnabled = json["StretchHeightEnable"] || false;
var horizontalEdge = json["HorizontalEdge"];// = ccui.LayoutComponent.horizontalEdge.LEFT;
var verticalEdge = json["VerticalEdge"]; // = ccui.LayoutComponent.verticalEdge.TOP;
var horizontalEdge = json["HorizontalEdge"];
var verticalEdge = json["VerticalEdge"];
var leftMargin = json["LeftMargin"] || 0;
var rightMargin = json["RightMargin"] || 0;
var topMargin = json["TopMargin"] || 0;
@@ -401,7 +394,6 @@
layoutComponent.setPercentHeightEnabled(sizeYPercentEnable);
layoutComponent.setPercentWidth(sizeXPercent);
layoutComponent.setPercentHeight(sizeYPercent);
layoutComponent.setPercentWidthEnabled(sizeXPercentEnable || sizeYPercentEnable);
layoutComponent.setStretchWidthEnabled(stretchHorizontalEnabled);
layoutComponent.setStretchHeightEnabled(stretchVerticalEnabled);
@@ -425,26 +417,20 @@
}
layoutComponent.setVerticalEdge(verticalEdgeType);
layoutComponent.setTopMargin(topMargin);
layoutComponent.setBottomMargin(bottomMargin);
layoutComponent.setLeftMargin(leftMargin);
layoutComponent.setRightMargin(rightMargin);
layoutComponent.setVerticalEdge(verticalEdgeType);
layoutComponent.setTopMargin(topMargin);
layoutComponent.setBottomMargin(bottomMargin);
layoutComponent.setLeftMargin(leftMargin);
layoutComponent.setRightMargin(rightMargin);
if(topMargin !== 0)
layoutComponent.setTopMargin(topMargin);
if(bottomMargin !== 0)
layoutComponent.setBottomMargin(bottomMargin);
if(leftMargin !== 0)
layoutComponent.setLeftMargin(leftMargin);
if(rightMargin !== 0)
layoutComponent.setRightMargin(rightMargin);
};
var setLayoutBackground = function(layout, single, first, end){
if( layout.getBackGroundColorType() === 2 ){
first = first || {};
end = end || {};
layout.setBackGroundColor(getColor(first), getColor(end));
}else{
single = single || {};
layout.setBackGroundColor(getColor(single));
}
};
@@ -463,31 +449,30 @@
*/
parser.initPanel = function(json, resourcePath){
var widget = new ccui.Layout();
this.widgetAttributes(widget, json);
var clipEnabled = json["ClipAble"] || false;
if(clipEnabled != null)
if(clipEnabled)
widget.setClippingEnabled(clipEnabled);
var colorType = getParam(json["ComboBoxIndex"], 0);
widget.setBackGroundColorType(colorType);
var backGroundScale9Enabled = json["Scale9Enable"] || false;
if(backGroundScale9Enabled)
widget.setBackGroundImageScale9Enabled(true);
var bgColorType = getParam(json["ComboBoxIndex"], 0);
if(bgColorType !== 0) {
widget.setBackGroundColorType(bgColorType);
}
setLayoutBackgroundVector(widget, json["ColorVector"]);
setLayoutBackground(widget, json["SingleColor"], json["FirstColor"], json["EndColor"]);
var bgColorOpacity = getParam(json["BackColorAlpha"], 255);
if(bgColorOpacity != null)
if(bgColorOpacity !== 255)
widget.setBackGroundColorOpacity(bgColorOpacity);
var backGroundScale9Enabled = json["Scale9Enable"];
if(backGroundScale9Enabled != null)
widget.setBackGroundImageScale9Enabled(backGroundScale9Enabled);
var opacity = getParam(json["Alpha"], 255);
widget.setOpacity(opacity);
loadTexture(json["FileData"], resourcePath, function(path, type){
loadTexture(json["FileData"], resourcePath, function(path, type) {
widget.setBackGroundImage(path, type);
});
if(backGroundScale9Enabled){
var scale9OriginX = json["Scale9OriginX"] || 0;
var scale9OriginY = json["Scale9OriginY"] || 0;
@@ -498,18 +483,8 @@
widget.setBackGroundImageCapInsets(cc.rect(
scale9OriginX, scale9OriginY, scale9Width, scale9Height
));
setContentSize(widget, json["Size"]);
}else{
if (!widget.isIgnoreContentAdaptWithSize()){
setContentSize(widget, json["Size"]);
}
}
setLayoutBackground(widget, json["SingleColor"], json["FirstColor"], json["EndColor"]);
setLayoutBackgroundVector(widget, json["ColorVector"]);
return widget;
};
@@ -519,7 +494,6 @@
* @param resourcePath
*/
parser.initText = function(json, resourcePath){
var widget = new ccui.Text();
var touchScaleEnabled = json["TouchScaleChangeAble"];
@@ -527,15 +501,15 @@
widget.setTouchScaleChangeEnabled(touchScaleEnabled);
var text = json["LabelText"];
if(text != null)
if(text)
widget.setString(text);
var fontSize = json["FontSize"];
if(fontSize != null)
if(typeof fontSize === 'number')
widget.setFontSize(fontSize);
var fontName = json["FontName"];
if(fontName && '' !== fontName)
if(fontName)
widget.setFontName(fontName);
var areaWidth = json["AreaWidth"];
@@ -570,7 +544,6 @@
var fontResource = json["FontResource"];
if(fontResource != null){
var path = fontResource["Path"];
//resoutceType = fontResource["Type"];
if(path){
if (cc.sys.isNative) {
fontName = cc.path.join(cc.loader.resPath, resourcePath, path);
@@ -604,7 +577,6 @@
this.widgetAttributes(widget, json, widget.isIgnoreContentAdaptWithSize());
json["CColor"] = color;
return widget;
};
/**
@@ -613,7 +585,6 @@
* @param resourcePath
*/
parser.initButton = function(json, resourcePath){
var widget = new ccui.Button();
loadTexture(json["NormalFileData"], resourcePath, function(path, type){
@@ -640,7 +611,7 @@
widget.setTitleFontSize(fontSize);
var fontName = json["FontName"];
if(fontName && '' !== fontName)
if(fontName)
widget.setTitleFontName(fontName);
var textColor = json["TextColor"];
@@ -654,7 +625,6 @@
var fontResource = json["FontResource"];
if(fontResource != null){
var path = fontResource["Path"];
//resoutceType = fontResource["Type"];
if(path){
if (cc.sys.isNative) {
fontName = cc.path.join(cc.loader.resPath, resourcePath, path);
@@ -671,7 +641,7 @@
label.enableShadow(
getColor(json["ShadowColor"]),
cc.size(getParam(json["ShadowOffsetX"], 2), getParam(json["ShadowOffsetY"], -2)),
json["ShadowBlurRadius"] || 0
0
);
}
if(label && json["OutlineEnabled"] && json["OutlineColor"] && label.enableStroke)
@@ -689,13 +659,11 @@
json["Scale9Height"] || 0
);
widget.setCapInsets(capInsets);
}
setContentSize(widget, json["Size"]);
return widget;
};
/**
@@ -704,7 +672,6 @@
* @param resourcePath
*/
parser.initCheckBox = function(json, resourcePath){
var widget = new ccui.CheckBox();
this.widgetAttributes(widget, json);
@@ -761,7 +728,6 @@
if(backGroundScale9Enabled){
widget.setBackGroundImageScale9Enabled(true);
var scale9OriginX = json["Scale9OriginX"] || 0;
var scale9OriginY = json["Scale9OriginY"] || 0;
var scale9Width = json["Scale9Width"] || 0;
@@ -802,7 +768,6 @@
* @param resourcePath
*/
parser.initImageView = function(json, resourcePath){
var widget = new ccui.ImageView();
loadTexture(json["FileData"], resourcePath, function(path, type){
@@ -828,7 +793,8 @@
scale9Width,
scale9Height
));
} else
}
else
setContentSize(widget, json["Size"]);
this.widgetAttributes(widget, json);
@@ -843,7 +809,6 @@
* @returns {ccui.LoadingBar}
*/
parser.initLoadingBar = function(json, resourcePath){
var widget = new ccui.LoadingBar();
this.widgetAttributes(widget, json);
@@ -860,7 +825,6 @@
widget.setPercent(percent);
return widget;
};
/**
@@ -869,7 +833,6 @@
* @param resourcePath
*/
parser.initSlider = function(json, resourcePath){
var widget = new ccui.Slider();
var loader = cc.loader;
@@ -904,7 +867,6 @@
* @param resourcePath
*/
parser.initPageView = function(json, resourcePath){
var widget = new ccui.PageView();
this.widgetAttributes(widget, json);
@@ -945,7 +907,6 @@
setContentSize(widget, json["Size"]);
return widget;
};
/**
@@ -955,7 +916,6 @@
* @returns {ccui.ListView}
*/
parser.initListView = function(json, resourcePath){
var widget = new ccui.ListView();
this.widgetAttributes(widget, json);
@@ -971,6 +931,9 @@
widget.setBackGroundColorType(colorType);
var bgColorOpacity = getParam(json["BackColorAlpha"], 255);
if(bgColorOpacity !== 255)
widget.setBackGroundColorOpacity(bgColorOpacity);
var backGroundScale9Enabled = json["Scale9Enable"];
if(backGroundScale9Enabled){
widget.setBackGroundImageScale9Enabled(true);
@@ -1008,7 +971,6 @@
widget.setGravity(ccui.ListView.GRAVITY_CENTER_HORIZONTAL);
}
var bounceEnabled = getParam(json["IsBounceEnabled"], false);
widget.setBounceEnabled(bounceEnabled);
@@ -1017,15 +979,12 @@
var innerSize = json["InnerNodeSize"];
//Width
if(innerSize != null)
if(innerSize)
widget.setInnerContainerSize(cc.size(innerSize["Widget"]||0, innerSize["Height"]||0));
setLayoutBackground(widget, json["SingleColor"], json["FirstColor"], json["EndColor"]);
setLayoutBackgroundVector(widget, json["ColorVector"]);
if(bgColorOpacity != null)
widget.setBackGroundColorOpacity(bgColorOpacity);
setContentSize(widget, json["Size"]);
return widget;
@@ -1038,7 +997,6 @@
* @returns {ccui.TextAtlas}
*/
parser.initTextAtlas = function(json, resourcePath){
var widget = new ccui.TextAtlas();
var stringValue = json["LabelText"];
@@ -1064,12 +1022,12 @@
* @returns {ccui.TextBMFont}
*/
parser.initTextBMFont = function(json, resourcePath){
var widget = new ccui.TextBMFont();
this.widgetAttributes(widget, json);
var text = json["LabelText"];
widget.setString(text);
if(text)
widget.setString(text);
loadTexture(json["LabelBMFontFile_CNB"], resourcePath, function(path, type){
widget.setFntFile(path);
@@ -1095,15 +1053,15 @@
}
var placeHolder = json["PlaceHolderText"];
if(placeHolder != null)
if(placeHolder)
widget.setPlaceHolder(placeHolder);
var fontSize = json["FontSize"];
if(fontSize != null)
if(typeof fontSize === 'number')
widget.setFontSize(fontSize);
var fontName = json["FontName"];
if(fontName && '' !== fontName)
if(fontName)
widget.setFontName(fontName);
var maxLengthEnabled = json["MaxLengthEnable"];
@@ -1117,13 +1075,12 @@
this.widgetAttributes(widget, json);
var text = json["LabelText"];
if(text != null)
if(text)
widget.setString(text);
var fontResource = json["FontResource"];
if(fontResource != null){
if(fontResource){
var path = fontResource["Path"];
//resoutceType = fontResource["Type"];
if(path){
if (cc.sys.isNative) {
fontName = cc.path.join(cc.loader.resPath, resourcePath, path);
@@ -1148,9 +1105,7 @@
widget.getVirtualRenderer().setLineBreakWithoutSpace(true);
}
return widget;
};
/**
@@ -1159,7 +1114,6 @@
* @param resourcePath
*/
parser.initSimpleAudio = function(json, resourcePath){
var node = new ccs.ComAudio();
var loop = json["Loop"] || false;
//var volume = json["Volume"] || 0;
@@ -1168,7 +1122,6 @@
loadTexture(json["FileData"], resourcePath, function(path, type){
node.setFile(path);
});
};
/**
@@ -1178,7 +1131,6 @@
* @returns {*}
*/
parser.initGameMap = function(json, resourcePath){
var node = null;
loadTexture(json["FileData"], resourcePath, function(path, type){
@@ -1199,7 +1151,7 @@
*/
parser.initProjectNode = function(json, resourcePath){
var projectFile = json["FileData"];
if(projectFile != null && projectFile["Path"]){
if(projectFile && projectFile["Path"]){
var file = resourcePath + projectFile["Path"];
if(cc.loader.getRes(file)){
var obj = ccs.load(file, resourcePath);
@@ -1259,7 +1211,6 @@
node.getAnimation().play(currentAnimationName);
node.getAnimation().gotoAndPause(0);
}
});
parser.generalAttributes(node, json);
@@ -1296,7 +1247,7 @@
var loadedPlist = {};
var loadTexture = function(json, resourcePath, cb){
if(json != null){
if(json !== undefined && json !== null){
var path = json["Path"];
var type;
if(json["Type"] === "Default" || json["Type"] === "Normal")
@@ -1321,7 +1272,7 @@
}
else {
var filePath = resourcePath + path;
if(path && "" !== path && jsb.fileUtils.isFileExist(filePath))
if(path && jsb.fileUtils.isFileExist(filePath))
cb(filePath, type);
else
cb("", type);
@@ -1330,11 +1281,14 @@
};
var getColor = function(json){
if(!json) return;
if(json === undefined || json === null)
return cc.color(255,255,255,255);
var r = cc.isValidValue(json["R"]) ? json["R"] : 255;
var g = cc.isValidValue(json["G"]) ? json["G"] : 255;
var b = cc.isValidValue(json["B"]) ? json["B"] : 255;
var a = cc.isValidValue(json["A"]) ? json["A"] : 255;
return cc.color(r, g, b, a);
};
@@ -98,14 +98,14 @@
widget.setScaleY(scaleY);
var rotation = options["rotation"];
if(cc.isValidValue(rotation) && rotation !== 0)
if(rotation)
widget.setRotation(rotation);
if(options["visible"] === false)
widget.setVisible(false);
var ZOrder = options["ZOrder"];
if(cc.isValidValue(ZOrder) && ZOrder !== 0)
if(ZOrder)
widget.setLocalZOrder(ZOrder);
var layout = options["layoutParameter"];
@@ -302,7 +302,7 @@
var sw = options["scale9Width"];
var sh = options["scale9Height"];
if (cc.isValidValue(sw) && cc.isValidValue(sh))
button.setSize(cc.size(sw, sh));
button.setContentSize(cc.size(sw, sh));
}
var text = options["text"];
if (text)
@@ -389,7 +389,7 @@
var sw = options["scale9Width"];
var sh = options["scale9Height"];
if (cc.isValidValue(sw) && cc.isValidValue(sh)) {
widget.setSize(cc.size(sw, sh));
widget.setContentSize(cc.size(sw, sh));
}
var cx = options["capInsetsX"];
+1
View File
@@ -161,6 +161,7 @@ void ImageView::setTextureRect(const Rect &rect)
if (sprite)
{
sprite->setTextureRect(rect);
setupTexture();
}
else
{
Submodule native/tools/bindings-generator updated: a96c5e38fd...d73c478763